5887 want bootfs
[unleashed.git] / usr / src / cmd / fs.d / bootfs / mount.c
blob5363a4f872eb6c12459d7bda8e7f15243e74390d
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright (c) 2014 Joyent, Inc. All rights reserved.
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <libintl.h>
32 #include <errno.h>
33 #include <sys/fstyp.h>
34 #include <sys/fsid.h>
35 #include <sys/mntent.h>
36 #include <sys/mnttab.h>
37 #include <sys/mount.h>
38 #include <sys/signal.h>
39 #include <sys/stat.h>
40 #include <fslib.h>
42 #define MNTTYPE_BOOTFS "bootfs"
44 static char optbuf[MAX_MNTOPT_STR] = { '\0', };
45 static int optsize = 0;
47 static void
48 usage(void)
50 (void) fprintf(stderr,
51 "Usage: mount [-Ormq] [-o options] special mountpoint\n");
52 exit(2);
56 * usage: mount [-Ormq] [-o options] special mountp
58 * This mount program is exec'ed by /usr/sbin/mount if '-F bootfs' is
59 * specified.
61 int
62 main(int argc, char *argv[])
64 int c;
65 char *special; /* Entity being mounted */
66 char *mountp; /* Entity being mounted on */
67 char *savedoptbuf;
68 char *myname;
69 char typename[64];
70 int flags = 0;
71 int errflag = 0;
72 int qflg = 0;
74 myname = strrchr(argv[0], '/');
75 myname = myname ? myname+1 : argv[0];
76 (void) snprintf(typename, sizeof (typename), "%s %s", MNTTYPE_BOOTFS,
77 myname);
78 argv[0] = typename;
80 while ((c = getopt(argc, argv, "o:rmOq")) != EOF) {
81 switch (c) {
82 case '?':
83 errflag++;
84 break;
86 case 'o':
87 if (strlcpy(optbuf, optarg, sizeof (optbuf)) >=
88 sizeof (optbuf)) {
89 (void) fprintf(stderr,
90 gettext("%s: Invalid argument: %s\n"),
91 myname, optarg);
92 return (2);
94 optsize = strlen(optbuf);
95 break;
96 case 'O':
97 flags |= MS_OVERLAY;
98 break;
99 case 'r':
100 flags |= MS_RDONLY;
101 break;
103 case 'm':
104 flags |= MS_NOMNTTAB;
105 break;
107 case 'q':
108 qflg = 1;
109 break;
111 default:
112 usage();
115 if ((argc - optind != 2) || errflag) {
116 usage();
118 special = argv[argc - 2];
119 mountp = argv[argc - 1];
121 if ((savedoptbuf = strdup(optbuf)) == NULL) {
122 (void) fprintf(stderr, gettext("%s: out of memory\n"),
123 myname);
124 exit(2);
127 if (mount(special, mountp, flags | MS_OPTIONSTR, MNTTYPE_BOOTFS, NULL,
128 0, optbuf, MAX_MNTOPT_STR)) {
129 (void) fprintf(stderr, "mount: ");
130 perror(special);
131 exit(2);
133 if (optsize && !qflg) {
134 cmp_requested_to_actual_options(savedoptbuf, optbuf,
135 special, mountp);
138 return (0);