1*3957Sth199096 /*
2*3957Sth199096 * CDDL HEADER START
3*3957Sth199096 *
4*3957Sth199096 * The contents of this file are subject to the terms of the
5*3957Sth199096 * Common Development and Distribution License (the "License").
6*3957Sth199096 * You may not use this file except in compliance with the License.
7*3957Sth199096 *
8*3957Sth199096 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*3957Sth199096 * or http://www.opensolaris.org/os/licensing.
10*3957Sth199096 * See the License for the specific language governing permissions
11*3957Sth199096 * and limitations under the License.
12*3957Sth199096 *
13*3957Sth199096 * When distributing Covered Code, include this CDDL HEADER in each
14*3957Sth199096 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*3957Sth199096 * If applicable, add the following below this CDDL HEADER, with the
16*3957Sth199096 * fields enclosed by brackets "[]" replaced with your own identifying
17*3957Sth199096 * information: Portions Copyright [yyyy] [name of copyright owner]
18*3957Sth199096 *
19*3957Sth199096 * CDDL HEADER END
20*3957Sth199096 */
21*3957Sth199096 /*
22*3957Sth199096 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23*3957Sth199096 * Use is subject to license terms.
24*3957Sth199096 */
25*3957Sth199096
26*3957Sth199096 #pragma ident "%Z%%M% %I% %E% SMI"
27*3957Sth199096
28*3957Sth199096 #include <stdio.h>
29*3957Sth199096 #include <stdlib.h>
30*3957Sth199096 #include <string.h>
31*3957Sth199096 #include <libintl.h>
32*3957Sth199096 #include <errno.h>
33*3957Sth199096 #include <sys/fstyp.h>
34*3957Sth199096 #include <sys/fsid.h>
35*3957Sth199096 #include <sys/mntent.h>
36*3957Sth199096 #include <sys/mnttab.h>
37*3957Sth199096 #include <sys/mount.h>
38*3957Sth199096 #include <sys/signal.h>
39*3957Sth199096 #include <sys/stat.h>
40*3957Sth199096 #include <fslib.h>
41*3957Sth199096 #include <locale.h>
42*3957Sth199096
43*3957Sth199096 #define RET_OK 0
44*3957Sth199096 #define RET_ERR 33
45*3957Sth199096 #define EXIT_MAGIC 2
46*3957Sth199096
47*3957Sth199096 static void usage(void);
48*3957Sth199096
49*3957Sth199096 static char optbuf[MAX_MNTOPT_STR] = { '\0', };
50*3957Sth199096 static int optsize = 0;
51*3957Sth199096
52*3957Sth199096 static char fstype[] = "sharefs";
53*3957Sth199096
54*3957Sth199096 /*
55*3957Sth199096 * usage: mount [-Ormq] [-o options] special mountp
56*3957Sth199096 *
57*3957Sth199096 * This mount program is exec'ed by /usr/sbin/mount if '-F sharefs' is
58*3957Sth199096 * specified.
59*3957Sth199096 */
60*3957Sth199096 int
main(int argc,char * argv[])61*3957Sth199096 main(int argc, char *argv[])
62*3957Sth199096 {
63*3957Sth199096 int c;
64*3957Sth199096 char *special; /* Entity being mounted */
65*3957Sth199096 char *mountp; /* Entity being mounted on */
66*3957Sth199096 char *savedoptbuf;
67*3957Sth199096 char *myname;
68*3957Sth199096 char *typename;
69*3957Sth199096 int flags = 0;
70*3957Sth199096 int error_flag = 0;
71*3957Sth199096 int q_flag = 0;
72*3957Sth199096
73*3957Sth199096 int len;
74*3957Sth199096
75*3957Sth199096 (void) setlocale(LC_ALL, "");
76*3957Sth199096
77*3957Sth199096 #if !defined(TEXT_DOMAIN)
78*3957Sth199096 #define TEXT_DOMAIN "SYS_TEST"
79*3957Sth199096 #endif
80*3957Sth199096 (void) textdomain(TEXT_DOMAIN);
81*3957Sth199096
82*3957Sth199096
83*3957Sth199096 myname = strrchr(argv[0], '/');
84*3957Sth199096 myname = myname ? myname + 1 : argv[0];
85*3957Sth199096
86*3957Sth199096 len = strlen(fstype) + 1 + strlen(myname);
87*3957Sth199096 typename = malloc(len + 1);
88*3957Sth199096 if (!typename) {
89*3957Sth199096 (void) fprintf(stderr, gettext("%s: out of memory\n"),
90*3957Sth199096 myname);
91*3957Sth199096 return (EXIT_MAGIC);
92*3957Sth199096 }
93*3957Sth199096
94*3957Sth199096 (void) snprintf(typename, len, "%s %s", fstype, myname);
95*3957Sth199096 argv[0] = typename;
96*3957Sth199096
97*3957Sth199096 while ((c = getopt(argc, argv, "o:rmOq")) != EOF) {
98*3957Sth199096 switch (c) {
99*3957Sth199096 case '?':
100*3957Sth199096 error_flag = 1;
101*3957Sth199096 break;
102*3957Sth199096
103*3957Sth199096 case 'o':
104*3957Sth199096 if (strlcpy(optbuf, optarg, sizeof (optbuf)) >=
105*3957Sth199096 sizeof (optbuf)) {
106*3957Sth199096 (void) fprintf(stderr,
107*3957Sth199096 gettext("%s: Invalid argument: %s\n"),
108*3957Sth199096 myname, optarg);
109*3957Sth199096 free(typename);
110*3957Sth199096 return (EXIT_MAGIC);
111*3957Sth199096 }
112*3957Sth199096 optsize = strlen(optbuf);
113*3957Sth199096 break;
114*3957Sth199096 case 'O':
115*3957Sth199096 flags |= MS_OVERLAY;
116*3957Sth199096 break;
117*3957Sth199096 case 'r':
118*3957Sth199096 flags |= MS_RDONLY;
119*3957Sth199096 break;
120*3957Sth199096
121*3957Sth199096 case 'm':
122*3957Sth199096 flags |= MS_NOMNTTAB;
123*3957Sth199096 break;
124*3957Sth199096
125*3957Sth199096 case 'q':
126*3957Sth199096 q_flag = 1;
127*3957Sth199096 break;
128*3957Sth199096
129*3957Sth199096 default:
130*3957Sth199096 usage();
131*3957Sth199096 }
132*3957Sth199096 }
133*3957Sth199096 if ((argc - optind != 2) || error_flag) {
134*3957Sth199096 usage();
135*3957Sth199096 }
136*3957Sth199096 special = argv[argc - 2];
137*3957Sth199096 mountp = argv[argc - 1];
138*3957Sth199096
139*3957Sth199096 if ((savedoptbuf = strdup(optbuf)) == NULL) {
140*3957Sth199096 (void) fprintf(stderr, gettext("%s: out of memory\n"),
141*3957Sth199096 myname);
142*3957Sth199096 free(typename);
143*3957Sth199096 exit(EXIT_MAGIC);
144*3957Sth199096 }
145*3957Sth199096 if (mount(special, mountp, flags | MS_OPTIONSTR, fstype, NULL, 0,
146*3957Sth199096 optbuf, MAX_MNTOPT_STR)) {
147*3957Sth199096 (void) fprintf(stderr, "mount: ");
148*3957Sth199096 perror(special);
149*3957Sth199096 free(typename);
150*3957Sth199096 exit(RET_ERR);
151*3957Sth199096 }
152*3957Sth199096 if (optsize && !q_flag)
153*3957Sth199096 cmp_requested_to_actual_options(savedoptbuf, optbuf,
154*3957Sth199096 special, mountp);
155*3957Sth199096 free(typename);
156*3957Sth199096 return (RET_OK);
157*3957Sth199096 }
158*3957Sth199096
159*3957Sth199096 static void
usage(void)160*3957Sth199096 usage(void)
161*3957Sth199096 {
162*3957Sth199096 (void) fprintf(stderr,
163*3957Sth199096 gettext("Usage: mount [-Ormq] [-o options] special mountpoint\n"));
164*3957Sth199096 exit(RET_ERR);
165*3957Sth199096 }
166