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