xref: /csrg-svn/sbin/mount/mount_ufs.c (revision 66489)
166462Sbostic /*-
266462Sbostic  * Copyright (c) 1993, 1994
366462Sbostic  *	The Regents of the University of California.  All rights reserved.
466462Sbostic  *
566462Sbostic  * %sccs.include.redist.c%
666462Sbostic  */
766462Sbostic 
866462Sbostic #ifndef lint
966462Sbostic static char copyright[] =
1066462Sbostic "@(#) Copyright (c) 1993, 1994\n\
1166462Sbostic 	The Regents of the University of California.  All rights reserved.\n";
1266462Sbostic #endif /* not lint */
1366462Sbostic 
1466462Sbostic #ifndef lint
15*66489Sbostic static char sccsid[] = "@(#)mount_ufs.c	8.2 (Berkeley) 03/27/94";
1666462Sbostic #endif /* not lint */
1766462Sbostic 
1866462Sbostic #include <sys/param.h>
1966462Sbostic #include <sys/mount.h>
2066462Sbostic 
2166462Sbostic #include <err.h>
2266462Sbostic #include <errno.h>
2366462Sbostic #include <stdio.h>
2466462Sbostic #include <stdlib.h>
2566462Sbostic #include <string.h>
2666462Sbostic #include <unistd.h>
2766462Sbostic 
2866462Sbostic #include "mntopts.h"
2966462Sbostic 
3066462Sbostic void	ufs_usage __P((void));
3166462Sbostic 
3266462Sbostic static struct mntopt mopts[] = {
3366462Sbostic 	MOPT_STDOPTS,
34*66489Sbostic 	MOPT_ASYNC,
35*66489Sbostic 	MOPT_SYNC,
3666462Sbostic 	MOPT_UPDATE,
3766462Sbostic 	{ NULL }
3866462Sbostic };
3966462Sbostic 
4066462Sbostic int
4166462Sbostic mount_ufs(argc, argv)
4266462Sbostic 	int argc;
4366462Sbostic 	char * const argv[];
4466462Sbostic {
4566462Sbostic 	extern int optreset;
4666462Sbostic 	struct ufs_args args;
4766462Sbostic 	int ch, mntflags;
4866462Sbostic 	char *fs_name;
4966462Sbostic 
5066462Sbostic 	mntflags = 0;
5166462Sbostic 	optind = optreset = 1;		/* Reset for parse of new argv. */
5266462Sbostic 	while ((ch = getopt(argc, argv, "o:")) != EOF)
5366462Sbostic 		switch (ch) {
5466462Sbostic 		case 'o':
5566462Sbostic 			getmntopts(optarg, mopts, &mntflags);
5666462Sbostic 			break;
5766462Sbostic 		case '?':
5866462Sbostic 		default:
5966462Sbostic 			ufs_usage();
6066462Sbostic 		}
6166462Sbostic 	argc -= optind;
6266462Sbostic 	argv += optind;
6366462Sbostic 
6466462Sbostic 	if (argc != 2)
6566462Sbostic 		ufs_usage();
6666462Sbostic 
6766462Sbostic         args.fspec = argv[0];		/* The name of the device file. */
6866462Sbostic 	fs_name = argv[1];		/* The mount point. */
6966462Sbostic 
7066462Sbostic #define DEFAULT_ROOTUID	-2
7166462Sbostic 	args.export.ex_root = DEFAULT_ROOTUID;
7266462Sbostic 	if (mntflags & MNT_RDONLY)
7366462Sbostic 		args.export.ex_flags = MNT_EXRDONLY;
7466462Sbostic 	else
7566462Sbostic 		args.export.ex_flags = 0;
7666462Sbostic 
7766462Sbostic 	if (mount(MOUNT_UFS, fs_name, mntflags, &args) < 0) {
7866462Sbostic 		(void)fprintf(stderr, "%s on %s: ", args.fspec, fs_name);
7966462Sbostic 		switch (errno) {
8066462Sbostic 		case EMFILE:
8166462Sbostic 			(void)fprintf(stderr, "mount table full.\n");
8266462Sbostic 			break;
8366462Sbostic 		case EINVAL:
8466462Sbostic 			if (mntflags & MNT_UPDATE)
8566462Sbostic 				(void)fprintf(stderr,
8666462Sbostic 		    "Specified device does not match mounted device.\n");
8766462Sbostic 			else
8866462Sbostic 				(void)fprintf(stderr,
8966462Sbostic 				    "Incorrect super block.\n");
9066462Sbostic 			break;
9166462Sbostic 		default:
9266462Sbostic 			(void)fprintf(stderr, "%s\n", strerror(errno));
9366462Sbostic 			break;
9466462Sbostic 		}
9566462Sbostic 		return (1);
9666462Sbostic 	}
9766462Sbostic 	return (0);
9866462Sbostic }
9966462Sbostic 
10066462Sbostic void
10166462Sbostic ufs_usage()
10266462Sbostic {
10366462Sbostic 	(void)fprintf(stderr, "usage: mount_ufs [-o options] special node\n");
10466462Sbostic 	exit(1);
10566462Sbostic }
106