10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * 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.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*3957Sth199096 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
270Sstevel@tonic-gate
280Sstevel@tonic-gate #include <stdio.h>
290Sstevel@tonic-gate #include <stdlib.h>
300Sstevel@tonic-gate #include <string.h>
310Sstevel@tonic-gate #include <libintl.h>
320Sstevel@tonic-gate #include <errno.h>
330Sstevel@tonic-gate #include <sys/fstyp.h>
340Sstevel@tonic-gate #include <sys/fsid.h>
350Sstevel@tonic-gate #include <sys/mntent.h>
360Sstevel@tonic-gate #include <sys/mnttab.h>
370Sstevel@tonic-gate #include <sys/mount.h>
380Sstevel@tonic-gate #include <sys/signal.h>
390Sstevel@tonic-gate #include <sys/stat.h>
400Sstevel@tonic-gate #include <fslib.h>
41*3957Sth199096 #include <locale.h>
420Sstevel@tonic-gate
430Sstevel@tonic-gate #define RET_OK 0
440Sstevel@tonic-gate #define RET_ERR 33
45*3957Sth199096 #define EXIT_MAGIC 2
460Sstevel@tonic-gate
470Sstevel@tonic-gate static void usage(void);
480Sstevel@tonic-gate
490Sstevel@tonic-gate static char optbuf[MAX_MNTOPT_STR] = { '\0', };
500Sstevel@tonic-gate static int optsize = 0;
510Sstevel@tonic-gate
520Sstevel@tonic-gate static char fstype[] = "objfs";
530Sstevel@tonic-gate
540Sstevel@tonic-gate /*
550Sstevel@tonic-gate * usage: mount [-Ormq] [-o options] special mountp
560Sstevel@tonic-gate *
570Sstevel@tonic-gate * This mount program is exec'ed by /usr/sbin/mount if '-F objfs' is
580Sstevel@tonic-gate * specified.
590Sstevel@tonic-gate */
600Sstevel@tonic-gate int
main(int argc,char * argv[])610Sstevel@tonic-gate main(int argc, char *argv[])
620Sstevel@tonic-gate {
630Sstevel@tonic-gate int c;
640Sstevel@tonic-gate char *special; /* Entity being mounted */
650Sstevel@tonic-gate char *mountp; /* Entity being mounted on */
660Sstevel@tonic-gate char *savedoptbuf;
670Sstevel@tonic-gate char *myname;
68*3957Sth199096 char *typename;
690Sstevel@tonic-gate 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
820Sstevel@tonic-gate
830Sstevel@tonic-gate 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);
950Sstevel@tonic-gate argv[0] = typename;
960Sstevel@tonic-gate
970Sstevel@tonic-gate while ((c = getopt(argc, argv, "o:rmOq")) != EOF) {
980Sstevel@tonic-gate switch (c) {
990Sstevel@tonic-gate case '?':
100*3957Sth199096 error_flag = 1;
1010Sstevel@tonic-gate break;
1020Sstevel@tonic-gate
1030Sstevel@tonic-gate case 'o':
1040Sstevel@tonic-gate if (strlcpy(optbuf, optarg, sizeof (optbuf)) >=
1050Sstevel@tonic-gate sizeof (optbuf)) {
1060Sstevel@tonic-gate (void) fprintf(stderr,
1070Sstevel@tonic-gate gettext("%s: Invalid argument: %s\n"),
1080Sstevel@tonic-gate myname, optarg);
109*3957Sth199096 free(typename);
110*3957Sth199096 return (EXIT_MAGIC);
1110Sstevel@tonic-gate }
1120Sstevel@tonic-gate optsize = strlen(optbuf);
1130Sstevel@tonic-gate break;
1140Sstevel@tonic-gate case 'O':
1150Sstevel@tonic-gate flags |= MS_OVERLAY;
1160Sstevel@tonic-gate break;
1170Sstevel@tonic-gate case 'r':
1180Sstevel@tonic-gate flags |= MS_RDONLY;
1190Sstevel@tonic-gate break;
1200Sstevel@tonic-gate
1210Sstevel@tonic-gate case 'm':
1220Sstevel@tonic-gate flags |= MS_NOMNTTAB;
1230Sstevel@tonic-gate break;
1240Sstevel@tonic-gate
1250Sstevel@tonic-gate case 'q':
126*3957Sth199096 q_flag = 1;
1270Sstevel@tonic-gate break;
1280Sstevel@tonic-gate
1290Sstevel@tonic-gate default:
1300Sstevel@tonic-gate usage();
1310Sstevel@tonic-gate }
1320Sstevel@tonic-gate }
133*3957Sth199096 if ((argc - optind != 2) || error_flag) {
1340Sstevel@tonic-gate usage();
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate special = argv[argc - 2];
1370Sstevel@tonic-gate mountp = argv[argc - 1];
1380Sstevel@tonic-gate
1390Sstevel@tonic-gate if ((savedoptbuf = strdup(optbuf)) == NULL) {
1400Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: out of memory\n"),
1410Sstevel@tonic-gate myname);
142*3957Sth199096 free(typename);
143*3957Sth199096 exit(EXIT_MAGIC);
1440Sstevel@tonic-gate }
1450Sstevel@tonic-gate if (mount(special, mountp, flags | MS_OPTIONSTR, fstype, NULL, 0,
1460Sstevel@tonic-gate optbuf, MAX_MNTOPT_STR)) {
1470Sstevel@tonic-gate (void) fprintf(stderr, "mount: ");
1480Sstevel@tonic-gate perror(special);
149*3957Sth199096 free(typename);
1500Sstevel@tonic-gate exit(RET_ERR);
1510Sstevel@tonic-gate }
152*3957Sth199096 if (optsize && !q_flag)
1530Sstevel@tonic-gate cmp_requested_to_actual_options(savedoptbuf, optbuf,
1540Sstevel@tonic-gate special, mountp);
155*3957Sth199096 free(typename);
156*3957Sth199096 return (RET_OK);
1570Sstevel@tonic-gate }
1580Sstevel@tonic-gate
159*3957Sth199096 static void
usage(void)1600Sstevel@tonic-gate usage(void)
1610Sstevel@tonic-gate {
1620Sstevel@tonic-gate (void) fprintf(stderr,
163*3957Sth199096 gettext("Usage: mount [-Ormq] [-o options] special mountpoint\n"));
1640Sstevel@tonic-gate exit(RET_ERR);
1650Sstevel@tonic-gate }
166