1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */
29*7c478bd9Sstevel@tonic-gate
30*7c478bd9Sstevel@tonic-gate #include <stdio.h>
31*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
32*7c478bd9Sstevel@tonic-gate #include <signal.h>
33*7c478bd9Sstevel@tonic-gate #include <errno.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/mnttab.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/mount.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
37*7c478bd9Sstevel@tonic-gate #include <locale.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/stat.h>
39*7c478bd9Sstevel@tonic-gate #include <string.h>
40*7c478bd9Sstevel@tonic-gate
41*7c478bd9Sstevel@tonic-gate #include <fslib.h>
42*7c478bd9Sstevel@tonic-gate
43*7c478bd9Sstevel@tonic-gate #define NAME_MAX 64 /* sizeof "fstype myname" */
44*7c478bd9Sstevel@tonic-gate
45*7c478bd9Sstevel@tonic-gate #define FSTYPE "mntfs"
46*7c478bd9Sstevel@tonic-gate
47*7c478bd9Sstevel@tonic-gate static void do_mount(char *, char *, int);
48*7c478bd9Sstevel@tonic-gate static void usage(void);
49*7c478bd9Sstevel@tonic-gate static void rpterr(char *, char *);
50*7c478bd9Sstevel@tonic-gate
51*7c478bd9Sstevel@tonic-gate static char optbuf[MAX_MNTOPT_STR] = { '\0', };
52*7c478bd9Sstevel@tonic-gate static int optsize = 0;
53*7c478bd9Sstevel@tonic-gate
54*7c478bd9Sstevel@tonic-gate static int flags = 0;
55*7c478bd9Sstevel@tonic-gate static int mflg = 0; /* don't update /etc/mnttab flag */
56*7c478bd9Sstevel@tonic-gate static int Oflg = 0;
57*7c478bd9Sstevel@tonic-gate static int qflg = 0;
58*7c478bd9Sstevel@tonic-gate
59*7c478bd9Sstevel@tonic-gate static char typename[NAME_MAX], *myname;
60*7c478bd9Sstevel@tonic-gate static char fstype[] = FSTYPE;
61*7c478bd9Sstevel@tonic-gate
62*7c478bd9Sstevel@tonic-gate int
main(int argc,char * argv[])63*7c478bd9Sstevel@tonic-gate main(int argc, char *argv[])
64*7c478bd9Sstevel@tonic-gate {
65*7c478bd9Sstevel@tonic-gate char *special, *mountp;
66*7c478bd9Sstevel@tonic-gate int errflag = 0;
67*7c478bd9Sstevel@tonic-gate int cc;
68*7c478bd9Sstevel@tonic-gate
69*7c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
70*7c478bd9Sstevel@tonic-gate
71*7c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
72*7c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST"
73*7c478bd9Sstevel@tonic-gate #endif
74*7c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
75*7c478bd9Sstevel@tonic-gate
76*7c478bd9Sstevel@tonic-gate myname = strrchr(argv[0], '/');
77*7c478bd9Sstevel@tonic-gate if (myname)
78*7c478bd9Sstevel@tonic-gate myname++;
79*7c478bd9Sstevel@tonic-gate else
80*7c478bd9Sstevel@tonic-gate myname = argv[0];
81*7c478bd9Sstevel@tonic-gate (void) snprintf(typename, sizeof (typename), "%s %s", fstype, myname);
82*7c478bd9Sstevel@tonic-gate argv[0] = typename;
83*7c478bd9Sstevel@tonic-gate
84*7c478bd9Sstevel@tonic-gate /*
85*7c478bd9Sstevel@tonic-gate * check for proper arguments
86*7c478bd9Sstevel@tonic-gate */
87*7c478bd9Sstevel@tonic-gate
88*7c478bd9Sstevel@tonic-gate while ((cc = getopt(argc, argv, "?rmOo:q")) != -1)
89*7c478bd9Sstevel@tonic-gate switch (cc) {
90*7c478bd9Sstevel@tonic-gate case 'm':
91*7c478bd9Sstevel@tonic-gate mflg++;
92*7c478bd9Sstevel@tonic-gate break;
93*7c478bd9Sstevel@tonic-gate case 'r':
94*7c478bd9Sstevel@tonic-gate flags |= MS_RDONLY;
95*7c478bd9Sstevel@tonic-gate break;
96*7c478bd9Sstevel@tonic-gate case 'O':
97*7c478bd9Sstevel@tonic-gate Oflg++;
98*7c478bd9Sstevel@tonic-gate break;
99*7c478bd9Sstevel@tonic-gate case 'o':
100*7c478bd9Sstevel@tonic-gate if (strlcpy(optbuf, optarg, sizeof (optbuf)) >=
101*7c478bd9Sstevel@tonic-gate sizeof (optbuf)) {
102*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
103*7c478bd9Sstevel@tonic-gate gettext("%s: Invalid argument: %s\n"),
104*7c478bd9Sstevel@tonic-gate myname, optarg);
105*7c478bd9Sstevel@tonic-gate return (2);
106*7c478bd9Sstevel@tonic-gate }
107*7c478bd9Sstevel@tonic-gate optsize = strlen(optbuf);
108*7c478bd9Sstevel@tonic-gate break;
109*7c478bd9Sstevel@tonic-gate case 'q':
110*7c478bd9Sstevel@tonic-gate qflg++;
111*7c478bd9Sstevel@tonic-gate break;
112*7c478bd9Sstevel@tonic-gate case '?':
113*7c478bd9Sstevel@tonic-gate default:
114*7c478bd9Sstevel@tonic-gate errflag = 1;
115*7c478bd9Sstevel@tonic-gate break;
116*7c478bd9Sstevel@tonic-gate }
117*7c478bd9Sstevel@tonic-gate
118*7c478bd9Sstevel@tonic-gate /*
119*7c478bd9Sstevel@tonic-gate * There must be at least 2 more arguments, the
120*7c478bd9Sstevel@tonic-gate * special file and the directory.
121*7c478bd9Sstevel@tonic-gate */
122*7c478bd9Sstevel@tonic-gate
123*7c478bd9Sstevel@tonic-gate if (((argc - optind) != 2) || (errflag))
124*7c478bd9Sstevel@tonic-gate usage();
125*7c478bd9Sstevel@tonic-gate
126*7c478bd9Sstevel@tonic-gate special = argv[optind++];
127*7c478bd9Sstevel@tonic-gate mountp = argv[optind++];
128*7c478bd9Sstevel@tonic-gate
129*7c478bd9Sstevel@tonic-gate /*
130*7c478bd9Sstevel@tonic-gate * Perform the mount.
131*7c478bd9Sstevel@tonic-gate */
132*7c478bd9Sstevel@tonic-gate if (mflg)
133*7c478bd9Sstevel@tonic-gate flags |= MS_NOMNTTAB;
134*7c478bd9Sstevel@tonic-gate do_mount(special, mountp, flags);
135*7c478bd9Sstevel@tonic-gate return (0);
136*7c478bd9Sstevel@tonic-gate }
137*7c478bd9Sstevel@tonic-gate
138*7c478bd9Sstevel@tonic-gate static void
rpterr(char * bs,char * mp)139*7c478bd9Sstevel@tonic-gate rpterr(char *bs, char *mp)
140*7c478bd9Sstevel@tonic-gate {
141*7c478bd9Sstevel@tonic-gate switch (errno) {
142*7c478bd9Sstevel@tonic-gate case EPERM:
143*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: insufficient privileges\n"),
144*7c478bd9Sstevel@tonic-gate myname);
145*7c478bd9Sstevel@tonic-gate break;
146*7c478bd9Sstevel@tonic-gate case ENXIO:
147*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: %s no such device\n"),
148*7c478bd9Sstevel@tonic-gate myname, bs);
149*7c478bd9Sstevel@tonic-gate break;
150*7c478bd9Sstevel@tonic-gate case ENOTDIR:
151*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
152*7c478bd9Sstevel@tonic-gate gettext("%s: %s not a directory\n\tor a component of %s is not a directory\n"),
153*7c478bd9Sstevel@tonic-gate myname, mp, bs);
154*7c478bd9Sstevel@tonic-gate break;
155*7c478bd9Sstevel@tonic-gate case ENOENT:
156*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
157*7c478bd9Sstevel@tonic-gate gettext("%s: %s or %s, no such file or directory\n"),
158*7c478bd9Sstevel@tonic-gate myname, bs, mp);
159*7c478bd9Sstevel@tonic-gate break;
160*7c478bd9Sstevel@tonic-gate case EINVAL:
161*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: %s is not this fstype.\n"),
162*7c478bd9Sstevel@tonic-gate myname, bs);
163*7c478bd9Sstevel@tonic-gate break;
164*7c478bd9Sstevel@tonic-gate case EBUSY:
165*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
166*7c478bd9Sstevel@tonic-gate gettext("%s: %s is already mounted or %s is busy\n"),
167*7c478bd9Sstevel@tonic-gate myname, bs, mp);
168*7c478bd9Sstevel@tonic-gate break;
169*7c478bd9Sstevel@tonic-gate case EROFS:
170*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: %s write-protected\n"),
171*7c478bd9Sstevel@tonic-gate myname, bs);
172*7c478bd9Sstevel@tonic-gate break;
173*7c478bd9Sstevel@tonic-gate case ENOSPC:
174*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
175*7c478bd9Sstevel@tonic-gate gettext("%s: the state of %s is not okay\n"
176*7c478bd9Sstevel@tonic-gate "\tand it was attempted to mount read/write\n"),
177*7c478bd9Sstevel@tonic-gate myname, bs);
178*7c478bd9Sstevel@tonic-gate break;
179*7c478bd9Sstevel@tonic-gate default:
180*7c478bd9Sstevel@tonic-gate perror(myname);
181*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: cannot mount %s\n"),
182*7c478bd9Sstevel@tonic-gate myname, bs);
183*7c478bd9Sstevel@tonic-gate }
184*7c478bd9Sstevel@tonic-gate }
185*7c478bd9Sstevel@tonic-gate
186*7c478bd9Sstevel@tonic-gate static void
do_mount(char * special,char * mountp,int rflag)187*7c478bd9Sstevel@tonic-gate do_mount(char *special, char *mountp, int rflag)
188*7c478bd9Sstevel@tonic-gate {
189*7c478bd9Sstevel@tonic-gate char *savedoptbuf;
190*7c478bd9Sstevel@tonic-gate
191*7c478bd9Sstevel@tonic-gate if ((savedoptbuf = strdup(optbuf)) == NULL) {
192*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: out of memory\n"),
193*7c478bd9Sstevel@tonic-gate myname);
194*7c478bd9Sstevel@tonic-gate exit(1);
195*7c478bd9Sstevel@tonic-gate }
196*7c478bd9Sstevel@tonic-gate
197*7c478bd9Sstevel@tonic-gate rflag |= Oflg ? MS_OVERLAY : 0;
198*7c478bd9Sstevel@tonic-gate if (mount(special, mountp, rflag | MS_OPTIONSTR, fstype, NULL, 0,
199*7c478bd9Sstevel@tonic-gate optbuf, MAX_MNTOPT_STR)) {
200*7c478bd9Sstevel@tonic-gate rpterr(special, mountp);
201*7c478bd9Sstevel@tonic-gate exit(1);
202*7c478bd9Sstevel@tonic-gate }
203*7c478bd9Sstevel@tonic-gate
204*7c478bd9Sstevel@tonic-gate if (optsize && !qflg)
205*7c478bd9Sstevel@tonic-gate cmp_requested_to_actual_options(savedoptbuf, optbuf,
206*7c478bd9Sstevel@tonic-gate special, mountp);
207*7c478bd9Sstevel@tonic-gate }
208*7c478bd9Sstevel@tonic-gate
209*7c478bd9Sstevel@tonic-gate static void
usage(void)210*7c478bd9Sstevel@tonic-gate usage(void)
211*7c478bd9Sstevel@tonic-gate {
212*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
213*7c478bd9Sstevel@tonic-gate gettext("%s usage:\n%s [-F %s] [-r] [-o specific_options] "
214*7c478bd9Sstevel@tonic-gate "{special | mount_point}\n%s [-F %s] [-r] [-o specific_options]"
215*7c478bd9Sstevel@tonic-gate " special mount_point\n"),
216*7c478bd9Sstevel@tonic-gate fstype, myname, fstype, myname, fstype);
217*7c478bd9Sstevel@tonic-gate exit(2);
218*7c478bd9Sstevel@tonic-gate }
219