xref: /original-bsd/sbin/mount/mount_ufs.c (revision deff14a8)
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.3 (Berkeley) 07/07/94";
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 "mntopts.h"
29 
30 void	ufs_usage __P((void));
31 
32 static struct mntopt mopts[] = {
33 	MOPT_STDOPTS,
34 	MOPT_ASYNC,
35 	MOPT_SYNC,
36 	MOPT_UPDATE,
37 	MOPT_FORCE,
38 	{ NULL }
39 };
40 
41 int
42 mount_ufs(argc, argv)
43 	int argc;
44 	char * const argv[];
45 {
46 	extern int optreset;
47 	struct ufs_args args;
48 	int ch, mntflags;
49 	char *fs_name;
50 
51 	mntflags = 0;
52 	optind = optreset = 1;		/* Reset for parse of new argv. */
53 	while ((ch = getopt(argc, argv, "o:")) != EOF)
54 		switch (ch) {
55 		case 'o':
56 			getmntopts(optarg, mopts, &mntflags);
57 			break;
58 		case '?':
59 		default:
60 			ufs_usage();
61 		}
62 	argc -= optind;
63 	argv += optind;
64 
65 	if (argc != 2)
66 		ufs_usage();
67 
68         args.fspec = argv[0];		/* The name of the device file. */
69 	fs_name = argv[1];		/* The mount point. */
70 
71 #define DEFAULT_ROOTUID	-2
72 	args.export.ex_root = DEFAULT_ROOTUID;
73 	if (mntflags & MNT_RDONLY)
74 		args.export.ex_flags = MNT_EXRDONLY;
75 	else
76 		args.export.ex_flags = 0;
77 
78 	if (mount(MOUNT_UFS, fs_name, mntflags, &args) < 0) {
79 		(void)fprintf(stderr, "%s on %s: ", args.fspec, fs_name);
80 		switch (errno) {
81 		case EMFILE:
82 			(void)fprintf(stderr, "mount table full.\n");
83 			break;
84 		case EINVAL:
85 			if (mntflags & MNT_UPDATE)
86 				(void)fprintf(stderr,
87 		    "Specified device does not match mounted device.\n");
88 			else
89 				(void)fprintf(stderr,
90 				    "Incorrect super block.\n");
91 			break;
92 		default:
93 			(void)fprintf(stderr, "%s\n", strerror(errno));
94 			break;
95 		}
96 		return (1);
97 	}
98 	return (0);
99 }
100 
101 void
102 ufs_usage()
103 {
104 	(void)fprintf(stderr, "usage: mount_ufs [-o options] special node\n");
105 	exit(1);
106 }
107