1 /* $OpenBSD: mount_procfs.c,v 1.15 2005/04/08 20:09:37 jaredy Exp $ */
2 /* $NetBSD: mount_procfs.c,v 1.7 1996/04/13 01:31:59 jtc Exp $ */
3
4 /*
5 * Copyright (c) 1990, 1992, 1993 Jan-Simon Pendry
6 * Copyright (c) 1992, 1993, 1994
7 * The Regents of the University of California. All rights reserved.
8 *
9 * This code is derived from software contributed to Berkeley by
10 * Jan-Simon Pendry.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37 #ifndef lint
38 char copyright[] =
39 "@(#) Copyright (c) 1992, 1993, 1994\n\
40 The Regents of the University of California. All rights reserved.\n";
41 #endif /* not lint */
42
43 #ifndef lint
44 #if 0
45 static char sccsid[] = "@(#)mount_procfs.c 8.3 (Berkeley) 3/27/94";
46 #else
47 static char rcsid[] = "$OpenBSD: mount_procfs.c,v 1.15 2005/04/08 20:09:37 jaredy Exp $";
48 #endif
49 #endif /* not lint */
50
51 #include <sys/param.h>
52 #include <sys/mount.h>
53
54 #include <err.h>
55 #include <errno.h>
56 #include <unistd.h>
57 #include <stdio.h>
58 #include <stdlib.h>
59 #include <string.h>
60
61 #include <miscfs/procfs/procfs.h>
62
63 #include "mntopts.h"
64
65 const struct mntopt mopts[] = {
66 MOPT_STDOPTS,
67 { "linux", PROCFSMNT_LINUXCOMPAT, 0 },
68 { NULL }
69 };
70
71 void usage(void);
72
73 int
main(int argc,char * argv[])74 main(int argc, char *argv[])
75 {
76 int ch, mntflags, altflags;
77 struct procfs_args args;
78 char path[MAXPATHLEN];
79
80 mntflags = altflags = 0;
81 while ((ch = getopt(argc, argv, "o:")) != -1)
82 switch (ch) {
83 case 'o':
84 altflags |= getmntopts(optarg, mopts, &mntflags);
85 break;
86 case '?':
87 default:
88 usage();
89 }
90 argc -= optind;
91 argv += optind;
92
93 if (argc != 2)
94 usage();
95
96 if (realpath(argv[1], path) == NULL)
97 err(1, "realpath %s", argv[1]);
98
99 args.version = PROCFS_ARGSVERSION;
100 args.flags = altflags;
101
102 if (mount(MOUNT_PROCFS, path, mntflags, &args)) {
103 if (errno == EOPNOTSUPP)
104 errx(1, "%s: Filesystem not supported by kernel",
105 argv[1]);
106 else
107 err(1, "%s", argv[1]);
108 }
109 exit(0);
110 }
111
112 void
usage(void)113 usage(void)
114 {
115 (void)fprintf(stderr,
116 "usage: mount_procfs [-o options] /proc mount_point\n");
117 exit(1);
118 }
119