Changeset 5f70118 in mainline for uspace/srv/vfs/vfs_ops.c


Ignore:
Timestamp:
2010-01-10T12:16:59Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c77a64f
Parents:
309ede1 (diff), 1ac3a52 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

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

    r309ede1 r5f70118  
    4444#include <string.h>
    4545#include <bool.h>
    46 #include <fibril_sync.h>
     46#include <fibril_synch.h>
    4747#include <adt/list.h>
    4848#include <unistd.h>
     
    125125                            (ipcarg_t) dev_handle, &answer);
    126126                        /* send the mount options */
    127                         rc = ipc_data_write_start(phone, (void *)opts,
     127                        rc = async_data_write_start(phone, (void *)opts,
    128128                            str_size(opts));
    129129                        if (rc != EOK) {
     
    207207       
    208208        /* send the mount options */
    209         rc = ipc_data_write_start(phone, (void *)opts, str_size(opts));
     209        rc = async_data_write_start(phone, (void *)opts, str_size(opts));
    210210        if (rc != EOK) {
    211211                async_wait_for(msg, NULL);
     
    268268        ipc_callid_t callid;
    269269        size_t size;
    270         if (!ipc_data_write_receive(&callid, &size)) {
     270        if (!async_data_write_receive(&callid, &size)) {
    271271                ipc_answer_0(callid, EINVAL);
    272272                ipc_answer_0(rid, EINVAL);
     
    290290       
    291291        /* Deliver the mount point. */
    292         ipcarg_t retval = ipc_data_write_finalize(callid, mp, size);
     292        ipcarg_t retval = async_data_write_finalize(callid, mp, size);
    293293        if (retval != EOK) {
    294294                ipc_answer_0(rid, retval);
     
    299299       
    300300        /* Now we expect to receive the mount options. */
    301         if (!ipc_data_write_receive(&callid, &size)) {
     301        if (!async_data_write_receive(&callid, &size)) {
    302302                ipc_answer_0(callid, EINVAL);
    303303                ipc_answer_0(rid, EINVAL);
     
    324324
    325325        /* Deliver the mount options. */
    326         retval = ipc_data_write_finalize(callid, opts, size);
     326        retval = async_data_write_finalize(callid, opts, size);
    327327        if (retval != EOK) {
    328328                ipc_answer_0(rid, retval);
     
    337337         * system.
    338338         */
    339         if (!ipc_data_write_receive(&callid, &size)) {
     339        if (!async_data_write_receive(&callid, &size)) {
    340340                ipc_answer_0(callid, EINVAL);
    341341                ipc_answer_0(rid, EINVAL);
     
    370370       
    371371        /* Deliver the file system name. */
    372         retval = ipc_data_write_finalize(callid, fs_name, size);
     372        retval = async_data_write_finalize(callid, fs_name, size);
    373373        if (retval != EOK) {
    374374                ipc_answer_0(rid, retval);
     
    469469       
    470470        ipc_callid_t callid;
    471         if (!ipc_data_write_receive(&callid, &len)) {
     471        if (!async_data_write_receive(&callid, &len)) {
    472472                ipc_answer_0(callid, EINVAL);
    473473                ipc_answer_0(rid, EINVAL);
     
    483483       
    484484        int rc;
    485         if ((rc = ipc_data_write_finalize(callid, path, len))) {
     485        if ((rc = async_data_write_finalize(callid, path, len))) {
    486486                ipc_answer_0(rid, rc);
    487487                free(path);
     
    543543         * structure.
    544544         */
    545         int fd = vfs_fd_alloc();
     545        int fd = vfs_fd_alloc((oflag & O_DESC) != 0);
    546546        if (fd < 0) {
    547547                vfs_node_put(node);
     
    620620         * structure.
    621621         */
    622         int fd = vfs_fd_alloc();
     622        int fd = vfs_fd_alloc((oflag & O_DESC) != 0);
    623623        if (fd < 0) {
    624624                vfs_node_put(node);
     
    679679}
    680680
     681static int vfs_close_internal(vfs_file_t *file)
     682{
     683        /*
     684         * Lock the open file structure so that no other thread can manipulate
     685         * the same open file at a time.
     686         */
     687        fibril_mutex_lock(&file->lock);
     688       
     689        if (file->refcnt <= 1) {
     690                /* Only close the file on the destination FS server
     691                   if there are no more file descriptors (except the
     692                   present one) pointing to this file. */
     693               
     694                int fs_phone = vfs_grab_phone(file->node->fs_handle);
     695               
     696                /* Make a VFS_OUT_CLOSE request at the destination FS server. */
     697                aid_t msg;
     698                ipc_call_t answer;
     699                msg = async_send_2(fs_phone, VFS_OUT_CLOSE, file->node->dev_handle,
     700                    file->node->index, &answer);
     701               
     702                /* Wait for reply from the FS server. */
     703                ipcarg_t rc;
     704                async_wait_for(msg, &rc);
     705               
     706                vfs_release_phone(fs_phone);
     707                fibril_mutex_unlock(&file->lock);
     708               
     709                return IPC_GET_ARG1(answer);
     710        }
     711       
     712        fibril_mutex_unlock(&file->lock);
     713        return EOK;
     714}
     715
    681716void vfs_close(ipc_callid_t rid, ipc_call_t *request)
    682717{
     
    690725        }
    691726       
    692         /*
    693          * Lock the open file structure so that no other thread can manipulate
    694          * the same open file at a time.
    695          */
    696         fibril_mutex_lock(&file->lock);
    697         int fs_phone = vfs_grab_phone(file->node->fs_handle);
    698        
    699         /* Make a VFS_OUT_CLOSE request at the destination FS server. */
    700         aid_t msg;
    701         ipc_call_t answer;
    702         msg = async_send_2(fs_phone, VFS_OUT_CLOSE, file->node->dev_handle,
    703             file->node->index, &answer);
    704 
    705         /* Wait for reply from the FS server. */
    706         ipcarg_t rc;
    707         async_wait_for(msg, &rc);
    708 
    709         vfs_release_phone(fs_phone);
    710         fibril_mutex_unlock(&file->lock);
    711        
    712         int retval = IPC_GET_ARG1(answer);
    713         if (retval != EOK)
    714                 ipc_answer_0(rid, retval);
    715        
    716         retval = vfs_fd_free(fd);
    717         ipc_answer_0(rid, retval);
     727        int ret = vfs_close_internal(file);
     728        if (ret != EOK)
     729                ipc_answer_0(rid, ret);
     730       
     731        ret = vfs_fd_free(fd);
     732        ipc_answer_0(rid, ret);
    718733}
    719734
     
    747762        int res;
    748763        if (read)
    749                 res = ipc_data_read_receive(&callid, NULL);
     764                res = async_data_read_receive(&callid, NULL);
    750765        else
    751                 res = ipc_data_write_receive(&callid, NULL);
     766                res = async_data_write_receive(&callid, NULL);
    752767        if (!res) {
    753768                ipc_answer_0(callid, EINVAL);
     
    885900                }
    886901                newpos = size + off;
     902                file->pos = newpos;
    887903                fibril_mutex_unlock(&file->lock);
    888904                ipc_answer_1(rid, EOK, newpos);
     
    934950{
    935951        int fd = IPC_GET_ARG1(*request);
    936         size_t size = IPC_GET_ARG2(*request);
    937952        ipcarg_t rc;
    938953
     
    944959
    945960        ipc_callid_t callid;
    946         if (!ipc_data_read_receive(&callid, NULL)) {
     961        if (!async_data_read_receive(&callid, NULL)) {
    947962                ipc_answer_0(callid, EINVAL);
    948963                ipc_answer_0(rid, EINVAL);
     
    970985        ipc_callid_t callid;
    971986
    972         if (!ipc_data_write_receive(&callid, &len)) {
     987        if (!async_data_write_receive(&callid, &len)) {
    973988                ipc_answer_0(callid, EINVAL);
    974989                ipc_answer_0(rid, EINVAL);
     
    982997        }
    983998        int rc;
    984         if ((rc = ipc_data_write_finalize(callid, path, len))) {
     999        if ((rc = async_data_write_finalize(callid, path, len))) {
    9851000                ipc_answer_0(rid, rc);
    9861001                free(path);
     
    9891004        path[len] = '\0';
    9901005
    991         if (!ipc_data_read_receive(&callid, NULL)) {
     1006        if (!async_data_read_receive(&callid, NULL)) {
    9921007                free(path);
    9931008                ipc_answer_0(callid, EINVAL);
     
    10381053        ipc_callid_t callid;
    10391054
    1040         if (!ipc_data_write_receive(&callid, &len)) {
     1055        if (!async_data_write_receive(&callid, &len)) {
    10411056                ipc_answer_0(callid, EINVAL);
    10421057                ipc_answer_0(rid, EINVAL);
     
    10501065        }
    10511066        int rc;
    1052         if ((rc = ipc_data_write_finalize(callid, path, len))) {
     1067        if ((rc = async_data_write_finalize(callid, path, len))) {
    10531068                ipc_answer_0(rid, rc);
    10541069                free(path);
     
    10751090        ipc_callid_t callid;
    10761091
    1077         if (!ipc_data_write_receive(&callid, &len)) {
     1092        if (!async_data_write_receive(&callid, &len)) {
    10781093                ipc_answer_0(callid, EINVAL);
    10791094                ipc_answer_0(rid, EINVAL);
     
    10871102        }
    10881103        int rc;
    1089         if ((rc = ipc_data_write_finalize(callid, path, len))) {
     1104        if ((rc = async_data_write_finalize(callid, path, len))) {
    10901105                ipc_answer_0(rid, rc);
    10911106                free(path);
     
    11261141
    11271142        /* Retrieve the old path. */
    1128         if (!ipc_data_write_receive(&callid, &olen)) {
     1143        if (!async_data_write_receive(&callid, &olen)) {
    11291144                ipc_answer_0(callid, EINVAL);
    11301145                ipc_answer_0(rid, EINVAL);
     
    11371152                return;
    11381153        }
    1139         if ((rc = ipc_data_write_finalize(callid, old, olen))) {
     1154        if ((rc = async_data_write_finalize(callid, old, olen))) {
    11401155                ipc_answer_0(rid, rc);
    11411156                free(old);
     
    11451160       
    11461161        /* Retrieve the new path. */
    1147         if (!ipc_data_write_receive(&callid, &nlen)) {
     1162        if (!async_data_write_receive(&callid, &nlen)) {
    11481163                ipc_answer_0(callid, EINVAL);
    11491164                ipc_answer_0(rid, EINVAL);
     
    11581173                return;
    11591174        }
    1160         if ((rc = ipc_data_write_finalize(callid, new, nlen))) {
     1175        if ((rc = async_data_write_finalize(callid, new, nlen))) {
    11611176                ipc_answer_0(rid, rc);
    11621177                free(old);
     
    13111326}
    13121327
     1328void vfs_dup(ipc_callid_t rid, ipc_call_t *request)
     1329{
     1330        int oldfd = IPC_GET_ARG1(*request);
     1331        int newfd = IPC_GET_ARG2(*request);
     1332       
     1333        /* Lookup the file structure corresponding to oldfd. */
     1334        vfs_file_t *oldfile = vfs_file_get(oldfd);
     1335        if (!oldfile) {
     1336                ipc_answer_0(rid, EBADF);
     1337                return;
     1338        }
     1339       
     1340        /* If the file descriptors are the same, do nothing. */
     1341        if (oldfd == newfd) {
     1342                ipc_answer_1(rid, EOK, newfd);
     1343                return;
     1344        }
     1345       
     1346        /*
     1347         * Lock the open file structure so that no other thread can manipulate
     1348         * the same open file at a time.
     1349         */
     1350        fibril_mutex_lock(&oldfile->lock);
     1351       
     1352        /* Lookup an open file structure possibly corresponding to newfd. */
     1353        vfs_file_t *newfile = vfs_file_get(newfd);
     1354        if (newfile) {
     1355                /* Close the originally opened file. */
     1356                int ret = vfs_close_internal(newfile);
     1357                if (ret != EOK) {
     1358                        ipc_answer_0(rid, ret);
     1359                        return;
     1360                }
     1361               
     1362                ret = vfs_fd_free(newfd);
     1363                if (ret != EOK) {
     1364                        ipc_answer_0(rid, ret);
     1365                        return;
     1366                }
     1367        }
     1368       
     1369        /* Assign the old file to newfd. */
     1370        int ret = vfs_fd_assign(oldfile, newfd);
     1371        fibril_mutex_unlock(&oldfile->lock);
     1372       
     1373        if (ret != EOK)
     1374                ipc_answer_0(rid, ret);
     1375        else
     1376                ipc_answer_1(rid, EOK, newfd);
     1377}
     1378
    13131379/**
    13141380 * @}
Note: See TracChangeset for help on using the changeset viewer.