mount_procfs.c revision 1.15
11.15Sagc/* $NetBSD: mount_procfs.c,v 1.15 2003/08/07 10:04:31 agc 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.8Slukem__COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\n\ 731.8Slukem The Regents of the University of California. All rights reserved.\n"); 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.15Sagc__RCSID("$NetBSD: mount_procfs.c,v 1.15 2003/08/07 10:04:31 agc 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.11Sjdolecekstatic const struct mntopt mopts[] = { 991.5Smycroft MOPT_STDOPTS, 1001.13Schristos MOPT_GETARGS, 1011.12Sfvdl { "linux", 0, PROCFSMNT_LINUXCOMPAT, 1}, 1021.5Smycroft { NULL } 1031.5Smycroft}; 1041.5Smycroft 1051.8Slukemint main __P((int, char *[])); 1061.11Sjdolecekint mount_procfs __P((int argc, char **argv)); 1071.11Sjdolecekstatic void usage __P((void)); 1081.1Spk 1091.11Sjdolecek#ifndef MOUNT_NOMAIN 1101.1Spkint 1111.4Scgdmain(argc, argv) 1121.4Scgd int argc; 1131.11Sjdolecek char **argv; 1141.11Sjdolecek{ 1151.11Sjdolecek return mount_procfs(argc, argv); 1161.11Sjdolecek} 1171.11Sjdolecek#endif 1181.11Sjdolecek 1191.11Sjdolecekint 1201.11Sjdolecekmount_procfs(argc, argv) 1211.11Sjdolecek int argc; 1221.4Scgd char *argv[]; 1231.1Spk{ 1241.12Sfvdl int ch, mntflags, altflags; 1251.12Sfvdl struct procfs_args args; 1261.1Spk 1271.12Sfvdl mntflags = altflags = 0; 1281.8Slukem while ((ch = getopt(argc, argv, "o:")) != -1) 1291.5Smycroft switch (ch) { 1301.5Smycroft case 'o': 1311.12Sfvdl getmntopts(optarg, mopts, &mntflags, &altflags); 1321.1Spk break; 1331.4Scgd case '?': 1341.1Spk default: 1351.4Scgd usage(); 1361.1Spk } 1371.4Scgd argc -= optind; 1381.4Scgd argv += optind; 1391.1Spk 1401.4Scgd if (argc != 2) 1411.4Scgd usage(); 1421.1Spk 1431.12Sfvdl args.version = PROCFS_ARGSVERSION; 1441.12Sfvdl args.flags = altflags; 1451.12Sfvdl 1461.12Sfvdl if (mount(MOUNT_PROCFS, argv[1], mntflags, &args)) 1471.10Sperseant err(1, "procfs on %s", argv[1]); 1481.13Schristos if (mntflags & MNT_GETARGS) { 1491.13Schristos char buf[1024]; 1501.13Schristos (void)snprintb(buf, sizeof(buf), PROCFSMNT_BITS, args.flags); 1511.13Schristos printf("version=%d, flags=%s\n", args.version, buf); 1521.13Schristos } 1531.4Scgd exit(0); 1541.4Scgd} 1551.1Spk 1561.11Sjdolecekstatic void 1571.4Scgdusage() 1581.4Scgd{ 1591.4Scgd (void)fprintf(stderr, 1601.5Smycroft "usage: mount_procfs [-o options] /proc mount_point\n"); 1611.4Scgd exit(1); 1621.1Spk} 163