Sync usage with man page.
[netbsd-mini2440.git] / usr.sbin / puffs / rump_syspuffs / rump_syspuffs.c
blob11dce53eb468ef4e4b36c5aabf9256b826eab0b0
1 /* $NetBSD: rump_syspuffs.c,v 1.9 2009/04/15 08:36:21 pooka Exp $ */
3 /*
4 * Copyright (c) 2008 Antti Kantee. All Rights Reserved.
6 * Development of this software was supported by the
7 * Research Foundation of Helsinki University of Technology
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
31 #include <sys/types.h>
32 #include <sys/mount.h>
33 #include <sys/socket.h>
34 #include <sys/syslimits.h>
36 #include <assert.h>
37 #include <err.h>
38 #include <paths.h>
39 #include <puffs.h>
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <unistd.h>
44 #include <rump/rump.h>
46 #include "rump_syspuffs.h"
48 #ifndef MOUNT_NOMAIN
49 #include <rump/p2k.h>
51 int
52 main(int argc, char *argv[])
54 char canon_dev[MAXPATHLEN], canon_dir[MAXPATHLEN];
55 struct syspuffs_args args;
56 int mntflags, rv;
58 #if 0
59 extern int rumpns_puffsdebug;
60 extern int rumpns_putterdebug;
62 rumpns_puffsdebug = rumpns_putterdebug = 1;
63 #endif
65 setprogname(argv[0]);
67 mount_syspuffs_parseargs(argc, argv, &args, &mntflags,
68 canon_dev, canon_dir);
70 rv = p2k_run_fs(MOUNT_PUFFS, canon_dev, canon_dir, mntflags,
71 &args.us_kargs, sizeof(args.us_kargs), args.us_pflags);
72 if (rv)
73 err(1, "mount");
75 return 0;
77 #endif /* MOUNT_NOMAIN */
79 static void
80 usage(void)
83 errx(1, "%s: server server_parameters", getprogname());
86 void
87 mount_syspuffs_parseargs(int argc, char *argv[],
88 struct syspuffs_args *args, int *mntflags,
89 char *canon_dev, char *canon_dir)
91 struct puffs_kargs *kargs = &args->us_kargs;
92 int *pflags = &args->us_pflags;
93 char comfd[16];
94 int sv[2];
95 size_t len;
96 int rv;
98 if (argc < 2)
99 usage();
101 /* Create sucketpair for communication with the real file server */
102 if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) == -1)
103 err(1, "socketpair");
105 if ((rv = rump_init()) == -1)
106 err(1, "rump_init");
108 switch (fork()) {
109 case 0:
110 close(sv[1]);
111 snprintf(comfd, sizeof(sv[0]), "%d", sv[0]);
112 if (setenv("PUFFS_COMFD", comfd, 1) == -1)
113 err(1, "setenv");
115 argv++;
116 if (execvp(argv[0], argv) == -1)
117 err(1, "execvp");
118 /*NOTREACHED*/
119 case -1:
120 err(1, "fork");
121 /*NOTREACHED*/
122 default:
123 close(sv[0]);
124 break;
127 /* read args */
128 if (read(sv[1], &len, sizeof(len)) != sizeof(len))
129 err(1, "mp 1");
130 if (len > MAXPATHLEN)
131 err(1, "mntpath > MAXPATHLEN");
132 if ((size_t)read(sv[1], canon_dir, len) != len)
133 err(1, "mp 2");
134 if (read(sv[1], &len, sizeof(len)) != sizeof(len))
135 err(1, "fn 1");
136 if (len > MAXPATHLEN)
137 err(1, "devpath > MAXPATHLEN");
138 if ((size_t)read(sv[1], canon_dev, len) != len)
139 err(1, "fn 2");
140 if (read(sv[1], mntflags, sizeof(*mntflags)) != sizeof(*mntflags))
141 err(1, "mntflags");
142 if (read(sv[1], kargs, sizeof(*kargs)) != sizeof(*kargs))
143 err(1, "puffs_args");
144 if (read(sv[1], pflags, sizeof(*pflags)) != sizeof(*pflags))
145 err(1, "pflags");
147 /* XXX: some adjustments */
148 *pflags |= PUFFS_KFLAG_NOCACHE;
149 *pflags &= ~PUFFS_FLAG_BUILDPATH;
151 rv = rump_pub_syspuffs_glueinit(sv[1], &kargs->pa_fd);
152 assert(rv == 0);