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