source: src-sh/pbi-manager10/mount_nullfs/mount_nullfs.c @ 1934da2

9.2-releasereleng/10.0releng/10.0.1
Last change on this file since 1934da2 was 1934da2, checked in by Kris Moore <kris@…>, 7 months ago

Finish bootstrapping the new PBI format essentials for 10, add
the mount_nullfs binary we will be using, as well as fix some issues
creating the wrapper files to use it.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Copyright (c) 1992, 1993, 1994
3 *      The Regents of the University of California.  All rights reserved.
4 *
5 * Modifed 2013 - Kris Moore (iXsystems)
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 * 4. Neither the name of the University nor the names of its contributors
19 *    may be used to endorse or promote products derived from this software
20 *    without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35#ifndef lint
36static const char copyright[] =
37"@(#) Copyright (c) 1992, 1993, 1994\n\
38        The Regents of the University of California.  All rights reserved.\n";
39#endif /* not lint */
40
41#ifndef lint
42#if 0
43static char sccsid[] = "@(#)mount_null.c        8.6 (Berkeley) 4/26/95";
44#endif
45static const char rcsid[] =
46  "$FreeBSD: release/9.1.0/sbin/mount_nullfs/mount_nullfs.c 201227 2009-12-29 22:53:27Z ed $";
47#endif /* not lint */
48
49#include <sys/param.h>
50#include <sys/mount.h>
51#include <sys/uio.h>
52
53#include <err.h>
54#include <stdio.h>
55#include <stdlib.h>
56#include <string.h>
57#include <sysexits.h>
58#include <unistd.h>
59
60#include "mntopts.h"
61
62struct mntopt mopts[] = {
63        MOPT_STDOPTS,
64        MOPT_END
65};
66
67int     subdir(const char *, const char *);
68static void     usage(void) __dead2;
69
70int
71main(int argc, char *argv[])
72{
73        struct iovec iov[6];
74        int ch, mntflags;
75        char source[MAXPATHLEN];
76        char target[MAXPATHLEN];
77
78        mntflags = 0;
79        while ((ch = getopt(argc, argv, "o:")) != -1)
80                switch(ch) {
81                case 'o':
82                        getmntopts(optarg, mopts, &mntflags, 0);
83                        break;
84                case '?':
85                default:
86                        usage();
87                }
88        argc -= optind;
89        argv += optind;
90
91        if (argc != 2)
92                usage();
93
94        /* resolve target and source with realpath(3) */
95        (void)checkpath(argv[0], target);
96        (void)checkpath(argv[1], source);
97
98        iov[0].iov_base = strdup("fstype");
99        iov[0].iov_len = sizeof("fstype");
100        iov[1].iov_base = strdup("nullfs");
101        iov[1].iov_len = strlen(iov[1].iov_base) + 1;
102        iov[2].iov_base = strdup("fspath");
103        iov[2].iov_len = sizeof("fspath");
104        iov[3].iov_base = source;
105        iov[3].iov_len = strlen(source) + 1;
106        iov[4].iov_base = strdup("target");
107        iov[4].iov_len = sizeof("target");
108        iov[5].iov_base = target;
109        iov[5].iov_len = strlen(target) + 1;
110
111        if (nmount(iov, 6, mntflags))
112                err(1, NULL);
113        exit(0);
114}
115
116int
117subdir(const char *p, const char *dir)
118{
119        int l;
120
121        l = strlen(dir);
122        if (l <= 1)
123                return (1);
124
125        if ((strncmp(p, dir, l) == 0) && (p[l] == '/' || p[l] == '\0'))
126                return (1);
127
128        return (0);
129}
130
131static void
132usage(void)
133{
134        (void)fprintf(stderr,
135                "usage: mount_nullfs [-o options] target mount-point\n");
136        exit(1);
137}
Note: See TracBrowser for help on using the repository browser.