1 /*- 2 * Copyright (c) 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char copyright[] = 10 "@(#) Copyright (c) 1993, 1994\n\ 11 The Regents of the University of California. All rights reserved.\n"; 12 #endif /* not lint */ 13 14 #ifndef lint 15 static char sccsid[] = "@(#)mount_ufs.c 8.4 (Berkeley) 04/26/95"; 16 #endif /* not lint */ 17 18 #include <sys/param.h> 19 #include <sys/mount.h> 20 21 #include <err.h> 22 #include <errno.h> 23 #include <stdio.h> 24 #include <stdlib.h> 25 #include <string.h> 26 #include <unistd.h> 27 28 #include <ufs/ufs/ufsmount.h> 29 30 #include "mntopts.h" 31 32 void ufs_usage __P((void)); 33 34 static struct mntopt mopts[] = { 35 MOPT_STDOPTS, 36 MOPT_ASYNC, 37 MOPT_SYNC, 38 MOPT_UPDATE, 39 MOPT_FORCE, 40 { NULL } 41 }; 42 43 int 44 mount_ufs(argc, argv) 45 int argc; 46 char * const argv[]; 47 { 48 extern int optreset; 49 struct ufs_args args; 50 int ch, mntflags; 51 char *fs_name; 52 53 mntflags = 0; 54 optind = optreset = 1; /* Reset for parse of new argv. */ 55 while ((ch = getopt(argc, argv, "o:")) != EOF) 56 switch (ch) { 57 case 'o': 58 getmntopts(optarg, mopts, &mntflags, 0); 59 break; 60 case '?': 61 default: 62 ufs_usage(); 63 } 64 argc -= optind; 65 argv += optind; 66 67 if (argc != 2) 68 ufs_usage(); 69 70 args.fspec = argv[0]; /* The name of the device file. */ 71 fs_name = argv[1]; /* The mount point. */ 72 73 #define DEFAULT_ROOTUID -2 74 args.export.ex_root = DEFAULT_ROOTUID; 75 if (mntflags & MNT_RDONLY) 76 args.export.ex_flags = MNT_EXRDONLY; 77 else 78 args.export.ex_flags = 0; 79 80 if (mount("ufs", fs_name, mntflags, &args) < 0) { 81 (void)fprintf(stderr, "%s on %s: ", args.fspec, fs_name); 82 switch (errno) { 83 case EMFILE: 84 (void)fprintf(stderr, "mount table full.\n"); 85 break; 86 case EINVAL: 87 if (mntflags & MNT_UPDATE) 88 (void)fprintf(stderr, 89 "Specified device does not match mounted device.\n"); 90 else 91 (void)fprintf(stderr, 92 "Incorrect super block.\n"); 93 break; 94 default: 95 (void)fprintf(stderr, "%s\n", strerror(errno)); 96 break; 97 } 98 return (1); 99 } 100 return (0); 101 } 102 103 void 104 ufs_usage() 105 { 106 (void)fprintf(stderr, "usage: mount_ufs [-o options] special node\n"); 107 exit(1); 108 } 109