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