Changeset 923c39e in mainline for uspace/lib/libc/generic/vfs/vfs.c
- Timestamp:
- 2008-03-11T21:18:03Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- cbd6545f
- Parents:
- f2ec8c8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/vfs/vfs.c
rf2ec8c8 r923c39e 40 40 #include <fcntl.h> 41 41 #include <sys/stat.h> 42 #include <stdio.h> 42 43 #include <sys/types.h> 43 44 #include <ipc/ipc.h> … … 58 59 size_t cwd_len = 0; 59 60 60 static char *absolutize(const char *path )61 static char *absolutize(const char *path, size_t *retlen) 61 62 { 62 63 char *ncwd_path; … … 86 87 } 87 88 strcat(ncwd_path, path); 89 if (!canonify(ncwd_path, retlen)) { 90 futex_up(&cwd_futex); 91 free(ncwd_path); 92 return NULL; 93 } 88 94 futex_up(&cwd_futex); 89 95 return ncwd_path; … … 103 109 aid_t req; 104 110 105 int dev_handle = 0; /* TODO */ 106 107 char *mpa = absolutize(mp); 111 dev_handle_t dev_handle = 0; /* TODO */ 112 113 size_t mpa_len; 114 char *mpa = absolutize(mp, &mpa_len); 108 115 if (!mpa) 109 116 return ENOMEM; 110 size_t mpc_len;111 char *mpc = canonify(mpa, &mpc_len);112 if (!mpc) {113 free(mpa);114 return EINVAL;115 }116 117 117 118 futex_down(&vfs_phone_futex); … … 135 136 return (int) rc; 136 137 } 137 rc = ipc_data_write_start(vfs_phone, (void *)mp c, mpc_len);138 rc = ipc_data_write_start(vfs_phone, (void *)mpa, mpa_len); 138 139 if (rc != EOK) { 139 140 async_wait_for(req, NULL); … … 157 158 aid_t req; 158 159 159 char *pa = absolutize(path); 160 size_t pa_len; 161 char *pa = absolutize(path, &pa_len); 160 162 if (!pa) 161 163 return ENOMEM; 162 size_t pc_len;163 char *pc = canonify(pa, &pc_len);164 if (!pc) {165 free(pa);166 return EINVAL;167 }168 164 169 165 futex_down(&vfs_phone_futex); … … 179 175 } 180 176 req = async_send_3(vfs_phone, VFS_OPEN, lflag, oflag, 0, &answer); 181 rc = ipc_data_write_start(vfs_phone, p c, pc_len);177 rc = ipc_data_write_start(vfs_phone, pa, pa_len); 182 178 if (rc != EOK) { 183 179 async_wait_for(req, NULL); … … 380 376 aid_t req; 381 377 382 char *pa = absolutize(path); 378 size_t pa_len; 379 char *pa = absolutize(path, &pa_len); 383 380 if (!pa) 384 381 return ENOMEM; 385 size_t pc_len;386 char *pc = canonify(pa, &pc_len);387 if (!pc) {388 free(pa);389 return EINVAL;390 }391 382 392 383 futex_down(&vfs_phone_futex); … … 402 393 } 403 394 req = async_send_1(vfs_phone, VFS_MKDIR, mode, NULL); 404 rc = ipc_data_write_start(vfs_phone, p c, pc_len);395 rc = ipc_data_write_start(vfs_phone, pa, pa_len); 405 396 if (rc != EOK) { 406 397 async_wait_for(req, NULL); … … 423 414 aid_t req; 424 415 425 char *pa = absolutize(path); 416 size_t pa_len; 417 char *pa = absolutize(path, &pa_len); 426 418 if (!pa) 427 419 return ENOMEM; 428 size_t pc_len; 429 char *pc = canonify(pa, &pc_len); 430 if (!pc) { 431 free(pa); 432 return EINVAL; 433 } 420 434 421 futex_down(&vfs_phone_futex); 435 422 async_serialize_start(); … … 444 431 } 445 432 req = async_send_0(vfs_phone, VFS_UNLINK, NULL); 446 rc = ipc_data_write_start(vfs_phone, p c, pc_len);433 rc = ipc_data_write_start(vfs_phone, pa, pa_len); 447 434 if (rc != EOK) { 448 435 async_wait_for(req, NULL); … … 475 462 aid_t req; 476 463 477 char *olda = absolutize(old); 464 size_t olda_len; 465 char *olda = absolutize(old, &olda_len); 478 466 if (!olda) 479 467 return ENOMEM; 480 size_t oldc_len; 481 char *oldc = canonify(olda, &oldc_len); 482 if (!oldc) { 483 free(olda); 484 return EINVAL; 485 } 486 char *newa = absolutize(new); 468 469 size_t newa_len; 470 char *newa = absolutize(new, &newa_len); 487 471 if (!newa) { 488 472 free(olda); 489 473 return ENOMEM; 490 474 } 491 size_t newc_len; 492 char *newc = canonify(newa, &newc_len); 493 if (!newc) { 475 476 futex_down(&vfs_phone_futex); 477 async_serialize_start(); 478 if (vfs_phone < 0) { 479 res = 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 } 488 req = async_send_0(vfs_phone, VFS_RENAME, NULL); 489 rc = ipc_data_write_start(vfs_phone, olda, olda_len); 490 if (rc != EOK) { 491 async_wait_for(req, NULL); 492 async_serialize_end(); 493 futex_up(&vfs_phone_futex); 494 494 free(olda); 495 495 free(newa); 496 return EINVAL; 497 } 498 499 futex_down(&vfs_phone_futex); 500 async_serialize_start(); 501 if (vfs_phone < 0) { 502 res = vfs_connect(); 503 if (res < 0) { 504 async_serialize_end(); 505 futex_up(&vfs_phone_futex); 506 free(olda); 507 free(newa); 508 return res; 509 } 510 } 511 req = async_send_0(vfs_phone, VFS_RENAME, NULL); 512 rc = ipc_data_write_start(vfs_phone, oldc, oldc_len); 513 if (rc != EOK) { 514 async_wait_for(req, NULL); 515 async_serialize_end(); 516 futex_up(&vfs_phone_futex); 517 free(olda); 518 free(newa); 519 return (int) rc; 520 } 521 rc = ipc_data_write_start(vfs_phone, newc, newc_len); 496 return (int) rc; 497 } 498 rc = ipc_data_write_start(vfs_phone, newa, newa_len); 522 499 if (rc != EOK) { 523 500 async_wait_for(req, NULL); … … 538 515 int chdir(const char *path) 539 516 { 540 char *pa = absolutize(path); 517 size_t pa_len; 518 char *pa = absolutize(path, &pa_len); 541 519 if (!pa) 542 520 return ENOMEM; 543 size_t pc_len; 544 char *pc = canonify(pa, &pc_len); 545 if (!pc) { 546 free(pa); 547 return ENOENT; 548 } 549 550 DIR *d = opendir(pc); 521 522 DIR *d = opendir(pa); 551 523 if (!d) { 552 524 free(pa); … … 563 535 } 564 536 cwd_dir = d; 565 cwd_path = p c;566 cwd_len = p c_len;537 cwd_path = pa; 538 cwd_len = pa_len; 567 539 futex_up(&cwd_futex); 568 540 }
Note:
See TracChangeset
for help on using the changeset viewer.