2 * Copyright (c) 2018 The NetBSD Foundation, Inc.
5 * This code is derived from software contributed to The NetBSD Foundation
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/param.h>
31 #include <sys/mount.h>
32 #include <sys/cdefs.h>
42 #include <vfs/autofs/autofs_mount.h>
44 #include "mount_autofs.h"
46 static const struct mntopt mopts[] = {
51 static void usage(void) __dead2;
54 main(int argc, char **argv)
56 return mount_autofs(argc, argv);
60 mount_autofs_parseargs(int argc, char *argv[], void *v, int *mntflags,
61 char *canon_dev, char *canon_dir)
64 struct autofs_mount_info *am = v;
67 while ((ch = getopt(argc, argv, "f:o:O:p:")) != -1)
70 strlcpy(__DECONST(char*, am->from), optarg, MAXPATHLEN);
73 getmntopts(optarg, mopts, mntflags, 0);
76 strlcpy(__DECONST(char*, am->master_options), optarg,
80 strlcpy(__DECONST(char*, am->master_prefix), optarg,
93 strlcpy(canon_dev, argv[0], MAXPATHLEN);
94 if (realpath(argv[1], canon_dir) == NULL) /* Check mounton path */
95 err(EXIT_FAILURE, "realpath %s", canon_dir);
96 if (strncmp(argv[1], canon_dir, MAXPATHLEN)) {
97 warnx("\"%s\" is a relative path.", argv[1]);
98 warnx("using \"%s\" instead.", canon_dir);
103 mount_autofs(int argc, char *argv[])
105 char canon_dev[MAXPATHLEN], canon_dir[MAXPATHLEN];
106 char from[MAXPATHLEN], master_options[MAXPATHLEN];
107 char master_prefix[MAXPATHLEN];
110 struct autofs_mount_info am = {
112 .master_options = master_options,
113 .master_prefix = master_prefix,
116 mount_autofs_parseargs(argc, argv, &am, &mntflags,
117 canon_dev, canon_dir);
119 error = getvfsbyname("autofs", &vfc);
120 if (error && vfsisloadable("autofs")) {
121 if(vfsload("autofs"))
122 err(EX_OSERR, "vfsload(%s)", "autofs");
124 error = getvfsbyname("autofs", &vfc);
127 errx(EX_OSERR, "%s filesystem not available", "autofs");
129 if (mount(vfc.vfc_name, canon_dir, mntflags, &am) == -1)
130 err(EXIT_FAILURE, "autofs on %s", canon_dir);
138 (void)fprintf(stderr,
139 "Usage: %s [-o options] [-O master_options] [-p master_prefix] "
140 "[-f <from>] autofs mount_point\n", getprogname());