Rev 2741 | Rev 2755 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2741 | Rev 2753 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2008 Jakub Jermar |
2 | * Copyright (c) 2008 Jakub Jermar |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup libc |
29 | /** @addtogroup libc |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #include <vfs.h> |
35 | #include <vfs.h> |
36 | #include <stdlib.h> |
36 | #include <stdlib.h> |
37 | #include <unistd.h> |
37 | #include <unistd.h> |
38 | #include <dirent.h> |
38 | #include <dirent.h> |
39 | #include <fcntl.h> |
39 | #include <fcntl.h> |
40 | #include <sys/stat.h> |
40 | #include <sys/stat.h> |
41 | #include <sys/types.h> |
41 | #include <sys/types.h> |
42 | #include <ipc/ipc.h> |
42 | #include <ipc/ipc.h> |
43 | #include <ipc/services.h> |
43 | #include <ipc/services.h> |
44 | #include <async.h> |
44 | #include <async.h> |
45 | #include <atomic.h> |
45 | #include <atomic.h> |
46 | #include <futex.h> |
46 | #include <futex.h> |
47 | #include <errno.h> |
47 | #include <errno.h> |
48 | #include <string.h> |
48 | #include <string.h> |
49 | #include "../../srv/vfs/vfs.h" |
49 | #include "../../srv/vfs/vfs.h" |
50 | 50 | ||
51 | int vfs_phone = -1; |
51 | int vfs_phone = -1; |
52 | atomic_t vfs_phone_futex = FUTEX_INITIALIZER; |
52 | atomic_t vfs_phone_futex = FUTEX_INITIALIZER; |
53 | 53 | ||
54 | static int vfs_connect(void) |
54 | static int vfs_connect(void) |
55 | { |
55 | { |
56 | if (vfs_phone < 0) |
56 | if (vfs_phone < 0) |
57 | vfs_phone = ipc_connect_me_to(PHONE_NS, SERVICE_VFS, 0, 0); |
57 | vfs_phone = ipc_connect_me_to(PHONE_NS, SERVICE_VFS, 0, 0); |
58 | return vfs_phone; |
58 | return vfs_phone; |
59 | } |
59 | } |
60 | 60 | ||
61 | int mount(const char *fs_name, const char *mp, const char *dev) |
61 | int mount(const char *fs_name, const char *mp, const char *dev) |
62 | { |
62 | { |
63 | int res; |
63 | int res; |
64 | ipcarg_t rc; |
64 | ipcarg_t rc; |
65 | aid_t req; |
65 | aid_t req; |
66 | 66 | ||
67 | int dev_handle = 0; /* TODO */ |
67 | int dev_handle = 0; /* TODO */ |
68 | 68 | ||
69 | futex_down(&vfs_phone_futex); |
69 | futex_down(&vfs_phone_futex); |
70 | async_serialize_start(); |
70 | async_serialize_start(); |
71 | if (vfs_phone < 0) { |
71 | if (vfs_phone < 0) { |
72 | res = vfs_connect(); |
72 | res = vfs_connect(); |
73 | if (res < 0) { |
73 | if (res < 0) { |
74 | async_serialize_end(); |
74 | async_serialize_end(); |
75 | futex_up(&vfs_phone_futex); |
75 | futex_up(&vfs_phone_futex); |
76 | return res; |
76 | return res; |
77 | } |
77 | } |
78 | } |
78 | } |
79 | req = async_send_1(vfs_phone, VFS_MOUNT, dev_handle, NULL); |
79 | req = async_send_1(vfs_phone, VFS_MOUNT, dev_handle, NULL); |
80 | rc = ipc_data_write_start(vfs_phone, (void *)fs_name, strlen(fs_name)); |
80 | rc = ipc_data_write_start(vfs_phone, (void *)fs_name, strlen(fs_name)); |
81 | if (rc != EOK) { |
81 | if (rc != EOK) { |
82 | async_wait_for(req, NULL); |
82 | async_wait_for(req, NULL); |
83 | async_serialize_end(); |
83 | async_serialize_end(); |
84 | futex_up(&vfs_phone_futex); |
84 | futex_up(&vfs_phone_futex); |
85 | return (int) rc; |
85 | return (int) rc; |
86 | } |
86 | } |
87 | rc = ipc_data_write_start(vfs_phone, (void *)mp, strlen(mp)); |
87 | rc = ipc_data_write_start(vfs_phone, (void *)mp, strlen(mp)); |
88 | if (rc != EOK) { |
88 | if (rc != EOK) { |
89 | async_wait_for(req, NULL); |
89 | async_wait_for(req, NULL); |
90 | async_serialize_end(); |
90 | async_serialize_end(); |
91 | futex_up(&vfs_phone_futex); |
91 | futex_up(&vfs_phone_futex); |
92 | return (int) rc; |
92 | return (int) rc; |
93 | } |
93 | } |
94 | async_wait_for(req, &rc); |
94 | async_wait_for(req, &rc); |
95 | async_serialize_end(); |
95 | async_serialize_end(); |
96 | futex_up(&vfs_phone_futex); |
96 | futex_up(&vfs_phone_futex); |
97 | return (int) rc; |
97 | return (int) rc; |
98 | } |
98 | } |
99 | 99 | ||
100 | static int _open(const char *path, int lflag, int oflag, ...) |
100 | static int _open(const char *path, int lflag, int oflag, ...) |
101 | { |
101 | { |
102 | int res; |
102 | int res; |
103 | ipcarg_t rc; |
103 | ipcarg_t rc; |
104 | ipc_call_t answer; |
104 | ipc_call_t answer; |
105 | aid_t req; |
105 | aid_t req; |
106 | 106 | ||
107 | futex_down(&vfs_phone_futex); |
107 | futex_down(&vfs_phone_futex); |
108 | async_serialize_start(); |
108 | async_serialize_start(); |
109 | if (vfs_phone < 0) { |
109 | if (vfs_phone < 0) { |
110 | res = vfs_connect(); |
110 | res = vfs_connect(); |
111 | if (res < 0) { |
111 | if (res < 0) { |
112 | async_serialize_end(); |
112 | async_serialize_end(); |
113 | futex_up(&vfs_phone_futex); |
113 | futex_up(&vfs_phone_futex); |
114 | return res; |
114 | return res; |
115 | } |
115 | } |
116 | } |
116 | } |
117 | req = async_send_3(vfs_phone, VFS_OPEN, lflag, oflag, 0, &answer); |
117 | req = async_send_3(vfs_phone, VFS_OPEN, lflag, oflag, 0, &answer); |
118 | rc = ipc_data_write_start(vfs_phone, path, strlen(path)); |
118 | rc = ipc_data_write_start(vfs_phone, path, strlen(path)); |
119 | if (rc != EOK) { |
119 | if (rc != EOK) { |
120 | async_wait_for(req, NULL); |
120 | async_wait_for(req, NULL); |
121 | async_serialize_end(); |
121 | async_serialize_end(); |
122 | futex_up(&vfs_phone_futex); |
122 | futex_up(&vfs_phone_futex); |
123 | return (int) rc; |
123 | return (int) rc; |
124 | } |
124 | } |
125 | async_wait_for(req, &rc); |
125 | async_wait_for(req, &rc); |
126 | async_serialize_end(); |
126 | async_serialize_end(); |
127 | futex_up(&vfs_phone_futex); |
127 | futex_up(&vfs_phone_futex); |
128 | return (int) IPC_GET_ARG1(answer); |
128 | return (int) IPC_GET_ARG1(answer); |
129 | } |
129 | } |
130 | 130 | ||
131 | int open(const char *path, int oflag, ...) |
131 | int open(const char *path, int oflag, ...) |
132 | { |
132 | { |
133 | return _open(path, L_FILE, oflag); |
133 | return _open(path, L_FILE, oflag); |
134 | } |
134 | } |
135 | 135 | ||
136 | int close(int fildes) |
136 | int close(int fildes) |
137 | { |
137 | { |
138 | int res; |
138 | int res; |
139 | ipcarg_t rc; |
139 | ipcarg_t rc; |
140 | 140 | ||
141 | futex_down(&vfs_phone_futex); |
141 | futex_down(&vfs_phone_futex); |
142 | async_serialize_start(); |
142 | async_serialize_start(); |
143 | if (vfs_phone < 0) { |
143 | if (vfs_phone < 0) { |
144 | res = vfs_connect(); |
144 | res = vfs_connect(); |
145 | if (res < 0) { |
145 | if (res < 0) { |
146 | async_serialize_end(); |
146 | async_serialize_end(); |
147 | futex_up(&vfs_phone_futex); |
147 | futex_up(&vfs_phone_futex); |
148 | return res; |
148 | return res; |
149 | } |
149 | } |
150 | } |
150 | } |
151 | 151 | ||
152 | rc = async_req_1_0(vfs_phone, VFS_CLOSE, fildes); |
152 | rc = async_req_1_0(vfs_phone, VFS_CLOSE, fildes); |
153 | 153 | ||
154 | async_serialize_end(); |
154 | async_serialize_end(); |
155 | futex_up(&vfs_phone_futex); |
155 | futex_up(&vfs_phone_futex); |
156 | 156 | ||
157 | return (int)rc; |
157 | return (int)rc; |
158 | } |
158 | } |
159 | 159 | ||
160 | ssize_t read(int fildes, void *buf, size_t nbyte) |
160 | ssize_t read(int fildes, void *buf, size_t nbyte) |
161 | { |
161 | { |
162 | int res; |
162 | int res; |
163 | ipcarg_t rc; |
163 | ipcarg_t rc; |
164 | ipc_call_t answer; |
164 | ipc_call_t answer; |
165 | aid_t req; |
165 | aid_t req; |
166 | 166 | ||
167 | futex_down(&vfs_phone_futex); |
167 | futex_down(&vfs_phone_futex); |
168 | async_serialize_start(); |
168 | async_serialize_start(); |
169 | if (vfs_phone < 0) { |
169 | if (vfs_phone < 0) { |
170 | res = vfs_connect(); |
170 | res = vfs_connect(); |
171 | if (res < 0) { |
171 | if (res < 0) { |
172 | async_serialize_end(); |
172 | async_serialize_end(); |
173 | futex_up(&vfs_phone_futex); |
173 | futex_up(&vfs_phone_futex); |
174 | return res; |
174 | return res; |
175 | } |
175 | } |
176 | } |
176 | } |
177 | req = async_send_1(vfs_phone, VFS_READ, fildes, &answer); |
177 | req = async_send_1(vfs_phone, VFS_READ, fildes, &answer); |
178 | rc = ipc_data_read_start(vfs_phone, (void *)buf, nbyte); |
178 | rc = ipc_data_read_start(vfs_phone, (void *)buf, nbyte); |
179 | if (rc != EOK) { |
179 | if (rc != EOK) { |
180 | async_wait_for(req, NULL); |
180 | async_wait_for(req, NULL); |
181 | async_serialize_end(); |
181 | async_serialize_end(); |
182 | futex_up(&vfs_phone_futex); |
182 | futex_up(&vfs_phone_futex); |
183 | return (ssize_t) rc; |
183 | return (ssize_t) rc; |
184 | } |
184 | } |
185 | async_wait_for(req, &rc); |
185 | async_wait_for(req, &rc); |
186 | async_serialize_end(); |
186 | async_serialize_end(); |
187 | futex_up(&vfs_phone_futex); |
187 | futex_up(&vfs_phone_futex); |
188 | if (rc == EOK) |
188 | if (rc == EOK) |
189 | return (ssize_t) IPC_GET_ARG1(answer); |
189 | return (ssize_t) IPC_GET_ARG1(answer); |
190 | else |
190 | else |
191 | return -1; |
191 | return -1; |
192 | } |
192 | } |
193 | 193 | ||
194 | ssize_t write(int fildes, const void *buf, size_t nbyte) |
194 | ssize_t write(int fildes, const void *buf, size_t nbyte) |
195 | { |
195 | { |
196 | int res; |
196 | int res; |
197 | ipcarg_t rc; |
197 | ipcarg_t rc; |
198 | ipc_call_t answer; |
198 | ipc_call_t answer; |
199 | aid_t req; |
199 | aid_t req; |
200 | 200 | ||
201 | futex_down(&vfs_phone_futex); |
201 | futex_down(&vfs_phone_futex); |
202 | async_serialize_start(); |
202 | async_serialize_start(); |
203 | if (vfs_phone < 0) { |
203 | if (vfs_phone < 0) { |
204 | res = vfs_connect(); |
204 | res = vfs_connect(); |
205 | if (res < 0) { |
205 | if (res < 0) { |
206 | async_serialize_end(); |
206 | async_serialize_end(); |
207 | futex_up(&vfs_phone_futex); |
207 | futex_up(&vfs_phone_futex); |
208 | return res; |
208 | return res; |
209 | } |
209 | } |
210 | } |
210 | } |
211 | req = async_send_1(vfs_phone, VFS_WRITE, fildes, &answer); |
211 | req = async_send_1(vfs_phone, VFS_WRITE, fildes, &answer); |
212 | rc = ipc_data_write_start(vfs_phone, (void *)buf, nbyte); |
212 | rc = ipc_data_write_start(vfs_phone, (void *)buf, nbyte); |
213 | if (rc != EOK) { |
213 | if (rc != EOK) { |
214 | async_wait_for(req, NULL); |
214 | async_wait_for(req, NULL); |
215 | async_serialize_end(); |
215 | async_serialize_end(); |
216 | futex_up(&vfs_phone_futex); |
216 | futex_up(&vfs_phone_futex); |
217 | return (ssize_t) rc; |
217 | return (ssize_t) rc; |
218 | } |
218 | } |
219 | async_wait_for(req, &rc); |
219 | async_wait_for(req, &rc); |
220 | async_serialize_end(); |
220 | async_serialize_end(); |
221 | futex_up(&vfs_phone_futex); |
221 | futex_up(&vfs_phone_futex); |
222 | if (rc == EOK) |
222 | if (rc == EOK) |
223 | return (ssize_t) IPC_GET_ARG1(answer); |
223 | return (ssize_t) IPC_GET_ARG1(answer); |
224 | else |
224 | else |
225 | return -1; |
225 | return -1; |
226 | } |
226 | } |
227 | 227 | ||
228 | off_t lseek(int fildes, off_t offset, int whence) |
228 | off_t lseek(int fildes, off_t offset, int whence) |
229 | { |
229 | { |
230 | int res; |
230 | int res; |
231 | ipcarg_t rc; |
231 | ipcarg_t rc; |
232 | 232 | ||
233 | futex_down(&vfs_phone_futex); |
233 | futex_down(&vfs_phone_futex); |
234 | async_serialize_start(); |
234 | async_serialize_start(); |
235 | if (vfs_phone < 0) { |
235 | if (vfs_phone < 0) { |
236 | res = vfs_connect(); |
236 | res = vfs_connect(); |
237 | if (res < 0) { |
237 | if (res < 0) { |
238 | async_serialize_end(); |
238 | async_serialize_end(); |
239 | futex_up(&vfs_phone_futex); |
239 | futex_up(&vfs_phone_futex); |
240 | return res; |
240 | return res; |
241 | } |
241 | } |
242 | } |
242 | } |
243 | 243 | ||
244 | off_t newoffs; |
244 | off_t newoffs; |
245 | rc = async_req_3_1(vfs_phone, VFS_SEEK, fildes, offset, whence, |
245 | rc = async_req_3_1(vfs_phone, VFS_SEEK, fildes, offset, whence, |
246 | (ipcarg_t)&newoffs); |
246 | (ipcarg_t)&newoffs); |
247 | 247 | ||
248 | async_serialize_end(); |
248 | async_serialize_end(); |
249 | futex_up(&vfs_phone_futex); |
249 | futex_up(&vfs_phone_futex); |
250 | 250 | ||
251 | if (rc != EOK) |
251 | if (rc != EOK) |
252 | return (off_t) -1; |
252 | return (off_t) -1; |
253 | 253 | ||
254 | return newoffs; |
254 | return newoffs; |
255 | } |
255 | } |
256 | 256 | ||
257 | int ftruncate(int fildes, off_t length) |
257 | int ftruncate(int fildes, off_t length) |
258 | { |
258 | { |
259 | int res; |
259 | int res; |
260 | ipcarg_t rc; |
260 | ipcarg_t rc; |
261 | 261 | ||
262 | futex_down(&vfs_phone_futex); |
262 | futex_down(&vfs_phone_futex); |
263 | async_serialize_start(); |
263 | async_serialize_start(); |
264 | if (vfs_phone < 0) { |
264 | if (vfs_phone < 0) { |
265 | res = vfs_connect(); |
265 | res = vfs_connect(); |
266 | if (res < 0) { |
266 | if (res < 0) { |
267 | async_serialize_end(); |
267 | async_serialize_end(); |
268 | futex_up(&vfs_phone_futex); |
268 | futex_up(&vfs_phone_futex); |
269 | return res; |
269 | return res; |
270 | } |
270 | } |
271 | } |
271 | } |
272 | rc = async_req_2_0(vfs_phone, VFS_TRUNCATE, fildes, length); |
272 | rc = async_req_2_0(vfs_phone, VFS_TRUNCATE, fildes, length); |
273 | async_serialize_end(); |
273 | async_serialize_end(); |
274 | futex_up(&vfs_phone_futex); |
274 | futex_up(&vfs_phone_futex); |
275 | return (int) rc; |
275 | return (int) rc; |
276 | } |
276 | } |
277 | 277 | ||
278 | DIR *opendir(const char *dirname) |
278 | DIR *opendir(const char *dirname) |
279 | { |
279 | { |
280 | DIR *dirp = malloc(sizeof(DIR)); |
280 | DIR *dirp = malloc(sizeof(DIR)); |
281 | if (!dirp) |
281 | if (!dirp) |
282 | return NULL; |
282 | return NULL; |
283 | dirp->fd = _open(dirname, L_DIRECTORY, 0); |
283 | dirp->fd = _open(dirname, L_DIRECTORY, 0); |
284 | if (dirp->fd < 0) { |
284 | if (dirp->fd < 0) { |
285 | free(dirp); |
285 | free(dirp); |
286 | return NULL; |
286 | return NULL; |
287 | } |
287 | } |
288 | return dirp; |
288 | return dirp; |
289 | } |
289 | } |
290 | 290 | ||
291 | struct dirent *readdir(DIR *dirp) |
291 | struct dirent *readdir(DIR *dirp) |
292 | { |
292 | { |
293 | ssize_t len = read(dirp->fd, &dirp->res.d_name[0], NAME_MAX + 1); |
293 | ssize_t len = read(dirp->fd, &dirp->res.d_name[0], NAME_MAX + 1); |
294 | if (len <= 0) |
294 | if (len <= 0) |
295 | return NULL; |
295 | return NULL; |
296 | return &dirp->res; |
296 | return &dirp->res; |
297 | } |
297 | } |
298 | 298 | ||
299 | void rewinddir(DIR *dirp) |
299 | void rewinddir(DIR *dirp) |
300 | { |
300 | { |
301 | (void) lseek(dirp->fd, 0, SEEK_SET); |
301 | (void) lseek(dirp->fd, 0, SEEK_SET); |
302 | } |
302 | } |
303 | 303 | ||
304 | int closedir(DIR *dirp) |
304 | int closedir(DIR *dirp) |
305 | { |
305 | { |
306 | (void) close(dirp->fd); |
306 | (void) close(dirp->fd); |
307 | free(dirp); |
307 | free(dirp); |
308 | return 0; |
308 | return 0; |
309 | } |
309 | } |
310 | 310 | ||
311 | int mkdir(const char *path, mode_t mode) |
311 | int mkdir(const char *path, mode_t mode) |
312 | { |
312 | { |
313 | int res; |
313 | int res; |
314 | ipcarg_t rc; |
314 | ipcarg_t rc; |
315 | aid_t req; |
315 | aid_t req; |
316 | 316 | ||
317 | futex_down(&vfs_phone_futex); |
317 | futex_down(&vfs_phone_futex); |
318 | async_serialize_start(); |
318 | async_serialize_start(); |
319 | if (vfs_phone < 0) { |
319 | if (vfs_phone < 0) { |
320 | res = vfs_connect(); |
320 | res = vfs_connect(); |
321 | if (res < 0) { |
321 | if (res < 0) { |
322 | async_serialize_end(); |
322 | async_serialize_end(); |
323 | futex_up(&vfs_phone_futex); |
323 | futex_up(&vfs_phone_futex); |
324 | return res; |
324 | return res; |
325 | } |
325 | } |
326 | } |
326 | } |
327 | req = async_send_1(vfs_phone, VFS_MKDIR, mode, NULL); |
327 | req = async_send_1(vfs_phone, VFS_MKDIR, mode, NULL); |
328 | rc = ipc_data_write_start(vfs_phone, path, strlen(path)); |
328 | rc = ipc_data_write_start(vfs_phone, path, strlen(path)); |
329 | if (rc != EOK) { |
329 | if (rc != EOK) { |
330 | async_wait_for(req, NULL); |
330 | async_wait_for(req, NULL); |
331 | async_serialize_end(); |
331 | async_serialize_end(); |
332 | futex_up(&vfs_phone_futex); |
332 | futex_up(&vfs_phone_futex); |
333 | return (int) rc; |
333 | return (int) rc; |
334 | } |
334 | } |
335 | async_wait_for(req, &rc); |
335 | async_wait_for(req, &rc); |
336 | async_serialize_end(); |
336 | async_serialize_end(); |
337 | futex_up(&vfs_phone_futex); |
337 | futex_up(&vfs_phone_futex); |
338 | return EOK; |
338 | return EOK; |
339 | } |
339 | } |
340 | 340 | ||
341 | static int _unlink(const char *path, int lflag) |
341 | static int _unlink(const char *path, int lflag) |
342 | { |
342 | { |
343 | int res; |
343 | int res; |
344 | ipcarg_t rc; |
344 | ipcarg_t rc; |
345 | aid_t req; |
345 | aid_t req; |
346 | 346 | ||
347 | futex_down(&vfs_phone_futex); |
347 | futex_down(&vfs_phone_futex); |
348 | async_serialize_start(); |
348 | async_serialize_start(); |
349 | if (vfs_phone < 0) { |
349 | if (vfs_phone < 0) { |
350 | res = vfs_connect(); |
350 | res = vfs_connect(); |
351 | if (res < 0) { |
351 | if (res < 0) { |
352 | async_serialize_end(); |
352 | async_serialize_end(); |
353 | futex_up(&vfs_phone_futex); |
353 | futex_up(&vfs_phone_futex); |
354 | return res; |
354 | return res; |
355 | } |
355 | } |
356 | } |
356 | } |
357 | req = async_send_0(vfs_phone, VFS_UNLINK, NULL); |
357 | req = async_send_0(vfs_phone, VFS_UNLINK, NULL); |
358 | rc = ipc_data_write_start(vfs_phone, path, strlen(path)); |
358 | rc = ipc_data_write_start(vfs_phone, path, strlen(path)); |
359 | if (rc != EOK) { |
359 | if (rc != EOK) { |
360 | async_wait_for(req, NULL); |
360 | async_wait_for(req, NULL); |
361 | async_serialize_end(); |
361 | async_serialize_end(); |
362 | futex_up(&vfs_phone_futex); |
362 | futex_up(&vfs_phone_futex); |
363 | return (int) rc; |
363 | return (int) rc; |
364 | } |
364 | } |
365 | async_wait_for(req, &rc); |
365 | async_wait_for(req, &rc); |
366 | async_serialize_end(); |
366 | async_serialize_end(); |
367 | futex_up(&vfs_phone_futex); |
367 | futex_up(&vfs_phone_futex); |
368 | return EOK; |
368 | return EOK; |
369 | } |
369 | } |
370 | 370 | ||
371 | int unlink(const char *path) |
371 | int unlink(const char *path) |
372 | { |
372 | { |
373 | return _unlink(path, L_NONE); |
373 | return _unlink(path, L_NONE); |
374 | } |
374 | } |
375 | 375 | ||
376 | int rmdir(const char *path) |
376 | int rmdir(const char *path) |
377 | { |
377 | { |
378 | return _unlink(path, L_DIRECTORY); |
378 | return _unlink(path, L_DIRECTORY); |
379 | } |
379 | } |
380 | 380 | ||
381 | /** @} |
381 | /** @} |
382 | */ |
382 | */ |
383 | 383 |