Changes in uspace/lib/libc/generic/vfs/vfs.c [2b88074b:0da4e41] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/vfs/vfs.c
r2b88074b r0da4e41 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) … … 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 = async_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 … … 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 } … … 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 } … … 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.