Module Name:    src
Committed By:   christos
Date:           Sun Jan 14 22:44:04 UTC 2018

Modified Files:
        src/sbin: Makefile
Added Files:
        src/sbin/mount_autofs: Makefile mount_autofs.c mount_autofs.h

Log Message:
Add mount_autofs


To generate a diff of this commit:
cvs rdiff -u -r1.131 -r1.132 src/sbin/Makefile
cvs rdiff -u -r0 -r1.1 src/sbin/mount_autofs/Makefile \
    src/sbin/mount_autofs/mount_autofs.c src/sbin/mount_autofs/mount_autofs.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/Makefile
diff -u src/sbin/Makefile:1.131 src/sbin/Makefile:1.132
--- src/sbin/Makefile:1.131	Sat Nov 25 18:29:43 2017
+++ src/sbin/Makefile	Sun Jan 14 17:44:04 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.131 2017/11/25 23:29:43 jmcneill Exp $
+#	$NetBSD: Makefile,v 1.132 2018/01/14 22:44:04 christos Exp $
 #	@(#)Makefile	8.5 (Berkeley) 3/31/94
 
 # Not ported: XNSrouted enpload scsiformat startslip
@@ -25,6 +25,7 @@ SUBDIR+= newfs_sysvbfs
 SUBDIR+= newfs_udf
 SUBDIR+= newfs_v7fs fsck_v7fs
 SUBDIR+= mount_ados
+SUBDIR+= mount_autofs
 SUBDIR+= mount_cd9660
 SUBDIR+= mount_chfs
 SUBDIR+= mount_efs

Added files:

Index: src/sbin/mount_autofs/Makefile
diff -u /dev/null src/sbin/mount_autofs/Makefile:1.1
--- /dev/null	Sun Jan 14 17:44:05 2018
+++ src/sbin/mount_autofs/Makefile	Sun Jan 14 17:44:04 2018
@@ -0,0 +1,14 @@
+#	$NetBSD: Makefile,v 1.1 2018/01/14 22:44:04 christos Exp $
+#	@(#)Makefile	8.2 (Berkeley) 3/27/94
+
+NOMAN=
+.include <bsd.own.mk>
+
+PROG=	mount_autofs
+SRCS=	mount_autofs.c
+#MAN=	mount_autofs.8
+
+DPADD+=${LIBUTIL}
+LDADD+=-lutil
+
+.include <bsd.prog.mk>
Index: src/sbin/mount_autofs/mount_autofs.c
diff -u /dev/null src/sbin/mount_autofs/mount_autofs.c:1.1
--- /dev/null	Sun Jan 14 17:44:05 2018
+++ src/sbin/mount_autofs/mount_autofs.c	Sun Jan 14 17:44:04 2018
@@ -0,0 +1,146 @@
+/*	$NetBSD: mount_autofs.c,v 1.1 2018/01/14 22:44:04 christos Exp $	*/
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: mount_autofs.c,v 1.1 2018/01/14 22:44:04 christos Exp $");
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/mount.h>
+
+#include <err.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <mntopts.h>
+
+#include <fs/autofs/autofs_mount.h>
+
+#include "mount_autofs.h"
+
+static const struct mntopt mopts[] = {
+	MOPT_STDOPTS,
+	MOPT_GETARGS,
+	MOPT_NULL,
+};
+
+int	mount_autofs(int argc, char **argv);
+__dead static void	usage(void);
+
+#ifndef MOUNT_NOMAIN
+int
+main(int argc, char **argv)
+{
+	return mount_autofs(argc, argv);
+}
+#endif
+
+void
+mount_autofs_parseargs(int argc, char *argv[], void *v, int *mntflags,
+	char *canon_dev, char *canon_dir)
+{
+	int ch;
+	mntoptparse_t mp;
+	struct autofs_args *am = v;
+
+	*mntflags = 0;
+	while ((ch = getopt(argc, argv, "f:o:O:p:")) != -1)
+		switch (ch) {
+		case 'f':
+			strlcpy(am->from, optarg, MAXPATHLEN);
+			break;
+		case 'o':
+			mp = getmntopts(optarg, mopts, mntflags, 0);
+			if (mp == NULL)
+				err(EXIT_FAILURE, "getmntopts");
+			freemntopts(mp);
+			break;
+		case 'O':
+			strlcpy(am->master_options, optarg, MAXPATHLEN);
+			break;
+		case 'p':
+			strlcpy(am->master_prefix, optarg, MAXPATHLEN);
+			break;
+			
+		case '?':
+		default:
+			usage();
+		}
+	argc -= optind;
+	argv += optind;
+
+	if (argc != 2)
+		usage();
+
+	strlcpy(canon_dev, argv[0], MAXPATHLEN);
+	if (realpath(argv[1], canon_dir) == NULL)    /* Check mounton path */
+		err(EXIT_FAILURE, "realpath %s", canon_dir);
+	if (strncmp(argv[1], canon_dir, MAXPATHLEN)) {
+		warnx("\"%s\" is a relative path.", argv[1]);
+		warnx("using \"%s\" instead.", canon_dir);
+	}
+}
+
+int
+mount_autofs(int argc, char *argv[])
+{
+	char canon_dev[MAXPATHLEN], canon_dir[MAXPATHLEN];
+	char from[MAXPATHLEN], master_options[MAXPATHLEN];
+	char master_prefix[MAXPATHLEN];
+	int mntflags;
+	struct autofs_args am = {
+		.from = from,
+		.master_options = master_options,
+		.master_prefix = master_prefix,
+	};
+
+	mount_autofs_parseargs(argc, argv, &am, &mntflags,
+	    canon_dev, canon_dir);
+	if (mount(MOUNT_KERNFS, canon_dir, mntflags, &am, sizeof(am)) == -1)
+		err(EXIT_FAILURE, "kernfs on %s", canon_dir);
+        if (mntflags & MNT_GETARGS) {
+		printf("from=%s, master_options=%s, master_prefix=%s\n",
+		    am.from, am.master_options, am.master_prefix);
+	}
+
+	return EXIT_SUCCESS;
+}
+
+static void
+usage(void)
+{
+	(void)fprintf(stderr,
+	    "Usage: %s [-o options] [-O autofs_options] [-p <prefix>] "
+		"[-f <from>] autofs mount_point\n", getprogname());
+	exit(EXIT_FAILURE);
+}
Index: src/sbin/mount_autofs/mount_autofs.h
diff -u /dev/null src/sbin/mount_autofs/mount_autofs.h:1.1
--- /dev/null	Sun Jan 14 17:44:05 2018
+++ src/sbin/mount_autofs/mount_autofs.h	Sun Jan 14 17:44:04 2018
@@ -0,0 +1,34 @@
+/*	$NetBSD: mount_autofs.h,v 1.1 2018/01/14 22:44:04 christos Exp $	*/
+
+/*
+ * Copyright (c) 2008 The NetBSD Foundation.  All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _SBIN_MOUNT_AUTOFS_MOUNT_AUTOFS_H_
+#define _SBIN_MOUNT_AUTOFS_MOUNT_AUTOFS_H_
+
+int	mount_kernfs(int, char **);
+void	mount_autofs_parseargs(int, char **, void *, int *, char *, char *);
+
+#endif /* _SBIN_MOUNT_AUTOFS_MOUNT_AUTOFS_H_ */

Reply via email to