Changeset 72bde81 in mainline


Ignore:
Timestamp:
2008-01-27T14:59:32Z (16 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().

Location:
uspace
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/tester/vfs/vfs1.c

    r1fe186f r72bde81  
    3131#include <stdlib.h>
    3232#include <string.h>
    33 #include <sys/types.h>
    3433#include <vfs.h>
    3534#include <unistd.h>
    3635#include <fcntl.h>
    3736#include <dirent.h>
     37#include <sys/types.h>
     38#include <sys/stat.h>
    3839#include "../tester.h"
    3940
     
    4344                return "Mount failed.\n";
    4445
     46        if (mkdir("/mydir", 0) != 0)
     47                return "mkdir() failed.\n";
    4548
    4649        DIR *dirp;
  • uspace/lib/libc/generic/vfs.c

    r1fe186f r72bde81  
    3838#include <dirent.h>
    3939#include <fcntl.h>
     40#include <sys/stat.h>
     41#include <sys/types.h>
    4042#include <ipc/ipc.h>
    4143#include <ipc/services.h>
     
    132134}
    133135
     136int close(int fildes)
     137{
     138        return 0;       /* TODO */
     139}
     140
    134141ssize_t read(int fildes, void *buf, size_t nbyte)
    135142{
     
    210217        off_t newoffs;
    211218        rc = async_req_3_1(vfs_phone, VFS_SEEK, fildes, offset, whence,
    212             &newoffs);
     219            (ipcarg_t)&newoffs);
    213220
    214221        async_serialize_end();
     
    275282}
    276283
    277 int close(int fildes)
    278 {
    279         return 0;       /* TODO */
     284int mkdir(const char *path, mode_t mode)
     285{
     286        int res;
     287        ipcarg_t rc;
     288        ipc_call_t answer;
     289        aid_t req;
     290       
     291        futex_down(&vfs_phone_futex);
     292        async_serialize_start();
     293        if (vfs_phone < 0) {
     294                res = vfs_connect();
     295                if (res < 0) {
     296                        async_serialize_end();
     297                        futex_up(&vfs_phone_futex);
     298                        return res;
     299                }
     300        }
     301        req = async_send_1(vfs_phone, VFS_MKDIR, mode, &answer);
     302        rc = ipc_data_write_start(vfs_phone, path, strlen(path));
     303        if (rc != EOK) {
     304                async_wait_for(req, NULL);
     305                async_serialize_end();
     306                futex_up(&vfs_phone_futex);
     307                return (int) rc;
     308        }
     309        async_wait_for(req, &rc);
     310        async_serialize_end();
     311        futex_up(&vfs_phone_futex);
     312        return EOK;
    280313}
    281314
  • uspace/lib/libc/include/sys/types.h

    r1fe186f r72bde81  
    4141typedef signed long ssize_t;
    4242typedef long off_t;
     43typedef int mode_t;
    4344
    4445#endif
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    r1fe186f r72bde81  
    212212    const char *component, int lflag)
    213213{
    214         return 0;
     214        assert(dentry->type == TMPFS_DIRECTORY);
     215        assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY));
     216
     217        tmpfs_dentry_t *node = malloc(sizeof(tmpfs_dentry_t));
     218        if (!node)
     219                return 0;
     220        size_t len = strlen(component);
     221        char *name = malloc(len + 1);
     222        if (!name) {
     223                free(node);
     224                return 0;
     225        }
     226        strcpy(name, component);
     227
     228        tmpfs_dentry_initialize(node);
     229        node->index = tmpfs_next_index++;
     230        node->name = name;
     231        node->parent = dentry;
     232        if (lflag & L_DIRECTORY)
     233                node->type = TMPFS_DIRECTORY;
     234        else
     235                node->type = TMPFS_FILE;
     236
     237        /* Insert the new node into the namespace. */
     238        if (dentry->child) {
     239                tmpfs_dentry_t *tmp = dentry->child;
     240                while (tmp->sibling)
     241                        tmp = tmp->sibling;
     242                tmp->sibling = node;
     243        } else {
     244                dentry->child = node;
     245        }
     246
     247        /* Insert the new node into the dentry hash table. */
     248        hash_table_insert(&dentries, &node->index, &node->dh_link);
     249        return node->index;
    215250}
    216251
     
    257292                        component[len++] = PLB_GET_CHAR(next);
    258293                        next++; /* process next character */
    259                         if (next <= last)
     294                        if (next <= last) 
    260295                                continue;
    261296                }
     
    280315                                unsigned long index = create_node(dcur,
    281316                                    component, lflag);
    282                                 if (index) {
     317                                if (index > 0) {
    283318                                        ipc_answer_4(rid, EOK,
    284319                                            tmpfs_reg.fs_handle, dev_handle,
  • uspace/srv/vfs/vfs.c

    r1fe186f r72bde81  
    106106                        vfs_truncate(callid, &call);
    107107                        break;
    108                 case VFS_UNMOUNT:
    109                 case VFS_CLOSE:
    110                 case VFS_UNLINK:
    111                 case VFS_RENAME:
    112                 case VFS_OPENDIR:
    113                 case VFS_READDIR:
    114                 case VFS_CLOSEDIR:
     108                case VFS_MKDIR:
     109                        vfs_mkdir(callid, &call);
     110                        break;
    115111                default:
    116112                        ipc_answer_0(callid, ENOTSUP);
  • uspace/srv/vfs/vfs.h

    r1fe186f r72bde81  
    5757        VFS_READDIR,
    5858        VFS_CLOSEDIR,
     59        VFS_MKDIR,
    5960        VFS_UNLINK,
    6061        VFS_MOUNT,
     
    262263extern void vfs_seek(ipc_callid_t, ipc_call_t *);
    263264extern void vfs_truncate(ipc_callid_t, ipc_call_t *);
     265extern void vfs_mkdir(ipc_callid_t, ipc_call_t *);
    264266
    265267#endif
  • uspace/srv/vfs/vfs_lookup.c

    r1fe186f r72bde81  
    5858 * @param lflag         Flags to be used during lookup.
    5959 * @param result        Empty structure where the lookup result will be stored.
     60 *                      Can be NULL.
    6061 * @param altroot       If non-empty, will be used instead of rootfs as the root
    6162 *                      of the whole VFS tree.
     
    163164        futex_up(&plb_futex);
    164165
    165         if (rc == EOK) {
     166        if ((rc == EOK) && result) {
    166167                result->triplet.fs_handle = (int) IPC_GET_ARG1(answer);
    167168                result->triplet.dev_handle = (int) IPC_GET_ARG2(answer);
  • 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.