Changeset 354b642 in mainline for uspace/srv/vfs/vfs_ops.c


Ignore:
Timestamp:
2017-03-07T10:53:31Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a274a5f
Parents:
c577a9a
git-author:
Jiri Zarevucky <zarevucky.jiri@…> (2017-03-07 10:53:31)
git-committer:
Jakub Jermar <jakub@…> (2017-03-07 10:53:31)
Message:

Merge from lp:~zarevucky-jiri/helenos/vfs-2.5/ revisions 1932-1936

Original commit messages:

1936: Jiri Zarevucky 2013-08-05 Modifications to vfs_rdwr.
1935: Jiri Zarevucky 2013-08-05 Fix a bug in read/write.
1934: Jiri Zarevucky 2013-08-05 Fix a hidden bug in handle passing.
1933: Jiri Zarevucky 2013-08-05 Add VFS_IN_CLONE.
1932: Jiri Zarevucky 2013-08-05 Add functions for passing handles around.

Modifications:

  • New vcl_* interfaces renamed to vfs_*
  • Server-side vfs_pass_handle() and vfs_clone() renamed to vfs_op_* to avoid name conflict with libc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/vfs/vfs_ops.c

    rc577a9a r354b642  
    696696        vfs_file_t *file = vfs_file_get(fd);
    697697        if (!file)
    698                 return ENOENT;
     698                return EBADF;
    699699       
    700700        if ((read && !file->open_read) || (!read && !file->open_write)) {
     
    705705        vfs_info_t *fs_info = fs_handle_to_info(file->node->fs_handle);
    706706        assert(fs_info);
     707       
     708        bool rlock = read || ((fs_info->concurrent_read_write) && (fs_info->write_retains_size));
    707709       
    708710        /*
     
    711713         * write implementation does not modify the file size.
    712714         */
    713         if ((read) ||
    714             ((fs_info->concurrent_read_write) && (fs_info->write_retains_size)))
     715        if (rlock) {
    715716                fibril_rwlock_read_lock(&file->node->contents_rwlock);
    716         else
     717        } else {
    717718                fibril_rwlock_write_lock(&file->node->contents_rwlock);
     719        }
    718720       
    719721        if (file->node->type == VFS_NODE_DIRECTORY) {
     
    722724                 * while we are in readdir().
    723725                 */
    724                 assert(read);
     726               
     727                if (!read) {
     728                        if (rlock) {
     729                                fibril_rwlock_read_unlock(&file->node->contents_rwlock);
     730                        } else {
     731                                fibril_rwlock_write_unlock(&file->node->contents_rwlock);
     732                        }
     733                        vfs_file_put(file);
     734                        return EINVAL;
     735                }
     736               
    725737                fibril_rwlock_read_lock(&namespace_rwlock);
    726738        }
     
    746758       
    747759        /* Unlock the VFS node. */
    748         if ((read) ||
    749             ((fs_info->concurrent_read_write) && (fs_info->write_retains_size)))
     760        if (rlock) {
    750761                fibril_rwlock_read_unlock(&file->node->contents_rwlock);
    751         else {
     762        } else {
    752763                /* Update the cached version of node's size. */
    753                 if (rc == EOK)
     764                if (rc == EOK) {
    754765                        file->node->size = MERGE_LOUP32(IPC_GET_ARG2(answer),
    755766                            IPC_GET_ARG3(answer));
     767                }
    756768                fibril_rwlock_write_unlock(&file->node->contents_rwlock);
    757769        }
    758770       
    759771        /* Update the position pointer and unlock the open file. */
    760         if (rc == EOK)
     772        if (rc == EOK) {
    761773                file->pos += bytes;
     774        }
    762775        vfs_file_put(file);     
    763776
     
    13541367}
    13551368
     1369void vfs_op_clone(ipc_callid_t rid, ipc_call_t *request)
     1370{
     1371        int oldfd = IPC_GET_ARG1(*request);
     1372        bool desc = IPC_GET_ARG2(*request);
     1373       
     1374        /* Lookup the file structure corresponding to fd. */
     1375        vfs_file_t *oldfile = vfs_file_get(oldfd);
     1376        if (!oldfile) {
     1377                async_answer_0(rid, EBADF);
     1378                return;
     1379        }
     1380       
     1381        vfs_file_t *newfile;
     1382        int newfd = vfs_fd_alloc(&newfile, desc);
     1383        if (newfd < 0) {
     1384                async_answer_0(rid, newfd);
     1385                vfs_file_put(oldfile);
     1386                return;
     1387        }
     1388       
     1389        assert(oldfile->node != NULL);
     1390       
     1391        newfile->node = oldfile->node;
     1392        newfile->permissions = oldfile->permissions;
     1393
     1394        vfs_file_put(oldfile);
     1395        vfs_file_put(newfile);
     1396       
     1397        async_answer_0(rid, newfd);
     1398}
     1399
    13561400/**
    13571401 * @}
Note: See TracChangeset for help on using the changeset viewer.