mount_procfs.c revision 1.13
11.13Schristos/*	$NetBSD: mount_procfs.c,v 1.13 2002/09/21 18:43:38 christos Exp $	*/
21.6Scgd
31.2Spk/*
41.4Scgd * Copyright (c) 1990, 1992, 1993 Jan-Simon Pendry
51.5Smycroft * Copyright (c) 1992, 1993, 1994
61.4Scgd *	The Regents of the University of California.  All rights reserved.
71.4Scgd *
81.4Scgd * This code is derived from software contributed to Berkeley by
91.4Scgd * Jan-Simon Pendry.
101.2Spk *
111.2Spk * Redistribution and use in source and binary forms, with or without
121.2Spk * modification, are permitted provided that the following conditions
131.2Spk * are met:
141.2Spk * 1. Redistributions of source code must retain the above copyright
151.2Spk *    notice, this list of conditions and the following disclaimer.
161.2Spk * 2. Redistributions in binary form must reproduce the above copyright
171.2Spk *    notice, this list of conditions and the following disclaimer in the
181.2Spk *    documentation and/or other materials provided with the distribution.
191.2Spk * 3. All advertising materials mentioning features or use of this software
201.2Spk *    must display the following acknowledgement:
211.4Scgd *	This product includes software developed by the University of
221.4Scgd *	California, Berkeley and its contributors.
231.4Scgd * 4. Neither the name of the University nor the names of its contributors
241.4Scgd *    may be used to endorse or promote products derived from this software
251.4Scgd *    without specific prior written permission.
261.2Spk *
271.4Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
281.4Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
291.4Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
301.4Scgd * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
311.4Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
321.4Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
331.4Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
341.4Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
351.4Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
361.4Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
371.4Scgd * SUCH DAMAGE.
381.2Spk */
391.2Spk
401.8Slukem#include <sys/cdefs.h>
411.5Smycroft#ifndef lint
421.8Slukem__COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\n\
431.8Slukem	The Regents of the University of California.  All rights reserved.\n");
441.5Smycroft#endif /* not lint */
451.5Smycroft
461.5Smycroft#ifndef lint
471.6Scgd#if 0
481.9Slukemstatic char sccsid[] = "@(#)mount_procfs.c	8.4 (Berkeley) 4/26/95";
491.6Scgd#else
501.13Schristos__RCSID("$NetBSD: mount_procfs.c,v 1.13 2002/09/21 18:43:38 christos Exp $");
511.6Scgd#endif
521.5Smycroft#endif /* not lint */
531.5Smycroft
541.4Scgd#include <sys/param.h>
551.4Scgd#include <sys/mount.h>
561.4Scgd
571.5Smycroft#include <err.h>
581.4Scgd#include <unistd.h>
591.1Spk#include <stdio.h>
601.4Scgd#include <stdlib.h>
611.4Scgd#include <string.h>
621.13Schristos#include <util.h>
631.4Scgd
641.12Sfvdl#include <miscfs/procfs/procfs.h>
651.12Sfvdl
661.5Smycroft#include "mntopts.h"
671.5Smycroft
681.11Sjdolecekstatic const struct mntopt mopts[] = {
691.5Smycroft	MOPT_STDOPTS,
701.13Schristos	MOPT_GETARGS,
711.12Sfvdl	{ "linux", 0, PROCFSMNT_LINUXCOMPAT, 1},
721.5Smycroft	{ NULL }
731.5Smycroft};
741.5Smycroft
751.8Slukemint	main __P((int, char *[]));
761.11Sjdolecekint	mount_procfs __P((int argc, char **argv));
771.11Sjdolecekstatic void	usage __P((void));
781.1Spk
791.11Sjdolecek#ifndef MOUNT_NOMAIN
801.1Spkint
811.4Scgdmain(argc, argv)
821.4Scgd	int argc;
831.11Sjdolecek	char **argv;
841.11Sjdolecek{
851.11Sjdolecek	return mount_procfs(argc, argv);
861.11Sjdolecek}
871.11Sjdolecek#endif
881.11Sjdolecek
891.11Sjdolecekint
901.11Sjdolecekmount_procfs(argc, argv)
911.11Sjdolecek	int argc;
921.4Scgd	char *argv[];
931.1Spk{
941.12Sfvdl	int ch, mntflags, altflags;
951.12Sfvdl	struct procfs_args args;
961.1Spk
971.12Sfvdl	mntflags = altflags = 0;
981.8Slukem	while ((ch = getopt(argc, argv, "o:")) != -1)
991.5Smycroft		switch (ch) {
1001.5Smycroft		case 'o':
1011.12Sfvdl			getmntopts(optarg, mopts, &mntflags, &altflags);
1021.1Spk			break;
1031.4Scgd		case '?':
1041.1Spk		default:
1051.4Scgd			usage();
1061.1Spk		}
1071.4Scgd	argc -= optind;
1081.4Scgd	argv += optind;
1091.1Spk
1101.4Scgd	if (argc != 2)
1111.4Scgd		usage();
1121.1Spk
1131.12Sfvdl	args.version = PROCFS_ARGSVERSION;
1141.12Sfvdl	args.flags = altflags;
1151.12Sfvdl
1161.12Sfvdl	if (mount(MOUNT_PROCFS, argv[1], mntflags, &args))
1171.10Sperseant		err(1, "procfs on %s", argv[1]);
1181.13Schristos	if (mntflags & MNT_GETARGS) {
1191.13Schristos		char buf[1024];
1201.13Schristos		(void)snprintb(buf, sizeof(buf), PROCFSMNT_BITS, args.flags);
1211.13Schristos		printf("version=%d, flags=%s\n", args.version, buf);
1221.13Schristos	}
1231.4Scgd	exit(0);
1241.4Scgd}
1251.1Spk
1261.11Sjdolecekstatic void
1271.4Scgdusage()
1281.4Scgd{
1291.4Scgd	(void)fprintf(stderr,
1301.5Smycroft		"usage: mount_procfs [-o options] /proc mount_point\n");
1311.4Scgd	exit(1);
1321.1Spk}
133