1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24*0Sstevel@tonic-gate * Use is subject to license terms.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate #include <ctype.h>
30*0Sstevel@tonic-gate #include <string.h>
31*0Sstevel@tonic-gate #include <stdio.h>
32*0Sstevel@tonic-gate #include <unistd.h> /* defines F_LOCK for lockf */
33*0Sstevel@tonic-gate #include <stdlib.h> /* for getopt(3) */
34*0Sstevel@tonic-gate #include <signal.h>
35*0Sstevel@tonic-gate #include <locale.h>
36*0Sstevel@tonic-gate #include <fslib.h>
37*0Sstevel@tonic-gate #include <sys/types.h>
38*0Sstevel@tonic-gate #include <errno.h>
39*0Sstevel@tonic-gate #include <sys/mnttab.h>
40*0Sstevel@tonic-gate #include <sys/mntent.h>
41*0Sstevel@tonic-gate #include <sys/mount.h>
42*0Sstevel@tonic-gate #include <sys/vfs.h>
43*0Sstevel@tonic-gate #include <sys/fs/hsfs_susp.h>
44*0Sstevel@tonic-gate #include <sys/fs/hsfs_rrip.h>
45*0Sstevel@tonic-gate
46*0Sstevel@tonic-gate extern int optind;
47*0Sstevel@tonic-gate extern char *optarg;
48*0Sstevel@tonic-gate
49*0Sstevel@tonic-gate #define NAME_MAX 64
50*0Sstevel@tonic-gate #define GLOBAL 0
51*0Sstevel@tonic-gate #define NOGLOBAL 1
52*0Sstevel@tonic-gate
53*0Sstevel@tonic-gate #ifndef MNTOPT_NOGLOBAL
54*0Sstevel@tonic-gate #define MNTOPT_NOGLOBAL "noglobal"
55*0Sstevel@tonic-gate #endif /* MNTOPT_NOGLOBAL */
56*0Sstevel@tonic-gate
57*0Sstevel@tonic-gate static int gflg = 0; /* mount into global name space: flag form */
58*0Sstevel@tonic-gate static int global = 0; /* mount into global name space: option form */
59*0Sstevel@tonic-gate static int havegblopt = 0; /* global value supercedes gflg value */
60*0Sstevel@tonic-gate static int qflg = 0; /* quiet option - don't flag bad options */
61*0Sstevel@tonic-gate
62*0Sstevel@tonic-gate static char fstype[] = MNTTYPE_HSFS;
63*0Sstevel@tonic-gate
64*0Sstevel@tonic-gate static char typename[NAME_MAX], *myname;
65*0Sstevel@tonic-gate /*
66*0Sstevel@tonic-gate * Mount options that require special handling
67*0Sstevel@tonic-gate */
68*0Sstevel@tonic-gate static char *myopts[] = {
69*0Sstevel@tonic-gate MNTOPT_GLOBAL,
70*0Sstevel@tonic-gate MNTOPT_NOGLOBAL,
71*0Sstevel@tonic-gate NULL
72*0Sstevel@tonic-gate };
73*0Sstevel@tonic-gate
74*0Sstevel@tonic-gate
75*0Sstevel@tonic-gate static void rpterr(char *, char *);
76*0Sstevel@tonic-gate static void usage(void);
77*0Sstevel@tonic-gate
78*0Sstevel@tonic-gate int
main(int argc,char ** argv)79*0Sstevel@tonic-gate main(int argc, char **argv)
80*0Sstevel@tonic-gate {
81*0Sstevel@tonic-gate char *options, *value;
82*0Sstevel@tonic-gate char *special, *mountp;
83*0Sstevel@tonic-gate char *gopt;
84*0Sstevel@tonic-gate struct mnttab mm;
85*0Sstevel@tonic-gate int c;
86*0Sstevel@tonic-gate char obuff[MAX_MNTOPT_STR];
87*0Sstevel@tonic-gate char saved_input_options[MAX_MNTOPT_STR];
88*0Sstevel@tonic-gate int hsfs_flags;
89*0Sstevel@tonic-gate
90*0Sstevel@tonic-gate int flags;
91*0Sstevel@tonic-gate int Oflg = 0; /* Overlay mounts */
92*0Sstevel@tonic-gate
93*0Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
94*0Sstevel@tonic-gate
95*0Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
96*0Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST"
97*0Sstevel@tonic-gate #endif
98*0Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
99*0Sstevel@tonic-gate
100*0Sstevel@tonic-gate myname = strrchr(argv[0], '/');
101*0Sstevel@tonic-gate if (myname)
102*0Sstevel@tonic-gate myname++;
103*0Sstevel@tonic-gate else
104*0Sstevel@tonic-gate myname = argv[0];
105*0Sstevel@tonic-gate snprintf(typename, sizeof (typename), "%s %s", fstype, myname);
106*0Sstevel@tonic-gate argv[0] = typename;
107*0Sstevel@tonic-gate
108*0Sstevel@tonic-gate /*
109*0Sstevel@tonic-gate * Check for arguments requiring special handling. Ignore
110*0Sstevel@tonic-gate * unrecognized options.
111*0Sstevel@tonic-gate */
112*0Sstevel@tonic-gate strcpy(obuff, "ro"); /* default */
113*0Sstevel@tonic-gate while ((c = getopt(argc, argv, "o:rmOgq")) != EOF) {
114*0Sstevel@tonic-gate switch (c) {
115*0Sstevel@tonic-gate case 'o':
116*0Sstevel@tonic-gate if (strlen(optarg) > MAX_MNTOPT_STR) {
117*0Sstevel@tonic-gate (void) fprintf(stderr, gettext(
118*0Sstevel@tonic-gate "%s: option set too long\n"),
119*0Sstevel@tonic-gate myname);
120*0Sstevel@tonic-gate exit(1);
121*0Sstevel@tonic-gate }
122*0Sstevel@tonic-gate if (strlen(optarg) == 0) {
123*0Sstevel@tonic-gate (void) fprintf(stderr, gettext(
124*0Sstevel@tonic-gate "%s: missing suboptions\n"),
125*0Sstevel@tonic-gate myname);
126*0Sstevel@tonic-gate exit(1);
127*0Sstevel@tonic-gate }
128*0Sstevel@tonic-gate strcpy(obuff, optarg);
129*0Sstevel@tonic-gate options = optarg;
130*0Sstevel@tonic-gate while (*options != '\0') {
131*0Sstevel@tonic-gate switch (getsubopt(&options, myopts,
132*0Sstevel@tonic-gate &value)) {
133*0Sstevel@tonic-gate case GLOBAL:
134*0Sstevel@tonic-gate havegblopt = 1;
135*0Sstevel@tonic-gate global = 1;
136*0Sstevel@tonic-gate break;
137*0Sstevel@tonic-gate case NOGLOBAL:
138*0Sstevel@tonic-gate havegblopt = 1;
139*0Sstevel@tonic-gate global = 0;
140*0Sstevel@tonic-gate break;
141*0Sstevel@tonic-gate }
142*0Sstevel@tonic-gate }
143*0Sstevel@tonic-gate break;
144*0Sstevel@tonic-gate case 'O':
145*0Sstevel@tonic-gate Oflg++;
146*0Sstevel@tonic-gate break;
147*0Sstevel@tonic-gate case 'r':
148*0Sstevel@tonic-gate /* accept for backwards compatibility */
149*0Sstevel@tonic-gate break;
150*0Sstevel@tonic-gate case 'm':
151*0Sstevel@tonic-gate break;
152*0Sstevel@tonic-gate case 'g':
153*0Sstevel@tonic-gate gflg++;
154*0Sstevel@tonic-gate break;
155*0Sstevel@tonic-gate case 'q':
156*0Sstevel@tonic-gate qflg++;
157*0Sstevel@tonic-gate break;
158*0Sstevel@tonic-gate
159*0Sstevel@tonic-gate }
160*0Sstevel@tonic-gate }
161*0Sstevel@tonic-gate
162*0Sstevel@tonic-gate if ((argc - optind) != 2)
163*0Sstevel@tonic-gate usage();
164*0Sstevel@tonic-gate
165*0Sstevel@tonic-gate special = argv[optind++];
166*0Sstevel@tonic-gate mountp = argv[optind++];
167*0Sstevel@tonic-gate
168*0Sstevel@tonic-gate /*
169*0Sstevel@tonic-gate * Force readonly. obuff is guaranteed to have something in
170*0Sstevel@tonic-gate * it. We might end up with "ro,ro", but that's acceptable.
171*0Sstevel@tonic-gate */
172*0Sstevel@tonic-gate flags = MS_RDONLY;
173*0Sstevel@tonic-gate
174*0Sstevel@tonic-gate if ((strlen(obuff) + strlen(MNTOPT_RO) + 2) > MAX_MNTOPT_STR) {
175*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: option set too long\n"),
176*0Sstevel@tonic-gate myname);
177*0Sstevel@tonic-gate exit(1);
178*0Sstevel@tonic-gate }
179*0Sstevel@tonic-gate
180*0Sstevel@tonic-gate strcat(obuff, ",");
181*0Sstevel@tonic-gate strcat(obuff, MNTOPT_RO);
182*0Sstevel@tonic-gate
183*0Sstevel@tonic-gate flags |= Oflg ? MS_OVERLAY : 0;
184*0Sstevel@tonic-gate
185*0Sstevel@tonic-gate /*
186*0Sstevel@tonic-gate * xxx it's not clear if should just put MS_GLOBAL in flags,
187*0Sstevel@tonic-gate * or provide it as a string. Be safe, do both. The subopt
188*0Sstevel@tonic-gate * version has precedence over the switch version.
189*0Sstevel@tonic-gate */
190*0Sstevel@tonic-gate gopt = NULL;
191*0Sstevel@tonic-gate if ((havegblopt && global) || gflg) {
192*0Sstevel@tonic-gate gopt = MNTOPT_GLOBAL;
193*0Sstevel@tonic-gate flags |= MS_GLOBAL;
194*0Sstevel@tonic-gate } else if (havegblopt) {
195*0Sstevel@tonic-gate gopt = MNTOPT_NOGLOBAL;
196*0Sstevel@tonic-gate }
197*0Sstevel@tonic-gate
198*0Sstevel@tonic-gate if (gopt != NULL) {
199*0Sstevel@tonic-gate if ((strlen(obuff) + strlen(gopt) + 2) > MAX_MNTOPT_STR) {
200*0Sstevel@tonic-gate (void) fprintf(stderr,
201*0Sstevel@tonic-gate gettext("%s: option set too long\n"), myname);
202*0Sstevel@tonic-gate exit(1);
203*0Sstevel@tonic-gate }
204*0Sstevel@tonic-gate
205*0Sstevel@tonic-gate strcat(obuff, ",");
206*0Sstevel@tonic-gate strcat(obuff, gopt);
207*0Sstevel@tonic-gate }
208*0Sstevel@tonic-gate
209*0Sstevel@tonic-gate signal(SIGHUP, SIG_IGN);
210*0Sstevel@tonic-gate signal(SIGQUIT, SIG_IGN);
211*0Sstevel@tonic-gate signal(SIGINT, SIG_IGN);
212*0Sstevel@tonic-gate
213*0Sstevel@tonic-gate /*
214*0Sstevel@tonic-gate * Save a copy of the options to compare with the options that
215*0Sstevel@tonic-gate * were actually recognized and supported by the kernel.
216*0Sstevel@tonic-gate */
217*0Sstevel@tonic-gate
218*0Sstevel@tonic-gate (void) strcpy(saved_input_options, obuff);
219*0Sstevel@tonic-gate
220*0Sstevel@tonic-gate /*
221*0Sstevel@tonic-gate * Perform the mount.
222*0Sstevel@tonic-gate */
223*0Sstevel@tonic-gate
224*0Sstevel@tonic-gate if (mount(special, mountp, flags | MS_OPTIONSTR, fstype, NULL, 0,
225*0Sstevel@tonic-gate obuff, sizeof (obuff)) == -1) {
226*0Sstevel@tonic-gate rpterr(special, mountp);
227*0Sstevel@tonic-gate exit(31+2);
228*0Sstevel@tonic-gate }
229*0Sstevel@tonic-gate
230*0Sstevel@tonic-gate if (!qflg) {
231*0Sstevel@tonic-gate cmp_requested_to_actual_options(saved_input_options, obuff,
232*0Sstevel@tonic-gate special, mountp);
233*0Sstevel@tonic-gate }
234*0Sstevel@tonic-gate
235*0Sstevel@tonic-gate exit(0);
236*0Sstevel@tonic-gate /* NOTREACHED */
237*0Sstevel@tonic-gate }
238*0Sstevel@tonic-gate
239*0Sstevel@tonic-gate
240*0Sstevel@tonic-gate static void
rpterr(char * bs,char * mp)241*0Sstevel@tonic-gate rpterr(char *bs, char *mp)
242*0Sstevel@tonic-gate {
243*0Sstevel@tonic-gate switch (errno) {
244*0Sstevel@tonic-gate case EPERM:
245*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: insufficient privileges\n"),
246*0Sstevel@tonic-gate myname);
247*0Sstevel@tonic-gate break;
248*0Sstevel@tonic-gate case ENXIO:
249*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: %s no such device\n"),
250*0Sstevel@tonic-gate myname, bs);
251*0Sstevel@tonic-gate break;
252*0Sstevel@tonic-gate case ENOTDIR:
253*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: %s not a directory\n\tor a "
254*0Sstevel@tonic-gate "component of %s is not a directory\n"), myname, mp, bs);
255*0Sstevel@tonic-gate break;
256*0Sstevel@tonic-gate case ENOENT:
257*0Sstevel@tonic-gate (void) fprintf(stderr,
258*0Sstevel@tonic-gate gettext("%s: %s or %s, no such file or directory\n"),
259*0Sstevel@tonic-gate myname, bs, mp);
260*0Sstevel@tonic-gate break;
261*0Sstevel@tonic-gate case EINVAL:
262*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: %s is not an hsfs file "
263*0Sstevel@tonic-gate "system.\n"), typename, bs);
264*0Sstevel@tonic-gate break;
265*0Sstevel@tonic-gate case EBUSY:
266*0Sstevel@tonic-gate (void) fprintf(stderr,
267*0Sstevel@tonic-gate gettext("%s: %s is already mounted or %s is busy\n"),
268*0Sstevel@tonic-gate myname, bs, mp);
269*0Sstevel@tonic-gate break;
270*0Sstevel@tonic-gate case ENOTBLK:
271*0Sstevel@tonic-gate (void) fprintf(stderr,
272*0Sstevel@tonic-gate gettext("%s: %s not a block device\n"), myname, bs);
273*0Sstevel@tonic-gate break;
274*0Sstevel@tonic-gate case EROFS:
275*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: %s write-protected\n"),
276*0Sstevel@tonic-gate myname, bs);
277*0Sstevel@tonic-gate break;
278*0Sstevel@tonic-gate case ENOSPC:
279*0Sstevel@tonic-gate (void) fprintf(stderr,
280*0Sstevel@tonic-gate gettext("%s: %s is corrupted. needs checking\n"),
281*0Sstevel@tonic-gate myname, bs);
282*0Sstevel@tonic-gate break;
283*0Sstevel@tonic-gate default:
284*0Sstevel@tonic-gate perror(myname);
285*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: cannot mount %s\n"), myname,
286*0Sstevel@tonic-gate bs);
287*0Sstevel@tonic-gate }
288*0Sstevel@tonic-gate }
289*0Sstevel@tonic-gate
290*0Sstevel@tonic-gate
291*0Sstevel@tonic-gate static void
usage()292*0Sstevel@tonic-gate usage()
293*0Sstevel@tonic-gate {
294*0Sstevel@tonic-gate char *opts;
295*0Sstevel@tonic-gate
296*0Sstevel@tonic-gate opts = "{-r | -o ro | -o nrr | -o nosuid | -o notraildot | -o nomaplcase}";
297*0Sstevel@tonic-gate (void) fprintf(stdout,
298*0Sstevel@tonic-gate gettext("hsfs usage: mount [-F hsfs] %s {special | mount_point}\n"), opts);
299*0Sstevel@tonic-gate (void) fprintf(stdout,
300*0Sstevel@tonic-gate gettext("hsfs usage: mount [-F hsfs] %s special mount_point\n"), opts);
301*0Sstevel@tonic-gate exit(32);
302*0Sstevel@tonic-gate }
303