154843Sheideman /* 261513Sbostic * Copyright (c) 1992, 1993 361513Sbostic * The Regents of the University of California. All rights reserved. 454843Sheideman * All rights reserved. 554843Sheideman * 654843Sheideman * This code is derived from software donated to Berkeley by 754843Sheideman * Jan-Simon Pendry. 854843Sheideman * 954843Sheideman * %sccs.include.redist.c% 1054843Sheideman * 11*66135Spendry * @(#)mount_null.c 8.2 (Berkeley) 02/17/94 1254843Sheideman */ 1354843Sheideman 1454843Sheideman #include <sys/param.h> 1554843Sheideman #include <sys/mount.h> 1655038Sbostic #include <miscfs/nullfs/null.h> 1754843Sheideman 1854843Sheideman #include <errno.h> 1954843Sheideman #include <stdio.h> 2054843Sheideman #include <unistd.h> 2154843Sheideman #include <stdlib.h> 2254843Sheideman #include <string.h> 2354843Sheideman 24*66135Spendry static int subdir __P((char *, char *)); 2554843Sheideman void usage __P((void)); 2654843Sheideman 2754843Sheideman int 2854843Sheideman main(argc, argv) 2954843Sheideman int argc; 3054843Sheideman char *argv[]; 3154843Sheideman { 3254952Sheideman struct null_args args; 3354843Sheideman int ch, mntflags; 34*66135Spendry char target[MAXPATHLEN]; 3554843Sheideman 3654843Sheideman mntflags = 0; 3754843Sheideman while ((ch = getopt(argc, argv, "F:")) != EOF) 3854843Sheideman switch(ch) { 3954843Sheideman case 'F': 4054843Sheideman mntflags = atoi(optarg); 4154843Sheideman break; 4254843Sheideman case '?': 4354843Sheideman default: 4454843Sheideman usage(); 4554843Sheideman } 4654843Sheideman argc -= optind; 4754843Sheideman argv += optind; 4854843Sheideman 4954843Sheideman if (argc != 2) 5054843Sheideman usage(); 5154843Sheideman 52*66135Spendry if (realpath(argv[0], target) == 0) { 53*66135Spendry (void)fprintf(stderr, "mount_lofs: %s: %s\n", 54*66135Spendry target, strerror(errno)); 55*66135Spendry exit(1); 56*66135Spendry } 5754843Sheideman 58*66135Spendry if (subdir(target, argv[1])) { 59*66135Spendry (void)fprintf(stderr, 60*66135Spendry "mount_null: %s (%s) is a sub directory of %s\n", 61*66135Spendry argv[0], target, argv[1]); 62*66135Spendry exit(1); 63*66135Spendry } 64*66135Spendry 65*66135Spendry args.target = target; 66*66135Spendry 6754952Sheideman if (mount(MOUNT_NULL, argv[1], mntflags, &args)) { 6854952Sheideman (void)fprintf(stderr, "mount_null: %s\n", strerror(errno)); 6954843Sheideman exit(1); 7054843Sheideman } 7154843Sheideman exit(0); 7254843Sheideman } 7354843Sheideman 74*66135Spendry static int 75*66135Spendry subdir(p, dir) 76*66135Spendry char *p; 77*66135Spendry char *dir; 78*66135Spendry { 79*66135Spendry int l; 80*66135Spendry 81*66135Spendry l = strlen(dir); 82*66135Spendry if (l <= 1) 83*66135Spendry return (1); 84*66135Spendry 85*66135Spendry if ((strncmp(p, dir, l) == 0) && (p[l] == '/')) 86*66135Spendry return (1); 87*66135Spendry 88*66135Spendry return (0); 89*66135Spendry } 90*66135Spendry 9154843Sheideman void 9254843Sheideman usage() 9354843Sheideman { 9454843Sheideman (void)fprintf(stderr, 9554952Sheideman "usage: mount_null [ -F fsoptions ] target_fs mount_point\n"); 9654843Sheideman exit(1); 9754843Sheideman } 98