Changeset f77c1c9 in mainline


Ignore:
Timestamp:
2017-12-08T21:03:35Z (6 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
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)
Message:

Return VFS handles separately from error codes.

Location:
uspace
Files:
33 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/cat/cat.c

    rc1694b6b rf77c1c9  
    195195                /* Allow storing the whole UTF-8 character. */
    196196                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        }
    199203       
    200204        if (fd < 0) {
  • uspace/app/bdsh/cmds/modules/cmp/cmp.c

    rc1694b6b rf77c1c9  
    8080
    8181        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) {
    8584                        printf("Unable to open %s\n", fn[i]);
    8685                        goto end;
  • uspace/app/bdsh/cmds/modules/cp/cp.c

    rc1694b6b rf77c1c9  
    394394                printf("Copying %s to %s\n", src, dest);
    395395
    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) {
    398398                printf("Unable to open source file %s\n", src);
    399399                return -1;
    400400        }
    401401
    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) {
    404404                printf("Unable to open destination file %s\n", dest);
    405405                vfs_put(fd1);
  • uspace/app/bdsh/cmds/modules/mkfile/mkfile.c

    rc1694b6b rf77c1c9  
    163163        file_name = argv[optind];
    164164
    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) {
    167167                printf("%s: failed to create file %s.\n", cmdname, file_name);
    168168                return CMD_FAILURE;
  • uspace/app/bdsh/cmds/modules/rm/rm.c

    rc1694b6b rf77c1c9  
    149149        }
    150150
    151         fd = vfs_lookup(path, WALK_REGULAR);
    152         if (fd >= 0) {
     151        if (vfs_lookup(path, WALK_REGULAR, &fd) == EOK) {
    153152                vfs_put(fd);
    154153                return RM_FILE;
  • uspace/app/bdsh/cmds/modules/touch/touch.c

    rc1694b6b rf77c1c9  
    123123                if ((!no_create) ||
    124124                    ((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                        }
    126129                }
    127130               
  • uspace/app/bdsh/exec.c

    rc1694b6b rf77c1c9  
    5858        int fd;
    5959
    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) {
    6262                vfs_put(fd);
    6363                return 0;
  • uspace/app/getterm/getterm.c

    rc1694b6b rf77c1c9  
    6565        *stream = NULL;
    6666       
    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)
    6970                return;
    7071       
    7172        if (oldfd != fd) {
    72                 if (vfs_clone(oldfd, fd, false) != fd)
     73                int newfd;
     74                if (vfs_clone(oldfd, fd, false, &newfd) != EOK)
    7375                        return;
    7476               
     77                assert(newfd == fd);
     78
    7579                if (vfs_put(oldfd))
    7680                        return;
  • uspace/app/redir/redir.c

    rc1694b6b rf77c1c9  
    5959        *stream = NULL;
    6060       
    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)
    6364                return;
    6465       
    6566        if (oldfd != fd) {
    66                 if (vfs_clone(oldfd, fd, false) != fd)
     67                int newfd;
     68                if (vfs_clone(oldfd, fd, false, &newfd) != EOK)
    6769                        return;
    6870               
     71                assert(newfd == fd);
     72
    6973                if (vfs_put(oldfd))
    7074                        return;
  • uspace/app/sysinst/futil.c

    rc1694b6b rf77c1c9  
    6363        printf("Copy '%s' to '%s'.\n", srcp, destp);
    6464
    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)
    7171                return EIO;
    7272
     
    8787
    8888        rc = vfs_put(df);
    89         if (rc < 0)
     89        if (rc != EOK)
    9090                return EIO;
    9191
     
    167167        struct stat st;
    168168
    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)
    171171                return ENOENT;
    172172
  • uspace/app/taskdump/elf_core.c

    rc1694b6b rf77c1c9  
    123123        }
    124124
    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));
    129129                free(p_hdr);
    130130                return ENOENT;
  • uspace/app/taskdump/symtab.c

    rc1694b6b rf77c1c9  
    8282                return ENOMEM;
    8383
    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));
    8787                free(stab);
    8888                return ENOENT;
  • uspace/app/tester/mm/pager1.c

    rc1694b6b rf77c1c9  
    4949        TPRINTF("Creating temporary file...\n");
    5050
    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)
    5454                return NULL;
    5555        (void) vfs_unlink_path(TEST_FILE);
  • uspace/app/tester/vfs/vfs1.c

    rc1694b6b rf77c1c9  
    7373        rc = vfs_link_path(TEST_DIRECTORY, KIND_DIRECTORY, NULL);
    7474        if (rc != EOK) {
    75                 TPRINTF("rc=%d\n", rc);
     75                TPRINTF("rc=%s\n", str_error_name(rc));
    7676                return "vfs_link_path() failed";
    7777        }
    7878        TPRINTF("Created directory %s\n", TEST_DIRECTORY);
    7979       
    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)
    8384                return "vfs_lookup_open() failed";
    8485        TPRINTF("Created file %s (fd=%d)\n", TEST_FILE, fd0);
  • uspace/app/viewer/viewer.c

    rc1694b6b rf77c1c9  
    109109static bool img_load(const char *fname, surface_t **p_local_surface)
    110110{
    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)
    113114                return false;
    114115       
    115116        struct stat stat;
    116         int rc = vfs_stat(fd, &stat);
     117        rc = vfs_stat(fd, &stat);
    117118        if (rc != EOK) {
    118119                vfs_put(fd);
  • uspace/app/websrv/websrv.c

    rc1694b6b rf77c1c9  
    265265        }
    266266       
    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) {
    269269                rc = send_response(conn, msg_not_found);
    270270                goto out;
  • uspace/drv/bus/isa/isa.c

    rc1694b6b rf77c1c9  
    281281        struct stat st;
    282282
    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) {
    285285                ddf_msg(LVL_ERROR, "Unable to open %s", conf_path);
    286286                goto cleanup;
  • uspace/lib/bithenge/src/file.c

    rc1694b6b rf77c1c9  
    145145        assert(filename);
    146146
    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;
    150151
    151152        return new_file_blob(out, fd, true);
  • uspace/lib/c/generic/dirent.c

    rc1694b6b rf77c1c9  
    5454        }
    5555       
    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) {
    5859                free(dirp);
    59                 errno = fd;
     60                errno = rc;
    6061                return NULL;
    6162        }
    6263       
    63         int rc = vfs_open(fd, MODE_READ);
    64         if (rc < 0) {
     64        rc = vfs_open(fd, MODE_READ);
     65        if (rc != EOK) {
    6566                free(dirp);
    6667                vfs_put(fd);
  • uspace/lib/c/generic/elf/elf_mod.c

    rc1694b6b rf77c1c9  
    9797        elf_ld_t elf;
    9898
    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        }
    101104        if (rc != EOK) {
    102105                return rc;
     
    116119    elf_finfo_t *info)
    117120{
    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        }
    121127        return rc;
    122128}
  • uspace/lib/c/generic/io/io.c

    rc1694b6b rf77c1c9  
    108108         * This will probably be removed later.
    109109         */
    110          
    111110        int infd = inbox_get("stdin");
    112111        if (infd >= 0) {
    113                 int stdinfd = vfs_clone(infd, -1, false);
     112                int stdinfd = -1;
     113                (void) vfs_clone(infd, -1, false, &stdinfd);
    114114                assert(stdinfd == 0);
    115115                vfs_open(stdinfd, MODE_READ);
     
    122122        int outfd = inbox_get("stdout");
    123123        if (outfd >= 0) {
    124                 int stdoutfd = vfs_clone(outfd, -1, false);
     124                int stdoutfd = -1;
     125                (void) vfs_clone(outfd, -1, false, &stdoutfd);
    125126                assert(stdoutfd <= 1);
    126127                while (stdoutfd < 1)
    127                         stdoutfd = vfs_clone(outfd, -1, false);
     128                        (void) vfs_clone(outfd, -1, false, &stdoutfd);
    128129                vfs_open(stdoutfd, MODE_APPEND);
    129130                stdout = fdopen(stdoutfd, "a");
     
    135136        int errfd = inbox_get("stderr");
    136137        if (errfd >= 0) {
    137                 int stderrfd = vfs_clone(errfd, -1, false);
     138                int stderrfd = -1;
     139                (void) vfs_clone(errfd, -1, false, &stderrfd);
    138140                assert(stderrfd <= 2);
    139141                while (stderrfd < 2)
    140                         stderrfd = vfs_clone(errfd, -1, false);
     142                        (void) vfs_clone(errfd, -1, false, &stderrfd);
    141143                vfs_open(stderrfd, MODE_APPEND);
    142144                stderr = fdopen(stderrfd, "a");
     
    294296        if (create)
    295297                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;
    299302                free(stream);
    300303                return NULL;
    301304        }
    302305
    303         int rc = vfs_open(file, mode);
     306        rc = vfs_open(file, mode);
    304307        if (rc != EOK) {
    305308                errno = rc;
     
    373376        list_remove(&stream->link);
    374377       
    375         if (rc != 0) {
    376                 /* errno was set by close() */
     378        if (rc != EOK) {
     379                errno = rc;
    377380                return EOF;
    378381        }
  • uspace/lib/c/generic/loader.c

    rc1694b6b rf77c1c9  
    5252 * @param name Symbolic name to set on the newly created task.
    5353 *
    54  * @return Pointer to the loader connection structure (should be
    55  *         deallocated using free() after use).
    56  *
     54 * @return Error code.
    5755 */
    5856int loader_spawn(const char *name)
     
    198196        }
    199197       
    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);
    206205        vfs_put(fd);
    207206        return rc;
  • uspace/lib/c/generic/vfs/vfs.c

    rc1694b6b rf77c1c9  
    128128static int root_fd = -1;
    129129
    130 static int get_parent_and_child(const char *path, char **child)
     130static int get_parent_and_child(const char *path, int *parent, char **child)
    131131{
    132132        size_t size;
     
    136136
    137137        char *slash = str_rchr(apath, L'/');
    138         int parent;
    139138        if (slash == apath) {
    140                 parent = vfs_root();
     139                *parent = vfs_root();
     140                if (*parent < 0) {
     141                        free(apath);
     142                        return EBADF;
     143                }
    141144                *child = apath;
     145                return EOK;
    142146        } else {
    143147                *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) {
    146150                        free(apath);
    147                         return parent;
     151                        return rc;
    148152                }
    149153                *slash = '/';
     
    151155                free(apath);
    152156                if (!*child) {
    153                         vfs_put(parent);
     157                        vfs_put(*parent);
    154158                        return ENOMEM;
    155159                }
    156         }
    157 
    158         return parent;
     160
     161                return rc;
     162        }
     163
    159164}
    160165
     
    233238 * @return              New file handle on success or a negative error code
    234239 */
    235 int vfs_clone(int file_from, int file_to, bool high)
    236 {
     240int vfs_clone(int file_from, int file_to, bool high, int *handle)
     241{
     242        assert(handle != NULL);
     243
    237244        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);
    240248        vfs_exchange_end(vfs_exch);
     249
     250        if (rc == EOK) {
     251                *handle = ret;
     252        }
    241253        return rc;
    242254}
     
    277289                return ENOMEM;
    278290       
    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) {
    281294                free(abs);
    282                 return fd;
     295                return rc;
    283296        }
    284297       
     
    491504{
    492505        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;
    497510
    498511        if (linkedfd)
     
    521534{
    522535        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);
    528542
    529543        free(child);
    530544        vfs_put(parent);
    531545        return rc;
    532 }       
     546}
    533547
    534548/** Lookup a path relative to the local root
     
    536550 * @param path  Path to be looked up
    537551 * @param flags Walk flags
    538  *
    539  * @return      File handle representing the result on success or a negative
    540  *              error code on error
    541  */
    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 */
     556int vfs_lookup(const char *path, int flags, int *handle)
    543557{
    544558        size_t size;
     
    546560        if (!p)
    547561                return ENOMEM;
     562
    548563        int root = vfs_root();
    549564        if (root < 0) {
     
    551566                return ENOENT;
    552567        }
    553         int rc = vfs_walk(root, p, flags);
     568
     569        int rc = vfs_walk(root, p, flags, handle);
    554570        vfs_put(root);
    555571        free(p);
     
    564580 * @param flags Walk flags
    565581 * @param mode  Mode in which to open file in
     582 * @param[out] handle Pointer to variable where handle is to be written.
    566583 *
    567584 * @return      EOK on success or a negative error code
    568585 */
    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);
     586int 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);
    576594        if (rc != EOK) {
    577595                vfs_put(file);
    578596                return rc;
    579597        }
    580        
    581         return file;
     598
     599        *handle = file;
     600        return EOK;
    582601}
    583602
     
    707726                }
    708727               
    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) {
    711731                        rc = vfs_mount(mpfd, fs_name, service_id, opts, flags,
    712732                            instance, NULL);
    713733                        vfs_put(mpfd);
    714                 } else {
    715                         rc = mpfd;
    716734                }
    717735        }
     
    775793 * @param high   If true, the received file handle will be allocated from high
    776794 *               indices
     795 * @param[out] handle  Received handle.
    777796 *
    778797 * @return       EOK on success or a negative error code
    779798 */
    780 int vfs_receive_handle(bool high)
     799int vfs_receive_handle(bool high, int *handle)
    781800{
    782801        ipc_callid_t callid;
     
    795814        async_exchange_end(vfs_exch);
    796815
    797         if (rc != EOK)
    798                 return rc;
    799         return ret;
     816        if (rc == EOK) {
     817                *handle = (int) ret;
     818        }
     819
     820        return rc;
    800821}
    801822
     
    976997/** Return a new file handle representing the local root
    977998 *
    978  * @return      A clone of the local root file handle or a negative error code
     999 * @return      A clone of the local root file handle or -1
    9791000 */
    9801001int vfs_root(void)
    9811002{
    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        }
    9881013        fibril_mutex_unlock(&root_mutex);
    989         return r;
     1014        return fd;
    9901015}
    9911016
     
    9971022 *
    9981023 * @param nroot The new local root file handle
    999  */
    1000 void vfs_root_set(int nroot)
    1001 {
     1024 *
     1025 * @return  Error code
     1026 */
     1027int 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
    10021035        fibril_mutex_lock(&root_mutex);
    10031036        if (root_fd >= 0)
    10041037                vfs_put(root_fd);
    1005         root_fd = vfs_clone(nroot, -1, true);
     1038        root_fd = new_root;
    10061039        fibril_mutex_unlock(&root_mutex);
     1040
     1041        return EOK;
    10071042}
    10081043
     
    10501085int vfs_stat_path(const char *path, struct stat *stat)
    10511086{
    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);
    10571093
    10581094        vfs_put(file);
     
    10951131int vfs_statfs_path(const char *path, struct statfs *st)
    10961132{
    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);
    11021139
    11031140        vfs_put(file);
     
    11651202int vfs_unlink_path(const char *path)
    11661203{
    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;
    11701208
    11711209        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) {
    11741213                vfs_put(expect);
    1175                 return parent;
    1176         }
    1177 
    1178         int rc = vfs_unlink(parent, child, expect);
     1214                return rc;
     1215        }
     1216
     1217        rc = vfs_unlink(parent, child, expect);
    11791218       
    11801219        free(child);
     
    12061245int vfs_unmount_path(const char *mpp)
    12071246{
    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);
    12131253        vfs_put(mp);
    12141254        return rc;
     
    12201260 * @param path          Parent-relative path to be walked
    12211261 * @param flags         Flags influencing the walk
    1222  *
    1223  * @retrun              File handle representing the result on success or
    1224  *                      a negative error code on error
    1225  */
    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 */
     1266int vfs_walk(int parent, const char *path, int flags, int *handle)
    12271267{
    12281268        async_exch_t *exch = vfs_exchange_begin();
     
    12421282                return (int) rc;
    12431283       
    1244         return (int) IPC_GET_ARG1(answer);
     1284        *handle = (int) IPC_GET_ARG1(answer);
     1285        return EOK;
    12451286}
    12461287
  • uspace/lib/c/include/vfs/vfs.h

    rc1694b6b rf77c1c9  
    8585
    8686extern char *vfs_absolutize(const char *, size_t *);
    87 extern int vfs_clone(int, int, bool);
     87extern int vfs_clone(int, int, bool, int *);
    8888extern int vfs_cwd_get(char *path, size_t);
    8989extern int vfs_cwd_set(const char *path);
     
    9595extern int vfs_link(int, const char *, vfs_file_kind_t, int *);
    9696extern 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);
     97extern int vfs_lookup(const char *, int, int *);
     98extern int vfs_lookup_open(const char *, int, int, int *);
    9999extern int vfs_mount_path(const char *, const char *, const char *,
    100100    const char *, unsigned int, unsigned int);
     
    106106extern int vfs_read(int, aoff64_t *, void *, size_t, size_t *);
    107107extern int vfs_read_short(int, aoff64_t, void *, size_t, ssize_t *);
    108 extern int vfs_receive_handle(bool);
     108extern int vfs_receive_handle(bool, int *);
    109109extern int vfs_rename_path(const char *, const char *);
    110110extern int vfs_resize(int, aoff64_t);
    111111extern int vfs_root(void);
    112 extern void vfs_root_set(int);
     112extern int vfs_root_set(int);
    113113extern int vfs_stat(int, struct stat *);
    114114extern int vfs_stat_path(const char *, struct stat *);
     
    120120extern int vfs_unmount(int);
    121121extern int vfs_unmount_path(const char *);
    122 extern int vfs_walk(int, const char *, int);
     122extern int vfs_walk(int, const char *, int, int *);
    123123extern int vfs_write(int, aoff64_t *, const void *, size_t, size_t *);
    124124extern int vfs_write_short(int, aoff64_t, const void *, size_t, ssize_t *);
  • uspace/lib/pcut/src/os/helenos.c

    rc1694b6b rf77c1c9  
    159159        char tempfile_name[PCUT_TEMP_FILENAME_BUFFER_SIZE];
    160160        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) {
    163164                pcut_report_test_done(test, PCUT_OUTCOME_INTERNAL_ERROR, "Failed to create temporary file.", NULL, NULL);
    164165                return PCUT_OUTCOME_INTERNAL_ERROR;
     
    177178
    178179        task_wait_t test_task_wait;
    179         int rc = task_spawnvf(&test_task_id, &test_task_wait, self_path, arguments,
     180        rc = task_spawnvf(&test_task_id, &test_task_wait, self_path, arguments,
    180181            fileno(stdin), tempfile, tempfile);
    181182        if (rc != EOK) {
  • uspace/lib/posix/source/fcntl.c

    rc1694b6b rf77c1c9  
    135135            ((posix_flags & O_APPEND) ? MODE_APPEND : 0);
    136136
    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)
    139140                return -1;
    140141
  • uspace/lib/posix/source/unistd.c

    rc1694b6b rf77c1c9  
    355355int posix_dup2(int fildes, int fildes2)
    356356{
    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;
    358364}
    359365
  • uspace/srv/devman/match.c

    rc1694b6b rf77c1c9  
    202202        struct stat st;
    203203       
    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) {
    206206                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));
    208208                goto cleanup;
    209209        }
    210210        opened = true;
    211211       
    212         if (vfs_stat(fd, &st) != EOK) {
     212        rc = vfs_stat(fd, &st);
     213        if (rc != EOK) {
    213214                log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to fstat %d: %s.", fd,
    214                     str_error(errno));
     215                    str_error(rc));
    215216                goto cleanup;
    216217        }
     
    230231       
    231232        size_t read_bytes;
    232         int rc = vfs_read(fd, (aoff64_t []) {0}, buf, len, &read_bytes);
     233        rc = vfs_read(fd, (aoff64_t []) {0}, buf, len, &read_bytes);
    233234        if (rc != EOK) {
    234235                log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to read file '%s': %s.", conf_path,
    235                     str_error(errno));
     236                    str_error(rc));
    236237                goto cleanup;
    237238        }
  • uspace/srv/loader/main.c

    rc1694b6b rf77c1c9  
    152152        }
    153153
    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) {
    156157                async_answer_0(rid, EINVAL);
    157158                return;
     
    254255        }
    255256
    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) {
    258260                async_answer_0(rid, EINVAL);
    259261                return;
  • uspace/srv/logger/ctl.c

    rc1694b6b rf77c1c9  
    8787                }
    8888                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);
    9296                        break;
    9397                }
  • uspace/srv/vfs/vfs.h

    rc1694b6b rf77c1c9  
    206206extern int vfs_open_node_remote(vfs_node_t *);
    207207
    208 extern int vfs_op_clone(int oldfd, int newfd, bool desc);
     208extern int vfs_op_clone(int oldfd, int newfd, bool desc, int *);
    209209extern int vfs_op_fsprobe(const char *, service_id_t, vfs_fs_probe_info_t *);
    210210extern 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  
    4141        bool desc = IPC_GET_ARG3(*request);
    4242       
    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);
    4546}
    4647
  • uspace/srv/vfs/vfs_ops.c

    rc1694b6b rf77c1c9  
    8686}
    8787
    88 int vfs_op_clone(int oldfd, int newfd, bool desc)
     88int vfs_op_clone(int oldfd, int newfd, bool desc, int *out_fd)
    8989{
    9090        int rc;
     
    118118        vfs_file_put(oldfile);
    119119       
    120         return rc;
     120        if (rc < 0) {
     121                return rc;
     122        }
     123       
     124        *out_fd = rc;
     125        return EOK;
    121126}
    122127
Note: See TracChangeset for help on using the changeset viewer.