Changes in uspace/lib/libc/generic/vfs/vfs.c [1313ee9:3734106] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/vfs/vfs.c
r1313ee9 r3734106 57 57 static futex_t cwd_futex = FUTEX_INITIALIZER; 58 58 59 static int cwd_fd = -1;60 staticchar *cwd_path = NULL;61 s tatic size_t cwd_size = 0;59 DIR *cwd_dir = NULL; 60 char *cwd_path = NULL; 61 size_t cwd_size = 0; 62 62 63 63 char *absolutize(const char *path, size_t *retlen) … … 117 117 } 118 118 119 int mount(const char *fs_name, const char *mp, const char * fqdn,119 int mount(const char *fs_name, const char *mp, const char *dev, 120 120 const char *opts, unsigned int flags) 121 121 { … … 126 126 dev_handle_t dev_handle; 127 127 128 res = devmap_device_get_handle( fqdn, &dev_handle, flags);128 res = devmap_device_get_handle(dev, &dev_handle, flags); 129 129 if (res != EOK) 130 130 return res; … … 140 140 141 141 req = async_send_2(vfs_phone, VFS_IN_MOUNT, dev_handle, flags, NULL); 142 rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size);142 rc = ipc_data_write_start(vfs_phone, (void *) mpa, mpa_size); 143 143 if (rc != EOK) { 144 144 async_wait_for(req, &rc_orig); … … 152 152 } 153 153 154 rc = async_data_write_start(vfs_phone, (void *) opts, str_size(opts));154 rc = ipc_data_write_start(vfs_phone, (void *) opts, str_size(opts)); 155 155 if (rc != EOK) { 156 156 async_wait_for(req, &rc_orig); … … 164 164 } 165 165 166 rc = async_data_write_start(vfs_phone, (void *) fs_name, str_size(fs_name));166 rc = ipc_data_write_start(vfs_phone, (void *) fs_name, str_size(fs_name)); 167 167 if (rc != EOK) { 168 168 async_wait_for(req, &rc_orig); … … 197 197 } 198 198 199 static int open_internal(const char *abs, size_t abs_size, int lflag, int oflag) 200 { 201 futex_down(&vfs_phone_futex); 202 async_serialize_start(); 203 vfs_connect(); 204 199 static int _open(const char *path, int lflag, int oflag, ...) 200 { 201 ipcarg_t rc; 205 202 ipc_call_t answer; 206 aid_t req = async_send_3(vfs_phone, VFS_IN_OPEN, lflag, oflag, 0, &answer); 207 ipcarg_t rc = async_data_write_start(vfs_phone, abs, abs_size); 208 203 aid_t req; 204 205 size_t pa_size; 206 char *pa = absolutize(path, &pa_size); 207 if (!pa) 208 return ENOMEM; 209 210 futex_down(&vfs_phone_futex); 211 async_serialize_start(); 212 vfs_connect(); 213 214 req = async_send_3(vfs_phone, VFS_IN_OPEN, lflag, oflag, 0, &answer); 215 rc = ipc_data_write_start(vfs_phone, pa, pa_size); 209 216 if (rc != EOK) { 210 217 ipcarg_t rc_orig; 211 async_wait_for(req, &rc_orig);212 213 async_serialize_end(); 214 futex_up(&vfs_phone_futex); 215 216 if (rc_orig == EOK) 217 return (int) rc; 218 else 219 return (int) rc_orig; 220 } 221 222 async_ wait_for(req, &rc);223 async_serialize_end();224 f utex_up(&vfs_phone_futex);218 219 async_wait_for(req, &rc_orig); 220 async_serialize_end(); 221 futex_up(&vfs_phone_futex); 222 free(pa); 223 if (rc_orig == EOK) 224 return (int) rc; 225 else 226 return (int) rc_orig; 227 } 228 async_wait_for(req, &rc); 229 async_serialize_end(); 230 futex_up(&vfs_phone_futex); 231 free(pa); 225 232 226 233 if (rc != EOK) … … 232 239 int open(const char *path, int oflag, ...) 233 240 { 234 size_t abs_size; 235 char *abs = absolutize(path, &abs_size); 236 if (!abs) 237 return ENOMEM; 238 239 int ret = open_internal(abs, abs_size, L_FILE, oflag); 240 free(abs); 241 242 return ret; 241 return _open(path, L_FILE, oflag); 243 242 } 244 243 … … 291 290 292 291 req = async_send_1(vfs_phone, VFS_IN_READ, fildes, &answer); 293 rc = async_data_read_start(vfs_phone, (void *)buf, nbyte);292 rc = ipc_data_read_start(vfs_phone, (void *)buf, nbyte); 294 293 if (rc != EOK) { 295 294 ipcarg_t rc_orig; … … 323 322 324 323 req = async_send_1(vfs_phone, VFS_IN_WRITE, fildes, &answer); 325 rc = async_data_write_start(vfs_phone, (void *)buf, nbyte);324 rc = ipc_data_write_start(vfs_phone, (void *)buf, nbyte); 326 325 if (rc != EOK) { 327 326 ipcarg_t rc_orig; … … 403 402 404 403 req = async_send_1(vfs_phone, VFS_IN_FSTAT, fildes, NULL); 405 rc = async_data_read_start(vfs_phone, (void *)stat, sizeof(struct stat));404 rc = ipc_data_read_start(vfs_phone, (void *)stat, sizeof(struct stat)); 406 405 if (rc != EOK) { 407 406 ipcarg_t rc_orig; … … 438 437 439 438 req = async_send_0(vfs_phone, VFS_IN_STAT, NULL); 440 rc = async_data_write_start(vfs_phone, pa, pa_size);439 rc = ipc_data_write_start(vfs_phone, pa, pa_size); 441 440 if (rc != EOK) { 442 441 async_wait_for(req, &rc_orig); … … 449 448 return (int) rc_orig; 450 449 } 451 rc = async_data_read_start(vfs_phone, stat, sizeof(struct stat));450 rc = ipc_data_read_start(vfs_phone, stat, sizeof(struct stat)); 452 451 if (rc != EOK) { 453 452 async_wait_for(req, &rc_orig); … … 472 471 if (!dirp) 473 472 return NULL; 474 475 size_t abs_size; 476 char *abs = absolutize(dirname, &abs_size); 477 if (!abs) { 478 free(dirp); 479 return ENOMEM; 480 } 481 482 int ret = open_internal(abs, abs_size, L_DIRECTORY, 0); 483 free(abs); 484 485 if (ret < 0) { 473 dirp->fd = _open(dirname, L_DIRECTORY, 0); 474 if (dirp->fd < 0) { 486 475 free(dirp); 487 476 return NULL; 488 477 } 489 490 dirp->fd = ret;491 478 return dirp; 492 479 } … … 527 514 528 515 req = async_send_1(vfs_phone, VFS_IN_MKDIR, mode, NULL); 529 rc = async_data_write_start(vfs_phone, pa, pa_size);516 rc = ipc_data_write_start(vfs_phone, pa, pa_size); 530 517 if (rc != EOK) { 531 518 ipcarg_t rc_orig; … … 562 549 563 550 req = async_send_0(vfs_phone, VFS_IN_UNLINK, NULL); 564 rc = async_data_write_start(vfs_phone, pa, pa_size);551 rc = ipc_data_write_start(vfs_phone, pa, pa_size); 565 552 if (rc != EOK) { 566 553 ipcarg_t rc_orig; … … 615 602 616 603 req = async_send_0(vfs_phone, VFS_IN_RENAME, NULL); 617 rc = async_data_write_start(vfs_phone, olda, olda_size);604 rc = ipc_data_write_start(vfs_phone, olda, olda_size); 618 605 if (rc != EOK) { 619 606 async_wait_for(req, &rc_orig); … … 627 614 return (int) rc_orig; 628 615 } 629 rc = async_data_write_start(vfs_phone, newa, newa_size);616 rc = ipc_data_write_start(vfs_phone, newa, newa_size); 630 617 if (rc != EOK) { 631 618 async_wait_for(req, &rc_orig); … … 649 636 int chdir(const char *path) 650 637 { 651 size_t abs_size;652 char * abs = absolutize(path, &abs_size);653 if (! abs)638 size_t pa_size; 639 char *pa = absolutize(path, &pa_size); 640 if (!pa) 654 641 return ENOMEM; 655 656 int fd = open_internal(abs, abs_size, L_DIRECTORY, O_DESC); 657 658 if (fd < 0) { 659 free(abs); 642 643 DIR *d = opendir(pa); 644 if (!d) { 645 free(pa); 660 646 return ENOENT; 661 647 } 662 648 663 649 futex_down(&cwd_futex); 664 665 if (cwd_fd >= 0) 666 close(cwd_fd); 667 668 669 if (cwd_path) 670 free(cwd_path); 671 672 cwd_fd = fd; 673 cwd_path = abs; 674 cwd_size = abs_size; 675 650 if (cwd_dir) { 651 closedir(cwd_dir); 652 cwd_dir = NULL; 653 free(cwd_path); 654 cwd_path = NULL; 655 cwd_size = 0; 656 } 657 cwd_dir = d; 658 cwd_path = pa; 659 cwd_size = pa_size; 676 660 futex_up(&cwd_futex); 677 661 return EOK; … … 680 664 char *getcwd(char *buf, size_t size) 681 665 { 682 if ( size == 0)666 if (!size) 683 667 return NULL; 684 685 668 futex_down(&cwd_futex); 686 687 if ((cwd_size == 0) || (size < cwd_size + 1)) { 669 if (size < cwd_size + 1) { 688 670 futex_up(&cwd_futex); 689 671 return NULL; 690 672 } 691 692 673 str_cpy(buf, size, cwd_path); 693 674 futex_up(&cwd_futex); 694 695 675 return buf; 696 676 } … … 703 683 rc = fstat(fildes, &stat); 704 684 705 if (!stat.dev ice)685 if (!stat.devfs_stat.device) 706 686 return -1; 707 687 708 return devmap_device_connect(stat.dev ice, 0);688 return devmap_device_connect(stat.devfs_stat.device, 0); 709 689 } 710 690 … … 725 705 } 726 706 727 int dup2(int oldfd, int newfd)728 {729 futex_down(&vfs_phone_futex);730 async_serialize_start();731 vfs_connect();732 733 ipcarg_t ret;734 ipcarg_t rc = async_req_2_1(vfs_phone, VFS_IN_DUP, oldfd, newfd, &ret);735 736 async_serialize_end();737 futex_up(&vfs_phone_futex);738 739 if (rc == EOK)740 return (int) ret;741 742 return (int) rc;743 }744 745 707 /** @} 746 708 */
Note:
See TracChangeset
for help on using the changeset viewer.