1 /*- 2 * Copyright (c) 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char copyright[] = 10 "@(#) Copyright (c) 1993\n\ 11 The Regents of the University of California. All rights reserved.\n"; 12 #endif /* not lint */ 13 14 #ifndef lint 15 static char sccsid[] = "@(#)mount_lfs.c 8.2 (Berkeley) 01/23/94"; 16 #endif /* not lint */ 17 18 #include <sys/param.h> 19 #include <sys/mount.h> 20 21 #include <err.h> 22 #include <errno.h> 23 #include <stdio.h> 24 #include <stdlib.h> 25 #include <string.h> 26 #include <unistd.h> 27 28 #include "pathnames.h" 29 30 #define DEFAULT_ROOTUID -2 /* copied from mount's UFS code */ 31 32 void usage __P((void)); 33 void invoke_cleaner __P((char *)); 34 35 int short_rds, cleaner_debug; 36 37 int 38 main(argc, argv) 39 int argc; 40 char *argv[]; 41 { 42 struct ufs_args args; 43 int ch, mntflags; 44 int noclean; 45 char *fs_name; 46 47 mntflags = noclean = 0; 48 while ((ch = getopt(argc, argv, "F:nsd")) != EOF) 49 switch(ch) { 50 case 'F': 51 mntflags = atoi(optarg); 52 break; 53 case 'n': 54 noclean = 1; 55 break; 56 case 's': 57 short_rds = 1; 58 break; 59 case 'd': 60 cleaner_debug = 1; 61 break; 62 case '?': 63 default: 64 usage(); 65 } 66 argc -= optind; 67 argv += optind; 68 69 if (argc != 2) 70 usage(); 71 72 args.fspec = argv[0]; /* the name of the device file */ 73 fs_name = argv[1]; /* the mount point */ 74 75 /* copied from mount's UFS code */ 76 args.export.ex_root = DEFAULT_ROOTUID; 77 if (mntflags & MNT_RDONLY) 78 args.export.ex_flags = MNT_EXRDONLY; 79 else 80 args.export.ex_flags = 0; 81 82 if (mount(MOUNT_LFS, fs_name, mntflags, &args)) { 83 (void)fprintf(stderr, "mount_lfs: %s\n", strerror(errno)); 84 exit(1); 85 } 86 87 if (!noclean) { 88 /* 89 * invoke the lfs_cleanerd for this filesystem as its arg! 90 */ 91 invoke_cleaner(fs_name); 92 /* never returns */ 93 } 94 95 exit(0); 96 } 97 98 void 99 usage() 100 { 101 (void)fprintf(stderr, 102 "usage: mount_lfs [ -nsd ] [ -F fsoptions ] device mount_point\n"); 103 exit(1); 104 } 105 106 void 107 invoke_cleaner(name) 108 char *name; 109 { 110 char *args[6], **ap = args; 111 112 /* build the argument list */ 113 *ap++ = _PATH_LFS_CLEANERD; 114 if (short_rds) 115 *ap++ = "-s"; 116 if (cleaner_debug) 117 *ap++ = "-d"; 118 *ap++ = name; 119 *ap = NULL; 120 121 execv(args[0], args); 122 err(1, "exec of %x failed", _PATH_LFS_CLEANERD); 123 } 124