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 * @(#)mount_union.c 8.1 (Berkeley) 02/11/94 11 */ 12 13 #include <sys/param.h> 14 #include <sys/mount.h> 15 #include <miscfs/union/union.h> 16 17 #include <errno.h> 18 #include <stdio.h> 19 #include <unistd.h> 20 #include <stdlib.h> 21 #include <string.h> 22 23 void usage __P((void)); 24 25 int 26 main(argc, argv) 27 int argc; 28 char *argv[]; 29 { 30 struct union_args args; 31 int ch, mntflags; 32 int error = 0; 33 34 mntflags = 0; 35 args.mntflags = UNMNT_ABOVE; 36 37 while ((ch = getopt(argc, argv, "F:a:b:r:")) != EOF) { 38 switch(ch) { 39 case 'F': 40 mntflags = atoi(optarg); 41 break; 42 case 'a': 43 if (strcmp(optarg, "bove") == 0) { 44 args.mntflags &= ~UNMNT_OPMASK; 45 args.mntflags |= UNMNT_ABOVE; 46 } else { 47 error = 1; 48 } 49 break; 50 51 case 'b': 52 if (strcmp(optarg, "elow") == 0) { 53 args.mntflags &= ~UNMNT_OPMASK; 54 args.mntflags |= UNMNT_BELOW; 55 } else { 56 error = 1; 57 } 58 break; 59 60 case 'r': 61 if (strcmp(optarg, "eplace") == 0) { 62 args.mntflags &= ~UNMNT_OPMASK; 63 args.mntflags |= UNMNT_REPLACE; 64 } else { 65 error = 1; 66 } 67 break; 68 69 case '?': 70 default: 71 error = 1; 72 break; 73 } 74 } 75 argc -= optind; 76 argv += optind; 77 78 if (argc != 2) 79 error = 1; 80 81 if (error) 82 usage(); 83 84 args.target = argv[0]; 85 86 if (mount(MOUNT_UNION, argv[1], mntflags, &args)) { 87 (void)fprintf(stderr, "mount_union: %s\n", strerror(errno)); 88 exit(1); 89 } 90 exit(0); 91 } 92 93 void 94 usage() 95 { 96 (void)fprintf(stderr, 97 "usage: mount_union [ -F fsoptions ] target_fs mount_point\n"); 98 exit(1); 99 } 100