rump_syspuffs.c revision 1.3 1 /* $NetBSD: rump_syspuffs.c,v 1.3 2008/08/11 13:32:55 pooka Exp $ */
2
3 /*
4 * Copyright (c) 2008 Antti Kantee. All Rights Reserved.
5 *
6 * Development of this software was supported by the
7 * Research Foundation of Helsinki University of Technology
8 *
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.
17 *
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.
29 */
30
31 #include <sys/types.h>
32 #include <sys/mount.h>
33 #include <sys/socket.h>
34 #include <sys/syslimits.h>
35
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>
43
44 #include <rump/p2k.h>
45
46 #include "puffs_rumpglue.h"
47
48 static void
49 usage(void)
50 {
51
52 errx(1, "usage: %s file_server fs_opts", getprogname());
53 }
54
55 static void
56 trapchild(int sig)
57 {
58
59 /* XXX: yaya, not reentrant */
60 errx(1, "child died");
61 }
62
63 int
64 main(int argc, char *argv[])
65 {
66 struct puffs_kargs kargs;
67 char *mntpath, *fromname;
68 size_t len;
69 char comfd[16];
70 int sv[2];
71 int mntflags, pflags, rv;
72
73 #if 1
74 extern int puffsdebug;
75 extern int putterdebug;
76
77 puffsdebug = putterdebug = 1;
78 #endif
79
80 setprogname(argv[0]);
81
82 if (argc < 2)
83 usage();
84
85 /* Create sucketpair for communication with the real file server */
86 if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) == -1)
87 err(1, "socketpair");
88
89 signal(SIGCHLD, trapchild);
90
91 switch (fork()) {
92 case 0:
93 snprintf(comfd, sizeof(sv[0]), "%d", sv[0]);
94 if (setenv("PUFFS_COMFD", comfd, 1) == -1)
95 err(1, "setenv");
96
97 argv++;
98 if (execvp(argv[0], argv) == -1)
99 err(1, "execvp");
100 /*NOTREACHED*/
101 case -1:
102 err(1, "fork");
103 /*NOTREACHED*/
104 default:
105 break;
106 }
107
108 /* read args */
109 if (read(sv[1], &len, sizeof(len)) != sizeof(len))
110 err(1, "mp 1");
111 mntpath = malloc(len);
112 if (mntpath == NULL)
113 err(1, "malloc %zu", len);
114 if (read(sv[1], mntpath, len) != len)
115 err(1, "mp 2");
116 if (read(sv[1], &len, sizeof(len)) != sizeof(len))
117 err(1, "fn 1");
118 fromname = malloc(len);
119 if (fromname == NULL)
120 err(1, "malloc %zu", len);
121 if (read(sv[1], fromname, len) != len)
122 err(1, "fn 2");
123 if (read(sv[1], &mntflags, sizeof(mntflags)) != sizeof(mntflags))
124 err(1, "mntflags");
125 if (read(sv[1], &kargs, sizeof(kargs)) != sizeof(kargs))
126 err(1, "puffs_args");
127 if (read(sv[1], &pflags, sizeof(pflags)) != sizeof(pflags))
128 err(1, "pflags");
129
130 signal(SIGCHLD, SIG_DFL);
131
132 /* XXX: some adjustments */
133 pflags |= PUFFS_KFLAG_NOCACHE;
134 pflags &= ~PUFFS_FLAG_BUILDPATH;
135
136 rv = puffs_rumpglue_init(sv[1], &kargs.pa_fd);
137 assert(rv == 0);
138 rv = p2k_run_fs(MOUNT_PUFFS, fromname, mntpath, mntflags,
139 &kargs, sizeof(kargs), pflags);
140 if (rv)
141 err(1, "mount");
142
143 return 0;
144 }
145