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