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