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