Rev 3022 | Rev 4296 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3022 | Rev 4055 | ||
|---|---|---|---|
| Line 29... | Line 29... | ||
| 29 | /** @addtogroup libc |
29 | /** @addtogroup libc |
| 30 | * @{ |
30 | * @{ |
| 31 | */ |
31 | */ |
| 32 | /** @file |
32 | /** @file |
| 33 | */ |
33 | */ |
| 34 | 34 | ||
| 35 | #include <vfs/vfs.h> |
35 | #include <vfs/vfs.h> |
| 36 | #include <vfs/canonify.h> |
36 | #include <vfs/canonify.h> |
| 37 | #include <stdlib.h> |
37 | #include <stdlib.h> |
| 38 | #include <unistd.h> |
38 | #include <unistd.h> |
| 39 | #include <dirent.h> |
39 | #include <dirent.h> |
| Line 46... | Line 46... | ||
| 46 | #include <async.h> |
46 | #include <async.h> |
| 47 | #include <atomic.h> |
47 | #include <atomic.h> |
| 48 | #include <futex.h> |
48 | #include <futex.h> |
| 49 | #include <errno.h> |
49 | #include <errno.h> |
| 50 | #include <string.h> |
50 | #include <string.h> |
| - | 51 | #include <ipc/devmap.h> |
|
| 51 | #include "../../srv/vfs/vfs.h" |
52 | #include "../../../srv/vfs/vfs.h" |
| 52 | 53 | ||
| 53 | int vfs_phone = -1; |
54 | int vfs_phone = -1; |
| 54 | futex_t vfs_phone_futex = FUTEX_INITIALIZER; |
55 | futex_t vfs_phone_futex = FUTEX_INITIALIZER; |
| 55 | 56 | ||
| 56 | futex_t cwd_futex = FUTEX_INITIALIZER; |
57 | futex_t cwd_futex = FUTEX_INITIALIZER; |
| 57 | DIR *cwd_dir = NULL; |
58 | DIR *cwd_dir = NULL; |
| 58 | char *cwd_path = NULL; |
59 | char *cwd_path = NULL; |
| 59 | size_t cwd_len = 0; |
60 | size_t cwd_len = 0; |
| 60 | 61 | ||
| 61 | static char *absolutize(const char *path, size_t *retlen) |
62 | char *absolutize(const char *path, size_t *retlen) |
| 62 | { |
63 | { |
| 63 | char *ncwd_path; |
64 | char *ncwd_path; |
| - | 65 | char *ncwd_path_nc; |
|
| 64 | 66 | ||
| 65 | futex_down(&cwd_futex); |
67 | futex_down(&cwd_futex); |
| 66 | size_t len = strlen(path); |
68 | size_t len = strlen(path); |
| 67 | if (*path != '/') { |
69 | if (*path != '/') { |
| 68 | if (!cwd_path) { |
70 | if (!cwd_path) { |
| 69 | futex_up(&cwd_futex); |
71 | futex_up(&cwd_futex); |
| 70 | return NULL; |
72 | return NULL; |
| 71 | } |
73 | } |
| 72 | ncwd_path = malloc(len + cwd_len + 1); |
74 | ncwd_path_nc = malloc(cwd_len + 1 + len + 1); |
| 73 | if (!ncwd_path) { |
75 | if (!ncwd_path_nc) { |
| 74 | futex_up(&cwd_futex); |
76 | futex_up(&cwd_futex); |
| 75 | return NULL; |
77 | return NULL; |
| 76 | } |
78 | } |
| 77 | strcpy(ncwd_path, cwd_path); |
79 | strcpy(ncwd_path_nc, cwd_path); |
| 78 | ncwd_path[cwd_len] = '/'; |
80 | ncwd_path_nc[cwd_len] = '/'; |
| 79 | ncwd_path[cwd_len + 1] = '\0'; |
81 | ncwd_path_nc[cwd_len + 1] = '\0'; |
| 80 | } else { |
82 | } else { |
| 81 | ncwd_path = malloc(len + 1); |
83 | ncwd_path_nc = malloc(len + 1); |
| 82 | if (!ncwd_path) { |
84 | if (!ncwd_path_nc) { |
| 83 | futex_up(&cwd_futex); |
85 | futex_up(&cwd_futex); |
| 84 | return NULL; |
86 | return NULL; |
| 85 | } |
87 | } |
| 86 | ncwd_path[0] = '\0'; |
88 | ncwd_path_nc[0] = '\0'; |
| 87 | } |
89 | } |
| 88 | strcat(ncwd_path, path); |
90 | strcat(ncwd_path_nc, path); |
| 89 | if (!canonify(ncwd_path, retlen)) { |
91 | ncwd_path = canonify(ncwd_path_nc, retlen); |
| - | 92 | if (!ncwd_path) { |
|
| - | 93 | futex_up(&cwd_futex); |
|
| - | 94 | free(ncwd_path_nc); |
|
| - | 95 | return NULL; |
|
| - | 96 | } |
|
| - | 97 | /* |
|
| - | 98 | * We need to clone ncwd_path because canonify() works in-place and thus |
|
| - | 99 | * the address in ncwd_path need not be the same as ncwd_path_nc, even |
|
| - | 100 | * though they both point into the same dynamically allocated buffer. |
|
| - | 101 | */ |
|
| - | 102 | ncwd_path = strdup(ncwd_path); |
|
| - | 103 | free(ncwd_path_nc); |
|
| - | 104 | if (!ncwd_path) { |
|
| 90 | futex_up(&cwd_futex); |
105 | futex_up(&cwd_futex); |
| 91 | free(ncwd_path); |
- | |
| 92 | return NULL; |
106 | return NULL; |
| 93 | } |
107 | } |
| 94 | futex_up(&cwd_futex); |
108 | futex_up(&cwd_futex); |
| 95 | return ncwd_path; |
109 | return ncwd_path; |
| 96 | } |
110 | } |
| 97 | 111 | ||
| 98 | static int vfs_connect(void) |
112 | static void vfs_connect(void) |
| 99 | { |
113 | { |
| 100 | if (vfs_phone < 0) |
114 | while (vfs_phone < 0) |
| 101 | vfs_phone = ipc_connect_me_to(PHONE_NS, SERVICE_VFS, 0, 0); |
115 | vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 0); |
| 102 | return vfs_phone; |
- | |
| 103 | } |
116 | } |
| 104 | 117 | ||
| - | 118 | static int device_get_handle(const char *name, dev_handle_t *handle, |
|
| - | 119 | const unsigned int flags) |
|
| - | 120 | { |
|
| - | 121 | int phone; |
|
| - | 122 | ||
| - | 123 | if (flags & IPC_FLAG_BLOCKING) |
|
| - | 124 | phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAP, DEVMAP_CLIENT, 0); |
|
| - | 125 | else |
|
| - | 126 | phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_CLIENT, 0); |
|
| - | 127 | ||
| - | 128 | if (phone < 0) |
|
| - | 129 | return phone; |
|
| - | 130 | ||
| - | 131 | ipc_call_t answer; |
|
| - | 132 | aid_t req = async_send_2(phone, DEVMAP_DEVICE_GET_HANDLE, flags, 0, |
|
| - | 133 | &answer); |
|
| - | 134 | ||
| - | 135 | ipcarg_t retval = ipc_data_write_start(phone, name, strlen(name) + 1); |
|
| - | 136 | ||
| - | 137 | if (retval != EOK) { |
|
| - | 138 | async_wait_for(req, NULL); |
|
| - | 139 | ipc_hangup(phone); |
|
| - | 140 | return retval; |
|
| - | 141 | } |
|
| - | 142 | ||
| - | 143 | async_wait_for(req, &retval); |
|
| - | 144 | ||
| - | 145 | if (handle != NULL) |
|
| - | 146 | *handle = -1; |
|
| - | 147 | ||
| - | 148 | if (retval == EOK) { |
|
| - | 149 | if (handle != NULL) |
|
| - | 150 | *handle = (dev_handle_t) IPC_GET_ARG1(answer); |
|
| - | 151 | } |
|
| - | 152 | ||
| - | 153 | ipc_hangup(phone); |
|
| - | 154 | return retval; |
|
| - | 155 | } |
|
| - | 156 | ||
| 105 | int mount(const char *fs_name, const char *mp, const char *dev) |
157 | int mount(const char *fs_name, const char *mp, const char *dev, |
| - | 158 | const unsigned int flags) |
|
| 106 | { |
159 | { |
| 107 | int res; |
160 | int res; |
| 108 | ipcarg_t rc; |
161 | ipcarg_t rc; |
| 109 | aid_t req; |
162 | aid_t req; |
| - | 163 | dev_handle_t dev_handle; |
|
| 110 | 164 | ||
| 111 | dev_handle_t dev_handle = 0; /* TODO */ |
165 | res = device_get_handle(dev, &dev_handle, flags); |
| - | 166 | if (res != EOK) |
|
| - | 167 | return res; |
|
| 112 | 168 | ||
| 113 | size_t mpa_len; |
169 | size_t mpa_len; |
| 114 | char *mpa = absolutize(mp, &mpa_len); |
170 | char *mpa = absolutize(mp, &mpa_len); |
| 115 | if (!mpa) |
171 | if (!mpa) |
| 116 | return ENOMEM; |
172 | return ENOMEM; |
| 117 | 173 | ||
| 118 | futex_down(&vfs_phone_futex); |
174 | futex_down(&vfs_phone_futex); |
| 119 | async_serialize_start(); |
175 | async_serialize_start(); |
| 120 | if (vfs_phone < 0) { |
- | |
| 121 | res = vfs_connect(); |
176 | vfs_connect(); |
| 122 | if (res < 0) { |
- | |
| 123 | async_serialize_end(); |
- | |
| 124 | futex_up(&vfs_phone_futex); |
- | |
| 125 | free(mpa); |
- | |
| 126 | return res; |
- | |
| 127 | } |
- | |
| 128 | } |
177 | |
| 129 | req = async_send_1(vfs_phone, VFS_MOUNT, dev_handle, NULL); |
178 | req = async_send_2(vfs_phone, VFS_MOUNT, dev_handle, flags, NULL); |
| 130 | rc = ipc_data_write_start(vfs_phone, (void *)fs_name, strlen(fs_name)); |
179 | rc = ipc_data_write_start(vfs_phone, (void *) mpa, mpa_len); |
| 131 | if (rc != EOK) { |
180 | if (rc != EOK) { |
| 132 | async_wait_for(req, NULL); |
181 | async_wait_for(req, NULL); |
| 133 | async_serialize_end(); |
182 | async_serialize_end(); |
| 134 | futex_up(&vfs_phone_futex); |
183 | futex_up(&vfs_phone_futex); |
| 135 | free(mpa); |
184 | free(mpa); |
| 136 | return (int) rc; |
185 | return (int) rc; |
| 137 | } |
186 | } |
| - | 187 | ||
| 138 | rc = ipc_data_write_start(vfs_phone, (void *)mpa, mpa_len); |
188 | rc = ipc_data_write_start(vfs_phone, (void *) fs_name, strlen(fs_name)); |
| 139 | if (rc != EOK) { |
189 | if (rc != EOK) { |
| 140 | async_wait_for(req, NULL); |
190 | async_wait_for(req, NULL); |
| 141 | async_serialize_end(); |
191 | async_serialize_end(); |
| 142 | futex_up(&vfs_phone_futex); |
192 | futex_up(&vfs_phone_futex); |
| 143 | free(mpa); |
193 | free(mpa); |
| 144 | return (int) rc; |
194 | return (int) rc; |
| 145 | } |
195 | } |
| - | 196 | ||
| 146 | async_wait_for(req, &rc); |
197 | async_wait_for(req, &rc); |
| 147 | async_serialize_end(); |
198 | async_serialize_end(); |
| 148 | futex_up(&vfs_phone_futex); |
199 | futex_up(&vfs_phone_futex); |
| 149 | free(mpa); |
200 | free(mpa); |
| - | 201 | ||
| 150 | return (int) rc; |
202 | return (int) rc; |
| 151 | } |
203 | } |
| 152 | 204 | ||
| 153 | static int _open(const char *path, int lflag, int oflag, ...) |
205 | static int _open(const char *path, int lflag, int oflag, ...) |
| 154 | { |
206 | { |
| 155 | int res; |
- | |
| 156 | ipcarg_t rc; |
207 | ipcarg_t rc; |
| 157 | ipc_call_t answer; |
208 | ipc_call_t answer; |
| 158 | aid_t req; |
209 | aid_t req; |
| 159 | 210 | ||
| 160 | size_t pa_len; |
211 | size_t pa_len; |
| Line 162... | Line 213... | ||
| 162 | if (!pa) |
213 | if (!pa) |
| 163 | return ENOMEM; |
214 | return ENOMEM; |
| 164 | 215 | ||
| 165 | futex_down(&vfs_phone_futex); |
216 | futex_down(&vfs_phone_futex); |
| 166 | async_serialize_start(); |
217 | async_serialize_start(); |
| 167 | if (vfs_phone < 0) { |
- | |
| 168 | res = vfs_connect(); |
218 | vfs_connect(); |
| 169 | if (res < 0) { |
- | |
| 170 | async_serialize_end(); |
- | |
| 171 | futex_up(&vfs_phone_futex); |
- | |
| 172 | free(pa); |
- | |
| 173 | return res; |
- | |
| 174 | } |
- | |
| 175 | } |
219 | |
| 176 | req = async_send_3(vfs_phone, VFS_OPEN, lflag, oflag, 0, &answer); |
220 | req = async_send_3(vfs_phone, VFS_OPEN, lflag, oflag, 0, &answer); |
| 177 | rc = ipc_data_write_start(vfs_phone, pa, pa_len); |
221 | rc = ipc_data_write_start(vfs_phone, pa, pa_len); |
| 178 | if (rc != EOK) { |
222 | if (rc != EOK) { |
| 179 | async_wait_for(req, NULL); |
223 | async_wait_for(req, NULL); |
| 180 | async_serialize_end(); |
224 | async_serialize_end(); |
| Line 184... | Line 228... | ||
| 184 | } |
228 | } |
| 185 | async_wait_for(req, &rc); |
229 | async_wait_for(req, &rc); |
| 186 | async_serialize_end(); |
230 | async_serialize_end(); |
| 187 | futex_up(&vfs_phone_futex); |
231 | futex_up(&vfs_phone_futex); |
| 188 | free(pa); |
232 | free(pa); |
| - | 233 | ||
| - | 234 | if (rc != EOK) |
|
| - | 235 | return (int) rc; |
|
| 189 | return (int) IPC_GET_ARG1(answer); |
236 | return (int) IPC_GET_ARG1(answer); |
| 190 | } |
237 | } |
| 191 | 238 | ||
| 192 | int open(const char *path, int oflag, ...) |
239 | int open(const char *path, int oflag, ...) |
| 193 | { |
240 | { |
| 194 | return _open(path, L_FILE, oflag); |
241 | return _open(path, L_FILE, oflag); |
| 195 | } |
242 | } |
| 196 | 243 | ||
| 197 | int close(int fildes) |
244 | int close(int fildes) |
| 198 | { |
245 | { |
| 199 | int res; |
- | |
| 200 | ipcarg_t rc; |
246 | ipcarg_t rc; |
| 201 | 247 | ||
| 202 | futex_down(&vfs_phone_futex); |
248 | futex_down(&vfs_phone_futex); |
| 203 | async_serialize_start(); |
249 | async_serialize_start(); |
| 204 | if (vfs_phone < 0) { |
- | |
| 205 | res = vfs_connect(); |
250 | vfs_connect(); |
| 206 | if (res < 0) { |
- | |
| 207 | async_serialize_end(); |
- | |
| 208 | futex_up(&vfs_phone_futex); |
- | |
| 209 | return res; |
- | |
| 210 | } |
- | |
| 211 | } |
- | |
| 212 | 251 | ||
| 213 | rc = async_req_1_0(vfs_phone, VFS_CLOSE, fildes); |
252 | rc = async_req_1_0(vfs_phone, VFS_CLOSE, fildes); |
| 214 | 253 | ||
| 215 | async_serialize_end(); |
254 | async_serialize_end(); |
| 216 | futex_up(&vfs_phone_futex); |
255 | futex_up(&vfs_phone_futex); |
| 217 | 256 | ||
| 218 | return (int)rc; |
257 | return (int)rc; |
| 219 | } |
258 | } |
| 220 | 259 | ||
| 221 | ssize_t read(int fildes, void *buf, size_t nbyte) |
260 | ssize_t read(int fildes, void *buf, size_t nbyte) |
| 222 | { |
261 | { |
| 223 | int res; |
- | |
| 224 | ipcarg_t rc; |
262 | ipcarg_t rc; |
| 225 | ipc_call_t answer; |
263 | ipc_call_t answer; |
| 226 | aid_t req; |
264 | aid_t req; |
| 227 | 265 | ||
| 228 | futex_down(&vfs_phone_futex); |
266 | futex_down(&vfs_phone_futex); |
| 229 | async_serialize_start(); |
267 | async_serialize_start(); |
| 230 | if (vfs_phone < 0) { |
- | |
| 231 | res = vfs_connect(); |
268 | vfs_connect(); |
| 232 | if (res < 0) { |
- | |
| 233 | async_serialize_end(); |
- | |
| 234 | futex_up(&vfs_phone_futex); |
- | |
| 235 | return res; |
- | |
| 236 | } |
- | |
| 237 | } |
269 | |
| 238 | req = async_send_1(vfs_phone, VFS_READ, fildes, &answer); |
270 | req = async_send_1(vfs_phone, VFS_READ, fildes, &answer); |
| 239 | rc = ipc_data_read_start(vfs_phone, (void *)buf, nbyte); |
271 | rc = ipc_data_read_start(vfs_phone, (void *)buf, nbyte); |
| 240 | if (rc != EOK) { |
272 | if (rc != EOK) { |
| 241 | async_wait_for(req, NULL); |
273 | async_wait_for(req, NULL); |
| 242 | async_serialize_end(); |
274 | async_serialize_end(); |
| Line 247... | Line 279... | ||
| 247 | async_serialize_end(); |
279 | async_serialize_end(); |
| 248 | futex_up(&vfs_phone_futex); |
280 | futex_up(&vfs_phone_futex); |
| 249 | if (rc == EOK) |
281 | if (rc == EOK) |
| 250 | return (ssize_t) IPC_GET_ARG1(answer); |
282 | return (ssize_t) IPC_GET_ARG1(answer); |
| 251 | else |
283 | else |
| 252 | return -1; |
284 | return rc; |
| 253 | } |
285 | } |
| 254 | 286 | ||
| 255 | ssize_t write(int fildes, const void *buf, size_t nbyte) |
287 | ssize_t write(int fildes, const void *buf, size_t nbyte) |
| 256 | { |
288 | { |
| 257 | int res; |
- | |
| 258 | ipcarg_t rc; |
289 | ipcarg_t rc; |
| 259 | ipc_call_t answer; |
290 | ipc_call_t answer; |
| 260 | aid_t req; |
291 | aid_t req; |
| 261 | 292 | ||
| 262 | futex_down(&vfs_phone_futex); |
293 | futex_down(&vfs_phone_futex); |
| 263 | async_serialize_start(); |
294 | async_serialize_start(); |
| 264 | if (vfs_phone < 0) { |
- | |
| 265 | res = vfs_connect(); |
295 | vfs_connect(); |
| 266 | if (res < 0) { |
- | |
| 267 | async_serialize_end(); |
- | |
| 268 | futex_up(&vfs_phone_futex); |
- | |
| 269 | return res; |
- | |
| 270 | } |
- | |
| 271 | } |
296 | |
| 272 | req = async_send_1(vfs_phone, VFS_WRITE, fildes, &answer); |
297 | req = async_send_1(vfs_phone, VFS_WRITE, fildes, &answer); |
| 273 | rc = ipc_data_write_start(vfs_phone, (void *)buf, nbyte); |
298 | rc = ipc_data_write_start(vfs_phone, (void *)buf, nbyte); |
| 274 | if (rc != EOK) { |
299 | if (rc != EOK) { |
| 275 | async_wait_for(req, NULL); |
300 | async_wait_for(req, NULL); |
| 276 | async_serialize_end(); |
301 | async_serialize_end(); |
| Line 286... | Line 311... | ||
| 286 | return -1; |
311 | return -1; |
| 287 | } |
312 | } |
| 288 | 313 | ||
| 289 | off_t lseek(int fildes, off_t offset, int whence) |
314 | off_t lseek(int fildes, off_t offset, int whence) |
| 290 | { |
315 | { |
| 291 | int res; |
- | |
| 292 | ipcarg_t rc; |
316 | ipcarg_t rc; |
| 293 | 317 | ||
| 294 | futex_down(&vfs_phone_futex); |
318 | futex_down(&vfs_phone_futex); |
| 295 | async_serialize_start(); |
319 | async_serialize_start(); |
| 296 | if (vfs_phone < 0) { |
- | |
| 297 | res = vfs_connect(); |
320 | vfs_connect(); |
| 298 | if (res < 0) { |
- | |
| 299 | async_serialize_end(); |
- | |
| 300 | futex_up(&vfs_phone_futex); |
- | |
| 301 | return res; |
- | |
| 302 | } |
- | |
| 303 | } |
- | |
| 304 | 321 | ||
| 305 | off_t newoffs; |
322 | ipcarg_t newoffs; |
| 306 | rc = async_req_3_1(vfs_phone, VFS_SEEK, fildes, offset, whence, |
323 | rc = async_req_3_1(vfs_phone, VFS_SEEK, fildes, offset, whence, |
| 307 | (ipcarg_t)&newoffs); |
324 | &newoffs); |
| 308 | 325 | ||
| 309 | async_serialize_end(); |
326 | async_serialize_end(); |
| 310 | futex_up(&vfs_phone_futex); |
327 | futex_up(&vfs_phone_futex); |
| 311 | 328 | ||
| 312 | if (rc != EOK) |
329 | if (rc != EOK) |
| 313 | return (off_t) -1; |
330 | return (off_t) -1; |
| 314 | 331 | ||
| 315 | return newoffs; |
332 | return (off_t) newoffs; |
| 316 | } |
333 | } |
| 317 | 334 | ||
| 318 | int ftruncate(int fildes, off_t length) |
335 | int ftruncate(int fildes, off_t length) |
| 319 | { |
336 | { |
| 320 | int res; |
- | |
| 321 | ipcarg_t rc; |
337 | ipcarg_t rc; |
| 322 | 338 | ||
| 323 | futex_down(&vfs_phone_futex); |
339 | futex_down(&vfs_phone_futex); |
| 324 | async_serialize_start(); |
340 | async_serialize_start(); |
| 325 | if (vfs_phone < 0) { |
- | |
| 326 | res = vfs_connect(); |
341 | vfs_connect(); |
| 327 | if (res < 0) { |
- | |
| 328 | async_serialize_end(); |
- | |
| 329 | futex_up(&vfs_phone_futex); |
- | |
| 330 | return res; |
- | |
| 331 | } |
- | |
| 332 | } |
342 | |
| 333 | rc = async_req_2_0(vfs_phone, VFS_TRUNCATE, fildes, length); |
343 | rc = async_req_2_0(vfs_phone, VFS_TRUNCATE, fildes, length); |
| 334 | async_serialize_end(); |
344 | async_serialize_end(); |
| 335 | futex_up(&vfs_phone_futex); |
345 | futex_up(&vfs_phone_futex); |
| 336 | return (int) rc; |
346 | return (int) rc; |
| 337 | } |
347 | } |
| Line 369... | Line 379... | ||
| 369 | return 0; |
379 | return 0; |
| 370 | } |
380 | } |
| 371 | 381 | ||
| 372 | int mkdir(const char *path, mode_t mode) |
382 | int mkdir(const char *path, mode_t mode) |
| 373 | { |
383 | { |
| 374 | int res; |
- | |
| 375 | ipcarg_t rc; |
384 | ipcarg_t rc; |
| 376 | aid_t req; |
385 | aid_t req; |
| 377 | 386 | ||
| 378 | size_t pa_len; |
387 | size_t pa_len; |
| 379 | char *pa = absolutize(path, &pa_len); |
388 | char *pa = absolutize(path, &pa_len); |
| 380 | if (!pa) |
389 | if (!pa) |
| 381 | return ENOMEM; |
390 | return ENOMEM; |
| 382 | 391 | ||
| 383 | futex_down(&vfs_phone_futex); |
392 | futex_down(&vfs_phone_futex); |
| 384 | async_serialize_start(); |
393 | async_serialize_start(); |
| 385 | if (vfs_phone < 0) { |
- | |
| 386 | res = vfs_connect(); |
394 | vfs_connect(); |
| 387 | if (res < 0) { |
- | |
| 388 | async_serialize_end(); |
- | |
| 389 | futex_up(&vfs_phone_futex); |
- | |
| 390 | free(pa); |
- | |
| 391 | return res; |
- | |
| 392 | } |
- | |
| 393 | } |
395 | |
| 394 | req = async_send_1(vfs_phone, VFS_MKDIR, mode, NULL); |
396 | req = async_send_1(vfs_phone, VFS_MKDIR, mode, NULL); |
| 395 | rc = ipc_data_write_start(vfs_phone, pa, pa_len); |
397 | rc = ipc_data_write_start(vfs_phone, pa, pa_len); |
| 396 | if (rc != EOK) { |
398 | if (rc != EOK) { |
| 397 | async_wait_for(req, NULL); |
399 | async_wait_for(req, NULL); |
| 398 | async_serialize_end(); |
400 | async_serialize_end(); |
| Line 407... | Line 409... | ||
| 407 | return rc; |
409 | return rc; |
| 408 | } |
410 | } |
| 409 | 411 | ||
| 410 | static int _unlink(const char *path, int lflag) |
412 | static int _unlink(const char *path, int lflag) |
| 411 | { |
413 | { |
| 412 | int res; |
- | |
| 413 | ipcarg_t rc; |
414 | ipcarg_t rc; |
| 414 | aid_t req; |
415 | aid_t req; |
| 415 | 416 | ||
| 416 | size_t pa_len; |
417 | size_t pa_len; |
| 417 | char *pa = absolutize(path, &pa_len); |
418 | char *pa = absolutize(path, &pa_len); |
| 418 | if (!pa) |
419 | if (!pa) |
| 419 | return ENOMEM; |
420 | return ENOMEM; |
| 420 | 421 | ||
| 421 | futex_down(&vfs_phone_futex); |
422 | futex_down(&vfs_phone_futex); |
| 422 | async_serialize_start(); |
423 | async_serialize_start(); |
| 423 | if (vfs_phone < 0) { |
- | |
| 424 | res = vfs_connect(); |
424 | vfs_connect(); |
| 425 | if (res < 0) { |
- | |
| 426 | async_serialize_end(); |
- | |
| 427 | futex_up(&vfs_phone_futex); |
- | |
| 428 | free(pa); |
- | |
| 429 | return res; |
- | |
| 430 | } |
- | |
| 431 | } |
425 | |
| 432 | req = async_send_0(vfs_phone, VFS_UNLINK, NULL); |
426 | req = async_send_0(vfs_phone, VFS_UNLINK, NULL); |
| 433 | rc = ipc_data_write_start(vfs_phone, pa, pa_len); |
427 | rc = ipc_data_write_start(vfs_phone, pa, pa_len); |
| 434 | if (rc != EOK) { |
428 | if (rc != EOK) { |
| 435 | async_wait_for(req, NULL); |
429 | async_wait_for(req, NULL); |
| 436 | async_serialize_end(); |
430 | async_serialize_end(); |
| Line 455... | Line 449... | ||
| 455 | return _unlink(path, L_DIRECTORY); |
449 | return _unlink(path, L_DIRECTORY); |
| 456 | } |
450 | } |
| 457 | 451 | ||
| 458 | int rename(const char *old, const char *new) |
452 | int rename(const char *old, const char *new) |
| 459 | { |
453 | { |
| 460 | int res; |
- | |
| 461 | ipcarg_t rc; |
454 | ipcarg_t rc; |
| 462 | aid_t req; |
455 | aid_t req; |
| 463 | 456 | ||
| 464 | size_t olda_len; |
457 | size_t olda_len; |
| 465 | char *olda = absolutize(old, &olda_len); |
458 | char *olda = absolutize(old, &olda_len); |
| Line 473... | Line 466... | ||
| 473 | return ENOMEM; |
466 | return ENOMEM; |
| 474 | } |
467 | } |
| 475 | 468 | ||
| 476 | futex_down(&vfs_phone_futex); |
469 | futex_down(&vfs_phone_futex); |
| 477 | async_serialize_start(); |
470 | async_serialize_start(); |
| 478 | if (vfs_phone < 0) { |
- | |
| 479 | res = vfs_connect(); |
471 | vfs_connect(); |
| 480 | if (res < 0) { |
- | |
| 481 | async_serialize_end(); |
- | |
| 482 | futex_up(&vfs_phone_futex); |
- | |
| 483 | free(olda); |
- | |
| 484 | free(newa); |
- | |
| 485 | return res; |
- | |
| 486 | } |
- | |
| 487 | } |
472 | |
| 488 | req = async_send_0(vfs_phone, VFS_RENAME, NULL); |
473 | req = async_send_0(vfs_phone, VFS_RENAME, NULL); |
| 489 | rc = ipc_data_write_start(vfs_phone, olda, olda_len); |
474 | rc = ipc_data_write_start(vfs_phone, olda, olda_len); |
| 490 | if (rc != EOK) { |
475 | if (rc != EOK) { |
| 491 | async_wait_for(req, NULL); |
476 | async_wait_for(req, NULL); |
| 492 | async_serialize_end(); |
477 | async_serialize_end(); |
| Line 535... | Line 520... | ||
| 535 | } |
520 | } |
| 536 | cwd_dir = d; |
521 | cwd_dir = d; |
| 537 | cwd_path = pa; |
522 | cwd_path = pa; |
| 538 | cwd_len = pa_len; |
523 | cwd_len = pa_len; |
| 539 | futex_up(&cwd_futex); |
524 | futex_up(&cwd_futex); |
| - | 525 | return EOK; |
|
| 540 | } |
526 | } |
| 541 | 527 | ||
| 542 | char *getcwd(char *buf, size_t size) |
528 | char *getcwd(char *buf, size_t size) |
| 543 | { |
529 | { |
| 544 | if (!size) |
530 | if (!size) |