rump_syspuffs.c revision 1.1 1 1.1 pooka /* $NetBSD: rump_syspuffs.c,v 1.1 2008/07/29 13:17:48 pooka Exp $ */
2 1.1 pooka
3 1.1 pooka /*
4 1.1 pooka * Copyright (c) 2008 Antti Kantee. All Rights Reserved.
5 1.1 pooka *
6 1.1 pooka * Development of this software was supported by the
7 1.1 pooka * Research Foundation of Helsinki University of Technology
8 1.1 pooka *
9 1.1 pooka * Redistribution and use in source and binary forms, with or without
10 1.1 pooka * modification, are permitted provided that the following conditions
11 1.1 pooka * are met:
12 1.1 pooka * 1. Redistributions of source code must retain the above copyright
13 1.1 pooka * notice, this list of conditions and the following disclaimer.
14 1.1 pooka * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 pooka * notice, this list of conditions and the following disclaimer in the
16 1.1 pooka * documentation and/or other materials provided with the distribution.
17 1.1 pooka *
18 1.1 pooka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 1.1 pooka * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 1.1 pooka * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 1.1 pooka * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 1.1 pooka * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 1.1 pooka * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 1.1 pooka * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 1.1 pooka * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 1.1 pooka * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 1.1 pooka * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 1.1 pooka * SUCH DAMAGE.
29 1.1 pooka */
30 1.1 pooka
31 1.1 pooka #include <sys/types.h>
32 1.1 pooka #include <sys/mount.h>
33 1.1 pooka #include <sys/socket.h>
34 1.1 pooka
35 1.1 pooka #include <assert.h>
36 1.1 pooka #include <err.h>
37 1.1 pooka #include <paths.h>
38 1.1 pooka #include <puffs.h>
39 1.1 pooka #include <stdio.h>
40 1.1 pooka #include <stdlib.h>
41 1.1 pooka #include <unistd.h>
42 1.1 pooka
43 1.1 pooka #include <rump/p2k.h>
44 1.1 pooka
45 1.1 pooka #include "puffs_rumpglue.h"
46 1.1 pooka
47 1.1 pooka static void
48 1.1 pooka usage(void)
49 1.1 pooka {
50 1.1 pooka
51 1.1 pooka errx(1, "usage: %s file_server [fs opts] dev mountpath", getprogname());
52 1.1 pooka }
53 1.1 pooka
54 1.1 pooka int
55 1.1 pooka main(int argc, char *argv[])
56 1.1 pooka {
57 1.1 pooka struct puffs_kargs kargs;
58 1.1 pooka extern char **environ;
59 1.1 pooka char *mntpath, *fromname;
60 1.1 pooka size_t len;
61 1.1 pooka char comfd[16];
62 1.1 pooka int sv[2];
63 1.1 pooka int mntflags, pflags, rv;
64 1.1 pooka
65 1.1 pooka #if 1
66 1.1 pooka extern int puffsdebug;
67 1.1 pooka extern int putterdebug;
68 1.1 pooka
69 1.1 pooka puffsdebug = putterdebug = 1;
70 1.1 pooka #endif
71 1.1 pooka
72 1.1 pooka setprogname(argv[0]);
73 1.1 pooka
74 1.1 pooka if (argc < 2)
75 1.1 pooka usage();
76 1.1 pooka
77 1.1 pooka /* Create sucketpair for communication with the real file server */
78 1.1 pooka if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) == -1)
79 1.1 pooka err(1, "socketpair");
80 1.1 pooka snprintf(comfd, sizeof(sv[0]), "%d", sv[0]);
81 1.1 pooka if (setenv("PUFFS_COMFD", comfd, 1) == -1)
82 1.1 pooka err(1, "setenv");
83 1.1 pooka
84 1.1 pooka switch (fork()) {
85 1.1 pooka case 0:
86 1.1 pooka argv++;
87 1.1 pooka if (execve(argv[0], argv, environ) == -1)
88 1.1 pooka err(1, "execvp");
89 1.1 pooka /*NOTREACHED*/
90 1.1 pooka case -1:
91 1.1 pooka err(1, "fork");
92 1.1 pooka /*NOTREACHED*/
93 1.1 pooka default:
94 1.1 pooka unsetenv("PUFFS_COMFD");
95 1.1 pooka break;
96 1.1 pooka }
97 1.1 pooka
98 1.1 pooka /* read args */
99 1.1 pooka if (read(sv[1], &len, sizeof(len)) != sizeof(len))
100 1.1 pooka err(1, "mp 1");
101 1.1 pooka mntpath = malloc(len);
102 1.1 pooka if (mntpath == NULL)
103 1.1 pooka err(1, "malloc %zu", len);
104 1.1 pooka if (read(sv[1], mntpath, len) != len)
105 1.1 pooka err(1, "mp 2");
106 1.1 pooka if (read(sv[1], &len, sizeof(len)) != sizeof(len))
107 1.1 pooka err(1, "fn 1");
108 1.1 pooka fromname = malloc(len);
109 1.1 pooka if (fromname == NULL)
110 1.1 pooka err(1, "malloc %zu", len);
111 1.1 pooka if (read(sv[1], fromname, len) != len)
112 1.1 pooka err(1, "fn 2");
113 1.1 pooka if (read(sv[1], &mntflags, sizeof(mntflags)) != sizeof(mntflags))
114 1.1 pooka err(1, "mntflags");
115 1.1 pooka if (read(sv[1], &kargs, sizeof(kargs)) != sizeof(kargs))
116 1.1 pooka err(1, "puffs_args");
117 1.1 pooka if (read(sv[1], &pflags, sizeof(kargs)) != sizeof(pflags))
118 1.1 pooka err(1, "pflags");
119 1.1 pooka
120 1.1 pooka /* XXX: some adjustments */
121 1.1 pooka pflags |= PUFFS_KFLAG_NOCACHE;
122 1.1 pooka pflags &= ~PUFFS_FLAG_BUILDPATH;
123 1.1 pooka
124 1.1 pooka rv = puffs_rumpglue_init(sv[1], &kargs.pa_fd);
125 1.1 pooka assert(rv == 0);
126 1.1 pooka rv = p2k_run_fs(MOUNT_PUFFS, fromname, mntpath, mntflags,
127 1.1 pooka &kargs, sizeof(kargs), pflags);
128 1.1 pooka if (rv)
129 1.1 pooka err(1, "mount");
130 1.1 pooka
131 1.1 pooka return 0;
132 1.1 pooka }
133