1 /* $NetBSD: mount_filecore.c,v 1.5 2002/09/21 18:43:34 christos Exp $ */ 2 3 /* 4 * Copyright (c) 1998 Andrew McMurry 5 * Copyright (c) 1992, 1993, 1994 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * This code is contains code contributed to the NetBSD project by 9 * Christopher G. Demetriou 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by the University of 22 * California, Berkeley and its contributors. 23 * 4. Neither the name of the University nor the names of its contributors 24 * may be used to endorse or promote products derived from this software 25 * without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * 39 * mount_filecore.c 1.1 1998/6/26 40 */ 41 42 #include <sys/cdefs.h> 43 #ifndef lint 44 __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\ 45 The Regents of the University of California.\n\ 46 Copyright (c) 1998 Andrew McMurry\n\ 47 All rights reserved.\n"); 48 #endif /* not lint */ 49 50 #include <sys/param.h> 51 #include <sys/mount.h> 52 53 #include <ctype.h> 54 #include <err.h> 55 #include <grp.h> 56 #include <pwd.h> 57 #include <stdlib.h> 58 #include <stdio.h> 59 #include <string.h> 60 #include <unistd.h> 61 #include <util.h> 62 63 #include <filecorefs/filecore_mount.h> 64 65 #include "mntopts.h" 66 #include <fattr.h> 67 68 static const struct mntopt mopts[] = { 69 MOPT_STDOPTS, 70 MOPT_UPDATE, 71 MOPT_GETARGS, 72 { NULL } 73 }; 74 75 int main __P((int, char *[])); 76 int mount_filecore __P((int argc, char **argv)); 77 static void usage __P((void)); 78 79 #ifndef MOUNT_NOMAIN 80 int 81 main(argc, argv) 82 int argc; 83 char **argv; 84 { 85 return mount_filecore(argc, argv); 86 } 87 #endif 88 89 int 90 mount_filecore(argc, argv) 91 int argc; 92 char **argv; 93 { 94 struct filecore_args args; 95 int ch, mntflags, opts, useuid; 96 char *dev, *dir; 97 98 mntflags = opts = 0; 99 useuid = 1; 100 args.uid = 0; 101 args.gid = 0; 102 103 while ((ch = getopt(argc, argv, "anRfu:g:o:")) != -1) 104 switch (ch) { 105 case 'a': 106 args.flags |= FILECOREMNT_ALLACCESS; 107 break; 108 case 'n': 109 args.flags |= FILECOREMNT_OWNACCESS; 110 break; 111 case 'R': 112 args.flags |= FILECOREMNT_OWNREAD; 113 break; 114 case 'f': 115 args.flags |= FILECOREMNT_FILETYPE; 116 break; 117 case 'u': 118 args.uid = a_uid(optarg); 119 useuid = 0; 120 break; 121 case 'g': 122 args.gid = a_gid(optarg); 123 useuid = 0; 124 break; 125 case 'o': 126 getmntopts(optarg, mopts, &mntflags, 0); 127 break; 128 case '?': 129 default: 130 usage(); 131 } 132 argc -= optind; 133 argv += optind; 134 135 if (argc != 2) 136 usage(); 137 138 dev = argv[0]; 139 dir = argv[1]; 140 141 #define DEFAULT_ROOTUID -2 142 /* 143 * FILECORE filesystems are not writeable. 144 */ 145 mntflags |= MNT_RDONLY; 146 if (useuid) args.flags |= FILECOREMNT_USEUID; 147 args.export.ex_flags = MNT_EXRDONLY; 148 args.fspec = dev; 149 args.export.ex_root = DEFAULT_ROOTUID; 150 args.flags = opts; 151 152 if (mount(MOUNT_FILECORE, dir, mntflags, &args) < 0) 153 err(1, "%s on %s", dev, dir); 154 if (mntflags & MNT_GETARGS) { 155 char buf[1024]; 156 (void)snprintb(buf, sizeof(buf), FILECOREMNT_BITS, args.flags); 157 printf("uid=%d, gid=%d, flags=%s\n", args.uid, args.gid, buf); 158 } 159 exit(0); 160 } 161 162 static void 163 usage() 164 { 165 (void)fprintf(stderr, 166 "usage: mount_filecore [-o options] special node\n"); 167 exit(1); 168 } 169