1 /* $NetBSD: mount_msdos.c,v 1.46 2008/08/05 20:57:45 pooka Exp $ */
4 * Copyright (c) 1994 Christopher G. Demetriou
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
34 * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
37 #include <sys/cdefs.h>
39 __RCSID("$NetBSD: mount_msdos.c,v 1.46 2008/08/05 20:57:45 pooka Exp $");
42 #include <sys/param.h>
43 #include <sys/mount.h>
45 #include <msdosfs/msdosfsmount.h>
58 #include "mountprog.h"
59 #include "mount_msdos.h"
61 static const struct mntopt mopts
[] = {
70 static void usage(void) __dead
;
74 main(int argc
, char **argv
)
78 return mount_msdos(argc
, argv
);
83 mount_msdos_parseargs(int argc
, char **argv
,
84 struct msdosfs_args
*args
, int *mntflags
,
85 char *canon_dev
, char *canon_dir
)
88 int c
, set_gid
, set_uid
, set_mask
, set_dirmask
, set_gmtoff
;
94 *mntflags
= set_gid
= set_uid
= set_mask
= set_dirmask
= set_gmtoff
= 0;
95 (void)memset(args
, '\0', sizeof(*args
));
97 while ((c
= getopt(argc
, argv
, "Gsl9u:g:m:M:o:t:")) != -1) {
100 args
->flags
|= MSDOSFSMNT_GEMDOSFS
;
103 args
->flags
|= MSDOSFSMNT_SHORTNAME
;
106 args
->flags
|= MSDOSFSMNT_LONGNAME
;
109 args
->flags
|= MSDOSFSMNT_NOWIN95
;
112 args
->uid
= a_uid(optarg
);
116 args
->gid
= a_gid(optarg
);
120 args
->mask
= a_mask(optarg
);
124 args
->dirmask
= a_mask(optarg
);
128 mp
= getmntopts(optarg
, mopts
, mntflags
, 0);
130 err(1, "getmntopts");
134 args
->gmtoff
= atoi(optarg
);
144 if (optind
+ 2 != argc
)
147 if (set_mask
&& !set_dirmask
) {
148 args
->dirmask
= args
->mask
;
150 } else if (set_dirmask
&& !set_mask
) {
151 args
->mask
= args
->dirmask
;
156 dir
= argv
[optind
+ 1];
158 pathadj(dev
, canon_dev
);
159 pathadj(dir
, canon_dir
);
161 args
->fspec
= canon_dev
;
162 if (!set_gid
|| !set_uid
|| !set_mask
) {
163 if (stat(dir
, &sb
) == -1)
164 err(1, "stat %s", dir
);
167 args
->uid
= sb
.st_uid
;
169 args
->gid
= sb
.st_gid
;
171 args
->mask
= args
->dirmask
=
172 sb
.st_mode
& (S_IRWXU
| S_IRWXG
| S_IRWXO
);
177 /* use user's time zone as default */
179 tm
= localtime(&now
);
180 args
->gmtoff
= tm
->tm_gmtoff
;
183 args
->flags
|= MSDOSFSMNT_VERSIONED
;
184 args
->version
= MSDOSFSMNT_VERSION
;
188 mount_msdos(int argc
, char **argv
)
190 struct msdosfs_args args
;
191 char canon_dev
[MAXPATHLEN
], canon_dir
[MAXPATHLEN
];
194 mount_msdos_parseargs(argc
, argv
, &args
, &mntflags
,
195 canon_dev
, canon_dir
);
197 if (mount(MOUNT_MSDOS
, canon_dir
, mntflags
, &args
, sizeof args
) == -1)
198 err(1, "%s on %s", canon_dev
, canon_dir
);
200 if (mntflags
& MNT_GETARGS
) {
202 (void)snprintb(buf
, sizeof(buf
), MSDOSFSMNT_BITS
, args
.flags
);
203 printf("uid=%d, gid=%d, mask=0%o, dirmask=0%o, flags=%s\n",
204 args
.uid
, args
.gid
, args
.mask
, args
.dirmask
, buf
);
214 fprintf(stderr
, "usage: %s [-9Gls] [-g gid] [-M mask] [-m mask] "
215 "[-o options]\n\t[-t gmtoff] [-u uid] special mountpath\n",