11.25Smlelstv/*	$NetBSD: mount_procfs.c,v 1.25 2020/07/26 08:20:23 mlelstv Exp $	*/
21.6Scgd
31.2Spk/*
41.5Smycroft * Copyright (c) 1992, 1993, 1994
51.4Scgd *	The Regents of the University of California.  All rights reserved.
61.4Scgd *
71.4Scgd * This code is derived from software contributed to Berkeley by
81.4Scgd * Jan-Simon Pendry.
91.2Spk *
101.2Spk * Redistribution and use in source and binary forms, with or without
111.2Spk * modification, are permitted provided that the following conditions
121.2Spk * are met:
131.2Spk * 1. Redistributions of source code must retain the above copyright
141.2Spk *    notice, this list of conditions and the following disclaimer.
151.2Spk * 2. Redistributions in binary form must reproduce the above copyright
161.2Spk *    notice, this list of conditions and the following disclaimer in the
171.2Spk *    documentation and/or other materials provided with the distribution.
181.15Sagc * 3. Neither the name of the University nor the names of its contributors
191.15Sagc *    may be used to endorse or promote products derived from this software
201.15Sagc *    without specific prior written permission.
211.15Sagc *
221.15Sagc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
231.15Sagc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241.15Sagc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251.15Sagc * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
261.15Sagc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271.15Sagc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281.15Sagc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291.15Sagc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301.15Sagc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311.15Sagc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321.15Sagc * SUCH DAMAGE.
331.15Sagc */
341.15Sagc
351.15Sagc/*
361.15Sagc * Copyright (c) 1990, 1992, 1993 Jan-Simon Pendry
371.15Sagc *
381.15Sagc * This code is derived from software contributed to Berkeley by
391.15Sagc * Jan-Simon Pendry.
401.15Sagc *
411.15Sagc * Redistribution and use in source and binary forms, with or without
421.15Sagc * modification, are permitted provided that the following conditions
431.15Sagc * are met:
441.15Sagc * 1. Redistributions of source code must retain the above copyright
451.15Sagc *    notice, this list of conditions and the following disclaimer.
461.15Sagc * 2. Redistributions in binary form must reproduce the above copyright
471.15Sagc *    notice, this list of conditions and the following disclaimer in the
481.15Sagc *    documentation and/or other materials provided with the distribution.
491.2Spk * 3. All advertising materials mentioning features or use of this software
501.2Spk *    must display the following acknowledgement:
511.4Scgd *	This product includes software developed by the University of
521.4Scgd *	California, Berkeley and its contributors.
531.4Scgd * 4. Neither the name of the University nor the names of its contributors
541.4Scgd *    may be used to endorse or promote products derived from this software
551.4Scgd *    without specific prior written permission.
561.2Spk *
571.4Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
581.4Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
591.4Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
601.4Scgd * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
611.4Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
621.4Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
631.4Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
641.4Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
651.4Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
661.4Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
671.4Scgd * SUCH DAMAGE.
681.2Spk */
691.2Spk
701.8Slukem#include <sys/cdefs.h>
711.5Smycroft#ifndef lint
721.22Slukem__COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\
731.22Slukem The Regents of the University of California.  All rights reserved.");
741.5Smycroft#endif /* not lint */
751.5Smycroft
761.5Smycroft#ifndef lint
771.6Scgd#if 0
781.9Slukemstatic char sccsid[] = "@(#)mount_procfs.c	8.4 (Berkeley) 4/26/95";
791.6Scgd#else
801.25Smlelstv__RCSID("$NetBSD: mount_procfs.c,v 1.25 2020/07/26 08:20:23 mlelstv Exp $");
811.6Scgd#endif
821.5Smycroft#endif /* not lint */
831.5Smycroft
841.4Scgd#include <sys/param.h>
851.4Scgd#include <sys/mount.h>
861.4Scgd
871.5Smycroft#include <err.h>
881.4Scgd#include <unistd.h>
891.1Spk#include <stdio.h>
901.4Scgd#include <stdlib.h>
911.4Scgd#include <string.h>
921.13Schristos#include <util.h>
931.4Scgd
941.12Sfvdl#include <miscfs/procfs/procfs.h>
951.12Sfvdl
961.14Sjdolecek#include <mntopts.h>
971.5Smycroft
981.25Smlelstv#include "mountprog.h"
991.25Smlelstv
1001.11Sjdolecekstatic const struct mntopt mopts[] = {
1011.5Smycroft	MOPT_STDOPTS,
1021.13Schristos	MOPT_GETARGS,
1031.12Sfvdl	{ "linux", 0, PROCFSMNT_LINUXCOMPAT, 1},
1041.19Schristos	MOPT_NULL,
1051.5Smycroft};
1061.5Smycroft
1071.17Sxtraemeint	mount_procfs(int argc, char **argv);
1081.24Sjoerg__dead static void	usage(void);
1091.1Spk
1101.11Sjdolecek#ifndef MOUNT_NOMAIN
1111.1Spkint
1121.17Sxtraememain(int argc, char **argv)
1131.11Sjdolecek{
1141.11Sjdolecek	return mount_procfs(argc, argv);
1151.11Sjdolecek}
1161.11Sjdolecek#endif
1171.11Sjdolecek
1181.11Sjdolecekint
1191.17Sxtraememount_procfs(int argc, char *argv[])
1201.1Spk{
1211.12Sfvdl	int ch, mntflags, altflags;
1221.12Sfvdl	struct procfs_args args;
1231.16Serh	char canon_dir[MAXPATHLEN];
1241.18Schristos	mntoptparse_t mp;
1251.1Spk
1261.23Spooka	mntflags = 0;
1271.23Spooka	altflags = PROCFSMNT_LINUXCOMPAT;
1281.8Slukem	while ((ch = getopt(argc, argv, "o:")) != -1)
1291.5Smycroft		switch (ch) {
1301.5Smycroft		case 'o':
1311.18Schristos			mp = getmntopts(optarg, mopts, &mntflags, &altflags);
1321.18Schristos			if (mp == NULL)
1331.18Schristos				err(1, "getmntopts");
1341.18Schristos			freemntopts(mp);
1351.1Spk			break;
1361.4Scgd		case '?':
1371.1Spk		default:
1381.4Scgd			usage();
1391.1Spk		}
1401.4Scgd	argc -= optind;
1411.4Scgd	argv += optind;
1421.1Spk
1431.4Scgd	if (argc != 2)
1441.4Scgd		usage();
1451.1Spk
1461.25Smlelstv	pathadj(argv[1], canon_dir);
1471.16Serh
1481.12Sfvdl	args.version = PROCFS_ARGSVERSION;
1491.12Sfvdl	args.flags = altflags;
1501.12Sfvdl
1511.21Spooka	if (mount(MOUNT_PROCFS, canon_dir, mntflags, &args, sizeof args) == -1)
1521.16Serh		err(1, "procfs on %s", canon_dir);
1531.13Schristos	if (mntflags & MNT_GETARGS) {
1541.13Schristos		char buf[1024];
1551.13Schristos		(void)snprintb(buf, sizeof(buf), PROCFSMNT_BITS, args.flags);
1561.13Schristos		printf("version=%d, flags=%s\n", args.version, buf);
1571.13Schristos	}
1581.4Scgd	exit(0);
1591.4Scgd}
1601.1Spk
1611.11Sjdolecekstatic void
1621.17Sxtraemeusage(void)
1631.4Scgd{
1641.4Scgd	(void)fprintf(stderr,
1651.5Smycroft		"usage: mount_procfs [-o options] /proc mount_point\n");
1661.4Scgd	exit(1);
1671.1Spk}
168