Changeset 6ad454f 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:
a8c7a6d
Parents:
9246016
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2017-12-08 06:01:16)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2017-12-08 21:03:35)
Message:

Pass file handles separately from error codes.

Location:
uspace/srv/vfs
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/vfs/vfs.h

    r9246016 r6ad454f  
    194194
    195195extern void vfs_op_pass_handle(task_id_t, task_id_t, int);
    196 extern int vfs_wait_handle_internal(bool);
     196extern int vfs_wait_handle_internal(bool, int *);
    197197
    198198extern vfs_file_t *vfs_file_get(int);
    199199extern void vfs_file_put(vfs_file_t *);
    200200extern int vfs_fd_assign(vfs_file_t *, int);
    201 extern int vfs_fd_alloc(vfs_file_t **file, bool desc);
     201extern int vfs_fd_alloc(vfs_file_t **file, bool desc, int *);
    202202extern int vfs_fd_free(int);
    203203
     
    220220extern int vfs_op_unlink(int parentfd, int expectfd, char *path);
    221221extern int vfs_op_unmount(int mpfd);
    222 extern int vfs_op_wait_handle(bool high_fd);
     222extern int vfs_op_wait_handle(bool high_fd, int *out_fd);
    223223extern int vfs_op_walk(int parentfd, int flags, char *path, int *out_fd);
    224224extern int vfs_op_write(int fd, aoff64_t, size_t *out_bytes);
  • uspace/srv/vfs/vfs_file.c

    r9246016 r6ad454f  
    192192}
    193193
    194 static int _vfs_fd_alloc(vfs_client_data_t *vfs_data, vfs_file_t **file, bool desc)
     194static int _vfs_fd_alloc(vfs_client_data_t *vfs_data, vfs_file_t **file, bool desc, int *out_fd)
    195195{
    196196        if (!vfs_files_init(vfs_data))
     
    223223                       
    224224                        fibril_mutex_unlock(&vfs_data->lock);
    225                         return (int) i;
     225                        *out_fd = (int) i;
     226                        return EOK;
    226227                }
    227228               
     
    249250 *             in a descending order.
    250251 *
    251  * @return First available file descriptor or a negative error
    252  *         code.
    253  */
    254 int vfs_fd_alloc(vfs_file_t **file, bool desc)
    255 {
    256         return _vfs_fd_alloc(VFS_DATA, file, desc);
     252 * @param[out] out_fd  First available file descriptor
     253 *
     254 * @return Error code.
     255 */
     256int vfs_fd_alloc(vfs_file_t **file, bool desc, int *out_fd)
     257{
     258        return _vfs_fd_alloc(VFS_DATA, file, desc, out_fd);
    257259}
    258260
     
    427429}
    428430
    429 int vfs_wait_handle_internal(bool high_fd)
     431int vfs_wait_handle_internal(bool high_fd, int *out_fd)
    430432{
    431433        vfs_client_data_t *vfs_data = VFS_DATA;
     
    441443
    442444        vfs_file_t *file;
    443         int fd = _vfs_fd_alloc(vfs_data, &file, high_fd);
    444         if (fd < 0) {
     445        int rc = _vfs_fd_alloc(vfs_data, &file, high_fd, out_fd);
     446        if (rc != EOK) {
    445447                vfs_node_delref(bh->node);
    446448                free(bh);
    447                 return fd;
     449                return rc;
    448450        }
    449451       
     
    452454        vfs_file_put(file);
    453455        free(bh);
    454         return fd;
     456        return EOK;
    455457}
    456458
  • uspace/srv/vfs/vfs_ipc.c

    r9246016 r6ad454f  
    280280{
    281281        bool high_fd = IPC_GET_ARG1(*request);
    282         int fd = vfs_op_wait_handle(high_fd);
    283         async_answer_1(rid, EOK, fd);
     282        int fd = -1;
     283        int rc = vfs_op_wait_handle(high_fd, &fd);
     284        async_answer_1(rid, rc, fd);
    284285}
    285286
  • uspace/srv/vfs/vfs_ops.c

    r9246016 r6ad454f  
    104104                /* Assign the old file to newfd. */
    105105                rc = vfs_fd_assign(oldfile, newfd);
     106                *out_fd = newfd;
    106107        } else {
    107108                vfs_file_t *newfile;
    108                 int newfd = vfs_fd_alloc(&newfile, desc);
    109                 if (newfd >= 0) {
     109                rc = vfs_fd_alloc(&newfile, desc, out_fd);
     110                if (rc == EOK) {
    110111                        newfile->node = oldfile->node;
    111112                        newfile->permissions = oldfile->permissions;
     
    114115                        vfs_file_put(newfile);
    115116                }
    116                 rc = newfd;
    117117        }
    118118        vfs_file_put(oldfile);
    119119       
    120         if (rc < 0) {
    121                 return rc;
    122         }
    123        
    124         *out_fd = rc;
    125         return EOK;
     120        return rc;
    126121}
    127122
     
    228223
    229224int vfs_op_mount(int mpfd, unsigned service_id, unsigned flags,
    230     unsigned instance, const char *opts, const char *fs_name, int *outfd)
     225    unsigned instance, const char *opts, const char *fs_name, int *out_fd)
    231226{
    232227        int rc;
    233228        vfs_file_t *mp = NULL;
    234229        vfs_file_t *file = NULL;
    235         int fd = -1;
     230        *out_fd = -1;
    236231       
    237232        if (!(flags & VFS_MOUNT_CONNECT_ONLY)) {
     
    259254       
    260255        if (!(flags & VFS_MOUNT_NO_REF)) {
    261                 fd = vfs_fd_alloc(&file, false);
    262                 if (fd < 0) {
    263                         rc = fd;
     256                rc = vfs_fd_alloc(&file, false, out_fd);
     257                if (rc != EOK) {
    264258                        goto out;
    265259                }
     
    300294                vfs_file_put(file);
    301295
    302         if (rc != EOK && fd >= 0) {
    303                 vfs_fd_free(fd);
    304                 fd = 0;
    305         }
    306        
    307         *outfd = fd;
     296        if (rc != EOK && *out_fd >= 0) {
     297                vfs_fd_free(*out_fd);
     298                *out_fd = -1;
     299        }
     300       
    308301        return rc;
    309302}
     
    833826}
    834827
    835 int vfs_op_wait_handle(bool high_fd)
    836 {
    837         return vfs_wait_handle_internal(high_fd);
     828int vfs_op_wait_handle(bool high_fd, int *out_fd)
     829{
     830        return vfs_wait_handle_internal(high_fd, out_fd);
    838831}
    839832
     
    897890       
    898891        vfs_file_t *file;
    899         int fd = vfs_fd_alloc(&file, false);
    900         if (fd < 0) {
     892        rc = vfs_fd_alloc(&file, false, out_fd);
     893        if (rc != EOK) {
    901894                vfs_node_put(node);
    902895                vfs_file_put(parent);
    903                 return fd;
     896                return rc;
    904897        }
    905898        assert(file != NULL);
     
    915908        fibril_rwlock_read_unlock(&namespace_rwlock);
    916909
    917         *out_fd = fd;
    918910        return EOK;
    919911}
Note: See TracChangeset for help on using the changeset viewer.