1 /* 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * All rights reserved. 5 * 6 * This code is derived from software donated to Berkeley by 7 * Jan-Simon Pendry. 8 * 9 * %sccs.include.redist.c% 10 * 11 * @(#)mount_null.c 8.3 (Berkeley) 02/18/94 12 */ 13 14 #include <sys/param.h> 15 #include <sys/mount.h> 16 #include <miscfs/nullfs/null.h> 17 18 #include <errno.h> 19 #include <stdio.h> 20 #include <unistd.h> 21 #include <stdlib.h> 22 #include <string.h> 23 24 static int subdir __P((char *, char *)); 25 void usage __P((void)); 26 27 int 28 main(argc, argv) 29 int argc; 30 char *argv[]; 31 { 32 struct null_args args; 33 int ch, mntflags; 34 char target[MAXPATHLEN]; 35 36 mntflags = 0; 37 while ((ch = getopt(argc, argv, "F:")) != EOF) 38 switch(ch) { 39 case 'F': 40 mntflags = atoi(optarg); 41 break; 42 case '?': 43 default: 44 usage(); 45 } 46 argc -= optind; 47 argv += optind; 48 49 if (argc != 2) 50 usage(); 51 52 if (realpath(argv[0], target) == 0) { 53 (void)fprintf(stderr, "mount_null: %s: %s\n", 54 target, strerror(errno)); 55 exit(1); 56 } 57 58 if (subdir(target, argv[1])) { 59 (void)fprintf(stderr, 60 "mount_null: %s (%s) is a sub directory of %s\n", 61 argv[0], target, argv[1]); 62 exit(1); 63 } 64 65 args.target = target; 66 67 if (mount(MOUNT_NULL, argv[1], mntflags, &args)) { 68 (void)fprintf(stderr, "mount_null: %s\n", strerror(errno)); 69 exit(1); 70 } 71 exit(0); 72 } 73 74 static int 75 subdir(p, dir) 76 char *p; 77 char *dir; 78 { 79 int l; 80 81 l = strlen(dir); 82 if (l <= 1) 83 return (1); 84 85 if ((strncmp(p, dir, l) == 0) && (p[l] == '/')) 86 return (1); 87 88 return (0); 89 } 90 91 void 92 usage() 93 { 94 (void)fprintf(stderr, 95 "usage: mount_null [ -F fsoptions ] target_fs mount_point\n"); 96 exit(1); 97 } 98