2 * Copyright (c) 1994 Christopher G. Demetriou
3 * Copyright (c) 1999 Semen Ustimenko (semenu@FreeBSD.org)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Christopher G. Demetriou.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/cdefs.h>
35 #include <sys/param.h>
36 #include <sys/mount.h>
38 #include <fs/hpfs/hpfsmount.h>
51 static struct mntopt mopts[] = {
56 static gid_t a_gid(char *);
57 static uid_t a_uid(char *);
58 static mode_t a_mask(char *);
59 static void usage(void) __dead2;
60 static void load_u2wtable(struct hpfs_args *, char *);
67 struct hpfs_args args;
69 int c, mntflags, set_gid, set_uid, set_mask,error;
71 char *dev, *dir, ndir[MAXPATHLEN+1];
72 #if __FreeBSD_version >= 300000
78 mntflags = set_gid = set_uid = set_mask = 0;
79 (void)memset(&args, '\0', sizeof(args));
81 while ((c = getopt(argc, argv, "u:g:m:o:c:W:F")) != -1) {
87 args.uid = a_uid(optarg);
91 args.gid = a_gid(optarg);
95 args.mode = a_mask(optarg);
99 getmntopts(optarg, mopts, &mntflags, 0);
102 load_u2wtable(&args, optarg);
103 args.flags |= HPFSMNT_TABLES;
112 if (optind + 2 != argc)
115 if (!(mntflags & MNT_RDONLY) && !forcerw) {
116 warnx("Write support is BETA, you need -F flag to enable RW mount!");
121 dir = argv[optind + 1];
123 warnx("\"%s\" is a relative path", dir);
124 if (getcwd(ndir, sizeof(ndir)) == NULL)
125 err(EX_OSERR, "getcwd");
126 strncat(ndir, "/", sizeof(ndir) - strlen(ndir) - 1);
127 strncat(ndir, dir, sizeof(ndir) - strlen(ndir) - 1);
129 warnx("using \"%s\" instead", dir);
133 args.export.ex_root = 65534; /* unchecked anyway on DOS fs */
134 if (mntflags & MNT_RDONLY)
135 args.export.ex_flags = MNT_EXRDONLY;
137 args.export.ex_flags = 0;
139 if (!set_gid || !set_uid || !set_mask) {
140 if (stat(dir, &sb) == -1)
141 err(EX_OSERR, "stat %s", dir);
144 args.uid = sb.st_uid;
146 args.gid = sb.st_gid;
148 args.mode = sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
151 #if __FreeBSD_version >= 300000
152 error = getvfsbyname("hpfs", &vfc);
153 if(error && vfsisloadable("hpfs")) {
156 vfc = getvfsbyname("hpfs");
157 if(!vfc && vfsisloadable("hpfs")) {
160 err(EX_OSERR, "vfsload(hpfs)");
161 endvfsent(); /* clear cache */
162 #if __FreeBSD_version >= 300000
163 error = getvfsbyname("hpfs", &vfc);
165 vfc = getvfsbyname("hpfs");
168 #if __FreeBSD_version >= 300000
173 errx(EX_OSERR, "hpfs filesystem is not available");
175 #if __FreeBSD_version >= 300000
176 if (mount(vfc.vfc_name, dir, mntflags, &args) < 0)
178 if (mount(vfc->vfc_index, dir, mntflags, &args) < 0)
180 err(EX_OSERR, "%s", dev);
193 if ((gr = getgrnam(s)) != NULL)
196 for (gname = s; *s && isdigit(*s); ++s);
200 errx(EX_NOUSER, "unknown group id: %s", gname);
213 if ((pw = getpwnam(s)) != NULL)
216 for (uname = s; *s && isdigit(*s); ++s);
220 errx(EX_NOUSER, "unknown user id: %s", uname);
233 if (*s >= '0' && *s <= '7') {
235 rv = strtol(optarg, &ep, 8);
237 if (!done || rv < 0 || *ep)
238 errx(EX_USAGE, "invalid file mode: %s", s);
245 fprintf(stderr, "usage: mount_hpfs [-u user] [-g group] [-m mask] bdev dir\n");
250 load_u2wtable (pargs, name)
251 struct hpfs_args *pargs;
262 snprintf(buf, sizeof(buf), "/usr/libdata/msdosfs/%s", name);
266 if ((f = fopen(fn, "r")) == NULL)
267 err(EX_NOINPUT, "%s", fn);
268 for (i = 0; i < 128; i++) {
269 if (fscanf(f, "%i", &code) != 1)
270 errx(EX_DATAERR, "u2w: missing item number %d", i);
271 /* pargs->u2w[i] = code; */
273 for (i = 0; i < 128; i++) {
274 if (fscanf(f, "%i", &code) != 1)
275 errx(EX_DATAERR, "d2u: missing item number %d", i);
276 pargs->d2u[i] = code;
278 for (i = 0; i < 128; i++) {
279 if (fscanf(f, "%i", &code) != 1)
280 errx(EX_DATAERR, "u2d: missing item number %d", i);
281 pargs->u2d[i] = code;