mount_msdos.c revision 1.24 1 /* $NetBSD: mount_msdos.c,v 1.24 2000/10/30 20:57:00 jdolecek Exp $ */
2
3 /*
4 * Copyright (c) 1994 Christopher G. Demetriou
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the
18 * NetBSD Project. See http://www.netbsd.org/ for
19 * information about NetBSD.
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
35 */
36
37 #include <sys/cdefs.h>
38 #ifndef lint
39 __RCSID("$NetBSD: mount_msdos.c,v 1.24 2000/10/30 20:57:00 jdolecek Exp $");
40 #endif /* not lint */
41
42 #include <sys/cdefs.h>
43 #include <sys/param.h>
44 #include <sys/mount.h>
45 #include <sys/stat.h>
46 #include <msdosfs/msdosfsmount.h>
47 #include <ctype.h>
48 #include <err.h>
49 #include <grp.h>
50 #include <pwd.h>
51 #include <stdio.h>
52 #include <stdlib.h>
53 #include <string.h>
54 #include <unistd.h>
55
56 #include "mntopts.h"
57 #include <fattr.h>
58
59 static const struct mntopt mopts[] = {
60 MOPT_STDOPTS,
61 MOPT_ASYNC,
62 MOPT_SYNC,
63 MOPT_UPDATE,
64 { NULL }
65 };
66
67 int main __P((int, char *[]));
68 int mount_msdos __P((int argc, char **argv));
69 static void usage __P((void));
70
71 #ifndef MOUNT_NOMAIN
72 int
73 main(argc, argv)
74 int argc;
75 char **argv;
76 {
77 return mount_msdos(argc, argv);
78 }
79 #endif
80
81 int
82 mount_msdos(argc, argv)
83 int argc;
84 char **argv;
85 {
86 struct msdosfs_args args;
87 struct stat sb;
88 int c, mntflags, set_gid, set_uid, set_mask;
89 char *dev, *dir, ndir[MAXPATHLEN+1];
90
91 mntflags = set_gid = set_uid = set_mask = 0;
92 (void)memset(&args, '\0', sizeof(args));
93
94 while ((c = getopt(argc, argv, "Gsl9u:g:m:o:")) != -1) {
95 switch (c) {
96 case 'G':
97 args.flags |= MSDOSFSMNT_GEMDOSFS;
98 break;
99 case 's':
100 args.flags |= MSDOSFSMNT_SHORTNAME;
101 break;
102 case 'l':
103 args.flags |= MSDOSFSMNT_LONGNAME;
104 break;
105 case '9':
106 args.flags |= MSDOSFSMNT_NOWIN95;
107 break;
108 case 'u':
109 args.uid = a_uid(optarg);
110 set_uid = 1;
111 break;
112 case 'g':
113 args.gid = a_gid(optarg);
114 set_gid = 1;
115 break;
116 case 'm':
117 args.mask = a_mask(optarg);
118 set_mask = 1;
119 break;
120 case 'o':
121 getmntopts(optarg, mopts, &mntflags, 0);
122 break;
123 case '?':
124 default:
125 usage();
126 break;
127 }
128 }
129
130 if (optind + 2 != argc)
131 usage();
132
133 dev = argv[optind];
134 dir = argv[optind + 1];
135 if (dir[0] != '/') {
136 warnx("\"%s\" is a relative path.", dir);
137 if (getcwd(ndir, sizeof(ndir)) == NULL)
138 err(1, "getcwd");
139 strncat(ndir, "/", sizeof(ndir) - strlen(ndir) - 1);
140 strncat(ndir, dir, sizeof(ndir) - strlen(ndir) - 1);
141 dir = ndir;
142 warnx("using \"%s\" instead.", dir);
143 }
144
145 args.fspec = dev;
146 args.export.ex_root = -2; /* unchecked anyway on DOS fs */
147 if (mntflags & MNT_RDONLY)
148 args.export.ex_flags = MNT_EXRDONLY;
149 else
150 args.export.ex_flags = 0;
151 if (!set_gid || !set_uid || !set_mask) {
152 if (stat(dir, &sb) == -1)
153 err(1, "stat %s", dir);
154
155 if (!set_uid)
156 args.uid = sb.st_uid;
157 if (!set_gid)
158 args.gid = sb.st_gid;
159 if (!set_mask)
160 args.mask = sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
161 }
162
163 if (mount(MOUNT_MSDOS, dir, mntflags, &args) < 0)
164 err(1, "%s on %s", dev, dir);
165
166 exit (0);
167 }
168
169 static void
170 usage()
171 {
172
173 fprintf(stderr, "usage: mount_msdos [-o options] [-u user] [-g group] [-m mask] bdev dir\n");
174 exit(1);
175 }
176