1*d7259957Scheloha /* $OpenBSD: mount_ffs.c,v 1.26 2022/12/04 23:50:46 cheloha Exp $ */
2f3bae140Sderaadt /* $NetBSD: mount_ffs.c,v 1.3 1996/04/13 01:31:19 jtc Exp $ */
3df930be7Sderaadt
4df930be7Sderaadt /*-
5df930be7Sderaadt * Copyright (c) 1993, 1994
6df930be7Sderaadt * The Regents of the University of California. All rights reserved.
7df930be7Sderaadt *
8df930be7Sderaadt * Redistribution and use in source and binary forms, with or without
9df930be7Sderaadt * modification, are permitted provided that the following conditions
10df930be7Sderaadt * are met:
11df930be7Sderaadt * 1. Redistributions of source code must retain the above copyright
12df930be7Sderaadt * notice, this list of conditions and the following disclaimer.
13df930be7Sderaadt * 2. Redistributions in binary form must reproduce the above copyright
14df930be7Sderaadt * notice, this list of conditions and the following disclaimer in the
15df930be7Sderaadt * documentation and/or other materials provided with the distribution.
161ef0d710Smillert * 3. Neither the name of the University nor the names of its contributors
17df930be7Sderaadt * may be used to endorse or promote products derived from this software
18df930be7Sderaadt * without specific prior written permission.
19df930be7Sderaadt *
20df930be7Sderaadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21df930be7Sderaadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22df930be7Sderaadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23df930be7Sderaadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24df930be7Sderaadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25df930be7Sderaadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26df930be7Sderaadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27df930be7Sderaadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28df930be7Sderaadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29df930be7Sderaadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30df930be7Sderaadt * SUCH DAMAGE.
31df930be7Sderaadt */
32df930be7Sderaadt
33b9fc9a72Sderaadt #include <sys/types.h>
34df930be7Sderaadt #include <sys/mount.h>
35df930be7Sderaadt
36df930be7Sderaadt #include <err.h>
37df930be7Sderaadt #include <errno.h>
38df930be7Sderaadt #include <stdio.h>
39df930be7Sderaadt #include <stdlib.h>
40df930be7Sderaadt #include <string.h>
41df930be7Sderaadt #include <unistd.h>
42b9fc9a72Sderaadt #include <limits.h>
43df930be7Sderaadt
44df930be7Sderaadt #include "mntopts.h"
45df930be7Sderaadt
46c72b5b24Smillert void ffs_usage(void);
47df930be7Sderaadt
48f3bae140Sderaadt static const struct mntopt mopts[] = {
49df930be7Sderaadt MOPT_STDOPTS,
509f25ea04Sderaadt MOPT_WXALLOWED,
514fd6a335Snatano MOPT_NOPERM,
52df930be7Sderaadt MOPT_ASYNC,
53df930be7Sderaadt MOPT_SYNC,
54df930be7Sderaadt MOPT_UPDATE,
55df930be7Sderaadt MOPT_RELOAD,
564c51ec19Sniklas MOPT_FORCE,
5728122ad4Sgluk MOPT_SOFTDEP,
58df930be7Sderaadt { NULL }
59df930be7Sderaadt };
60df930be7Sderaadt
61df930be7Sderaadt int
main(int argc,char * argv[])628809fabbSderaadt main(int argc, char *argv[])
63df930be7Sderaadt {
64df930be7Sderaadt struct ufs_args args; /* XXX ffs_args */
65df930be7Sderaadt int ch, mntflags;
66b9fc9a72Sderaadt char fs_name[PATH_MAX], *errcause;
67df930be7Sderaadt
68df930be7Sderaadt mntflags = 0;
69df930be7Sderaadt optind = optreset = 1; /* Reset for parse of new argv. */
7072799b18Smillert while ((ch = getopt(argc, argv, "o:")) != -1)
71df930be7Sderaadt switch (ch) {
72df930be7Sderaadt case 'o':
73df930be7Sderaadt getmntopts(optarg, mopts, &mntflags);
74df930be7Sderaadt break;
75df930be7Sderaadt default:
76df930be7Sderaadt ffs_usage();
77df930be7Sderaadt }
78df930be7Sderaadt argc -= optind;
79df930be7Sderaadt argv += optind;
80df930be7Sderaadt
81df930be7Sderaadt if (argc != 2)
82df930be7Sderaadt ffs_usage();
83df930be7Sderaadt
84df930be7Sderaadt args.fspec = argv[0]; /* The name of the device file. */
8507e4edeaStedu if (realpath(argv[1], fs_name) == NULL) /* The mount point. */
86b0208e3fSjaredy err(1, "realpath %s", argv[1]);
87df930be7Sderaadt
88df930be7Sderaadt #define DEFAULT_ROOTUID -2
89ef9317a4Sespie args.export_info.ex_root = DEFAULT_ROOTUID;
90df930be7Sderaadt if (mntflags & MNT_RDONLY)
91ef9317a4Sespie args.export_info.ex_flags = MNT_EXRDONLY;
92df930be7Sderaadt else
93ef9317a4Sespie args.export_info.ex_flags = 0;
94df930be7Sderaadt
954fd6a335Snatano if (mntflags & MNT_NOPERM)
964fd6a335Snatano mntflags |= MNT_NODEV | MNT_NOEXEC;
974fd6a335Snatano
98df69c215Sderaadt if (mount(MOUNT_FFS, fs_name, mntflags, &args) == -1) {
99df930be7Sderaadt switch (errno) {
100df930be7Sderaadt case EMFILE:
101df930be7Sderaadt errcause = "mount table full";
102df930be7Sderaadt break;
103f4d426f7Smillert case EOPNOTSUPP:
1049802a1e1Smillert errcause = "filesystem not supported by kernel";
1059802a1e1Smillert break;
106edeef4a9Smillert case EROFS:
107edeef4a9Smillert errcause =
108edeef4a9Smillert "filesystem must be mounted read-only; you may need to run fsck";
109edeef4a9Smillert break;
110df930be7Sderaadt default:
111df930be7Sderaadt errcause = strerror(errno);
112df930be7Sderaadt break;
113df930be7Sderaadt }
114df930be7Sderaadt errx(1, "%s on %s: %s", args.fspec, fs_name, errcause);
115df930be7Sderaadt }
116df930be7Sderaadt exit(0);
117df930be7Sderaadt }
118df930be7Sderaadt
119df930be7Sderaadt void
ffs_usage(void)1208809fabbSderaadt ffs_usage(void)
121df930be7Sderaadt {
122df930be7Sderaadt (void)fprintf(stderr, "usage: mount_ffs [-o options] special node\n");
123df930be7Sderaadt exit(1);
124df930be7Sderaadt }
125