Changeset f77c1c9 in mainline
- Timestamp:
- 2017-12-08T21:03:35Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c19a5a59
- Parents:
- c1694b6b
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2017-12-07 19:44:55)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2017-12-08 21:03:35)
- Location:
- uspace
- Files:
-
- 33 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/cat/cat.c
rc1694b6b rf77c1c9 195 195 /* Allow storing the whole UTF-8 character. */ 196 196 blen = STR_BOUNDS(1); 197 } else 198 fd = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ); 197 } else { 198 int rc = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ, &fd); 199 if (rc != EOK) { 200 fd = -1; 201 } 202 } 199 203 200 204 if (fd < 0) { -
uspace/app/bdsh/cmds/modules/cmp/cmp.c
rc1694b6b rf77c1c9 80 80 81 81 for (int i = 0; i < 2; i++) { 82 fd[i] = vfs_lookup_open(fn[i], WALK_REGULAR, MODE_READ); 83 if (fd[i] < 0) { 84 rc = fd[i]; 82 rc = vfs_lookup_open(fn[i], WALK_REGULAR, MODE_READ, &(fd[i])); 83 if (rc != EOK) { 85 84 printf("Unable to open %s\n", fn[i]); 86 85 goto end; -
uspace/app/bdsh/cmds/modules/cp/cp.c
rc1694b6b rf77c1c9 394 394 printf("Copying %s to %s\n", src, dest); 395 395 396 fd1 = vfs_lookup_open(src, WALK_REGULAR, MODE_READ);397 if ( fd1 < 0) {396 rc = vfs_lookup_open(src, WALK_REGULAR, MODE_READ, &fd1); 397 if (rc != EOK) { 398 398 printf("Unable to open source file %s\n", src); 399 399 return -1; 400 400 } 401 401 402 fd2 = vfs_lookup_open(dest, WALK_REGULAR | WALK_MAY_CREATE, MODE_WRITE);403 if ( fd2 < 0) {402 rc = vfs_lookup_open(dest, WALK_REGULAR | WALK_MAY_CREATE, MODE_WRITE, &fd2); 403 if (rc != EOK) { 404 404 printf("Unable to open destination file %s\n", dest); 405 405 vfs_put(fd1); -
uspace/app/bdsh/cmds/modules/mkfile/mkfile.c
rc1694b6b rf77c1c9 163 163 file_name = argv[optind]; 164 164 165 fd = vfs_lookup_open(file_name, WALK_REGULAR | WALK_MUST_CREATE, MODE_WRITE);166 if ( fd < 0) {165 rc = vfs_lookup_open(file_name, WALK_REGULAR | WALK_MUST_CREATE, MODE_WRITE, &fd); 166 if (rc != EOK) { 167 167 printf("%s: failed to create file %s.\n", cmdname, file_name); 168 168 return CMD_FAILURE; -
uspace/app/bdsh/cmds/modules/rm/rm.c
rc1694b6b rf77c1c9 149 149 } 150 150 151 fd = vfs_lookup(path, WALK_REGULAR); 152 if (fd >= 0) { 151 if (vfs_lookup(path, WALK_REGULAR, &fd) == EOK) { 153 152 vfs_put(fd); 154 153 return RM_FILE; -
uspace/app/bdsh/cmds/modules/touch/touch.c
rc1694b6b rf77c1c9 123 123 if ((!no_create) || 124 124 ((no_create) && (vfs_stat_path(buff, &file_stat) == EOK))) { 125 fd = vfs_lookup(buff, WALK_REGULAR | WALK_MAY_CREATE); 125 int rc = vfs_lookup(buff, WALK_REGULAR | WALK_MAY_CREATE, &fd); 126 if (rc != EOK) { 127 fd = -1; 128 } 126 129 } 127 130 -
uspace/app/bdsh/exec.c
rc1694b6b rf77c1c9 58 58 int fd; 59 59 60 fd = vfs_lookup_open(f, WALK_REGULAR, MODE_READ);61 if ( fd >= 0) {60 int rc = vfs_lookup_open(f, WALK_REGULAR, MODE_READ, &fd); 61 if (rc == EOK) { 62 62 vfs_put(fd); 63 63 return 0; -
uspace/app/getterm/getterm.c
rc1694b6b rf77c1c9 65 65 *stream = NULL; 66 66 67 int oldfd = vfs_lookup_open(path, WALK_REGULAR, mode); 68 if (oldfd < 0) 67 int oldfd; 68 int rc = vfs_lookup_open(path, WALK_REGULAR, mode, &oldfd); 69 if (rc != EOK) 69 70 return; 70 71 71 72 if (oldfd != fd) { 72 if (vfs_clone(oldfd, fd, false) != fd) 73 int newfd; 74 if (vfs_clone(oldfd, fd, false, &newfd) != EOK) 73 75 return; 74 76 77 assert(newfd == fd); 78 75 79 if (vfs_put(oldfd)) 76 80 return; -
uspace/app/redir/redir.c
rc1694b6b rf77c1c9 59 59 *stream = NULL; 60 60 61 int oldfd = vfs_lookup_open(path, WALK_REGULAR | flags, mode); 62 if (oldfd < 0) 61 int oldfd; 62 int rc = vfs_lookup_open(path, WALK_REGULAR | flags, mode, &oldfd); 63 if (rc != EOK) 63 64 return; 64 65 65 66 if (oldfd != fd) { 66 if (vfs_clone(oldfd, fd, false) != fd) 67 int newfd; 68 if (vfs_clone(oldfd, fd, false, &newfd) != EOK) 67 69 return; 68 70 71 assert(newfd == fd); 72 69 73 if (vfs_put(oldfd)) 70 74 return; -
uspace/app/sysinst/futil.c
rc1694b6b rf77c1c9 63 63 printf("Copy '%s' to '%s'.\n", srcp, destp); 64 64 65 sf = vfs_lookup_open(srcp, WALK_REGULAR, MODE_READ);66 if ( sf < 0)67 return EIO; 68 69 df = vfs_lookup_open(destp, WALK_REGULAR | WALK_MAY_CREATE, MODE_WRITE);70 if ( df < 0)65 rc = vfs_lookup_open(srcp, WALK_REGULAR, MODE_READ, &sf); 66 if (rc != EOK) 67 return EIO; 68 69 rc = vfs_lookup_open(destp, WALK_REGULAR | WALK_MAY_CREATE, MODE_WRITE, &df); 70 if (rc != EOK) 71 71 return EIO; 72 72 … … 87 87 88 88 rc = vfs_put(df); 89 if (rc < 0)89 if (rc != EOK) 90 90 return EIO; 91 91 … … 167 167 struct stat st; 168 168 169 sf = vfs_lookup_open(srcp, WALK_REGULAR, MODE_READ);170 if ( sf < 0)169 rc = vfs_lookup_open(srcp, WALK_REGULAR, MODE_READ, &sf); 170 if (rc != EOK) 171 171 return ENOENT; 172 172 -
uspace/app/taskdump/elf_core.c
rc1694b6b rf77c1c9 123 123 } 124 124 125 fd= vfs_lookup_open(file_name, WALK_REGULAR | WALK_MAY_CREATE,126 MODE_WRITE );127 if ( fd < 0) {128 printf("Failed opening file .\n");125 rc = vfs_lookup_open(file_name, WALK_REGULAR | WALK_MAY_CREATE, 126 MODE_WRITE, &fd); 127 if (rc != EOK) { 128 printf("Failed opening file '%s': %s.\n", file_name, str_error(rc)); 129 129 free(p_hdr); 130 130 return ENOENT; -
uspace/app/taskdump/symtab.c
rc1694b6b rf77c1c9 82 82 return ENOMEM; 83 83 84 fd = vfs_lookup_open(file_name, WALK_REGULAR, MODE_READ);85 if ( fd < 0) {86 printf("failed opening file \n");84 rc = vfs_lookup_open(file_name, WALK_REGULAR, MODE_READ, &fd); 85 if (rc != EOK) { 86 printf("failed opening file '%s': %s\n", file_name, str_error(rc)); 87 87 free(stab); 88 88 return ENOENT; -
uspace/app/tester/mm/pager1.c
rc1694b6b rf77c1c9 49 49 TPRINTF("Creating temporary file...\n"); 50 50 51 fd= vfs_lookup_open(TEST_FILE, WALK_REGULAR | WALK_MAY_CREATE,52 MODE_READ | MODE_WRITE );53 if ( fd < 0)51 rc = vfs_lookup_open(TEST_FILE, WALK_REGULAR | WALK_MAY_CREATE, 52 MODE_READ | MODE_WRITE, &fd); 53 if (rc != EOK) 54 54 return NULL; 55 55 (void) vfs_unlink_path(TEST_FILE); -
uspace/app/tester/vfs/vfs1.c
rc1694b6b rf77c1c9 73 73 rc = vfs_link_path(TEST_DIRECTORY, KIND_DIRECTORY, NULL); 74 74 if (rc != EOK) { 75 TPRINTF("rc=% d\n", rc);75 TPRINTF("rc=%s\n", str_error_name(rc)); 76 76 return "vfs_link_path() failed"; 77 77 } 78 78 TPRINTF("Created directory %s\n", TEST_DIRECTORY); 79 79 80 int fd0 = vfs_lookup_open(TEST_FILE, WALK_REGULAR | WALK_MAY_CREATE, 81 MODE_READ | MODE_WRITE); 82 if (fd0 < 0) 80 int fd0; 81 rc = vfs_lookup_open(TEST_FILE, WALK_REGULAR | WALK_MAY_CREATE, 82 MODE_READ | MODE_WRITE, &fd0); 83 if (rc != EOK) 83 84 return "vfs_lookup_open() failed"; 84 85 TPRINTF("Created file %s (fd=%d)\n", TEST_FILE, fd0); -
uspace/app/viewer/viewer.c
rc1694b6b rf77c1c9 109 109 static bool img_load(const char *fname, surface_t **p_local_surface) 110 110 { 111 int fd = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ); 112 if (fd < 0) 111 int fd; 112 int rc = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ, &fd); 113 if (rc != EOK) 113 114 return false; 114 115 115 116 struct stat stat; 116 intrc = vfs_stat(fd, &stat);117 rc = vfs_stat(fd, &stat); 117 118 if (rc != EOK) { 118 119 vfs_put(fd); -
uspace/app/websrv/websrv.c
rc1694b6b rf77c1c9 265 265 } 266 266 267 fd = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ);268 if ( fd < 0) {267 rc = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ, &fd); 268 if (rc != EOK) { 269 269 rc = send_response(conn, msg_not_found); 270 270 goto out; -
uspace/drv/bus/isa/isa.c
rc1694b6b rf77c1c9 281 281 struct stat st; 282 282 283 fd = vfs_lookup_open(conf_path, WALK_REGULAR, MODE_READ);284 if ( fd < 0) {283 rc = vfs_lookup_open(conf_path, WALK_REGULAR, MODE_READ, &fd); 284 if (rc != EOK) { 285 285 ddf_msg(LVL_ERROR, "Unable to open %s", conf_path); 286 286 goto cleanup; -
uspace/lib/bithenge/src/file.c
rc1694b6b rf77c1c9 145 145 assert(filename); 146 146 147 int fd = vfs_lookup_open(filename, WALK_REGULAR, MODE_READ); 148 if (fd < 0) 149 return errno; 147 int fd; 148 int rc = vfs_lookup_open(filename, WALK_REGULAR, MODE_READ, &fd); 149 if (rc != EOK) 150 return rc; 150 151 151 152 return new_file_blob(out, fd, true); -
uspace/lib/c/generic/dirent.c
rc1694b6b rf77c1c9 54 54 } 55 55 56 int fd = vfs_lookup(dirname, WALK_DIRECTORY); 57 if (fd < 0) { 56 int fd; 57 int rc = vfs_lookup(dirname, WALK_DIRECTORY, &fd); 58 if (rc != EOK) { 58 59 free(dirp); 59 errno = fd;60 errno = rc; 60 61 return NULL; 61 62 } 62 63 63 intrc = vfs_open(fd, MODE_READ);64 if (rc < 0) {64 rc = vfs_open(fd, MODE_READ); 65 if (rc != EOK) { 65 66 free(dirp); 66 67 vfs_put(fd); -
uspace/lib/c/generic/elf/elf_mod.c
rc1694b6b rf77c1c9 97 97 elf_ld_t elf; 98 98 99 int ofile = vfs_clone(file, -1, true); 100 int rc = vfs_open(ofile, MODE_READ); 99 int ofile; 100 int rc = vfs_clone(file, -1, true, &ofile); 101 if (rc == EOK) { 102 rc = vfs_open(ofile, MODE_READ); 103 } 101 104 if (rc != EOK) { 102 105 return rc; … … 116 119 elf_finfo_t *info) 117 120 { 118 int file = vfs_lookup(path, 0); 119 int rc = elf_load_file(file, so_bias, flags, info); 120 vfs_put(file); 121 int file; 122 int rc = vfs_lookup(path, 0, &file); 123 if (rc == EOK) { 124 rc = elf_load_file(file, so_bias, flags, info); 125 vfs_put(file); 126 } 121 127 return rc; 122 128 } -
uspace/lib/c/generic/io/io.c
rc1694b6b rf77c1c9 108 108 * This will probably be removed later. 109 109 */ 110 111 110 int infd = inbox_get("stdin"); 112 111 if (infd >= 0) { 113 int stdinfd = vfs_clone(infd, -1, false); 112 int stdinfd = -1; 113 (void) vfs_clone(infd, -1, false, &stdinfd); 114 114 assert(stdinfd == 0); 115 115 vfs_open(stdinfd, MODE_READ); … … 122 122 int outfd = inbox_get("stdout"); 123 123 if (outfd >= 0) { 124 int stdoutfd = vfs_clone(outfd, -1, false); 124 int stdoutfd = -1; 125 (void) vfs_clone(outfd, -1, false, &stdoutfd); 125 126 assert(stdoutfd <= 1); 126 127 while (stdoutfd < 1) 127 stdoutfd = vfs_clone(outfd, -1, false);128 (void) vfs_clone(outfd, -1, false, &stdoutfd); 128 129 vfs_open(stdoutfd, MODE_APPEND); 129 130 stdout = fdopen(stdoutfd, "a"); … … 135 136 int errfd = inbox_get("stderr"); 136 137 if (errfd >= 0) { 137 int stderrfd = vfs_clone(errfd, -1, false); 138 int stderrfd = -1; 139 (void) vfs_clone(errfd, -1, false, &stderrfd); 138 140 assert(stderrfd <= 2); 139 141 while (stderrfd < 2) 140 stderrfd = vfs_clone(errfd, -1, false);142 (void) vfs_clone(errfd, -1, false, &stderrfd); 141 143 vfs_open(stderrfd, MODE_APPEND); 142 144 stderr = fdopen(stderrfd, "a"); … … 294 296 if (create) 295 297 flags |= WALK_MAY_CREATE; 296 int file = vfs_lookup(path, flags); 297 if (file < 0) { 298 errno = file; 298 int file; 299 int rc = vfs_lookup(path, flags, &file); 300 if (rc != EOK) { 301 errno = rc; 299 302 free(stream); 300 303 return NULL; 301 304 } 302 305 303 intrc = vfs_open(file, mode);306 rc = vfs_open(file, mode); 304 307 if (rc != EOK) { 305 308 errno = rc; … … 373 376 list_remove(&stream->link); 374 377 375 if (rc != 0) {376 /* errno was set by close() */378 if (rc != EOK) { 379 errno = rc; 377 380 return EOF; 378 381 } -
uspace/lib/c/generic/loader.c
rc1694b6b rf77c1c9 52 52 * @param name Symbolic name to set on the newly created task. 53 53 * 54 * @return Pointer to the loader connection structure (should be 55 * deallocated using free() after use). 56 * 54 * @return Error code. 57 55 */ 58 56 int loader_spawn(const char *name) … … 198 196 } 199 197 200 int fd = vfs_lookup(path, 0); 201 if (fd < 0) { 202 return fd; 203 } 204 205 int rc = loader_set_program(ldr, name, fd); 198 int fd; 199 int rc = vfs_lookup(path, 0, &fd); 200 if (rc != EOK) { 201 return rc; 202 } 203 204 rc = loader_set_program(ldr, name, fd); 206 205 vfs_put(fd); 207 206 return rc; -
uspace/lib/c/generic/vfs/vfs.c
rc1694b6b rf77c1c9 128 128 static int root_fd = -1; 129 129 130 static int get_parent_and_child(const char *path, char **child)130 static int get_parent_and_child(const char *path, int *parent, char **child) 131 131 { 132 132 size_t size; … … 136 136 137 137 char *slash = str_rchr(apath, L'/'); 138 int parent;139 138 if (slash == apath) { 140 parent = vfs_root(); 139 *parent = vfs_root(); 140 if (*parent < 0) { 141 free(apath); 142 return EBADF; 143 } 141 144 *child = apath; 145 return EOK; 142 146 } else { 143 147 *slash = '\0'; 144 parent = vfs_lookup(apath, WALK_DIRECTORY);145 if ( parent < 0) {148 int rc = vfs_lookup(apath, WALK_DIRECTORY, parent); 149 if (rc != EOK) { 146 150 free(apath); 147 return parent;151 return rc; 148 152 } 149 153 *slash = '/'; … … 151 155 free(apath); 152 156 if (!*child) { 153 vfs_put( parent);157 vfs_put(*parent); 154 158 return ENOMEM; 155 159 } 156 } 157 158 return parent; 160 161 return rc; 162 } 163 159 164 } 160 165 … … 233 238 * @return New file handle on success or a negative error code 234 239 */ 235 int vfs_clone(int file_from, int file_to, bool high) 236 { 240 int vfs_clone(int file_from, int file_to, bool high, int *handle) 241 { 242 assert(handle != NULL); 243 237 244 async_exch_t *vfs_exch = vfs_exchange_begin(); 238 int rc = async_req_3_0(vfs_exch, VFS_IN_CLONE, (sysarg_t) file_from, 239 (sysarg_t) file_to, (sysarg_t) high); 245 sysarg_t ret; 246 int rc = async_req_3_1(vfs_exch, VFS_IN_CLONE, (sysarg_t) file_from, 247 (sysarg_t) file_to, (sysarg_t) high, &ret); 240 248 vfs_exchange_end(vfs_exch); 249 250 if (rc == EOK) { 251 *handle = ret; 252 } 241 253 return rc; 242 254 } … … 277 289 return ENOMEM; 278 290 279 int fd = vfs_lookup(abs, WALK_DIRECTORY); 280 if (fd < 0) { 291 int fd; 292 int rc = vfs_lookup(abs, WALK_DIRECTORY, &fd); 293 if (rc != EOK) { 281 294 free(abs); 282 return fd;295 return rc; 283 296 } 284 297 … … 491 504 { 492 505 int flags = (kind == KIND_DIRECTORY) ? WALK_DIRECTORY : WALK_REGULAR; 493 int file = vfs_walk(parent, child, WALK_MUST_CREATE | flags);494 495 if ( file < 0)496 return file;506 int file = -1; 507 int rc = vfs_walk(parent, child, WALK_MUST_CREATE | flags, &file); 508 if (rc != EOK) 509 return rc; 497 510 498 511 if (linkedfd) … … 521 534 { 522 535 char *child; 523 int parent = get_parent_and_child(path, &child); 524 if (parent < 0) 525 return parent; 526 527 int rc = vfs_link(parent, child, kind, linkedfd); 536 int parent; 537 int rc = get_parent_and_child(path, &parent, &child); 538 if (rc != EOK) 539 return rc; 540 541 rc = vfs_link(parent, child, kind, linkedfd); 528 542 529 543 free(child); 530 544 vfs_put(parent); 531 545 return rc; 532 } 546 } 533 547 534 548 /** Lookup a path relative to the local root … … 536 550 * @param path Path to be looked up 537 551 * @param flags Walk flags 538 * 539 * @return File handle representing the result on success or a negative540 * error code on error541 */ 542 int vfs_lookup(const char *path, int flags )552 * @param[out] handle Pointer to variable where handle is to be written. 553 * 554 * @return EOK on success or an error code. 555 */ 556 int vfs_lookup(const char *path, int flags, int *handle) 543 557 { 544 558 size_t size; … … 546 560 if (!p) 547 561 return ENOMEM; 562 548 563 int root = vfs_root(); 549 564 if (root < 0) { … … 551 566 return ENOENT; 552 567 } 553 int rc = vfs_walk(root, p, flags); 568 569 int rc = vfs_walk(root, p, flags, handle); 554 570 vfs_put(root); 555 571 free(p); … … 564 580 * @param flags Walk flags 565 581 * @param mode Mode in which to open file in 582 * @param[out] handle Pointer to variable where handle is to be written. 566 583 * 567 584 * @return EOK on success or a negative error code 568 585 */ 569 int vfs_lookup_open(const char *path, int flags, int mode) 570 { 571 int file = vfs_lookup(path, flags); 572 if (file < 0) 573 return file; 574 575 int rc = vfs_open(file, mode); 586 int vfs_lookup_open(const char *path, int flags, int mode, int *handle) 587 { 588 int file; 589 int rc = vfs_lookup(path, flags, &file); 590 if (rc != EOK) 591 return rc; 592 593 rc = vfs_open(file, mode); 576 594 if (rc != EOK) { 577 595 vfs_put(file); 578 596 return rc; 579 597 } 580 581 return file; 598 599 *handle = file; 600 return EOK; 582 601 } 583 602 … … 707 726 } 708 727 709 int mpfd = vfs_walk(root_fd, mpa, WALK_DIRECTORY); 710 if (mpfd >= 0) { 728 int mpfd; 729 rc = vfs_walk(root_fd, mpa, WALK_DIRECTORY, &mpfd); 730 if (rc == EOK) { 711 731 rc = vfs_mount(mpfd, fs_name, service_id, opts, flags, 712 732 instance, NULL); 713 733 vfs_put(mpfd); 714 } else {715 rc = mpfd;716 734 } 717 735 } … … 775 793 * @param high If true, the received file handle will be allocated from high 776 794 * indices 795 * @param[out] handle Received handle. 777 796 * 778 797 * @return EOK on success or a negative error code 779 798 */ 780 int vfs_receive_handle(bool high )799 int vfs_receive_handle(bool high, int *handle) 781 800 { 782 801 ipc_callid_t callid; … … 795 814 async_exchange_end(vfs_exch); 796 815 797 if (rc != EOK) 798 return rc; 799 return ret; 816 if (rc == EOK) { 817 *handle = (int) ret; 818 } 819 820 return rc; 800 821 } 801 822 … … 976 997 /** Return a new file handle representing the local root 977 998 * 978 * @return A clone of the local root file handle or a negative error code999 * @return A clone of the local root file handle or -1 979 1000 */ 980 1001 int vfs_root(void) 981 1002 { 982 fibril_mutex_lock(&root_mutex); 983 int r; 984 if (root_fd < 0) 985 r = ENOENT; 986 else 987 r = vfs_clone(root_fd, -1, true); 1003 fibril_mutex_lock(&root_mutex); 1004 int fd; 1005 if (root_fd < 0) { 1006 fd = -1; 1007 } else { 1008 int rc = vfs_clone(root_fd, -1, true, &fd); 1009 if (rc != EOK) { 1010 fd = -1; 1011 } 1012 } 988 1013 fibril_mutex_unlock(&root_mutex); 989 return r;1014 return fd; 990 1015 } 991 1016 … … 997 1022 * 998 1023 * @param nroot The new local root file handle 999 */ 1000 void vfs_root_set(int nroot) 1001 { 1024 * 1025 * @return Error code 1026 */ 1027 int vfs_root_set(int nroot) 1028 { 1029 int new_root; 1030 int rc = vfs_clone(nroot, -1, true, &new_root); 1031 if (rc != EOK) { 1032 return rc; 1033 } 1034 1002 1035 fibril_mutex_lock(&root_mutex); 1003 1036 if (root_fd >= 0) 1004 1037 vfs_put(root_fd); 1005 root_fd = vfs_clone(nroot, -1, true);1038 root_fd = new_root; 1006 1039 fibril_mutex_unlock(&root_mutex); 1040 1041 return EOK; 1007 1042 } 1008 1043 … … 1050 1085 int vfs_stat_path(const char *path, struct stat *stat) 1051 1086 { 1052 int file = vfs_lookup(path, 0); 1053 if (file < 0) 1054 return file; 1055 1056 int rc = vfs_stat(file, stat); 1087 int file; 1088 int rc = vfs_lookup(path, 0, &file); 1089 if (rc != EOK) 1090 return rc; 1091 1092 rc = vfs_stat(file, stat); 1057 1093 1058 1094 vfs_put(file); … … 1095 1131 int vfs_statfs_path(const char *path, struct statfs *st) 1096 1132 { 1097 int file = vfs_lookup(path, 0); 1098 if (file < 0) 1099 return file; 1100 1101 int rc = vfs_statfs(file, st); 1133 int file; 1134 int rc = vfs_lookup(path, 0, &file); 1135 if (rc != EOK) 1136 return rc; 1137 1138 rc = vfs_statfs(file, st); 1102 1139 1103 1140 vfs_put(file); … … 1165 1202 int vfs_unlink_path(const char *path) 1166 1203 { 1167 int expect = vfs_lookup(path, 0); 1168 if (expect < 0) 1169 return expect; 1204 int expect; 1205 int rc = vfs_lookup(path, 0, &expect); 1206 if (rc != EOK) 1207 return rc; 1170 1208 1171 1209 char *child; 1172 int parent = get_parent_and_child(path, &child); 1173 if (parent < 0) { 1210 int parent; 1211 rc = get_parent_and_child(path, &parent, &child); 1212 if (rc != EOK) { 1174 1213 vfs_put(expect); 1175 return parent;1176 } 1177 1178 intrc = vfs_unlink(parent, child, expect);1214 return rc; 1215 } 1216 1217 rc = vfs_unlink(parent, child, expect); 1179 1218 1180 1219 free(child); … … 1206 1245 int vfs_unmount_path(const char *mpp) 1207 1246 { 1208 int mp = vfs_lookup(mpp, WALK_MOUNT_POINT | WALK_DIRECTORY); 1209 if (mp < 0) 1210 return mp; 1211 1212 int rc = vfs_unmount(mp); 1247 int mp; 1248 int rc = vfs_lookup(mpp, WALK_MOUNT_POINT | WALK_DIRECTORY, &mp); 1249 if (rc != EOK) 1250 return rc; 1251 1252 rc = vfs_unmount(mp); 1213 1253 vfs_put(mp); 1214 1254 return rc; … … 1220 1260 * @param path Parent-relative path to be walked 1221 1261 * @param flags Flags influencing the walk 1222 * 1223 * @retrun File handle representing the result on success or1224 * a negative error code on error1225 */ 1226 int vfs_walk(int parent, const char *path, int flags )1262 * @param[out] handle File handle representing the result on success. 1263 * 1264 * @return Error code. 1265 */ 1266 int vfs_walk(int parent, const char *path, int flags, int *handle) 1227 1267 { 1228 1268 async_exch_t *exch = vfs_exchange_begin(); … … 1242 1282 return (int) rc; 1243 1283 1244 return (int) IPC_GET_ARG1(answer); 1284 *handle = (int) IPC_GET_ARG1(answer); 1285 return EOK; 1245 1286 } 1246 1287 -
uspace/lib/c/include/vfs/vfs.h
rc1694b6b rf77c1c9 85 85 86 86 extern char *vfs_absolutize(const char *, size_t *); 87 extern int vfs_clone(int, int, bool );87 extern int vfs_clone(int, int, bool, int *); 88 88 extern int vfs_cwd_get(char *path, size_t); 89 89 extern int vfs_cwd_set(const char *path); … … 95 95 extern int vfs_link(int, const char *, vfs_file_kind_t, int *); 96 96 extern int vfs_link_path(const char *, vfs_file_kind_t, int *); 97 extern int vfs_lookup(const char *, int );98 extern int vfs_lookup_open(const char *, int, int );97 extern int vfs_lookup(const char *, int, int *); 98 extern int vfs_lookup_open(const char *, int, int, int *); 99 99 extern int vfs_mount_path(const char *, const char *, const char *, 100 100 const char *, unsigned int, unsigned int); … … 106 106 extern int vfs_read(int, aoff64_t *, void *, size_t, size_t *); 107 107 extern int vfs_read_short(int, aoff64_t, void *, size_t, ssize_t *); 108 extern int vfs_receive_handle(bool );108 extern int vfs_receive_handle(bool, int *); 109 109 extern int vfs_rename_path(const char *, const char *); 110 110 extern int vfs_resize(int, aoff64_t); 111 111 extern int vfs_root(void); 112 extern voidvfs_root_set(int);112 extern int vfs_root_set(int); 113 113 extern int vfs_stat(int, struct stat *); 114 114 extern int vfs_stat_path(const char *, struct stat *); … … 120 120 extern int vfs_unmount(int); 121 121 extern int vfs_unmount_path(const char *); 122 extern int vfs_walk(int, const char *, int );122 extern int vfs_walk(int, const char *, int, int *); 123 123 extern int vfs_write(int, aoff64_t *, const void *, size_t, size_t *); 124 124 extern int vfs_write_short(int, aoff64_t, const void *, size_t, ssize_t *); -
uspace/lib/pcut/src/os/helenos.c
rc1694b6b rf77c1c9 159 159 char tempfile_name[PCUT_TEMP_FILENAME_BUFFER_SIZE]; 160 160 snprintf(tempfile_name, PCUT_TEMP_FILENAME_BUFFER_SIZE - 1, "pcut_%lld.tmp", (unsigned long long) task_get_id()); 161 int tempfile = vfs_lookup_open(tempfile_name, WALK_REGULAR | WALK_MAY_CREATE, MODE_READ | MODE_WRITE); 162 if (tempfile < 0) { 161 int tempfile; 162 int rc = vfs_lookup_open(tempfile_name, WALK_REGULAR | WALK_MAY_CREATE, MODE_READ | MODE_WRITE, &tempfile); 163 if (rc != EOK) { 163 164 pcut_report_test_done(test, PCUT_OUTCOME_INTERNAL_ERROR, "Failed to create temporary file.", NULL, NULL); 164 165 return PCUT_OUTCOME_INTERNAL_ERROR; … … 177 178 178 179 task_wait_t test_task_wait; 179 intrc = task_spawnvf(&test_task_id, &test_task_wait, self_path, arguments,180 rc = task_spawnvf(&test_task_id, &test_task_wait, self_path, arguments, 180 181 fileno(stdin), tempfile, tempfile); 181 182 if (rc != EOK) { -
uspace/lib/posix/source/fcntl.c
rc1694b6b rf77c1c9 135 135 ((posix_flags & O_APPEND) ? MODE_APPEND : 0); 136 136 137 int file = rcerrno(vfs_lookup, pathname, flags); 138 if (file < 0) 137 int file; 138 rc = rcerrno(vfs_lookup, pathname, flags, &file); 139 if (rc != EOK) 139 140 return -1; 140 141 -
uspace/lib/posix/source/unistd.c
rc1694b6b rf77c1c9 355 355 int posix_dup2(int fildes, int fildes2) 356 356 { 357 return negerrno(vfs_clone, fildes, fildes2, false); 357 int file; 358 int rc = vfs_clone(fildes, fildes2, false, &file); 359 if (rc != EOK) { 360 errno = rc < 0 ? -rc : rc; 361 return -1; 362 } 363 return file; 358 364 } 359 365 -
uspace/srv/devman/match.c
rc1694b6b rf77c1c9 202 202 struct stat st; 203 203 204 fd = vfs_lookup_open(conf_path, WALK_REGULAR, MODE_READ);205 if ( fd < 0) {204 int rc = vfs_lookup_open(conf_path, WALK_REGULAR, MODE_READ, &fd); 205 if (rc != EOK) { 206 206 log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to open `%s' for reading: %s.", 207 conf_path, str_error( errno));207 conf_path, str_error(rc)); 208 208 goto cleanup; 209 209 } 210 210 opened = true; 211 211 212 if (vfs_stat(fd, &st) != EOK) { 212 rc = vfs_stat(fd, &st); 213 if (rc != EOK) { 213 214 log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to fstat %d: %s.", fd, 214 str_error( errno));215 str_error(rc)); 215 216 goto cleanup; 216 217 } … … 230 231 231 232 size_t read_bytes; 232 intrc = vfs_read(fd, (aoff64_t []) {0}, buf, len, &read_bytes);233 rc = vfs_read(fd, (aoff64_t []) {0}, buf, len, &read_bytes); 233 234 if (rc != EOK) { 234 235 log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to read file '%s': %s.", conf_path, 235 str_error( errno));236 str_error(rc)); 236 237 goto cleanup; 237 238 } -
uspace/srv/loader/main.c
rc1694b6b rf77c1c9 152 152 } 153 153 154 int file = vfs_receive_handle(true); 155 if (file < 0) { 154 int file; 155 rc = vfs_receive_handle(true, &file); 156 if (rc != EOK) { 156 157 async_answer_0(rid, EINVAL); 157 158 return; … … 254 255 } 255 256 256 int file = vfs_receive_handle(true); 257 if (file < 0) { 257 int file; 258 rc = vfs_receive_handle(true, &file); 259 if (rc != EOK) { 258 260 async_answer_0(rid, EINVAL); 259 261 return; -
uspace/srv/logger/ctl.c
rc1694b6b rf77c1c9 87 87 } 88 88 case LOGGER_CONTROL_SET_ROOT: { 89 int fd = vfs_receive_handle(true); 90 vfs_root_set(fd); 91 async_answer_0(callid, fd >= 0 ? EOK : fd); 89 int fd; 90 int rc = vfs_receive_handle(true, &fd); 91 if (rc == EOK) { 92 rc = vfs_root_set(fd); 93 vfs_put(fd); 94 } 95 async_answer_0(callid, rc); 92 96 break; 93 97 } -
uspace/srv/vfs/vfs.h
rc1694b6b rf77c1c9 206 206 extern int vfs_open_node_remote(vfs_node_t *); 207 207 208 extern int vfs_op_clone(int oldfd, int newfd, bool desc );208 extern int vfs_op_clone(int oldfd, int newfd, bool desc, int *); 209 209 extern int vfs_op_fsprobe(const char *, service_id_t, vfs_fs_probe_info_t *); 210 210 extern int vfs_op_mount(int mpfd, unsigned servid, unsigned flags, unsigned instance, const char *opts, const char *fsname, int *outfd); -
uspace/srv/vfs/vfs_ipc.c
rc1694b6b rf77c1c9 41 41 bool desc = IPC_GET_ARG3(*request); 42 42 43 int ret = vfs_op_clone(oldfd, newfd, desc); 44 async_answer_0(rid, ret); 43 int outfd = -1; 44 int rc = vfs_op_clone(oldfd, newfd, desc, &outfd); 45 async_answer_1(rid, rc, outfd); 45 46 } 46 47 -
uspace/srv/vfs/vfs_ops.c
rc1694b6b rf77c1c9 86 86 } 87 87 88 int vfs_op_clone(int oldfd, int newfd, bool desc )88 int vfs_op_clone(int oldfd, int newfd, bool desc, int *out_fd) 89 89 { 90 90 int rc; … … 118 118 vfs_file_put(oldfile); 119 119 120 return rc; 120 if (rc < 0) { 121 return rc; 122 } 123 124 *out_fd = rc; 125 return EOK; 121 126 } 122 127
Note:
See TracChangeset
for help on using the changeset viewer.