4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <unistd.h> /* defines F_LOCK for lockf */
33 #include <stdlib.h> /* for getopt(3) */
37 #include <sys/types.h>
39 #include <sys/mnttab.h>
40 #include <sys/mntent.h>
41 #include <sys/mount.h>
43 #include <sys/fs/hsfs_susp.h>
44 #include <sys/fs/hsfs_rrip.h>
53 #ifndef MNTOPT_NOGLOBAL
54 #define MNTOPT_NOGLOBAL "noglobal"
55 #endif /* MNTOPT_NOGLOBAL */
57 static int gflg
= 0; /* mount into global name space: flag form */
58 static int global
= 0; /* mount into global name space: option form */
59 static int havegblopt
= 0; /* global value supercedes gflg value */
60 static int qflg
= 0; /* quiet option - don't flag bad options */
62 static char fstype
[] = MNTTYPE_HSFS
;
64 static char typename
[NAME_MAX
], *myname
;
66 * Mount options that require special handling
68 static char *myopts
[] = {
75 static void rpterr(char *, char *);
76 static void usage(void);
79 main(int argc
, char **argv
)
81 char *options
, *value
;
82 char *special
, *mountp
;
86 char obuff
[MAX_MNTOPT_STR
];
87 char saved_input_options
[MAX_MNTOPT_STR
];
91 int Oflg
= 0; /* Overlay mounts */
93 (void) setlocale(LC_ALL
, "");
95 #if !defined(TEXT_DOMAIN)
96 #define TEXT_DOMAIN "SYS_TEST"
98 (void) textdomain(TEXT_DOMAIN
);
100 myname
= strrchr(argv
[0], '/');
105 snprintf(typename
, sizeof (typename
), "%s %s", fstype
, myname
);
109 * Check for arguments requiring special handling. Ignore
110 * unrecognized options.
112 strcpy(obuff
, "ro"); /* default */
113 while ((c
= getopt(argc
, argv
, "o:rmOgq")) != EOF
) {
116 if (strlen(optarg
) > MAX_MNTOPT_STR
) {
117 (void) fprintf(stderr
, gettext(
118 "%s: option set too long\n"),
122 if (strlen(optarg
) == 0) {
123 (void) fprintf(stderr
, gettext(
124 "%s: missing suboptions\n"),
128 strcpy(obuff
, optarg
);
130 while (*options
!= '\0') {
131 switch (getsubopt(&options
, myopts
,
148 /* accept for backwards compatibility */
162 if ((argc
- optind
) != 2)
165 special
= argv
[optind
++];
166 mountp
= argv
[optind
++];
169 * Force readonly. obuff is guaranteed to have something in
170 * it. We might end up with "ro,ro", but that's acceptable.
174 if ((strlen(obuff
) + strlen(MNTOPT_RO
) + 2) > MAX_MNTOPT_STR
) {
175 (void) fprintf(stderr
, gettext("%s: option set too long\n"),
181 strcat(obuff
, MNTOPT_RO
);
183 flags
|= Oflg
? MS_OVERLAY
: 0;
186 * xxx it's not clear if should just put MS_GLOBAL in flags,
187 * or provide it as a string. Be safe, do both. The subopt
188 * version has precedence over the switch version.
191 if ((havegblopt
&& global
) || gflg
) {
192 gopt
= MNTOPT_GLOBAL
;
194 } else if (havegblopt
) {
195 gopt
= MNTOPT_NOGLOBAL
;
199 if ((strlen(obuff
) + strlen(gopt
) + 2) > MAX_MNTOPT_STR
) {
200 (void) fprintf(stderr
,
201 gettext("%s: option set too long\n"), myname
);
209 signal(SIGHUP
, SIG_IGN
);
210 signal(SIGQUIT
, SIG_IGN
);
211 signal(SIGINT
, SIG_IGN
);
214 * Save a copy of the options to compare with the options that
215 * were actually recognized and supported by the kernel.
218 (void) strcpy(saved_input_options
, obuff
);
224 if (mount(special
, mountp
, flags
| MS_OPTIONSTR
, fstype
, NULL
, 0,
225 obuff
, sizeof (obuff
)) == -1) {
226 rpterr(special
, mountp
);
231 cmp_requested_to_actual_options(saved_input_options
, obuff
,
241 rpterr(char *bs
, char *mp
)
245 (void) fprintf(stderr
, gettext("%s: insufficient privileges\n"),
249 (void) fprintf(stderr
, gettext("%s: %s no such device\n"),
253 (void) fprintf(stderr
, gettext("%s: %s not a directory\n\tor a "
254 "component of %s is not a directory\n"), myname
, mp
, bs
);
257 (void) fprintf(stderr
,
258 gettext("%s: %s or %s, no such file or directory\n"),
262 (void) fprintf(stderr
, gettext("%s: %s is not an hsfs file "
263 "system.\n"), typename
, bs
);
266 (void) fprintf(stderr
,
267 gettext("%s: %s is already mounted or %s is busy\n"),
271 (void) fprintf(stderr
,
272 gettext("%s: %s not a block device\n"), myname
, bs
);
275 (void) fprintf(stderr
, gettext("%s: %s write-protected\n"),
279 (void) fprintf(stderr
,
280 gettext("%s: %s is corrupted. needs checking\n"),
285 (void) fprintf(stderr
, gettext("%s: cannot mount %s\n"), myname
,
296 opts
= "{-r | -o ro | -o nrr | -o nosuid | -o notraildot | -o nomaplcase}";
297 (void) fprintf(stdout
,
298 gettext("hsfs usage: mount [-F hsfs] %s {special | mount_point}\n"), opts
);
299 (void) fprintf(stdout
,
300 gettext("hsfs usage: mount [-F hsfs] %s special mount_point\n"), opts
);