8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / fs.d / lofs / mount / mount.c
blob9ae78ac226bbc418f3535292e230b3fa71981bf8
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.
27 #define LOFS
28 #define MNTTYPE_LOFS "lofs"
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <libintl.h>
33 #include <errno.h>
34 #include <sys/fstyp.h>
35 #include <sys/fsid.h>
36 #include <sys/mntent.h>
37 #include <sys/mnttab.h>
38 #include <sys/mount.h>
39 #include <sys/signal.h>
40 #include <sys/stat.h>
41 #include <fslib.h>
43 #define RET_OK 0
45 * /sbin/mount and the fs-local method understand this exit code to
46 * mean that all the mount failures were related to lofs mounts. Since
47 * this program only attempts to mount lofs file systems, when it fails
48 * it returns this exit status.
50 #define RET_ERR 111
52 static void usage(void);
54 static char optbuf[MAX_MNTOPT_STR] = { '\0', };
55 static int optsize = 0;
57 static char fstype[] = MNTTYPE_LOFS;
60 * usage: mount [-Ormq] [-o options] special mountp
62 * This mount program is exec'ed by /usr/sbin/mount if '-F lofs' is
63 * specified.
65 int
66 main(int argc, char *argv[])
68 int c;
69 char *special; /* Entity being mounted */
70 char *mountp; /* Entity being mounted on */
71 char *savedoptbuf;
72 char *myname;
73 char typename[64];
74 int flags = 0;
75 int errflag = 0;
76 int qflg = 0;
78 myname = strrchr(argv[0], '/');
79 myname = myname ? myname+1 : argv[0];
80 (void) snprintf(typename, sizeof (typename), "%s %s", fstype, myname);
81 argv[0] = typename;
83 while ((c = getopt(argc, argv, "o:rmOq")) != EOF) {
84 switch (c) {
85 case '?':
86 errflag++;
87 break;
89 case 'o':
90 if (strlcpy(optbuf, optarg, sizeof (optbuf)) >=
91 sizeof (optbuf)) {
92 (void) fprintf(stderr,
93 gettext("%s: Invalid argument: %s\n"),
94 myname, optarg);
95 return (2);
97 optsize = strlen(optbuf);
98 break;
99 case 'O':
100 flags |= MS_OVERLAY;
101 break;
102 case 'r':
103 flags |= MS_RDONLY;
104 break;
106 case 'm':
107 flags |= MS_NOMNTTAB;
108 break;
110 case 'q':
111 qflg = 1;
112 break;
114 default:
115 usage();
118 if ((argc - optind != 2) || errflag) {
119 usage();
121 special = argv[argc - 2];
122 mountp = argv[argc - 1];
124 if ((savedoptbuf = strdup(optbuf)) == NULL) {
125 (void) fprintf(stderr, gettext("%s: out of memory\n"),
126 myname);
127 exit(2);
129 if (mount(special, mountp, flags | MS_OPTIONSTR, fstype, NULL, 0,
130 optbuf, MAX_MNTOPT_STR)) {
131 (void) fprintf(stderr, "mount: ");
132 perror(special);
133 exit(RET_ERR);
135 if (optsize && !qflg)
136 cmp_requested_to_actual_options(savedoptbuf, optbuf,
137 special, mountp);
138 return (0);
141 void
142 usage(void)
144 (void) fprintf(stderr,
145 "Usage: mount [-Ormq] [-o options] special mountpoint\n");
146 exit(RET_ERR);