mount_sysvbfs.c revision 1.1 1 1.1 tsutsui /* $NetBSD: mount_sysvbfs.c,v 1.1 2005/12/29 14:53:45 tsutsui Exp $ */
2 1.1 tsutsui
3 1.1 tsutsui /*-
4 1.1 tsutsui * Copyright (c) 1993, 1994
5 1.1 tsutsui * The Regents of the University of California. All rights reserved.
6 1.1 tsutsui *
7 1.1 tsutsui * Redistribution and use in source and binary forms, with or without
8 1.1 tsutsui * modification, are permitted provided that the following conditions
9 1.1 tsutsui * are met:
10 1.1 tsutsui * 1. Redistributions of source code must retain the above copyright
11 1.1 tsutsui * notice, this list of conditions and the following disclaimer.
12 1.1 tsutsui * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 tsutsui * notice, this list of conditions and the following disclaimer in the
14 1.1 tsutsui * documentation and/or other materials provided with the distribution.
15 1.1 tsutsui * 3. Neither the name of the University nor the names of its contributors
16 1.1 tsutsui * may be used to endorse or promote products derived from this software
17 1.1 tsutsui * without specific prior written permission.
18 1.1 tsutsui *
19 1.1 tsutsui * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.1 tsutsui * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.1 tsutsui * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.1 tsutsui * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.1 tsutsui * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.1 tsutsui * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.1 tsutsui * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.1 tsutsui * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.1 tsutsui * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.1 tsutsui * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1 tsutsui * SUCH DAMAGE.
30 1.1 tsutsui */
31 1.1 tsutsui
32 1.1 tsutsui #include <sys/cdefs.h>
33 1.1 tsutsui #ifndef lint
34 1.1 tsutsui __COPYRIGHT("@(#) Copyright (c) 1993, 1994\n\
35 1.1 tsutsui The Regents of the University of California. All rights reserved.\n");
36 1.1 tsutsui #endif /* not lint */
37 1.1 tsutsui
38 1.1 tsutsui #ifndef lint
39 1.1 tsutsui __RCSID("$NetBSD: mount_sysvbfs.c,v 1.1 2005/12/29 14:53:45 tsutsui Exp $");
40 1.1 tsutsui #endif /* not lint */
41 1.1 tsutsui
42 1.1 tsutsui #include <sys/param.h>
43 1.1 tsutsui #include <sys/mount.h>
44 1.1 tsutsui
45 1.1 tsutsui #include <err.h>
46 1.1 tsutsui #include <errno.h>
47 1.1 tsutsui #include <stdio.h>
48 1.1 tsutsui #include <stdlib.h>
49 1.1 tsutsui
50 1.1 tsutsui #include <string.h>
51 1.1 tsutsui #include <unistd.h>
52 1.1 tsutsui
53 1.1 tsutsui #include <mntopts.h>
54 1.1 tsutsui #include <fs/sysvbfs/sysvbfs.h>
55 1.1 tsutsui
56 1.1 tsutsui static void sysvbfs_usage(void);
57 1.1 tsutsui int mount_sysvbfs(int argc, char **argv);
58 1.1 tsutsui
59 1.1 tsutsui static const struct mntopt mopts[] = {
60 1.1 tsutsui MOPT_STDOPTS,
61 1.1 tsutsui MOPT_UPDATE,
62 1.1 tsutsui MOPT_GETARGS,
63 1.1 tsutsui { NULL }
64 1.1 tsutsui };
65 1.1 tsutsui
66 1.1 tsutsui #ifndef MOUNT_NOMAIN
67 1.1 tsutsui int
68 1.1 tsutsui main(int argc, char **argv)
69 1.1 tsutsui {
70 1.1 tsutsui
71 1.1 tsutsui return mount_sysvbfs(argc, argv);
72 1.1 tsutsui }
73 1.1 tsutsui #endif
74 1.1 tsutsui
75 1.1 tsutsui int
76 1.1 tsutsui mount_sysvbfs(int argc, char *argv[])
77 1.1 tsutsui {
78 1.1 tsutsui struct sysvbfs_args args;
79 1.1 tsutsui int ch, mntflags;
80 1.1 tsutsui char fs_name[MAXPATHLEN], canon_dev[MAXPATHLEN];
81 1.1 tsutsui const char *errcause;
82 1.1 tsutsui
83 1.1 tsutsui mntflags = 0;
84 1.1 tsutsui optind = optreset = 1; /* Reset for parse of new argv. */
85 1.1 tsutsui while ((ch = getopt(argc, argv, "o:")) != -1)
86 1.1 tsutsui switch (ch) {
87 1.1 tsutsui case 'o':
88 1.1 tsutsui getmntopts(optarg, mopts, &mntflags, 0);
89 1.1 tsutsui break;
90 1.1 tsutsui case '?':
91 1.1 tsutsui default:
92 1.1 tsutsui sysvbfs_usage();
93 1.1 tsutsui }
94 1.1 tsutsui argc -= optind;
95 1.1 tsutsui argv += optind;
96 1.1 tsutsui
97 1.1 tsutsui if (argc != 2)
98 1.1 tsutsui sysvbfs_usage();
99 1.1 tsutsui
100 1.1 tsutsui if (realpath(argv[0], canon_dev) == NULL) /* Check device path */
101 1.1 tsutsui err(EXIT_FAILURE, "realpath %s", argv[0]);
102 1.1 tsutsui if (strncmp(argv[0], canon_dev, MAXPATHLEN)) {
103 1.1 tsutsui warnx("\"%s\" is a relative path.", argv[0]);
104 1.1 tsutsui warnx("using \"%s\" instead.", canon_dev);
105 1.1 tsutsui }
106 1.1 tsutsui args.fspec = canon_dev;
107 1.1 tsutsui
108 1.1 tsutsui if (realpath(argv[1], fs_name) == NULL) /* Check mounton path */
109 1.1 tsutsui err(EXIT_FAILURE, "realpath %s", argv[1]);
110 1.1 tsutsui if (strncmp(argv[1], fs_name, MAXPATHLEN)) {
111 1.1 tsutsui warnx("\"%s\" is a relative path.", argv[1]);
112 1.1 tsutsui warnx("using \"%s\" instead.", fs_name);
113 1.1 tsutsui }
114 1.1 tsutsui
115 1.1 tsutsui if (mount(MOUNT_SYSVBFS, fs_name, mntflags, &args) < 0) {
116 1.1 tsutsui switch (errno) {
117 1.1 tsutsui case EMFILE:
118 1.1 tsutsui errcause = "mount table full";
119 1.1 tsutsui break;
120 1.1 tsutsui case EINVAL:
121 1.1 tsutsui if (mntflags & MNT_UPDATE)
122 1.1 tsutsui errcause =
123 1.1 tsutsui "specified device does not match mounted device";
124 1.1 tsutsui else
125 1.1 tsutsui errcause = "incorrect super block";
126 1.1 tsutsui break;
127 1.1 tsutsui default:
128 1.1 tsutsui errcause = strerror(errno);
129 1.1 tsutsui break;
130 1.1 tsutsui }
131 1.1 tsutsui errx(EXIT_FAILURE, "%s on %s: %s",
132 1.1 tsutsui args.fspec, fs_name, errcause);
133 1.1 tsutsui }
134 1.1 tsutsui exit(EXIT_SUCCESS);
135 1.1 tsutsui }
136 1.1 tsutsui
137 1.1 tsutsui static void
138 1.1 tsutsui sysvbfs_usage(void)
139 1.1 tsutsui {
140 1.1 tsutsui
141 1.1 tsutsui (void)fprintf(stderr, "usage: %s [-o options] special node\n",
142 1.1 tsutsui getprogname());
143 1.1 tsutsui exit(EXIT_FAILURE);
144 1.1 tsutsui }
145