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 2004 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"
39 #include <sys/mnttab.h>
40 #include <sys/mount.h>
41 #include <sys/types.h>
45 #define NAME_MAX 64 /* sizeof "fstype myname" */
49 static char optbuf
[MAX_MNTOPT_STR
] = { '\0', };
50 static int optsize
= 0;
56 static char typename
[NAME_MAX
], *myname
;
57 static char fstype
[] = FSTYPE
;
59 static void usage(void);
60 static void do_mount(char *, char *, int);
63 main(int argc
, char **argv
)
65 char *special
, *mountp
;
69 (void) setlocale(LC_ALL
, "");
71 #if !defined(TEXT_DOMAIN)
72 #define TEXT_DOMAIN "SYS_TEST"
74 (void) textdomain(TEXT_DOMAIN
);
76 myname
= strrchr(argv
[0], '/');
81 (void) snprintf(typename
, sizeof (typename
), "%s %s", fstype
, myname
);
85 * check for proper arguments
88 while ((cc
= getopt(argc
, argv
, "o:rmOq")) != -1)
91 if (flags
& MS_RDONLY
)
106 if (strlcpy(optbuf
, optarg
, sizeof (optbuf
)) >=
108 (void) fprintf(stderr
,
109 gettext("%s: Invalid argument: %s\n"),
113 optsize
= strlen(optbuf
);
122 * There must be at least 2 more arguments, the
123 * special file and the directory.
126 if (((argc
- optind
) != 2) || (errflag
))
129 special
= argv
[optind
++];
130 mountp
= argv
[optind
++];
134 * Only the low-order bit of "flags" is used by the system
135 * calls (to denote read-only or read-write).
138 flags
|= MS_NOMNTTAB
;
139 do_mount(special
, mountp
, flags
);
145 rpterr(char *bs
, char *mp
)
149 (void) fprintf(stderr
,
150 gettext("%s: insufficient privileges\n"), myname
);
153 (void) fprintf(stderr
,
154 gettext("%s: %s no such device\n"), myname
, bs
);
157 (void) fprintf(stderr
,
158 gettext("%s: %s not a directory\n"
159 "\tor a component of %s is not a directory\n"),
163 (void) fprintf(stderr
,
164 gettext("%s: %s or %s, no such file or directory\n"),
168 (void) fprintf(stderr
, gettext("%s: %s is not this fstype.\n"),
172 (void) fprintf(stderr
,
173 gettext("%s: %s is already mounted or %s is busy\n"),
177 (void) fprintf(stderr
, gettext("%s: %s not a block device\n"),
181 (void) fprintf(stderr
,
182 gettext("%s: %s write-protected\n"), myname
, bs
);
185 (void) fprintf(stderr
,
186 gettext("%s: the state of %s is not okay\n"
187 "\tand it was attempted to mount read/write\n"),
192 (void) fprintf(stderr
, gettext("%s: cannot mount %s\n"),
199 do_mount(char *special
, char *mountp
, int rflag
)
203 if ((savedoptbuf
= strdup(optbuf
)) == NULL
) {
204 (void) fprintf(stderr
, gettext("%s: out of memory\n"),
208 if (mount(special
, mountp
, rflag
| MS_OPTIONSTR
,
209 fstype
, NULL
, 0, optbuf
, MAX_MNTOPT_STR
)) {
210 rpterr(special
, mountp
);
213 if (optsize
&& !qflg
)
214 cmp_requested_to_actual_options(savedoptbuf
, optbuf
,
222 (void) fprintf(stderr
,
223 gettext("Usage: %s [-rmOq] [-o specific_options]"
224 " special mount_point\n"), myname
);