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 <stdlib.h> /* for getopt(3) */
33*0Sstevel@tonic-gate #include <signal.h>
34*0Sstevel@tonic-gate #include <locale.h>
35*0Sstevel@tonic-gate #include <fslib.h>
36*0Sstevel@tonic-gate #include <errno.h>
37*0Sstevel@tonic-gate #include <sys/types.h>
38*0Sstevel@tonic-gate #include <sys/mnttab.h>
39*0Sstevel@tonic-gate #include <sys/mount.h>
40*0Sstevel@tonic-gate
41*0Sstevel@tonic-gate #define FSTYPE "udfs"
42*0Sstevel@tonic-gate #define NAME_MAX 64
43*0Sstevel@tonic-gate
44*0Sstevel@tonic-gate static int roflag = 0;
45*0Sstevel@tonic-gate static int mflag = 0;
46*0Sstevel@tonic-gate static int Oflag = 0;
47*0Sstevel@tonic-gate static int qflag = 0;
48*0Sstevel@tonic-gate
49*0Sstevel@tonic-gate static char optbuf[MAX_MNTOPT_STR] = { '\0', };
50*0Sstevel@tonic-gate static int optsize = 0;
51*0Sstevel@tonic-gate
52*0Sstevel@tonic-gate static char fstype[] = FSTYPE;
53*0Sstevel@tonic-gate
54*0Sstevel@tonic-gate static char typename[NAME_MAX], *myname;
55*0Sstevel@tonic-gate
56*0Sstevel@tonic-gate static void do_mount(char *, char *, int);
57*0Sstevel@tonic-gate static void rpterr(char *, char *);
58*0Sstevel@tonic-gate static void usage(void);
59*0Sstevel@tonic-gate
60*0Sstevel@tonic-gate int
main(int argc,char ** argv)61*0Sstevel@tonic-gate main(int argc, char **argv)
62*0Sstevel@tonic-gate {
63*0Sstevel@tonic-gate char *special, *mountp;
64*0Sstevel@tonic-gate int flags = 0;
65*0Sstevel@tonic-gate int c;
66*0Sstevel@tonic-gate
67*0Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
70*0Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST"
71*0Sstevel@tonic-gate #endif
72*0Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
73*0Sstevel@tonic-gate
74*0Sstevel@tonic-gate myname = strrchr(argv[0], '/');
75*0Sstevel@tonic-gate if (myname) {
76*0Sstevel@tonic-gate myname++;
77*0Sstevel@tonic-gate } else {
78*0Sstevel@tonic-gate myname = argv[0];
79*0Sstevel@tonic-gate }
80*0Sstevel@tonic-gate (void) snprintf(typename, sizeof (typename), "%s %s", fstype, myname);
81*0Sstevel@tonic-gate argv[0] = typename;
82*0Sstevel@tonic-gate
83*0Sstevel@tonic-gate /* check for proper arguments */
84*0Sstevel@tonic-gate
85*0Sstevel@tonic-gate while ((c = getopt(argc, argv, "mo:rOq")) != EOF) {
86*0Sstevel@tonic-gate switch (c) {
87*0Sstevel@tonic-gate case 'm':
88*0Sstevel@tonic-gate mflag++;
89*0Sstevel@tonic-gate break;
90*0Sstevel@tonic-gate case 'o':
91*0Sstevel@tonic-gate if (strlcpy(optbuf, optarg, sizeof (optbuf)) >=
92*0Sstevel@tonic-gate sizeof (optbuf)) {
93*0Sstevel@tonic-gate (void) fprintf(stderr,
94*0Sstevel@tonic-gate gettext("%s: Invalid argument: %s\n"),
95*0Sstevel@tonic-gate myname, optarg);
96*0Sstevel@tonic-gate return (2);
97*0Sstevel@tonic-gate }
98*0Sstevel@tonic-gate optsize = strlen(optbuf);
99*0Sstevel@tonic-gate break;
100*0Sstevel@tonic-gate case 'r':
101*0Sstevel@tonic-gate roflag++;
102*0Sstevel@tonic-gate break;
103*0Sstevel@tonic-gate case 'O':
104*0Sstevel@tonic-gate Oflag++;
105*0Sstevel@tonic-gate break;
106*0Sstevel@tonic-gate case 'q':
107*0Sstevel@tonic-gate qflag = 1;
108*0Sstevel@tonic-gate break;
109*0Sstevel@tonic-gate default :
110*0Sstevel@tonic-gate break;
111*0Sstevel@tonic-gate }
112*0Sstevel@tonic-gate }
113*0Sstevel@tonic-gate
114*0Sstevel@tonic-gate if ((argc - optind) != 2)
115*0Sstevel@tonic-gate usage();
116*0Sstevel@tonic-gate
117*0Sstevel@tonic-gate special = argv[optind++];
118*0Sstevel@tonic-gate mountp = argv[optind++];
119*0Sstevel@tonic-gate
120*0Sstevel@tonic-gate if (roflag)
121*0Sstevel@tonic-gate flags = MS_RDONLY;
122*0Sstevel@tonic-gate
123*0Sstevel@tonic-gate if (optsize > 0) {
124*0Sstevel@tonic-gate struct mnttab m;
125*0Sstevel@tonic-gate
126*0Sstevel@tonic-gate m.mnt_mntopts = optbuf;
127*0Sstevel@tonic-gate if (hasmntopt(&m, "m"))
128*0Sstevel@tonic-gate mflag++;
129*0Sstevel@tonic-gate }
130*0Sstevel@tonic-gate
131*0Sstevel@tonic-gate flags |= (Oflag ? MS_OVERLAY : 0);
132*0Sstevel@tonic-gate flags |= (mflag ? MS_NOMNTTAB : 0);
133*0Sstevel@tonic-gate
134*0Sstevel@tonic-gate
135*0Sstevel@tonic-gate /*
136*0Sstevel@tonic-gate * Perform the mount.
137*0Sstevel@tonic-gate * Only the low-order bit of "roflag" is used by the system
138*0Sstevel@tonic-gate * calls (to denote read-only or read-write).
139*0Sstevel@tonic-gate */
140*0Sstevel@tonic-gate do_mount(special, mountp, flags);
141*0Sstevel@tonic-gate return (0);
142*0Sstevel@tonic-gate }
143*0Sstevel@tonic-gate
144*0Sstevel@tonic-gate
145*0Sstevel@tonic-gate static void
rpterr(char * bs,char * mp)146*0Sstevel@tonic-gate rpterr(char *bs, char *mp)
147*0Sstevel@tonic-gate {
148*0Sstevel@tonic-gate switch (errno) {
149*0Sstevel@tonic-gate case EPERM:
150*0Sstevel@tonic-gate (void) fprintf(stderr,
151*0Sstevel@tonic-gate gettext("%s: insufficient privileges\n"), myname);
152*0Sstevel@tonic-gate break;
153*0Sstevel@tonic-gate case ENXIO:
154*0Sstevel@tonic-gate (void) fprintf(stderr,
155*0Sstevel@tonic-gate gettext("%s: %s no such device\n"), myname, bs);
156*0Sstevel@tonic-gate break;
157*0Sstevel@tonic-gate case ENOTDIR:
158*0Sstevel@tonic-gate (void) fprintf(stderr,
159*0Sstevel@tonic-gate gettext("%s: %s not a directory\n\t"
160*0Sstevel@tonic-gate "or a component of %s is not a directory\n"),
161*0Sstevel@tonic-gate myname, mp, bs);
162*0Sstevel@tonic-gate break;
163*0Sstevel@tonic-gate case ENOENT:
164*0Sstevel@tonic-gate (void) fprintf(stderr,
165*0Sstevel@tonic-gate gettext("%s: %s or %s, no such file or directory\n"),
166*0Sstevel@tonic-gate myname, bs, mp);
167*0Sstevel@tonic-gate break;
168*0Sstevel@tonic-gate case EINVAL:
169*0Sstevel@tonic-gate (void) fprintf(stderr,
170*0Sstevel@tonic-gate gettext("%s: %s is not an udfs file system.\n"),
171*0Sstevel@tonic-gate typename, bs);
172*0Sstevel@tonic-gate break;
173*0Sstevel@tonic-gate case EBUSY:
174*0Sstevel@tonic-gate (void) fprintf(stderr,
175*0Sstevel@tonic-gate gettext("%s: %s is already mounted or %s is busy\n"),
176*0Sstevel@tonic-gate myname, bs, mp);
177*0Sstevel@tonic-gate break;
178*0Sstevel@tonic-gate case ENOTBLK:
179*0Sstevel@tonic-gate (void) fprintf(stderr,
180*0Sstevel@tonic-gate gettext("%s: %s not a block device\n"), myname, bs);
181*0Sstevel@tonic-gate break;
182*0Sstevel@tonic-gate case EROFS:
183*0Sstevel@tonic-gate (void) fprintf(stderr,
184*0Sstevel@tonic-gate gettext("%s: %s write-protected\n"),
185*0Sstevel@tonic-gate myname, bs);
186*0Sstevel@tonic-gate break;
187*0Sstevel@tonic-gate case ENOSPC:
188*0Sstevel@tonic-gate (void) fprintf(stderr,
189*0Sstevel@tonic-gate gettext("%s: %s is corrupted. needs checking\n"),
190*0Sstevel@tonic-gate myname, bs);
191*0Sstevel@tonic-gate break;
192*0Sstevel@tonic-gate default:
193*0Sstevel@tonic-gate perror(myname);
194*0Sstevel@tonic-gate (void) fprintf(stderr,
195*0Sstevel@tonic-gate gettext("%s: cannot mount %s\n"), myname, bs);
196*0Sstevel@tonic-gate }
197*0Sstevel@tonic-gate }
198*0Sstevel@tonic-gate
199*0Sstevel@tonic-gate
200*0Sstevel@tonic-gate static void
do_mount(char * special,char * mountp,int flag)201*0Sstevel@tonic-gate do_mount(char *special, char *mountp, int flag)
202*0Sstevel@tonic-gate {
203*0Sstevel@tonic-gate char *savedoptbuf;
204*0Sstevel@tonic-gate
205*0Sstevel@tonic-gate if ((savedoptbuf = strdup(optbuf)) == NULL) {
206*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: out of memory\n"),
207*0Sstevel@tonic-gate myname);
208*0Sstevel@tonic-gate exit(2);
209*0Sstevel@tonic-gate }
210*0Sstevel@tonic-gate if (mount(special, mountp, flag | MS_DATA | MS_OPTIONSTR,
211*0Sstevel@tonic-gate fstype, NULL, 0, optbuf, MAX_MNTOPT_STR) == -1) {
212*0Sstevel@tonic-gate rpterr(special, mountp);
213*0Sstevel@tonic-gate exit(31+2);
214*0Sstevel@tonic-gate }
215*0Sstevel@tonic-gate if (optsize && !qflag)
216*0Sstevel@tonic-gate cmp_requested_to_actual_options(savedoptbuf, optbuf,
217*0Sstevel@tonic-gate special, mountp);
218*0Sstevel@tonic-gate }
219*0Sstevel@tonic-gate
220*0Sstevel@tonic-gate
221*0Sstevel@tonic-gate static void
usage(void)222*0Sstevel@tonic-gate usage(void)
223*0Sstevel@tonic-gate {
224*0Sstevel@tonic-gate (void) fprintf(stdout, gettext("udfs usage:\n"
225*0Sstevel@tonic-gate "mount [-F udfs] [generic options] "
226*0Sstevel@tonic-gate "[-o suboptions] {special | mount_point}\n"));
227*0Sstevel@tonic-gate (void) fprintf(stdout, gettext("\tsuboptions are: \n"
228*0Sstevel@tonic-gate "\t ro,rw,nosuid,remount,m\n"));
229*0Sstevel@tonic-gate (void) fprintf(stdout, gettext(
230*0Sstevel@tonic-gate "\t only one of ro, rw can be "
231*0Sstevel@tonic-gate "used at the same time\n"));
232*0Sstevel@tonic-gate (void) fprintf(stdout, gettext(
233*0Sstevel@tonic-gate "\t remount can be used only with rw\n"));
234*0Sstevel@tonic-gate
235*0Sstevel@tonic-gate exit(32);
236*0Sstevel@tonic-gate }
237