154698Sbostic /* 261509Sbostic * Copyright (c) 1992, 1993 361509Sbostic * The Regents of the University of California. All rights reserved. 454698Sbostic * All rights reserved. 554698Sbostic * 654698Sbostic * This code is derived from software donated to Berkeley by 754698Sbostic * Jan-Simon Pendry. 854698Sbostic * 954698Sbostic * %sccs.include.redist.c% 1054698Sbostic * 11*66134Spendry * @(#)mount_lofs.c 8.2 (Berkeley) 02/17/94 1254698Sbostic */ 1354698Sbostic 1454698Sbostic #include <sys/param.h> 1554698Sbostic #include <sys/mount.h> 1655026Sbostic #include <miscfs/lofs/lofs.h> 1754698Sbostic 1854699Sbostic #include <errno.h> 1954699Sbostic #include <stdio.h> 2054699Sbostic #include <unistd.h> 2154699Sbostic #include <stdlib.h> 2254699Sbostic #include <string.h> 2354699Sbostic 24*66134Spendry static int subdir __P((char *, char *)); 2554699Sbostic void usage __P((void)); 2654699Sbostic 2754699Sbostic int 2854699Sbostic main(argc, argv) 2954699Sbostic int argc; 3054699Sbostic char *argv[]; 3154698Sbostic { 3254698Sbostic struct lofs_args args; 3354699Sbostic int ch, mntflags; 34*66134Spendry char target[MAXPATHLEN]; 3554698Sbostic 3654699Sbostic mntflags = 0; 3754699Sbostic while ((ch = getopt(argc, argv, "F:")) != EOF) 3854699Sbostic switch(ch) { 3954699Sbostic case 'F': 4054699Sbostic mntflags = atoi(optarg); 4154699Sbostic break; 4254699Sbostic case '?': 4354699Sbostic default: 4454699Sbostic usage(); 4554699Sbostic } 4654699Sbostic argc -= optind; 4754699Sbostic argv += optind; 4854698Sbostic 4954699Sbostic if (argc != 2) 5054699Sbostic usage(); 5154698Sbostic 52*66134Spendry if (realpath(argv[0], target) == 0) { 53*66134Spendry (void)fprintf(stderr, "mount_lofs: %s: %s\n", 54*66134Spendry target, strerror(errno)); 55*66134Spendry exit(1); 56*66134Spendry } 5754698Sbostic 58*66134Spendry if (subdir(target, argv[1])) { 59*66134Spendry (void)fprintf(stderr, 60*66134Spendry "mount_lofs: %s (%s) is a sub directory of %s\n", 61*66134Spendry argv[0], target, argv[1]); 62*66134Spendry exit(1); 63*66134Spendry } 64*66134Spendry 65*66134Spendry args.target = target; 66*66134Spendry 6754699Sbostic if (mount(MOUNT_LOFS, argv[1], mntflags, &args)) { 6854699Sbostic (void)fprintf(stderr, "mount_lofs: %s\n", strerror(errno)); 6954698Sbostic exit(1); 7054698Sbostic } 7154698Sbostic exit(0); 7254698Sbostic } 7354699Sbostic 74*66134Spendry static int 75*66134Spendry subdir(p, dir) 76*66134Spendry char *p; 77*66134Spendry char *dir; 78*66134Spendry { 79*66134Spendry int l; 80*66134Spendry 81*66134Spendry l = strlen(dir); 82*66134Spendry if (l <= 1) 83*66134Spendry return (1); 84*66134Spendry 85*66134Spendry if ((strncmp(p, dir, l) == 0) && (p[l] == '/')) 86*66134Spendry return (1); 87*66134Spendry 88*66134Spendry return (0); 89*66134Spendry } 90*66134Spendry 9154699Sbostic void 9254699Sbostic usage() 9354699Sbostic { 9454699Sbostic (void)fprintf(stderr, 9554699Sbostic "usage: mount_lofs [ -F fsoptions ] target_fs mount_point\n"); 9654699Sbostic exit(1); 9754699Sbostic } 98