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*68897Smckusick static char sccsid[] = "@(#)mount_ufs.c 8.4 (Berkeley) 04/26/95";
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
28*68897Smckusick #include <ufs/ufs/ufsmount.h>
29*68897Smckusick
3066462Sbostic #include "mntopts.h"
3166462Sbostic
3266462Sbostic void ufs_usage __P((void));
3366462Sbostic
3466462Sbostic static struct mntopt mopts[] = {
3566462Sbostic MOPT_STDOPTS,
3666489Sbostic MOPT_ASYNC,
3766489Sbostic MOPT_SYNC,
3866462Sbostic MOPT_UPDATE,
3967492Smckusick MOPT_FORCE,
4066462Sbostic { NULL }
4166462Sbostic };
4266462Sbostic
4366462Sbostic int
mount_ufs(argc,argv)4466462Sbostic mount_ufs(argc, argv)
4566462Sbostic int argc;
4666462Sbostic char * const argv[];
4766462Sbostic {
4866462Sbostic extern int optreset;
4966462Sbostic struct ufs_args args;
5066462Sbostic int ch, mntflags;
5166462Sbostic char *fs_name;
5266462Sbostic
5366462Sbostic mntflags = 0;
5466462Sbostic optind = optreset = 1; /* Reset for parse of new argv. */
5566462Sbostic while ((ch = getopt(argc, argv, "o:")) != EOF)
5666462Sbostic switch (ch) {
5766462Sbostic case 'o':
58*68897Smckusick getmntopts(optarg, mopts, &mntflags, 0);
5966462Sbostic break;
6066462Sbostic case '?':
6166462Sbostic default:
6266462Sbostic ufs_usage();
6366462Sbostic }
6466462Sbostic argc -= optind;
6566462Sbostic argv += optind;
6666462Sbostic
6766462Sbostic if (argc != 2)
6866462Sbostic ufs_usage();
6966462Sbostic
7066462Sbostic args.fspec = argv[0]; /* The name of the device file. */
7166462Sbostic fs_name = argv[1]; /* The mount point. */
7266462Sbostic
7366462Sbostic #define DEFAULT_ROOTUID -2
7466462Sbostic args.export.ex_root = DEFAULT_ROOTUID;
7566462Sbostic if (mntflags & MNT_RDONLY)
7666462Sbostic args.export.ex_flags = MNT_EXRDONLY;
7766462Sbostic else
7866462Sbostic args.export.ex_flags = 0;
7966462Sbostic
80*68897Smckusick if (mount("ufs", fs_name, mntflags, &args) < 0) {
8166462Sbostic (void)fprintf(stderr, "%s on %s: ", args.fspec, fs_name);
8266462Sbostic switch (errno) {
8366462Sbostic case EMFILE:
8466462Sbostic (void)fprintf(stderr, "mount table full.\n");
8566462Sbostic break;
8666462Sbostic case EINVAL:
8766462Sbostic if (mntflags & MNT_UPDATE)
8866462Sbostic (void)fprintf(stderr,
8966462Sbostic "Specified device does not match mounted device.\n");
9066462Sbostic else
9166462Sbostic (void)fprintf(stderr,
9266462Sbostic "Incorrect super block.\n");
9366462Sbostic break;
9466462Sbostic default:
9566462Sbostic (void)fprintf(stderr, "%s\n", strerror(errno));
9666462Sbostic break;
9766462Sbostic }
9866462Sbostic return (1);
9966462Sbostic }
10066462Sbostic return (0);
10166462Sbostic }
10266462Sbostic
10366462Sbostic void
ufs_usage()10466462Sbostic ufs_usage()
10566462Sbostic {
10666462Sbostic (void)fprintf(stderr, "usage: mount_ufs [-o options] special node\n");
10766462Sbostic exit(1);
10866462Sbostic }
109