xref: /netbsd-src/sbin/mount_ffs/mount_ffs.c (revision 292aad75052ee582737b41ec7fb62ee1d9899a4f)
1*292aad75Schristos /*	$NetBSD: mount_ffs.c,v 1.30 2021/09/18 03:05:20 christos Exp $	*/
27fa5edbaScgd 
37fa5edbaScgd /*-
47fa5edbaScgd  * Copyright (c) 1993, 1994
57fa5edbaScgd  *	The Regents of the University of California.  All rights reserved.
67fa5edbaScgd  *
77fa5edbaScgd  * Redistribution and use in source and binary forms, with or without
87fa5edbaScgd  * modification, are permitted provided that the following conditions
97fa5edbaScgd  * are met:
107fa5edbaScgd  * 1. Redistributions of source code must retain the above copyright
117fa5edbaScgd  *    notice, this list of conditions and the following disclaimer.
127fa5edbaScgd  * 2. Redistributions in binary form must reproduce the above copyright
137fa5edbaScgd  *    notice, this list of conditions and the following disclaimer in the
147fa5edbaScgd  *    documentation and/or other materials provided with the distribution.
15276d62f6Sagc  * 3. Neither the name of the University nor the names of its contributors
167fa5edbaScgd  *    may be used to endorse or promote products derived from this software
177fa5edbaScgd  *    without specific prior written permission.
187fa5edbaScgd  *
197fa5edbaScgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
207fa5edbaScgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
217fa5edbaScgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
227fa5edbaScgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
237fa5edbaScgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
247fa5edbaScgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
257fa5edbaScgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
267fa5edbaScgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
277fa5edbaScgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
287fa5edbaScgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
297fa5edbaScgd  * SUCH DAMAGE.
307fa5edbaScgd  */
317fa5edbaScgd 
3298986b2eSlukem #include <sys/cdefs.h>
337fa5edbaScgd #ifndef lint
346543a91fSlukem __COPYRIGHT("@(#) Copyright (c) 1993, 1994\
356543a91fSlukem  The Regents of the University of California.  All rights reserved.");
367fa5edbaScgd #endif /* not lint */
377fa5edbaScgd 
387fa5edbaScgd #ifndef lint
397fa5edbaScgd #if 0
408895fa19Slukem static char sccsid[] = "@(#)mount_ufs.c	8.4 (Berkeley) 4/26/95";
417fa5edbaScgd #else
42*292aad75Schristos __RCSID("$NetBSD: mount_ffs.c,v 1.30 2021/09/18 03:05:20 christos Exp $");
437fa5edbaScgd #endif
447fa5edbaScgd #endif /* not lint */
457fa5edbaScgd 
467fa5edbaScgd #include <sys/param.h>
477fa5edbaScgd #include <sys/mount.h>
48e5bc90f4Sfvdl #include <ufs/ufs/ufsmount.h>
497fa5edbaScgd 
507fa5edbaScgd #include <err.h>
517fa5edbaScgd #include <errno.h>
527fa5edbaScgd #include <stdio.h>
537fa5edbaScgd #include <stdlib.h>
548895fa19Slukem 
557fa5edbaScgd #include <string.h>
567fa5edbaScgd #include <unistd.h>
577fa5edbaScgd 
58899bce09Sjdolecek #include <mntopts.h>
597fa5edbaScgd 
6099fed726Spooka #include "mountprog.h"
6199fed726Spooka #include "mount_ffs.h"
6299fed726Spooka 
63baa8e84bSjoerg __dead static void	ffs_usage(void);
647fa5edbaScgd 
656397db2dSjtc static const struct mntopt mopts[] = {
667fa5edbaScgd 	MOPT_STDOPTS,
67*292aad75Schristos 	MOPT_NFS4ACLS,
689aa2a9c3Schristos 	MOPT_POSIX1EACLS,
697fa5edbaScgd 	MOPT_ASYNC,
707fa5edbaScgd 	MOPT_SYNC,
717fa5edbaScgd 	MOPT_UPDATE,
727fa5edbaScgd 	MOPT_RELOAD,
73aeb2ee9aStls 	MOPT_NOATIME,
747171fafdSkenh 	MOPT_NODEVMTIME,
758895fa19Slukem 	MOPT_FORCE,
7656fb6920Sfvdl 	MOPT_SOFTDEP,
7736d65f11Ssimonb 	MOPT_LOG,
789f9ee297Schristos 	MOPT_GETARGS,
79448e1c49Smanu 	MOPT_EXTATTR,
805724e77fSdrochner 	MOPT_DISCARD,
815afd1c0aSchristos 	MOPT_NULL,
827fa5edbaScgd };
837fa5edbaScgd 
84debb6d80Sjdolecek #ifndef MOUNT_NOMAIN
857fa5edbaScgd int
main(int argc,char ** argv)8677bf7073Sxtraeme main(int argc, char **argv)
87debb6d80Sjdolecek {
8899fed726Spooka 
8999fed726Spooka 	setprogname(argv[0]);
90debb6d80Sjdolecek 	return mount_ffs(argc, argv);
91debb6d80Sjdolecek }
92debb6d80Sjdolecek #endif
93debb6d80Sjdolecek 
9499fed726Spooka void
mount_ffs_parseargs(int argc,char * argv[],struct ufs_args * args,int * mntflags,char * canon_dev,char * canon_dir)9599fed726Spooka mount_ffs_parseargs(int argc, char *argv[],
9699fed726Spooka 	struct ufs_args *args, int *mntflags,
9799fed726Spooka 	char *canon_dev, char *canon_dir)
987fa5edbaScgd {
9999fed726Spooka 	int ch;
1007067dcb9Schristos 	mntoptparse_t mp;
1017fa5edbaScgd 
10299fed726Spooka 	memset(args, 0, sizeof(*args));
10399fed726Spooka 	*mntflags = 0;
1047fa5edbaScgd 	optind = optreset = 1;		/* Reset for parse of new argv. */
10598986b2eSlukem 	while ((ch = getopt(argc, argv, "o:")) != -1)
1067fa5edbaScgd 		switch (ch) {
1077fa5edbaScgd 		case 'o':
10899fed726Spooka 			mp = getmntopts(optarg, mopts, mntflags, 0);
1097067dcb9Schristos 			if (mp == NULL)
1107067dcb9Schristos 				err(1, "getmntopts");
1117067dcb9Schristos 			freemntopts(mp);
1127fa5edbaScgd 			break;
1137fa5edbaScgd 		case '?':
1147fa5edbaScgd 		default:
1157fa5edbaScgd 			ffs_usage();
1167fa5edbaScgd 		}
1177fa5edbaScgd 	argc -= optind;
1187fa5edbaScgd 	argv += optind;
1197fa5edbaScgd 
1207fa5edbaScgd 	if (argc != 2)
1217fa5edbaScgd 		ffs_usage();
1227fa5edbaScgd 
12399fed726Spooka 	pathadj(argv[0], canon_dev);
12499fed726Spooka 	args->fspec = canon_dev;
125fdd16c54Serh 
12699fed726Spooka 	pathadj(argv[1], canon_dir);
127fdd16c54Serh }
1287fa5edbaScgd 
12999fed726Spooka int
mount_ffs(int argc,char * argv[])13099fed726Spooka mount_ffs(int argc, char *argv[])
13199fed726Spooka {
13299fed726Spooka 	char fs_name[MAXPATHLEN], canon_dev[MAXPATHLEN];
13399fed726Spooka 	struct ufs_args args;
13499fed726Spooka 	const char *errcause;
13599fed726Spooka 	int mntflags;
13699fed726Spooka 
13799fed726Spooka 	mount_ffs_parseargs(argc, argv, &args, &mntflags, canon_dev, fs_name);
13899fed726Spooka 
139704e0753Spooka 	if (mount(MOUNT_FFS, fs_name, mntflags, &args, sizeof args) == -1) {
1407fa5edbaScgd 		switch (errno) {
1417fa5edbaScgd 		case EMFILE:
1427fa5edbaScgd 			errcause = "mount table full";
1437fa5edbaScgd 			break;
1447fa5edbaScgd 		case EINVAL:
1457fa5edbaScgd 			if (mntflags & MNT_UPDATE)
1467fa5edbaScgd 				errcause =
1477fa5edbaScgd 			    "specified device does not match mounted device";
1487fa5edbaScgd 			else
1497fa5edbaScgd 				errcause = "incorrect super block";
1507fa5edbaScgd 			break;
1517fa5edbaScgd 		default:
1527fa5edbaScgd 			errcause = strerror(errno);
1537fa5edbaScgd 			break;
1547fa5edbaScgd 		}
1557fa5edbaScgd 		errx(1, "%s on %s: %s", args.fspec, fs_name, errcause);
1567fa5edbaScgd 	}
1577fa5edbaScgd 	exit(0);
1587fa5edbaScgd }
1597fa5edbaScgd 
160debb6d80Sjdolecek static void
ffs_usage(void)16177bf7073Sxtraeme ffs_usage(void)
1627fa5edbaScgd {
16399fed726Spooka 	fprintf(stderr, "usage: %s [-o options] special node\n", getprogname());
1647fa5edbaScgd 	exit(1);
1657fa5edbaScgd }
166