1 /* 2 * Copyright (c) 1992, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software donated to Berkeley by 6 * Jan-Simon Pendry. 7 * 8 * %sccs.include.redist.c% 9 */ 10 11 #ifndef lint 12 char copyright[] = 13 "@(#) Copyright (c) 1992, 1993, 1994\n\ 14 The Regents of the University of California. All rights reserved.\n"; 15 #endif /* not lint */ 16 17 #ifndef lint 18 static char sccsid[] = "@(#)mount_lofs.c 8.4 (Berkeley) 03/27/94"; 19 #endif /* not lint */ 20 21 #include <sys/param.h> 22 #include <sys/mount.h> 23 24 #include <miscfs/lofs/lofs.h> 25 26 #include <err.h> 27 #include <stdio.h> 28 #include <unistd.h> 29 #include <stdlib.h> 30 #include <string.h> 31 32 #include "mntopts.h" 33 34 struct mntopt mopts[] = { 35 MOPT_STDOPTS, 36 { NULL } 37 }; 38 39 int subdir __P((const char *, const char *)); 40 void usage __P((void)); 41 42 int 43 main(argc, argv) 44 int argc; 45 char *argv[]; 46 { 47 struct lofs_args args; 48 int ch, mntflags; 49 char target[MAXPATHLEN]; 50 51 mntflags = 0; 52 while ((ch = getopt(argc, argv, "o:")) != EOF) 53 switch (ch) { 54 case 'o': 55 getmntopts(optarg, mopts, &mntflags); 56 break; 57 case '?': 58 default: 59 usage(); 60 } 61 argc -= optind; 62 argv += optind; 63 64 if (argc != 2) 65 usage(); 66 67 if (realpath(argv[0], target) == 0) 68 err(1, "%s", target); 69 70 if (subdir(target, argv[1]) || subdir(argv[1], target)) 71 errx(1, "%s (%s) and %s are not distinct paths", 72 argv[0], target, argv[1]); 73 74 args.target = target; 75 76 if (mount(MOUNT_LOFS, argv[1], mntflags, &args)) 77 err(1, NULL); 78 exit(0); 79 } 80 81 int 82 subdir(p, dir) 83 const char *p; 84 const char *dir; 85 { 86 int l; 87 88 l = strlen(dir); 89 if (l <= 1) 90 return (1); 91 92 if ((strncmp(p, dir, l) == 0) && (p[l] == '/' || p[l] == '\0')) 93 return (1); 94 95 return (0); 96 } 97 98 void 99 usage() 100 { 101 (void)fprintf(stderr, 102 "usage: mount_lofs [-o options] target_fs mount_point\n"); 103 exit(1); 104 } 105