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