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>
41 #include <vfs/autofs/autofs_mount.h>
43 #include "mount_autofs.h"
47 * There is a reason to have const char*, so keep them const.
49 #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
51 static const struct mntopt mopts
[] = {
56 static void usage(void) __dead2
;
59 main(int argc
, char **argv
)
61 return mount_autofs(argc
, argv
);
65 mount_autofs_parseargs(int argc
, char *argv
[], void *v
, int *mntflags
,
66 char *canon_dev
, char *canon_dir
)
69 struct autofs_mount_info
*am
= v
;
72 while ((ch
= getopt(argc
, argv
, "f:o:O:p:")) != -1)
75 strlcpy(__UNCONST(am
->from
), optarg
, MAXPATHLEN
);
78 getmntopts(optarg
, mopts
, mntflags
, 0);
81 strlcpy(__UNCONST(am
->master_options
), optarg
,
85 strlcpy(__UNCONST(am
->master_prefix
), optarg
,
98 strlcpy(canon_dev
, argv
[0], MAXPATHLEN
);
99 if (realpath(argv
[1], canon_dir
) == NULL
) /* Check mounton path */
100 err(EXIT_FAILURE
, "realpath %s", canon_dir
);
101 if (strncmp(argv
[1], canon_dir
, MAXPATHLEN
)) {
102 warnx("\"%s\" is a relative path.", argv
[1]);
103 warnx("using \"%s\" instead.", canon_dir
);
108 mount_autofs(int argc
, char *argv
[])
110 char canon_dev
[MAXPATHLEN
], canon_dir
[MAXPATHLEN
];
111 char from
[MAXPATHLEN
], master_options
[MAXPATHLEN
];
112 char master_prefix
[MAXPATHLEN
];
115 struct autofs_mount_info am
= {
117 .master_options
= master_options
,
118 .master_prefix
= master_prefix
,
121 mount_autofs_parseargs(argc
, argv
, &am
, &mntflags
,
122 canon_dev
, canon_dir
);
124 error
= getvfsbyname("autofs", &vfc
);
125 if (error
&& vfsisloadable("autofs")) {
126 if(vfsload("autofs"))
127 err(EX_OSERR
, "vfsload(%s)", "autofs");
129 error
= getvfsbyname("autofs", &vfc
);
132 errx(EX_OSERR
, "%s filesystem not available", "autofs");
134 if (mount(vfc
.vfc_name
, canon_dir
, mntflags
, &am
) == -1)
135 err(EXIT_FAILURE
, "autofs on %s", canon_dir
);
143 (void)fprintf(stderr
,
144 "Usage: %s [-o options] [-O master_options] [-p master_prefix] "
145 "[-f <from>] autofs mount_point\n", getprogname());