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 #include <stdio.h>
27*a237e38eSth199096 #include <stdlib.h>
28*a237e38eSth199096 #include <string.h>
29*a237e38eSth199096 #include <libintl.h>
30*a237e38eSth199096 #include <errno.h>
31*a237e38eSth199096 #include <sys/fstyp.h>
32*a237e38eSth199096 #include <sys/fsid.h>
33*a237e38eSth199096 #include <sys/mntent.h>
34*a237e38eSth199096 #include <sys/mnttab.h>
35*a237e38eSth199096 #include <sys/mount.h>
36*a237e38eSth199096 #include <sys/signal.h>
37*a237e38eSth199096 #include <sys/stat.h>
38*a237e38eSth199096 #include <fslib.h>
39*a237e38eSth199096 #include <locale.h>
40*a237e38eSth199096
41*a237e38eSth199096 #define RET_OK 0
42*a237e38eSth199096 #define RET_ERR 33
43*a237e38eSth199096 #define EXIT_MAGIC 2
44*a237e38eSth199096
45*a237e38eSth199096 static void usage(void);
46*a237e38eSth199096
47*a237e38eSth199096 static char optbuf[MAX_MNTOPT_STR] = { '\0', };
48*a237e38eSth199096 static int optsize = 0;
49*a237e38eSth199096
50*a237e38eSth199096 static char fstype[] = "sharefs";
51*a237e38eSth199096
52*a237e38eSth199096 /*
53*a237e38eSth199096 * usage: mount [-Ormq] [-o options] special mountp
54*a237e38eSth199096 *
55*a237e38eSth199096 * This mount program is exec'ed by /usr/sbin/mount if '-F sharefs' is
56*a237e38eSth199096 * specified.
57*a237e38eSth199096 */
58*a237e38eSth199096 int
main(int argc,char * argv[])59*a237e38eSth199096 main(int argc, char *argv[])
60*a237e38eSth199096 {
61*a237e38eSth199096 int c;
62*a237e38eSth199096 char *special; /* Entity being mounted */
63*a237e38eSth199096 char *mountp; /* Entity being mounted on */
64*a237e38eSth199096 char *savedoptbuf;
65*a237e38eSth199096 char *myname;
66*a237e38eSth199096 char *typename;
67*a237e38eSth199096 int flags = 0;
68*a237e38eSth199096 int error_flag = 0;
69*a237e38eSth199096 int q_flag = 0;
70*a237e38eSth199096
71*a237e38eSth199096 int len;
72*a237e38eSth199096
73*a237e38eSth199096 (void) setlocale(LC_ALL, "");
74*a237e38eSth199096
75*a237e38eSth199096 #if !defined(TEXT_DOMAIN)
76*a237e38eSth199096 #define TEXT_DOMAIN "SYS_TEST"
77*a237e38eSth199096 #endif
78*a237e38eSth199096 (void) textdomain(TEXT_DOMAIN);
79*a237e38eSth199096
80*a237e38eSth199096
81*a237e38eSth199096 myname = strrchr(argv[0], '/');
82*a237e38eSth199096 myname = myname ? myname + 1 : argv[0];
83*a237e38eSth199096
84*a237e38eSth199096 len = strlen(fstype) + 1 + strlen(myname);
85*a237e38eSth199096 typename = malloc(len + 1);
86*a237e38eSth199096 if (!typename) {
87*a237e38eSth199096 (void) fprintf(stderr, gettext("%s: out of memory\n"),
88*a237e38eSth199096 myname);
89*a237e38eSth199096 return (EXIT_MAGIC);
90*a237e38eSth199096 }
91*a237e38eSth199096
92*a237e38eSth199096 (void) snprintf(typename, len, "%s %s", fstype, myname);
93*a237e38eSth199096 argv[0] = typename;
94*a237e38eSth199096
95*a237e38eSth199096 while ((c = getopt(argc, argv, "o:rmOq")) != EOF) {
96*a237e38eSth199096 switch (c) {
97*a237e38eSth199096 case '?':
98*a237e38eSth199096 error_flag = 1;
99*a237e38eSth199096 break;
100*a237e38eSth199096
101*a237e38eSth199096 case 'o':
102*a237e38eSth199096 if (strlcpy(optbuf, optarg, sizeof (optbuf)) >=
103*a237e38eSth199096 sizeof (optbuf)) {
104*a237e38eSth199096 (void) fprintf(stderr,
105*a237e38eSth199096 gettext("%s: Invalid argument: %s\n"),
106*a237e38eSth199096 myname, optarg);
107*a237e38eSth199096 free(typename);
108*a237e38eSth199096 return (EXIT_MAGIC);
109*a237e38eSth199096 }
110*a237e38eSth199096 optsize = strlen(optbuf);
111*a237e38eSth199096 break;
112*a237e38eSth199096 case 'O':
113*a237e38eSth199096 flags |= MS_OVERLAY;
114*a237e38eSth199096 break;
115*a237e38eSth199096 case 'r':
116*a237e38eSth199096 flags |= MS_RDONLY;
117*a237e38eSth199096 break;
118*a237e38eSth199096
119*a237e38eSth199096 case 'm':
120*a237e38eSth199096 flags |= MS_NOMNTTAB;
121*a237e38eSth199096 break;
122*a237e38eSth199096
123*a237e38eSth199096 case 'q':
124*a237e38eSth199096 q_flag = 1;
125*a237e38eSth199096 break;
126*a237e38eSth199096
127*a237e38eSth199096 default:
128*a237e38eSth199096 usage();
129*a237e38eSth199096 }
130*a237e38eSth199096 }
131*a237e38eSth199096 if ((argc - optind != 2) || error_flag) {
132*a237e38eSth199096 usage();
133*a237e38eSth199096 }
134*a237e38eSth199096 special = argv[argc - 2];
135*a237e38eSth199096 mountp = argv[argc - 1];
136*a237e38eSth199096
137*a237e38eSth199096 if ((savedoptbuf = strdup(optbuf)) == NULL) {
138*a237e38eSth199096 (void) fprintf(stderr, gettext("%s: out of memory\n"),
139*a237e38eSth199096 myname);
140*a237e38eSth199096 free(typename);
141*a237e38eSth199096 exit(EXIT_MAGIC);
142*a237e38eSth199096 }
143*a237e38eSth199096 if (mount(special, mountp, flags | MS_OPTIONSTR, fstype, NULL, 0,
144*a237e38eSth199096 optbuf, MAX_MNTOPT_STR)) {
145*a237e38eSth199096 (void) fprintf(stderr, "mount: ");
146*a237e38eSth199096 perror(special);
147*a237e38eSth199096 free(typename);
148*a237e38eSth199096 exit(RET_ERR);
149*a237e38eSth199096 }
150*a237e38eSth199096 if (optsize && !q_flag)
151*a237e38eSth199096 cmp_requested_to_actual_options(savedoptbuf, optbuf,
152*a237e38eSth199096 special, mountp);
153*a237e38eSth199096 free(typename);
154*a237e38eSth199096 return (RET_OK);
155*a237e38eSth199096 }
156*a237e38eSth199096
157*a237e38eSth199096 static void
usage(void)158*a237e38eSth199096 usage(void)
159*a237e38eSth199096 {
160*a237e38eSth199096 (void) fprintf(stderr,
161*a237e38eSth199096 gettext("Usage: mount [-Ormq] [-o options] special mountpoint\n"));
162*a237e38eSth199096 exit(RET_ERR);
163*a237e38eSth199096 }
164