1*a0647817Schristos /* $NetBSD: mount_ext2fs.c,v 1.23 2016/02/21 22:51:29 christos Exp $ */
28f7c2b37Sbouyer
38f7c2b37Sbouyer /*-
48f7c2b37Sbouyer * Copyright (c) 1993, 1994
58f7c2b37Sbouyer * The Regents of the University of California. All rights reserved.
68f7c2b37Sbouyer *
78f7c2b37Sbouyer * Redistribution and use in source and binary forms, with or without
88f7c2b37Sbouyer * modification, are permitted provided that the following conditions
98f7c2b37Sbouyer * are met:
108f7c2b37Sbouyer * 1. Redistributions of source code must retain the above copyright
118f7c2b37Sbouyer * notice, this list of conditions and the following disclaimer.
128f7c2b37Sbouyer * 2. Redistributions in binary form must reproduce the above copyright
138f7c2b37Sbouyer * notice, this list of conditions and the following disclaimer in the
148f7c2b37Sbouyer * documentation and/or other materials provided with the distribution.
15276d62f6Sagc * 3. Neither the name of the University nor the names of its contributors
168f7c2b37Sbouyer * may be used to endorse or promote products derived from this software
178f7c2b37Sbouyer * without specific prior written permission.
188f7c2b37Sbouyer *
198f7c2b37Sbouyer * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
208f7c2b37Sbouyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
218f7c2b37Sbouyer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
228f7c2b37Sbouyer * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
238f7c2b37Sbouyer * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
248f7c2b37Sbouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
258f7c2b37Sbouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
268f7c2b37Sbouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
278f7c2b37Sbouyer * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
288f7c2b37Sbouyer * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
298f7c2b37Sbouyer * SUCH DAMAGE.
308f7c2b37Sbouyer */
318f7c2b37Sbouyer
326a6a54d5Slukem #include <sys/cdefs.h>
338f7c2b37Sbouyer #ifndef lint
346543a91fSlukem __COPYRIGHT("@(#) Copyright (c) 1993, 1994\
356543a91fSlukem The Regents of the University of California. All rights reserved.");
368f7c2b37Sbouyer #endif /* not lint */
378f7c2b37Sbouyer
388f7c2b37Sbouyer #ifndef lint
398f7c2b37Sbouyer #if 0
408895fa19Slukem static char sccsid[] = "@(#)mount_ufs.c 8.4 (Berkeley) 4/26/95";
418f7c2b37Sbouyer #else
42*a0647817Schristos __RCSID("$NetBSD: mount_ext2fs.c,v 1.23 2016/02/21 22:51:29 christos Exp $");
438f7c2b37Sbouyer #endif
448f7c2b37Sbouyer #endif /* not lint */
458f7c2b37Sbouyer
468f7c2b37Sbouyer #include <sys/param.h>
478f7c2b37Sbouyer #include <sys/mount.h>
48e5bc90f4Sfvdl #include <ufs/ufs/ufsmount.h>
498f7c2b37Sbouyer
508f7c2b37Sbouyer #include <err.h>
518f7c2b37Sbouyer #include <errno.h>
528f7c2b37Sbouyer #include <stdio.h>
538f7c2b37Sbouyer #include <stdlib.h>
548895fa19Slukem
558f7c2b37Sbouyer #include <string.h>
568f7c2b37Sbouyer #include <unistd.h>
578f7c2b37Sbouyer
58899bce09Sjdolecek #include <mntopts.h>
598f7c2b37Sbouyer
6099fed726Spooka #include "mountprog.h"
6199fed726Spooka #include "mount_ext2fs.h"
6299fed726Spooka
63baa8e84bSjoerg __dead static void ext2fs_usage(void);
648f7c2b37Sbouyer
658f7c2b37Sbouyer static const struct mntopt mopts[] = {
668f7c2b37Sbouyer MOPT_STDOPTS,
678f7c2b37Sbouyer MOPT_ASYNC,
688f7c2b37Sbouyer MOPT_SYNC,
698f7c2b37Sbouyer MOPT_UPDATE,
708f7c2b37Sbouyer MOPT_RELOAD,
718895fa19Slukem MOPT_FORCE,
729f9ee297Schristos MOPT_GETARGS,
73484162b8Skenh MOPT_NODEVMTIME,
74*a0647817Schristos MOPT_NOATIME,
75*a0647817Schristos MOPT_RELATIME,
765afd1c0aSchristos MOPT_NULL,
778f7c2b37Sbouyer };
788f7c2b37Sbouyer
79debb6d80Sjdolecek #ifndef MOUNT_NOMAIN
808f7c2b37Sbouyer int
main(int argc,char * argv[])81816b5578Sxtraeme main(int argc, char *argv[])
828f7c2b37Sbouyer {
8399fed726Spooka
8499fed726Spooka setprogname(argv[0]);
85debb6d80Sjdolecek return mount_ext2fs(argc, argv);
86debb6d80Sjdolecek }
87debb6d80Sjdolecek #endif
88debb6d80Sjdolecek
8999fed726Spooka void
mount_ext2fs_parseargs(int argc,char * argv[],struct ufs_args * args,int * mntflags,char * canon_dev,char * canon_dir)9099fed726Spooka mount_ext2fs_parseargs(int argc, char *argv[],
9199fed726Spooka struct ufs_args *args, int *mntflags,
9299fed726Spooka char *canon_dev, char *canon_dir)
93debb6d80Sjdolecek {
9499fed726Spooka int ch;
957067dcb9Schristos mntoptparse_t mp;
968f7c2b37Sbouyer
9799fed726Spooka memset(args, 0, sizeof(*args));
9899fed726Spooka *mntflags = 0;
998f7c2b37Sbouyer optind = optreset = 1; /* Reset for parse of new argv. */
1006a6a54d5Slukem while ((ch = getopt(argc, argv, "o:")) != -1)
1018f7c2b37Sbouyer switch (ch) {
1028f7c2b37Sbouyer case 'o':
10399fed726Spooka mp = getmntopts(optarg, mopts, mntflags, 0);
1047067dcb9Schristos if (mp == NULL)
1057067dcb9Schristos err(1, "getmntopts");
1067067dcb9Schristos freemntopts(mp);
1078f7c2b37Sbouyer break;
1088f7c2b37Sbouyer case '?':
1098f7c2b37Sbouyer default:
1108f7c2b37Sbouyer ext2fs_usage();
1118f7c2b37Sbouyer }
1128f7c2b37Sbouyer argc -= optind;
1138f7c2b37Sbouyer argv += optind;
1148f7c2b37Sbouyer
1158f7c2b37Sbouyer if (argc != 2)
1168f7c2b37Sbouyer ext2fs_usage();
1178f7c2b37Sbouyer
11899fed726Spooka pathadj(argv[0], canon_dev);
11999fed726Spooka args->fspec = canon_dev;
120fdd16c54Serh
12199fed726Spooka pathadj(argv[1], canon_dir);
122fdd16c54Serh }
1238f7c2b37Sbouyer
12499fed726Spooka int
mount_ext2fs(int argc,char * argv[])12599fed726Spooka mount_ext2fs(int argc, char *argv[])
12699fed726Spooka {
12799fed726Spooka struct ufs_args args; /* XXX ffs_args */
12899fed726Spooka char fs_name[MAXPATHLEN], canon_dev[MAXPATHLEN];
12999fed726Spooka const char *errcause;
13099fed726Spooka int mntflags;
13199fed726Spooka
13299fed726Spooka mount_ext2fs_parseargs(argc, argv, &args, &mntflags,
13399fed726Spooka canon_dev, fs_name);
13499fed726Spooka
135704e0753Spooka if (mount(MOUNT_EXT2FS, fs_name, mntflags, &args, sizeof args) == -1) {
1368f7c2b37Sbouyer switch (errno) {
1378f7c2b37Sbouyer case EMFILE:
1388f7c2b37Sbouyer errcause = "mount table full";
1398f7c2b37Sbouyer break;
1408f7c2b37Sbouyer case EINVAL:
1418f7c2b37Sbouyer if (mntflags & MNT_UPDATE)
1428f7c2b37Sbouyer errcause =
1438f7c2b37Sbouyer "specified device does not match mounted device";
1448f7c2b37Sbouyer else
1458f7c2b37Sbouyer errcause = "incorrect super block";
1468f7c2b37Sbouyer break;
1478f7c2b37Sbouyer default:
1488f7c2b37Sbouyer errcause = strerror(errno);
1498f7c2b37Sbouyer break;
1508f7c2b37Sbouyer }
1518f7c2b37Sbouyer errx(1, "%s on %s: %s", args.fspec, fs_name, errcause);
1528f7c2b37Sbouyer }
1538f7c2b37Sbouyer exit(0);
1548f7c2b37Sbouyer }
1558f7c2b37Sbouyer
156debb6d80Sjdolecek static void
ext2fs_usage(void)157816b5578Sxtraeme ext2fs_usage(void)
1588f7c2b37Sbouyer {
1598f7c2b37Sbouyer (void)fprintf(stderr,
16099fed726Spooka "usage: %s [-o options] special node\n", getprogname());
1618f7c2b37Sbouyer exit(1);
1628f7c2b37Sbouyer }
163