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 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI"
37 #include <sys/mnttab.h>
38 #include <sys/mount.h>
39 #include <sys/types.h>
46 #define NAME_MAX 64 /* sizeof "fstype myname" */
50 static void rpterr(char *, char *);
51 static void do_mount(char *, char *, int);
52 static void usage(void);
54 static char optbuf
[MAX_MNTOPT_STR
] = { '\0', };
55 static int optsize
= 0;
57 static int roflag
= 0;
58 static int mflg
= 0; /* don't update /etc/mnttab flag */
62 static char typename
[NAME_MAX
], *myname
;
63 static char fstype
[] = FSTYPE
;
66 main(int argc
, char *argv
[])
68 char *special
, *mountp
;
72 (void) setlocale(LC_ALL
, "");
74 #if !defined(TEXT_DOMAIN)
75 #define TEXT_DOMAIN "SYS_TEST"
77 (void) textdomain(TEXT_DOMAIN
);
79 myname
= strrchr(argv
[0], '/');
84 (void) snprintf(typename
, sizeof (typename
), "%s %s", fstype
, myname
);
88 * check for proper arguments
91 while ((cc
= getopt(argc
, argv
, "?o:rmOq")) != -1)
106 if (strlcpy(optbuf
, optarg
, sizeof (optbuf
)) >=
108 (void) fprintf(stderr
,
109 gettext("%s: Invalid argument: %s\n"),
113 optsize
= strlen(optbuf
);
124 * There must be at least 2 more arguments, the
125 * special file and the directory.
128 if (((argc
- optind
) != 2) || (errflag
))
131 special
= argv
[optind
++];
132 mountp
= argv
[optind
++];
137 do_mount(special
, mountp
, roflag
? MS_RDONLY
: 0);
143 rpterr(char *bs
, char *mp
)
147 (void) fprintf(stderr
, gettext("%s: insufficient privileges\n"),
151 (void) fprintf(stderr
, gettext("%s: %s no such device\n"),
155 (void) fprintf(stderr
,
156 gettext("%s: %s not a directory\n\tor a component of %s is not a directory\n"),
160 (void) fprintf(stderr
,
161 gettext("%s: %s or %s, no such file or directory\n"),
165 (void) fprintf(stderr
, gettext("%s: %s is not this fstype.\n"),
169 (void) fprintf(stderr
,
170 gettext("%s: %s is already mounted or %s is busy\n"),
174 (void) fprintf(stderr
, gettext("%s: %s not a block device\n"),
178 (void) fprintf(stderr
, gettext("%s: %s write-protected\n"),
182 (void) fprintf(stderr
,
183 gettext("%s: the state of %s is not okay\n"
184 "\tand it was attempted to mount read/write\n"),
189 (void) fprintf(stderr
, gettext("%s: cannot mount %s\n"),
195 do_mount(char *special
, char *mountp
, int rflag
)
199 if ((savedoptbuf
= strdup(optbuf
)) == NULL
) {
200 (void) fprintf(stderr
, gettext("%s: out of memory\n"),
208 rflag
|= MS_NOMNTTAB
;
209 if (mount(special
, mountp
, rflag
| MS_OPTIONSTR
, fstype
, NULL
, 0,
210 optbuf
, MAX_MNTOPT_STR
)) {
211 rpterr(special
, mountp
);
214 if (optsize
&& !qflg
)
215 cmp_requested_to_actual_options(savedoptbuf
, optbuf
,
222 (void) fprintf(stderr
,
223 gettext("%s usage:\n%s [-F %s] [-r] [-o specific_options] "
224 "{special | mount_point}\n%s [-F %s] [-r] [-o specific_options]"
225 " special mount_point\n"),
226 fstype
, myname
, fstype
, myname
, fstype
);