mount_sysvbfs.c revision 1.6 1 1.6 lukem /* $NetBSD: mount_sysvbfs.c,v 1.6 2008/07/20 01:20:22 lukem 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.6 lukem __COPYRIGHT("@(#) Copyright (c) 1993, 1994\
35 1.6 lukem The Regents of the University of California. All rights reserved.");
36 1.1 tsutsui #endif /* not lint */
37 1.1 tsutsui
38 1.1 tsutsui #ifndef lint
39 1.6 lukem __RCSID("$NetBSD: mount_sysvbfs.c,v 1.6 2008/07/20 01:20:22 lukem 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.3 christos MOPT_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.2 christos mntoptparse_t mp;
83 1.1 tsutsui
84 1.1 tsutsui mntflags = 0;
85 1.1 tsutsui optind = optreset = 1; /* Reset for parse of new argv. */
86 1.1 tsutsui while ((ch = getopt(argc, argv, "o:")) != -1)
87 1.1 tsutsui switch (ch) {
88 1.1 tsutsui case 'o':
89 1.2 christos mp = getmntopts(optarg, mopts, &mntflags, 0);
90 1.2 christos if (mp == NULL)
91 1.2 christos err(1, "getmntopts");
92 1.2 christos freemntopts(mp);
93 1.1 tsutsui break;
94 1.1 tsutsui case '?':
95 1.1 tsutsui default:
96 1.1 tsutsui sysvbfs_usage();
97 1.1 tsutsui }
98 1.1 tsutsui argc -= optind;
99 1.1 tsutsui argv += optind;
100 1.1 tsutsui
101 1.1 tsutsui if (argc != 2)
102 1.1 tsutsui sysvbfs_usage();
103 1.1 tsutsui
104 1.1 tsutsui if (realpath(argv[0], canon_dev) == NULL) /* Check device path */
105 1.1 tsutsui err(EXIT_FAILURE, "realpath %s", argv[0]);
106 1.1 tsutsui if (strncmp(argv[0], canon_dev, MAXPATHLEN)) {
107 1.1 tsutsui warnx("\"%s\" is a relative path.", argv[0]);
108 1.1 tsutsui warnx("using \"%s\" instead.", canon_dev);
109 1.1 tsutsui }
110 1.1 tsutsui args.fspec = canon_dev;
111 1.1 tsutsui
112 1.1 tsutsui if (realpath(argv[1], fs_name) == NULL) /* Check mounton path */
113 1.1 tsutsui err(EXIT_FAILURE, "realpath %s", argv[1]);
114 1.1 tsutsui if (strncmp(argv[1], fs_name, MAXPATHLEN)) {
115 1.1 tsutsui warnx("\"%s\" is a relative path.", argv[1]);
116 1.1 tsutsui warnx("using \"%s\" instead.", fs_name);
117 1.1 tsutsui }
118 1.1 tsutsui
119 1.5 pooka if (mount(MOUNT_SYSVBFS, fs_name, mntflags, &args, sizeof args) == -1) {
120 1.1 tsutsui switch (errno) {
121 1.1 tsutsui case EMFILE:
122 1.1 tsutsui errcause = "mount table full";
123 1.1 tsutsui break;
124 1.1 tsutsui case EINVAL:
125 1.1 tsutsui if (mntflags & MNT_UPDATE)
126 1.1 tsutsui errcause =
127 1.1 tsutsui "specified device does not match mounted device";
128 1.1 tsutsui else
129 1.1 tsutsui errcause = "incorrect super block";
130 1.1 tsutsui break;
131 1.1 tsutsui default:
132 1.1 tsutsui errcause = strerror(errno);
133 1.1 tsutsui break;
134 1.1 tsutsui }
135 1.1 tsutsui errx(EXIT_FAILURE, "%s on %s: %s",
136 1.1 tsutsui args.fspec, fs_name, errcause);
137 1.1 tsutsui }
138 1.1 tsutsui exit(EXIT_SUCCESS);
139 1.1 tsutsui }
140 1.1 tsutsui
141 1.1 tsutsui static void
142 1.1 tsutsui sysvbfs_usage(void)
143 1.1 tsutsui {
144 1.1 tsutsui
145 1.1 tsutsui (void)fprintf(stderr, "usage: %s [-o options] special node\n",
146 1.1 tsutsui getprogname());
147 1.1 tsutsui exit(EXIT_FAILURE);
148 1.1 tsutsui }
149