xref: /netbsd-src/sbin/mount_procfs/mount_procfs.c (revision fd33bfb7f2a74c2ddd9aea91bb08026696cc083c)
1*fd33bfb7Smlelstv /*	$NetBSD: mount_procfs.c,v 1.25 2020/07/26 08:20:23 mlelstv Exp $	*/
2276d62f6Sagc 
3276d62f6Sagc /*
4276d62f6Sagc  * Copyright (c) 1992, 1993, 1994
5276d62f6Sagc  *	The Regents of the University of California.  All rights reserved.
6276d62f6Sagc  *
7276d62f6Sagc  * This code is derived from software contributed to Berkeley by
8276d62f6Sagc  * Jan-Simon Pendry.
9276d62f6Sagc  *
10276d62f6Sagc  * Redistribution and use in source and binary forms, with or without
11276d62f6Sagc  * modification, are permitted provided that the following conditions
12276d62f6Sagc  * are met:
13276d62f6Sagc  * 1. Redistributions of source code must retain the above copyright
14276d62f6Sagc  *    notice, this list of conditions and the following disclaimer.
15276d62f6Sagc  * 2. Redistributions in binary form must reproduce the above copyright
16276d62f6Sagc  *    notice, this list of conditions and the following disclaimer in the
17276d62f6Sagc  *    documentation and/or other materials provided with the distribution.
18276d62f6Sagc  * 3. Neither the name of the University nor the names of its contributors
19276d62f6Sagc  *    may be used to endorse or promote products derived from this software
20276d62f6Sagc  *    without specific prior written permission.
21276d62f6Sagc  *
22276d62f6Sagc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23276d62f6Sagc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24276d62f6Sagc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25276d62f6Sagc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26276d62f6Sagc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27276d62f6Sagc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28276d62f6Sagc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29276d62f6Sagc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30276d62f6Sagc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31276d62f6Sagc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32276d62f6Sagc  * SUCH DAMAGE.
33276d62f6Sagc  */
340114e805Scgd 
357f940b41Spk /*
361697887bScgd  * Copyright (c) 1990, 1992, 1993 Jan-Simon Pendry
371697887bScgd  *
381697887bScgd  * This code is derived from software contributed to Berkeley by
391697887bScgd  * Jan-Simon Pendry.
407f940b41Spk  *
417f940b41Spk  * Redistribution and use in source and binary forms, with or without
427f940b41Spk  * modification, are permitted provided that the following conditions
437f940b41Spk  * are met:
447f940b41Spk  * 1. Redistributions of source code must retain the above copyright
457f940b41Spk  *    notice, this list of conditions and the following disclaimer.
467f940b41Spk  * 2. Redistributions in binary form must reproduce the above copyright
477f940b41Spk  *    notice, this list of conditions and the following disclaimer in the
487f940b41Spk  *    documentation and/or other materials provided with the distribution.
497f940b41Spk  * 3. All advertising materials mentioning features or use of this software
507f940b41Spk  *    must display the following acknowledgement:
511697887bScgd  *	This product includes software developed by the University of
521697887bScgd  *	California, Berkeley and its contributors.
531697887bScgd  * 4. Neither the name of the University nor the names of its contributors
541697887bScgd  *    may be used to endorse or promote products derived from this software
551697887bScgd  *    without specific prior written permission.
567f940b41Spk  *
571697887bScgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
581697887bScgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
591697887bScgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
601697887bScgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
611697887bScgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
621697887bScgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
631697887bScgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
641697887bScgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
651697887bScgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
661697887bScgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
671697887bScgd  * SUCH DAMAGE.
687f940b41Spk  */
697f940b41Spk 
70f7868153Slukem #include <sys/cdefs.h>
715922d844Smycroft #ifndef lint
726543a91fSlukem __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\
736543a91fSlukem  The Regents of the University of California.  All rights reserved.");
745922d844Smycroft #endif /* not lint */
755922d844Smycroft 
765922d844Smycroft #ifndef lint
770114e805Scgd #if 0
784b0b1ba8Slukem static char sccsid[] = "@(#)mount_procfs.c	8.4 (Berkeley) 4/26/95";
790114e805Scgd #else
80*fd33bfb7Smlelstv __RCSID("$NetBSD: mount_procfs.c,v 1.25 2020/07/26 08:20:23 mlelstv Exp $");
810114e805Scgd #endif
825922d844Smycroft #endif /* not lint */
835922d844Smycroft 
841697887bScgd #include <sys/param.h>
85883ee6aeSpk #include <sys/mount.h>
86883ee6aeSpk 
875922d844Smycroft #include <err.h>
881697887bScgd #include <unistd.h>
891697887bScgd #include <stdio.h>
901697887bScgd #include <stdlib.h>
911697887bScgd #include <string.h>
929f9ee297Schristos #include <util.h>
931697887bScgd 
94a7fede80Sfvdl #include <miscfs/procfs/procfs.h>
95a7fede80Sfvdl 
96899bce09Sjdolecek #include <mntopts.h>
975922d844Smycroft 
98*fd33bfb7Smlelstv #include "mountprog.h"
99*fd33bfb7Smlelstv 
100debb6d80Sjdolecek static const struct mntopt mopts[] = {
1015922d844Smycroft 	MOPT_STDOPTS,
1029f9ee297Schristos 	MOPT_GETARGS,
103a7fede80Sfvdl 	{ "linux", 0, PROCFSMNT_LINUXCOMPAT, 1},
1045afd1c0aSchristos 	MOPT_NULL,
1055922d844Smycroft };
1065922d844Smycroft 
10760fef079Sxtraeme int	mount_procfs(int argc, char **argv);
108baa8e84bSjoerg __dead static void	usage(void);
109883ee6aeSpk 
110debb6d80Sjdolecek #ifndef MOUNT_NOMAIN
111883ee6aeSpk int
main(int argc,char ** argv)11260fef079Sxtraeme main(int argc, char **argv)
113debb6d80Sjdolecek {
114debb6d80Sjdolecek 	return mount_procfs(argc, argv);
115debb6d80Sjdolecek }
116debb6d80Sjdolecek #endif
117debb6d80Sjdolecek 
118debb6d80Sjdolecek int
mount_procfs(int argc,char * argv[])11960fef079Sxtraeme mount_procfs(int argc, char *argv[])
120883ee6aeSpk {
121a7fede80Sfvdl 	int ch, mntflags, altflags;
122a7fede80Sfvdl 	struct procfs_args args;
123fdd16c54Serh 	char canon_dir[MAXPATHLEN];
1247067dcb9Schristos 	mntoptparse_t mp;
125883ee6aeSpk 
1263f2d5fc9Spooka 	mntflags = 0;
1273f2d5fc9Spooka 	altflags = PROCFSMNT_LINUXCOMPAT;
128f7868153Slukem 	while ((ch = getopt(argc, argv, "o:")) != -1)
1291697887bScgd 		switch (ch) {
1305922d844Smycroft 		case 'o':
1317067dcb9Schristos 			mp = getmntopts(optarg, mopts, &mntflags, &altflags);
1327067dcb9Schristos 			if (mp == NULL)
1337067dcb9Schristos 				err(1, "getmntopts");
1347067dcb9Schristos 			freemntopts(mp);
135883ee6aeSpk 			break;
1361697887bScgd 		case '?':
137883ee6aeSpk 		default:
138883ee6aeSpk 			usage();
139883ee6aeSpk 		}
1401697887bScgd 	argc -= optind;
1411697887bScgd 	argv += optind;
142883ee6aeSpk 
1431697887bScgd 	if (argc != 2)
144883ee6aeSpk 		usage();
145883ee6aeSpk 
146*fd33bfb7Smlelstv 	pathadj(argv[1], canon_dir);
147fdd16c54Serh 
148a7fede80Sfvdl 	args.version = PROCFS_ARGSVERSION;
149a7fede80Sfvdl 	args.flags = altflags;
150a7fede80Sfvdl 
151704e0753Spooka 	if (mount(MOUNT_PROCFS, canon_dir, mntflags, &args, sizeof args) == -1)
152fdd16c54Serh 		err(1, "procfs on %s", canon_dir);
1539f9ee297Schristos 	if (mntflags & MNT_GETARGS) {
1549f9ee297Schristos 		char buf[1024];
1559f9ee297Schristos 		(void)snprintb(buf, sizeof(buf), PROCFSMNT_BITS, args.flags);
1569f9ee297Schristos 		printf("version=%d, flags=%s\n", args.version, buf);
1579f9ee297Schristos 	}
158883ee6aeSpk 	exit(0);
159883ee6aeSpk }
160883ee6aeSpk 
161debb6d80Sjdolecek static void
usage(void)16260fef079Sxtraeme usage(void)
1631697887bScgd {
1641697887bScgd 	(void)fprintf(stderr,
1655922d844Smycroft 		"usage: mount_procfs [-o options] /proc mount_point\n");
1661697887bScgd 	exit(1);
1671697887bScgd }
168