Changeset 72bde81 in mainline for uspace/srv/vfs/vfs_ops.c


Ignore:
Timestamp:
2008-01-27T14:59:32Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2db4ac8
Parents:
1fe186f
Message:

Support for mkdir().

File:
1 edited

Legend:

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

    r1fe186f r72bde81  
    116116        }
    117117
    118         /*
    119          * Deliver the file system name.
    120          */
     118        /* Deliver the file system name. */
    121119        char fs_name[FS_NAME_MAXLEN + 1];
    122120        (void) ipc_data_write_finalize(callid, fs_name, size);
     
    133131        }
    134132
    135         /*
    136          * Now, we want the client to send us the mount point.
    137          */
     133        /* Now, we want the client to send us the mount point. */
    138134        if (!ipc_data_write_receive(&callid, &size)) {
    139135                ipc_answer_0(callid, EINVAL);
     
    142138        }
    143139
    144         /*
    145          * Check whether size is reasonable wrt. the mount point.
    146          */
     140        /* Check whether size is reasonable wrt. the mount point. */
    147141        if (size < 1 || size > MAX_PATH_LEN) {
    148142                ipc_answer_0(callid, EINVAL);
     
    150144                return;
    151145        }
    152         /*
    153          * Allocate buffer for the mount point data being received.
    154          */
     146        /* Allocate buffer for the mount point data being received. */
    155147        uint8_t *buf;
    156148        buf = malloc(size);
     
    161153        }
    162154
    163         /*
    164          * Deliver the mount point.
    165          */
     155        /* Deliver the mount point. */
    166156        (void) ipc_data_write_finalize(callid, buf, size);
    167157
     
    187177        }
    188178
    189         /*
    190          * Finally, we need to resolve the path to the mountpoint.
    191          */
     179        /* Finally, we need to resolve the path to the mountpoint. */
    192180        vfs_lookup_res_t mp_res;
    193181        futex_down(&rootfs_futex);
    194182        if (rootfs.fs_handle) {
    195                 /*
    196                  * We already have the root FS.
    197                  */
     183                /* We already have the root FS. */
    198184                rwlock_write_lock(&namespace_rwlock);
    199185                rc = vfs_lookup_internal(buf, size, L_DIRECTORY, &mp_res,
    200186                    NULL);
    201187                if (rc != EOK) {
    202                         /*
    203                          * The lookup failed for some reason.
    204                          */
     188                        /* The lookup failed for some reason. */
    205189                        rwlock_write_unlock(&namespace_rwlock);
    206190                        futex_up(&rootfs_futex);
     
    226210                rwlock_write_unlock(&namespace_rwlock);
    227211        } else {
    228                 /*
    229                  * We still don't have the root file system mounted.
    230                  */
     212                /* We still don't have the root file system mounted. */
    231213                if ((size == 1) && (buf[0] == '/')) {
    232                         /*
    233                          * For this simple, but important case, we are done.
    234                          */
     214                        /* For this simple, but important case, we are done. */
    235215                        rootfs = mr_res.triplet;
    236216                        futex_up(&rootfs_futex);
     
    348328        rwlock_read_lock(&namespace_rwlock);
    349329
    350         /*
    351          * The path is now populated and we can call vfs_lookup_internal().
    352          */
     330        /* The path is now populated and we can call vfs_lookup_internal(). */
    353331        vfs_lookup_res_t lr;
    354332        rc = vfs_lookup_internal(path, len, lflag, &lr, NULL);
     
    360338        }
    361339
    362         /*
    363          * Path is no longer needed.
    364          */
     340        /** Path is no longer needed. */
    365341        free(path);
    366342
     
    391367        vfs_node_put(node);
    392368
    393         /*
    394          * Success! Return the new file descriptor to the client.
    395          */
     369        /* Success! Return the new file descriptor to the client. */
    396370        ipc_answer_1(rid, EOK, fd);
    397371}
     
    412386        int fd = IPC_GET_ARG1(*request);
    413387
    414         /*
    415          * Lookup the file structure corresponding to the file descriptor.
    416          */
     388        /* Lookup the file structure corresponding to the file descriptor. */
    417389        vfs_file_t *file = vfs_file_get(fd);
    418390        if (!file) {
     
    454426        int fs_phone = vfs_grab_phone(file->node->fs_handle);   
    455427       
    456         /*
    457          * Make a VFS_READ/VFS_WRITE request at the destination FS server.
    458          */
     428        /* Make a VFS_READ/VFS_WRITE request at the destination FS server. */
    459429        aid_t msg;
    460430        ipc_call_t answer;
     
    472442        vfs_release_phone(fs_phone);
    473443
    474         /*
    475          * Wait for reply from the FS server.
    476          */
     444        /* Wait for reply from the FS server. */
    477445        ipcarg_t rc;
    478446        async_wait_for(msg, &rc);
    479447        size_t bytes = IPC_GET_ARG1(answer);
    480448
    481         /*
    482          * Unlock the VFS node.
    483          */
     449        /* Unlock the VFS node. */
    484450        if (read)
    485451                rwlock_read_unlock(&file->node->contents_rwlock);
     
    490456        }
    491457
    492         /*
    493          * Update the position pointer and unlock the open file.
    494          */
     458        /* Update the position pointer and unlock the open file. */
    495459        file->pos += bytes;
    496460        futex_up(&file->lock);
     
    520484
    521485
    522         /*
    523          * Lookup the file structure corresponding to the file descriptor.
    524          */
     486        /* Lookup the file structure corresponding to the file descriptor. */
    525487        vfs_file_t *file = vfs_file_get(fd);
    526488        if (!file) {
     
    582544        rwlock_write_lock(&file->node->contents_rwlock);
    583545        int fs_phone = vfs_grab_phone(file->node->fs_handle);
    584         rc = async_req_3_0(fs_phone, VFS_TRUNCATE, (ipcarg_t)file->node->dev_handle,
    585             (ipcarg_t)file->node->index, (ipcarg_t)size);
     546        rc = async_req_3_0(fs_phone, VFS_TRUNCATE,
     547            (ipcarg_t)file->node->dev_handle, (ipcarg_t)file->node->index,
     548            (ipcarg_t)size);
    586549        vfs_release_phone(fs_phone);
    587550        if (rc == EOK)
     
    593556}
    594557
     558void vfs_mkdir(ipc_callid_t rid, ipc_call_t *request)
     559{
     560        int mode = IPC_GET_ARG1(*request);
     561        size_t len;
     562
     563        ipc_callid_t callid;
     564
     565        if (!ipc_data_write_receive(&callid, &len)) {
     566                ipc_answer_0(callid, EINVAL);
     567                ipc_answer_0(rid, EINVAL);
     568                return;
     569        }
     570
     571        /*
     572         * Now we are on the verge of accepting the path.
     573         *
     574         * There is one optimization we could do in the future: copy the path
     575         * directly into the PLB using some kind of a callback.
     576         */
     577        char *path = malloc(len);
     578       
     579        if (!path) {
     580                ipc_answer_0(callid, ENOMEM);
     581                ipc_answer_0(rid, ENOMEM);
     582                return;
     583        }
     584
     585        int rc;
     586        if ((rc = ipc_data_write_finalize(callid, path, len))) {
     587                ipc_answer_0(rid, rc);
     588                free(path);
     589                return;
     590        }
     591       
     592        rwlock_write_lock(&namespace_rwlock);
     593        int lflag = L_DIRECTORY | L_CREATE | L_EXCLUSIVE;
     594        rc = vfs_lookup_internal(path, len, lflag, NULL, NULL);
     595        rwlock_write_unlock(&namespace_rwlock);
     596        free(path);
     597        ipc_answer_0(rid, rc);
     598}
     599
    595600/**
    596601 * @}
Note: See TracChangeset for help on using the changeset viewer.