Rev 4401 | Rev 4491 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4401 | Rev 4482 | ||
|---|---|---|---|
| Line 47... | Line 47... | ||
| 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 <devmap.h> |
51 | #include <devmap.h> |
| 52 | #include "../../../srv/vfs/vfs.h" |
52 | #include <ipc/vfs.h> |
| - | 53 | #include <ipc/devmap.h> |
|
| 53 | 54 | ||
| 54 | int vfs_phone = -1; |
55 | static int vfs_phone = -1; |
| 55 | futex_t vfs_phone_futex = FUTEX_INITIALIZER; |
56 | static futex_t vfs_phone_futex = FUTEX_INITIALIZER; |
| - | 57 | static futex_t cwd_futex = FUTEX_INITIALIZER; |
|
| 56 | 58 | ||
| 57 | futex_t cwd_futex = FUTEX_INITIALIZER; |
- | |
| 58 | DIR *cwd_dir = NULL; |
59 | DIR *cwd_dir = NULL; |
| 59 | char *cwd_path = NULL; |
60 | char *cwd_path = NULL; |
| 60 | size_t cwd_size = 0; |
61 | size_t cwd_size = 0; |
| 61 | 62 | ||
| 62 | char *absolutize(const char *path, size_t *retlen) |
63 | char *absolutize(const char *path, size_t *retlen) |
| Line 208... | Line 209... | ||
| 208 | } |
209 | } |
| 209 | async_wait_for(req, &rc); |
210 | async_wait_for(req, &rc); |
| 210 | async_serialize_end(); |
211 | async_serialize_end(); |
| 211 | futex_up(&vfs_phone_futex); |
212 | futex_up(&vfs_phone_futex); |
| 212 | free(pa); |
213 | free(pa); |
| 213 | 214 | ||
| 214 | if (rc != EOK) |
215 | if (rc != EOK) |
| 215 | return (int) rc; |
216 | return (int) rc; |
| - | 217 | ||
| 216 | return (int) IPC_GET_ARG1(answer); |
218 | return (int) IPC_GET_ARG1(answer); |
| 217 | } |
219 | } |
| 218 | 220 | ||
| 219 | int open(const char *path, int oflag, ...) |
221 | int open(const char *path, int oflag, ...) |
| 220 | { |
222 | { |
| 221 | return _open(path, L_FILE, oflag); |
223 | return _open(path, L_FILE, oflag); |
| 222 | } |
224 | } |
| 223 | 225 | ||
| - | 226 | int open_node(fs_node_t *node, int oflag) |
|
| - | 227 | { |
|
| - | 228 | futex_down(&vfs_phone_futex); |
|
| - | 229 | async_serialize_start(); |
|
| - | 230 | vfs_connect(); |
|
| - | 231 | ||
| - | 232 | ipc_call_t answer; |
|
| - | 233 | aid_t req = async_send_4(vfs_phone, VFS_OPEN_NODE, node->fs_handle, |
|
| - | 234 | node->dev_handle, node->index, oflag, &answer); |
|
| - | 235 | ||
| - | 236 | ipcarg_t rc; |
|
| - | 237 | async_wait_for(req, &rc); |
|
| - | 238 | async_serialize_end(); |
|
| - | 239 | futex_up(&vfs_phone_futex); |
|
| - | 240 | ||
| - | 241 | if (rc != EOK) |
|
| - | 242 | return (int) rc; |
|
| - | 243 | ||
| - | 244 | return (int) IPC_GET_ARG1(answer); |
|
| - | 245 | } |
|
| - | 246 | ||
| 224 | int close(int fildes) |
247 | int close(int fildes) |
| 225 | { |
248 | { |
| 226 | ipcarg_t rc; |
249 | ipcarg_t rc; |
| 227 | 250 | ||
| 228 | futex_down(&vfs_phone_futex); |
251 | futex_down(&vfs_phone_futex); |
| Line 289... | Line 312... | ||
| 289 | return (ssize_t) IPC_GET_ARG1(answer); |
312 | return (ssize_t) IPC_GET_ARG1(answer); |
| 290 | else |
313 | else |
| 291 | return -1; |
314 | return -1; |
| 292 | } |
315 | } |
| 293 | 316 | ||
| - | 317 | int fd_phone(int fildes) |
|
| - | 318 | { |
|
| - | 319 | futex_down(&vfs_phone_futex); |
|
| - | 320 | async_serialize_start(); |
|
| - | 321 | vfs_connect(); |
|
| - | 322 | ||
| - | 323 | ipcarg_t device; |
|
| - | 324 | ipcarg_t rc = async_req_1_1(vfs_phone, VFS_DEVICE, fildes, &device); |
|
| - | 325 | ||
| - | 326 | async_serialize_end(); |
|
| - | 327 | futex_up(&vfs_phone_futex); |
|
| - | 328 | ||
| - | 329 | if (rc != EOK) |
|
| - | 330 | return -1; |
|
| - | 331 | ||
| - | 332 | return devmap_device_connect((dev_handle_t) device, 0); |
|
| - | 333 | } |
|
| - | 334 | ||
| - | 335 | void fd_node(int fildes, fs_node_t *node) |
|
| - | 336 | { |
|
| - | 337 | futex_down(&vfs_phone_futex); |
|
| - | 338 | async_serialize_start(); |
|
| - | 339 | vfs_connect(); |
|
| - | 340 | ||
| - | 341 | ipcarg_t fs_handle; |
|
| - | 342 | ipcarg_t dev_handle; |
|
| - | 343 | ipcarg_t index; |
|
| - | 344 | ipcarg_t rc = async_req_1_3(vfs_phone, VFS_NODE, fildes, &fs_handle, |
|
| - | 345 | &dev_handle, &index); |
|
| - | 346 | ||
| - | 347 | async_serialize_end(); |
|
| - | 348 | futex_up(&vfs_phone_futex); |
|
| - | 349 | ||
| - | 350 | if (rc == EOK) { |
|
| - | 351 | node->fs_handle = (fs_handle_t) fs_handle; |
|
| - | 352 | node->dev_handle = (dev_handle_t) dev_handle; |
|
| - | 353 | node->index = (fs_index_t) index; |
|
| - | 354 | } else { |
|
| - | 355 | node->fs_handle = 0; |
|
| - | 356 | node->dev_handle = 0; |
|
| - | 357 | node->index = 0; |
|
| - | 358 | } |
|
| - | 359 | } |
|
| - | 360 | ||
| - | 361 | int fsync(int fildes) |
|
| - | 362 | { |
|
| - | 363 | futex_down(&vfs_phone_futex); |
|
| - | 364 | async_serialize_start(); |
|
| - | 365 | vfs_connect(); |
|
| - | 366 | ||
| - | 367 | ipcarg_t rc = async_req_1_0(vfs_phone, VFS_SYNC, fildes); |
|
| - | 368 | ||
| - | 369 | async_serialize_end(); |
|
| - | 370 | futex_up(&vfs_phone_futex); |
|
| - | 371 | ||
| - | 372 | return (int) rc; |
|
| - | 373 | } |
|
| - | 374 | ||
| 294 | off_t lseek(int fildes, off_t offset, int whence) |
375 | off_t lseek(int fildes, off_t offset, int whence) |
| 295 | { |
376 | { |
| 296 | ipcarg_t rc; |
377 | ipcarg_t rc; |
| 297 | 378 | ||
| 298 | futex_down(&vfs_phone_futex); |
379 | futex_down(&vfs_phone_futex); |
| Line 384... | Line 465... | ||
| 384 | } |
465 | } |
| 385 | async_wait_for(req, &rc); |
466 | async_wait_for(req, &rc); |
| 386 | async_serialize_end(); |
467 | async_serialize_end(); |
| 387 | futex_up(&vfs_phone_futex); |
468 | futex_up(&vfs_phone_futex); |
| 388 | free(pa); |
469 | free(pa); |
| 389 | return rc; |
470 | return rc; |
| 390 | } |
471 | } |
| 391 | 472 | ||
| 392 | static int _unlink(const char *path, int lflag) |
473 | static int _unlink(const char *path, int lflag) |
| 393 | { |
474 | { |
| 394 | ipcarg_t rc; |
475 | ipcarg_t rc; |
| Line 414... | Line 495... | ||
| 414 | } |
495 | } |
| 415 | async_wait_for(req, &rc); |
496 | async_wait_for(req, &rc); |
| 416 | async_serialize_end(); |
497 | async_serialize_end(); |
| 417 | futex_up(&vfs_phone_futex); |
498 | futex_up(&vfs_phone_futex); |
| 418 | free(pa); |
499 | free(pa); |
| 419 | return rc; |
500 | return rc; |
| 420 | } |
501 | } |
| 421 | 502 | ||
| 422 | int unlink(const char *path) |
503 | int unlink(const char *path) |
| 423 | { |
504 | { |
| 424 | return _unlink(path, L_NONE); |
505 | return _unlink(path, L_NONE); |