Ignore:
File:
1 edited

Legend:

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

    r286286c r5bb9907  
    5454
    5555/* Forward declarations of static functions. */
    56 static int vfs_truncate_internal(fs_handle_t, service_id_t, fs_index_t,
     56static int vfs_truncate_internal(fs_handle_t, devmap_handle_t, fs_index_t,
    5757    aoff64_t);
    5858
     
    6565vfs_pair_t rootfs = {
    6666        .fs_handle = 0,
    67         .service_id = 0
     67        .devmap_handle = 0
    6868};
    6969
    70 static void vfs_mount_internal(ipc_callid_t rid, service_id_t service_id,
     70static void vfs_mount_internal(ipc_callid_t rid, devmap_handle_t devmap_handle,
    7171    fs_handle_t fs_handle, char *mp, char *opts)
    7272{
     
    125125                        exch = vfs_exchange_grab(fs_handle);
    126126                        msg = async_send_1(exch, VFS_OUT_MOUNTED,
    127                             (sysarg_t) service_id, &answer);
     127                            (sysarg_t) devmap_handle, &answer);
    128128                        /* Send the mount options */
    129129                        rc = async_data_write_start(exch, (void *)opts,
     
    146146
    147147                        rindex = (fs_index_t) IPC_GET_ARG1(answer);
    148                         rsize = (aoff64_t) MERGE_LOUP32(IPC_GET_ARG2(answer),
    149                             IPC_GET_ARG3(answer));
     148                        rsize = (aoff64_t) MERGE_LOUP32(IPC_GET_ARG2(answer), IPC_GET_ARG3(answer));
    150149                        rlnkcnt = (unsigned) IPC_GET_ARG4(answer);
    151150                       
    152151                        mr_res.triplet.fs_handle = fs_handle;
    153                         mr_res.triplet.service_id = service_id;
     152                        mr_res.triplet.devmap_handle = devmap_handle;
    154153                        mr_res.triplet.index = rindex;
    155154                        mr_res.size = rsize;
     
    158157                       
    159158                        rootfs.fs_handle = fs_handle;
    160                         rootfs.service_id = service_id;
     159                        rootfs.devmap_handle = devmap_handle;
    161160                       
    162161                        /* Add reference to the mounted root. */
     
    179178       
    180179        /*
    181          * At this point, we have all necessary pieces: file system handle
    182          * and service ID, and we know the mount point VFS node.
     180         * At this point, we have all necessary pieces: file system and device
     181         * handles, and we know the mount point VFS node.
    183182         */
    184183       
     
    188187        exch = vfs_exchange_grab(mp_res.triplet.fs_handle);
    189188        msg = async_send_4(exch, VFS_OUT_MOUNT,
    190             (sysarg_t) mp_res.triplet.service_id,
     189            (sysarg_t) mp_res.triplet.devmap_handle,
    191190            (sysarg_t) mp_res.triplet.index,
    192191            (sysarg_t) fs_handle,
    193             (sysarg_t) service_id, &answer);
     192            (sysarg_t) devmap_handle, &answer);
    194193       
    195194        /* Send connection */
     
    225224        }
    226225       
    227         /*
    228          * Wait for the answer before releasing the exchange to avoid deadlock
    229          * in case the answer depends on further calls to the same file system.
    230          * Think of a case when mounting a FS on a file_bd backed by a file on
    231          * the same FS.
    232          */
     226        vfs_exchange_release(exch);
    233227        async_wait_for(msg, &rc);
    234         vfs_exchange_release(exch);
    235228       
    236229        if (rc == EOK) {
     
    241234               
    242235                mr_res.triplet.fs_handle = fs_handle;
    243                 mr_res.triplet.service_id = service_id;
     236                mr_res.triplet.devmap_handle = devmap_handle;
    244237                mr_res.triplet.index = rindex;
    245238                mr_res.size = rsize;
     
    262255void vfs_mount(ipc_callid_t rid, ipc_call_t *request)
    263256{
    264         service_id_t service_id;
     257        devmap_handle_t devmap_handle;
    265258
    266259        /*
     
    269262         * in the request.
    270263         */
    271         service_id = (service_id_t) IPC_GET_ARG1(*request);
     264        devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
    272265       
    273266        /*
     
    277270       
    278271        /*
    279          * Instance number is passed as ARG3.
    280          */
    281         unsigned int instance = IPC_GET_ARG3(*request);
    282 
     272         * For now, don't make use of ARG3, but it can be used to
     273         * carry mount options in the future.
     274         */
     275       
    283276        /* We want the client to send us the mount point. */
    284277        char *mp;
     
    336329        fs_handle_t fs_handle;
    337330recheck:
    338         fs_handle = fs_name_to_handle(instance, fs_name, false);
     331        fs_handle = fs_name_to_handle(fs_name, false);
    339332        if (!fs_handle) {
    340333                if (flags & IPC_FLAG_BLOCKING) {
     
    357350       
    358351        /* Do the mount */
    359         vfs_mount_internal(rid, service_id, fs_handle, mp, opts);
     352        vfs_mount_internal(rid, devmap_handle, fs_handle, mp, opts);
    360353        free(mp);
    361354        free(fs_name);
     
    416409         */
    417410        if (vfs_nodes_refcount_sum_get(mr_node->fs_handle,
    418             mr_node->service_id) != 2) {
     411            mr_node->devmap_handle) != 2) {
    419412                fibril_rwlock_write_unlock(&namespace_rwlock);
    420413                vfs_node_put(mr_node);
     
    437430                exch = vfs_exchange_grab(mr_node->fs_handle);
    438431                rc = async_req_1_0(exch, VFS_OUT_UNMOUNTED,
    439                     mr_node->service_id);
     432                    mr_node->devmap_handle);
    440433                vfs_exchange_release(exch);
    441434               
     
    448441               
    449442                rootfs.fs_handle = 0;
    450                 rootfs.service_id = 0;
     443                rootfs.devmap_handle = 0;
    451444        } else {
    452445               
     
    477470                exch = vfs_exchange_grab(mp_node->fs_handle);
    478471                rc = async_req_2_0(exch, VFS_OUT_UNMOUNT,
    479                     mp_node->service_id, mp_node->index);
     472                    mp_node->devmap_handle, mp_node->index);
    480473                vfs_exchange_release(exch);
    481474               
     
    582575                if (node->size) {
    583576                        rc = vfs_truncate_internal(node->fs_handle,
    584                             node->service_id, node->index, 0);
     577                            node->devmap_handle, node->index, 0);
    585578                        if (rc) {
    586579                                fibril_rwlock_write_unlock(&node->contents_rwlock);
     
    625618}
    626619
     620void vfs_open_node(ipc_callid_t rid, ipc_call_t *request)
     621{
     622        // FIXME: check for sanity of the supplied fs, dev and index
     623       
     624        /*
     625         * The interface is open_node(fs, dev, index, oflag).
     626         */
     627        vfs_lookup_res_t lr;
     628       
     629        lr.triplet.fs_handle = IPC_GET_ARG1(*request);
     630        lr.triplet.devmap_handle = IPC_GET_ARG2(*request);
     631        lr.triplet.index = IPC_GET_ARG3(*request);
     632        int oflag = IPC_GET_ARG4(*request);
     633       
     634        fibril_rwlock_read_lock(&namespace_rwlock);
     635       
     636        int rc = vfs_open_node_internal(&lr);
     637        if (rc != EOK) {
     638                fibril_rwlock_read_unlock(&namespace_rwlock);
     639                async_answer_0(rid, rc);
     640                return;
     641        }
     642       
     643        vfs_node_t *node = vfs_node_get(&lr);
     644        fibril_rwlock_read_unlock(&namespace_rwlock);
     645       
     646        /* Truncate the file if requested and if necessary. */
     647        if (oflag & O_TRUNC) {
     648                fibril_rwlock_write_lock(&node->contents_rwlock);
     649                if (node->size) {
     650                        rc = vfs_truncate_internal(node->fs_handle,
     651                            node->devmap_handle, node->index, 0);
     652                        if (rc) {
     653                                fibril_rwlock_write_unlock(&node->contents_rwlock);
     654                                vfs_node_put(node);
     655                                async_answer_0(rid, rc);
     656                                return;
     657                        }
     658                        node->size = 0;
     659                }
     660                fibril_rwlock_write_unlock(&node->contents_rwlock);
     661        }
     662       
     663        /*
     664         * Get ourselves a file descriptor and the corresponding vfs_file_t
     665         * structure.
     666         */
     667        int fd = vfs_fd_alloc((oflag & O_DESC) != 0);
     668        if (fd < 0) {
     669                vfs_node_put(node);
     670                async_answer_0(rid, fd);
     671                return;
     672        }
     673        vfs_file_t *file = vfs_file_get(fd);
     674        file->node = node;
     675        if (oflag & O_APPEND)
     676                file->append = true;
     677       
     678        /*
     679         * The following increase in reference count is for the fact that the
     680         * file is being opened and that a file structure is pointing to it.
     681         * It is necessary so that the file will not disappear when
     682         * vfs_node_put() is called. The reference will be dropped by the
     683         * respective VFS_IN_CLOSE.
     684         */
     685        vfs_node_addref(node);
     686        vfs_node_put(node);
     687        vfs_file_put(file);
     688       
     689        /* Success! Return the new file descriptor to the client. */
     690        async_answer_1(rid, EOK, fd);
     691}
     692
    627693void vfs_sync(ipc_callid_t rid, ipc_call_t *request)
    628694{
     
    646712        aid_t msg;
    647713        ipc_call_t answer;
    648         msg = async_send_2(fs_exch, VFS_OUT_SYNC, file->node->service_id,
     714        msg = async_send_2(fs_exch, VFS_OUT_SYNC, file->node->devmap_handle,
    649715            file->node->index, &answer);
    650716       
     
    731797        if (read) {
    732798                rc = async_data_read_forward_4_1(fs_exch, VFS_OUT_READ,
    733                     file->node->service_id, file->node->index,
     799                    file->node->devmap_handle, file->node->index,
    734800                    LOWER32(file->pos), UPPER32(file->pos), &answer);
    735801        } else {
     
    738804               
    739805                rc = async_data_write_forward_4_1(fs_exch, VFS_OUT_WRITE,
    740                     file->node->service_id, file->node->index,
     806                    file->node->devmap_handle, file->node->index,
    741807                    LOWER32(file->pos), UPPER32(file->pos), &answer);
    742808        }
     
    869935}
    870936
    871 int vfs_truncate_internal(fs_handle_t fs_handle, service_id_t service_id,
     937int vfs_truncate_internal(fs_handle_t fs_handle, devmap_handle_t devmap_handle,
    872938    fs_index_t index, aoff64_t size)
    873939{
    874940        async_exch_t *exch = vfs_exchange_grab(fs_handle);
    875941        sysarg_t rc = async_req_4_0(exch, VFS_OUT_TRUNCATE,
    876             (sysarg_t) service_id, (sysarg_t) index, LOWER32(size),
     942            (sysarg_t) devmap_handle, (sysarg_t) index, LOWER32(size),
    877943            UPPER32(size));
    878944        vfs_exchange_release(exch);
     
    897963        fibril_rwlock_write_lock(&file->node->contents_rwlock);
    898964        rc = vfs_truncate_internal(file->node->fs_handle,
    899             file->node->service_id, file->node->index, size);
     965            file->node->devmap_handle, file->node->index, size);
    900966        if (rc == EOK)
    901967                file->node->size = size;
     
    931997       
    932998        aid_t msg;
    933         msg = async_send_3(exch, VFS_OUT_STAT, file->node->service_id,
     999        msg = async_send_3(exch, VFS_OUT_STAT, file->node->devmap_handle,
    9341000            file->node->index, true, NULL);
    9351001        async_forward_fast(callid, exch, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);
     
    9841050       
    9851051        aid_t msg;
    986         msg = async_send_3(exch, VFS_OUT_STAT, node->service_id,
     1052        msg = async_send_3(exch, VFS_OUT_STAT, node->devmap_handle,
    9871053            node->index, false, NULL);
    9881054        async_forward_fast(callid, exch, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);
     
    11611227        /* Check whether linking to the same file system instance. */
    11621228        if ((old_node->fs_handle != new_par_lr.triplet.fs_handle) ||
    1163             (old_node->service_id != new_par_lr.triplet.service_id)) {
     1229            (old_node->devmap_handle != new_par_lr.triplet.devmap_handle)) {
    11641230                fibril_rwlock_write_unlock(&namespace_rwlock);
    11651231                vfs_node_put(old_node);
     
    12831349}
    12841350
    1285 void vfs_wait_handle(ipc_callid_t rid, ipc_call_t *request)
    1286 {
    1287         int fd = vfs_wait_handle_internal();
    1288         async_answer_1(rid, EOK, fd);
    1289 }
    1290 
    12911351/**
    12921352 * @}
Note: See TracChangeset for help on using the changeset viewer.