dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / fs.d / hsfs / mount / mount.c
blob7d296567aa022436ee7a8fa3b78c9254b9096f78
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <ctype.h>
30 #include <string.h>
31 #include <stdio.h>
32 #include <unistd.h> /* defines F_LOCK for lockf */
33 #include <stdlib.h> /* for getopt(3) */
34 #include <signal.h>
35 #include <locale.h>
36 #include <fslib.h>
37 #include <sys/types.h>
38 #include <errno.h>
39 #include <sys/mnttab.h>
40 #include <sys/mntent.h>
41 #include <sys/mount.h>
42 #include <sys/vfs.h>
43 #include <sys/fs/hsfs_susp.h>
44 #include <sys/fs/hsfs_rrip.h>
46 extern int optind;
47 extern char *optarg;
49 #define NAME_MAX 64
51 static int qflg = 0; /* quiet option - don't flag bad options */
53 static char fstype[] = MNTTYPE_HSFS;
55 static char typename[NAME_MAX], *myname;
57 static void rpterr(char *, char *);
58 static void usage(void);
60 int
61 main(int argc, char **argv)
63 char *options, *value;
64 char *special, *mountp;
65 struct mnttab mm;
66 int c;
67 char obuff[MAX_MNTOPT_STR];
68 char saved_input_options[MAX_MNTOPT_STR];
69 int hsfs_flags;
71 int flags;
72 int Oflg = 0; /* Overlay mounts */
74 (void) setlocale(LC_ALL, "");
76 #if !defined(TEXT_DOMAIN)
77 #define TEXT_DOMAIN "SYS_TEST"
78 #endif
79 (void) textdomain(TEXT_DOMAIN);
81 myname = strrchr(argv[0], '/');
82 if (myname)
83 myname++;
84 else
85 myname = argv[0];
86 snprintf(typename, sizeof (typename), "%s %s", fstype, myname);
87 argv[0] = typename;
90 * Check for arguments requiring special handling. Ignore
91 * unrecognized options.
93 strcpy(obuff, "ro"); /* default */
94 while ((c = getopt(argc, argv, "rmOq")) != EOF) {
95 switch (c) {
96 case 'O':
97 Oflg++;
98 break;
99 case 'r':
100 /* accept for backwards compatibility */
101 break;
102 case 'm':
103 break;
104 case 'q':
105 qflg++;
106 break;
111 if ((argc - optind) != 2)
112 usage();
114 special = argv[optind++];
115 mountp = argv[optind++];
118 * Force readonly. obuff is guaranteed to have something in
119 * it. We might end up with "ro,ro", but that's acceptable.
121 flags = MS_RDONLY;
123 if ((strlen(obuff) + strlen(MNTOPT_RO) + 2) > MAX_MNTOPT_STR) {
124 (void) fprintf(stderr, gettext("%s: option set too long\n"),
125 myname);
126 exit(1);
129 strcat(obuff, ",");
130 strcat(obuff, MNTOPT_RO);
132 flags |= Oflg ? MS_OVERLAY : 0;
134 signal(SIGHUP, SIG_IGN);
135 signal(SIGQUIT, SIG_IGN);
136 signal(SIGINT, SIG_IGN);
139 * Save a copy of the options to compare with the options that
140 * were actually recognized and supported by the kernel.
143 (void) strcpy(saved_input_options, obuff);
146 * Perform the mount.
149 if (mount(special, mountp, flags | MS_OPTIONSTR, fstype, NULL, 0,
150 obuff, sizeof (obuff)) == -1) {
151 rpterr(special, mountp);
152 exit(31+2);
155 if (!qflg) {
156 cmp_requested_to_actual_options(saved_input_options, obuff,
157 special, mountp);
160 exit(0);
161 /* NOTREACHED */
165 static void
166 rpterr(char *bs, char *mp)
168 switch (errno) {
169 case EPERM:
170 (void) fprintf(stderr, gettext("%s: insufficient privileges\n"),
171 myname);
172 break;
173 case ENXIO:
174 (void) fprintf(stderr, gettext("%s: %s no such device\n"),
175 myname, bs);
176 break;
177 case ENOTDIR:
178 (void) fprintf(stderr, gettext("%s: %s not a directory\n\tor a "
179 "component of %s is not a directory\n"), myname, mp, bs);
180 break;
181 case ENOENT:
182 (void) fprintf(stderr,
183 gettext("%s: %s or %s, no such file or directory\n"),
184 myname, bs, mp);
185 break;
186 case EINVAL:
187 (void) fprintf(stderr, gettext("%s: %s is not an hsfs file "
188 "system.\n"), typename, bs);
189 break;
190 case EBUSY:
191 (void) fprintf(stderr,
192 gettext("%s: %s is already mounted or %s is busy\n"),
193 myname, bs, mp);
194 break;
195 case ENOTBLK:
196 (void) fprintf(stderr,
197 gettext("%s: %s not a block device\n"), myname, bs);
198 break;
199 case EROFS:
200 (void) fprintf(stderr, gettext("%s: %s write-protected\n"),
201 myname, bs);
202 break;
203 case ENOSPC:
204 (void) fprintf(stderr,
205 gettext("%s: %s is corrupted. needs checking\n"),
206 myname, bs);
207 break;
208 default:
209 perror(myname);
210 (void) fprintf(stderr, gettext("%s: cannot mount %s\n"), myname,
211 bs);
216 static void
217 usage()
219 char *opts;
221 opts = "{-r | -o ro | -o nrr | -o nosuid | -o notraildot | -o nomaplcase}";
222 (void) fprintf(stdout,
223 gettext("hsfs usage: mount [-F hsfs] %s {special | mount_point}\n"), opts);
224 (void) fprintf(stdout,
225 gettext("hsfs usage: mount [-F hsfs] %s special mount_point\n"), opts);
226 exit(32);