mount_procfs.c revision 1.21
11.21Spooka/* $NetBSD: mount_procfs.c,v 1.21 2007/07/16 17:06:54 pooka 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.21Spooka__RCSID("$NetBSD: mount_procfs.c,v 1.21 2007/07/16 17:06:54 pooka 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.19Schristos MOPT_NULL, 1031.5Smycroft}; 1041.5Smycroft 1051.17Sxtraemeint mount_procfs(int argc, char **argv); 1061.17Sxtraemestatic void usage(void); 1071.1Spk 1081.11Sjdolecek#ifndef MOUNT_NOMAIN 1091.1Spkint 1101.17Sxtraememain(int argc, char **argv) 1111.11Sjdolecek{ 1121.11Sjdolecek return mount_procfs(argc, argv); 1131.11Sjdolecek} 1141.11Sjdolecek#endif 1151.11Sjdolecek 1161.11Sjdolecekint 1171.17Sxtraememount_procfs(int argc, char *argv[]) 1181.1Spk{ 1191.12Sfvdl int ch, mntflags, altflags; 1201.12Sfvdl struct procfs_args args; 1211.16Serh char canon_dir[MAXPATHLEN]; 1221.18Schristos mntoptparse_t mp; 1231.1Spk 1241.12Sfvdl mntflags = altflags = 0; 1251.8Slukem while ((ch = getopt(argc, argv, "o:")) != -1) 1261.5Smycroft switch (ch) { 1271.5Smycroft case 'o': 1281.18Schristos mp = getmntopts(optarg, mopts, &mntflags, &altflags); 1291.18Schristos if (mp == NULL) 1301.18Schristos err(1, "getmntopts"); 1311.18Schristos freemntopts(mp); 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.16Serh if (realpath(argv[1], canon_dir) == NULL) /* Check mounton path */ 1441.16Serh err(1, "realpath %s", argv[1]); 1451.16Serh if (strncmp(argv[1], canon_dir, MAXPATHLEN)) { 1461.16Serh warnx("\"%s\" is a relative path.", argv[1]); 1471.16Serh warnx("using \"%s\" instead.", canon_dir); 1481.16Serh } 1491.16Serh 1501.12Sfvdl args.version = PROCFS_ARGSVERSION; 1511.12Sfvdl args.flags = altflags; 1521.12Sfvdl 1531.21Spooka if (mount(MOUNT_PROCFS, canon_dir, mntflags, &args, sizeof args) == -1) 1541.16Serh err(1, "procfs on %s", canon_dir); 1551.13Schristos if (mntflags & MNT_GETARGS) { 1561.13Schristos char buf[1024]; 1571.13Schristos (void)snprintb(buf, sizeof(buf), PROCFSMNT_BITS, args.flags); 1581.13Schristos printf("version=%d, flags=%s\n", args.version, buf); 1591.13Schristos } 1601.4Scgd exit(0); 1611.4Scgd} 1621.1Spk 1631.11Sjdolecekstatic void 1641.17Sxtraemeusage(void) 1651.4Scgd{ 1661.4Scgd (void)fprintf(stderr, 1671.5Smycroft "usage: mount_procfs [-o options] /proc mount_point\n"); 1681.4Scgd exit(1); 1691.1Spk} 170