Changeset a737667e in mainline


Ignore:
Timestamp:
2017-03-08T09:56:06Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5126f80
Parents:
bb9ec2d
Message:

Implement statfs() using _vfs_walk()

Location:
uspace
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/vfs/vfs.c

    rbb9ec2d ra737667e  
    11241124int statfs(const char *path, struct statfs *st)
    11251125{
    1126         sysarg_t rc, rc_orig;
     1126        size_t pa_size;
     1127        char *pa = vfs_absolutize(path, &pa_size);
     1128        if (!pa) {
     1129                errno = ENOMEM;
     1130                return -1;
     1131        }
     1132       
     1133        int fd = _vfs_walk(-1, pa, 0);
     1134        if (fd < 0) {
     1135                free(pa);
     1136                errno = fd;
     1137                return -1;
     1138        }
     1139
     1140        free(pa);
     1141       
     1142        sysarg_t rc, ret;
    11271143        aid_t req;
    1128         size_t pa_size;
    1129 
    1130         char *pa = vfs_absolutize(path, &pa_size);
    1131         if (pa == NULL) {
    1132                 errno = ENOMEM;
    1133                 return -1;
    1134         }
    1135 
    1136         async_exch_t *exch = vfs_exchange_begin();
    1137 
    1138         req = async_send_0(exch, VFS_IN_STATFS, NULL);
    1139         rc = async_data_write_start(exch, pa, pa_size);
    1140         if (rc != EOK)
    1141                 goto exit;
    1142 
     1144
     1145        async_exch_t *exch = vfs_exchange_begin();
     1146
     1147        req = async_send_1(exch, VFS_IN_STATFS, fd, NULL);
    11431148        rc = async_data_read_start(exch, (void *) st, sizeof(*st));
    11441149
    1145 exit:
    1146         vfs_exchange_end(exch);
    1147         free(pa);
    1148         async_wait_for(req, &rc_orig);
    1149         rc = (rc_orig != EOK ? rc_orig : rc);
    1150 
     1150        vfs_exchange_end(exch);
     1151        async_wait_for(req, &ret);
     1152        close(fd);
     1153
     1154        rc = (ret != EOK ? ret : rc);
    11511155        if (rc != EOK) {
    11521156                errno = rc;
  • uspace/srv/vfs/vfs_ops.c

    rbb9ec2d ra737667e  
    13171317void vfs_statfs(ipc_callid_t rid, ipc_call_t *request)
    13181318{
    1319         char *path;
    1320         int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL);
    1321         if (rc != EOK) {
    1322                 async_answer_0(rid, rc);
    1323                 return;
    1324         }
     1319        int fd = IPC_GET_ARG1(*request);
    13251320       
    13261321        ipc_callid_t callid;
    13271322        if (!async_data_read_receive(&callid, NULL)) {
    1328                 free(path);
    13291323                async_answer_0(callid, EINVAL);
    13301324                async_answer_0(rid, EINVAL);
     
    13321326        }
    13331327
    1334         vfs_lookup_res_t lr;
    1335         fibril_rwlock_read_lock(&namespace_rwlock);
    1336         rc = vfs_lookup_internal(root, path, L_NONE, &lr);
    1337         free(path);
    1338         if (rc != EOK) {
    1339                 fibril_rwlock_read_unlock(&namespace_rwlock);
    1340                 async_answer_0(callid, rc);
    1341                 async_answer_0(rid, rc);
    1342                 return;
    1343         }
    1344         vfs_node_t *node = vfs_node_get(&lr);
    1345         if (!node) {
    1346                 fibril_rwlock_read_unlock(&namespace_rwlock);
    1347                 async_answer_0(callid, ENOMEM);
    1348                 async_answer_0(rid, ENOMEM);
    1349                 return;
    1350         }
    1351 
    1352         fibril_rwlock_read_unlock(&namespace_rwlock);
     1328        vfs_file_t *file = vfs_file_get(fd);
     1329        if (!file) {
     1330                async_answer_0(callid, EBADF);
     1331                async_answer_0(rid, EBADF);
     1332        }
     1333
     1334        vfs_node_t *node = file->node;
    13531335
    13541336        async_exch_t *exch = vfs_exchange_grab(node->fs_handle);
     
    13641346        async_wait_for(msg, &rv);
    13651347
     1348        vfs_file_put(file);
     1349
    13661350        async_answer_0(rid, rv);
    1367 
    1368         vfs_node_put(node);
    13691351}
    13701352
Note: See TracChangeset for help on using the changeset viewer.