Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libfs/libfs.c

    r1313ee9 r2e983c7  
    11/*
    2  * Copyright (c) 2009 Jakub Jermar
     2 * Copyright (c) 2009 Jakub Jermar 
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libfs
     29/** @addtogroup libfs 
    3030 * @{
    31  */
     31 */ 
    3232/**
    3333 * @file
    34  * Glue code which is common to all FS implementations.
     34 * Glue code which is commonod to all FS implementations.
    3535 */
    3636
    37 #include "libfs.h"
     37#include "libfs.h" 
    3838#include "../../srv/vfs/vfs.h"
    3939#include <errno.h>
     
    6767 * code.
    6868 *
    69  * @param vfs_phone Open phone for communication with VFS.
    70  * @param reg       File system registration structure. It will be
    71  *                  initialized by this function.
    72  * @param info      VFS info structure supplied by the file system
    73  *                  implementation.
    74  * @param conn      Connection fibril for handling all calls originating in
    75  *                  VFS.
    76  *
    77  * @return EOK on success or a non-zero error code on errror.
    78  *
     69 * @param vfs_phone     Open phone for communication with VFS.
     70 * @param reg           File system registration structure. It will be
     71 *                      initialized by this function.
     72 * @param info          VFS info structure supplied by the file system
     73 *                      implementation.
     74 * @param conn          Connection fibril for handling all calls originating in
     75 *                      VFS.
     76 *
     77 * @return              EOK on success or a non-zero error code on errror.
    7978 */
    8079int fs_register(int vfs_phone, fs_reg_t *reg, vfs_info_t *info,
     
    8887        ipc_call_t answer;
    8988        aid_t req = async_send_0(vfs_phone, VFS_IN_REGISTER, &answer);
    90        
     89
    9190        /*
    9291         * Send our VFS info structure to VFS.
     
    9796                return rc;
    9897        }
    99        
     98
    10099        /*
    101100         * Ask VFS for callback connection.
    102101         */
    103102        ipc_connect_to_me(vfs_phone, 0, 0, 0, &reg->vfs_phonehash);
    104        
     103
    105104        /*
    106105         * Allocate piece of address space for PLB.
     
    111110                return ENOMEM;
    112111        }
    113        
     112
    114113        /*
    115114         * Request sharing the Path Lookup Buffer with VFS.
     
    137136         */
    138137        async_set_client_connection(conn);
    139        
     138
    140139        return IPC_GET_RETVAL(answer);
    141140}
     
    155154        int res;
    156155        ipcarg_t rc;
    157        
     156
    158157        ipc_call_t call;
    159158        ipc_callid_t callid;
    160        
    161         /* Accept the phone */
     159
     160        /* accept the phone */
    162161        callid = async_get_call(&call);
    163162        int mountee_phone = (int)IPC_GET_ARG1(call);
    164163        if ((IPC_GET_METHOD(call) != IPC_M_CONNECTION_CLONE) ||
    165             (mountee_phone < 0)) {
     164            mountee_phone < 0) {
    166165                ipc_answer_0(callid, EINVAL);
    167166                ipc_answer_0(rid, EINVAL);
    168167                return;
    169168        }
    170        
    171         /* Acknowledge the mountee_phone */
    172         ipc_answer_0(callid, EOK);
     169        ipc_answer_0(callid, EOK);      /* acknowledge the mountee_phone */
    173170       
    174171        res = async_data_write_receive(&callid, NULL);
     
    179176                return;
    180177        }
    181        
     178
    182179        fs_node_t *fn;
    183180        res = ops->node_get(&fn, mp_dev_handle, mp_fs_index);
    184         if ((res != EOK) || (!fn)) {
     181        if (res != EOK || !fn) {
    185182                ipc_hangup(mountee_phone);
    186183                ipc_answer_0(callid, combine_rc(res, ENOENT));
     
    188185                return;
    189186        }
    190        
     187
    191188        if (fn->mp_data.mp_active) {
    192189                ipc_hangup(mountee_phone);
     
    196193                return;
    197194        }
    198        
     195
    199196        rc = async_req_0_0(mountee_phone, IPC_M_CONNECT_ME);
    200197        if (rc != EOK) {
     
    218215                fn->mp_data.phone = mountee_phone;
    219216        }
    220        
    221217        /*
    222218         * Do not release the FS node so that it stays in memory.
     
    242238    ipc_call_t *request)
    243239{
    244         unsigned int first = IPC_GET_ARG1(*request);
    245         unsigned int last = IPC_GET_ARG2(*request);
    246         unsigned int next = first;
     240        unsigned first = IPC_GET_ARG1(*request);
     241        unsigned last = IPC_GET_ARG2(*request);
     242        unsigned next = first;
    247243        dev_handle_t dev_handle = IPC_GET_ARG3(*request);
    248244        int lflag = IPC_GET_ARG4(*request);
    249         fs_index_t index = IPC_GET_ARG5(*request);
     245        fs_index_t index = IPC_GET_ARG5(*request); /* when L_LINK specified */
    250246        char component[NAME_MAX + 1];
    251247        int len;
    252248        int rc;
    253        
     249
    254250        if (last < next)
    255251                last += PLB_SIZE;
    256        
     252
    257253        fs_node_t *par = NULL;
    258254        fs_node_t *cur = NULL;
    259255        fs_node_t *tmp = NULL;
    260        
     256
    261257        rc = ops->root_get(&cur, dev_handle);
    262258        on_error(rc, goto out_with_answer);
    263        
     259
    264260        if (cur->mp_data.mp_active) {
    265261                ipc_forward_slow(rid, cur->mp_data.phone, VFS_OUT_LOOKUP,
     
    269265                return;
    270266        }
    271        
    272         /* Eat slash */
     267
    273268        if (ops->plb_get_char(next) == '/')
    274                 next++;
     269                next++;         /* eat slash */
    275270       
    276271        while (next <= last) {
    277272                bool has_children;
    278                
     273
    279274                rc = ops->has_children(&has_children, cur);
    280275                on_error(rc, goto out_with_answer);
    281276                if (!has_children)
    282277                        break;
    283                
    284                 /* Collect the component */
     278
     279                /* collect the component */
    285280                len = 0;
    286                 while ((next <= last) && (ops->plb_get_char(next) != '/')) {
     281                while ((next <= last) &&  (ops->plb_get_char(next) != '/')) {
    287282                        if (len + 1 == NAME_MAX) {
    288                                 /* Component length overflow */
     283                                /* component length overflow */
    289284                                ipc_answer_0(rid, ENAMETOOLONG);
    290285                                goto out;
    291286                        }
    292287                        component[len++] = ops->plb_get_char(next);
    293                         /* Process next character */
    294                         next++;
     288                        next++; /* process next character */
    295289                }
    296                
     290
    297291                assert(len);
    298292                component[len] = '\0';
    299                 /* Eat slash */
    300                 next++;
    301                
    302                 /* Match the component */
     293                next++;         /* eat slash */
     294
     295                /* match the component */
    303296                rc = ops->match(&tmp, cur, component);
    304297                on_error(rc, goto out_with_answer);
    305                
    306                 if ((tmp) && (tmp->mp_data.mp_active)) {
     298
     299                if (tmp && tmp->mp_data.mp_active) {
    307300                        if (next > last)
    308301                                next = last = first;
    309302                        else
    310303                                next--;
    311                        
     304                               
    312305                        ipc_forward_slow(rid, tmp->mp_data.phone,
    313306                            VFS_OUT_LOOKUP, next, last, tmp->mp_data.dev_handle,
     
    319312                        return;
    320313                }
    321                
    322                 /* Handle miss: match amongst siblings */
     314
     315                /* handle miss: match amongst siblings */
    323316                if (!tmp) {
    324317                        if (next <= last) {
    325                                 /* There are unprocessed components */
     318                                /* there are unprocessed components */
    326319                                ipc_answer_0(rid, ENOENT);
    327320                                goto out;
    328321                        }
    329                        
    330                         /* Miss in the last component */
    331                         if (lflag & (L_CREATE | L_LINK)) {
    332                                 /* Request to create a new link */
     322                        /* miss in the last component */
     323                        if (lflag & (L_CREATE | L_LINK)) {
     324                                /* request to create a new link */
    333325                                if (!ops->is_directory(cur)) {
    334326                                        ipc_answer_0(rid, ENOTDIR);
    335327                                        goto out;
    336328                                }
    337                                
    338329                                fs_node_t *fn;
    339330                                if (lflag & L_CREATE)
     
    344335                                            index);
    345336                                on_error(rc, goto out_with_answer);
    346                                
    347337                                if (fn) {
    348338                                        rc = ops->link(cur, fn, component);
     
    359349                                                (void) ops->node_put(fn);
    360350                                        }
    361                                 } else
     351                                } else {
    362352                                        ipc_answer_0(rid, ENOSPC);
    363                                
     353                                }
    364354                                goto out;
    365                         }
    366                        
     355                        }
    367356                        ipc_answer_0(rid, ENOENT);
    368357                        goto out;
    369358                }
    370                
     359
    371360                if (par) {
    372361                        rc = ops->node_put(par);
    373362                        on_error(rc, goto out_with_answer);
    374363                }
    375                
    376                 /* Descend one level */
     364
     365                /* descend one level */
    377366                par = cur;
    378367                cur = tmp;
    379368                tmp = NULL;
    380369        }
    381        
    382         /* Handle miss: excessive components */
     370
     371        /* handle miss: excessive components */
    383372        if (next <= last) {
    384373                bool has_children;
     374
    385375                rc = ops->has_children(&has_children, cur);
    386376                on_error(rc, goto out_with_answer);
    387                
    388377                if (has_children)
    389378                        goto skip_miss;
    390                
     379
    391380                if (lflag & (L_CREATE | L_LINK)) {
    392381                        if (!ops->is_directory(cur)) {
     
    394383                                goto out;
    395384                        }
    396                        
    397                         /* Collect next component */
     385
     386                        /* collect next component */
    398387                        len = 0;
    399388                        while (next <= last) {
    400389                                if (ops->plb_get_char(next) == '/') {
    401                                         /* More than one component */
     390                                        /* more than one component */
    402391                                        ipc_answer_0(rid, ENOENT);
    403392                                        goto out;
    404393                                }
    405                                
    406394                                if (len + 1 == NAME_MAX) {
    407                                         /* Component length overflow */
     395                                        /* component length overflow */
    408396                                        ipc_answer_0(rid, ENAMETOOLONG);
    409397                                        goto out;
    410398                                }
    411                                
    412399                                component[len++] = ops->plb_get_char(next);
    413                                 /* Process next character */
    414                                 next++;
     400                                next++; /* process next character */
    415401                        }
    416                        
    417402                        assert(len);
    418403                        component[len] = '\0';
    419                        
     404                               
    420405                        fs_node_t *fn;
    421406                        if (lflag & L_CREATE)
     
    424409                                rc = ops->node_get(&fn, dev_handle, index);
    425410                        on_error(rc, goto out_with_answer);
    426                        
    427411                        if (fn) {
    428412                                rc = ops->link(cur, fn, component);
     
    439423                                        (void) ops->node_put(fn);
    440424                                }
    441                         } else
     425                        } else {
    442426                                ipc_answer_0(rid, ENOSPC);
    443                        
     427                        }
    444428                        goto out;
    445429                }
    446                
    447430                ipc_answer_0(rid, ENOENT);
    448431                goto out;
    449432        }
    450        
    451433skip_miss:
    452        
    453         /* Handle hit */
     434
     435        /* handle hit */
    454436        if (lflag & L_UNLINK) {
    455                 unsigned int old_lnkcnt = ops->lnkcnt_get(cur);
     437                unsigned old_lnkcnt = ops->lnkcnt_get(cur);
    456438                rc = ops->unlink(par, cur, component);
    457                 ipc_answer_5(rid, (ipcarg_t) rc, fs_handle, dev_handle,
     439                ipc_answer_5(rid, (ipcarg_t)rc, fs_handle, dev_handle,
    458440                    ops->index_get(cur), ops->size_get(cur), old_lnkcnt);
    459441                goto out;
    460442        }
    461        
    462443        if (((lflag & (L_CREATE | L_EXCLUSIVE)) == (L_CREATE | L_EXCLUSIVE)) ||
    463444            (lflag & L_LINK)) {
     
    465446                goto out;
    466447        }
    467        
    468448        if ((lflag & L_FILE) && (ops->is_directory(cur))) {
    469449                ipc_answer_0(rid, EISDIR);
    470450                goto out;
    471451        }
    472        
    473452        if ((lflag & L_DIRECTORY) && (ops->is_file(cur))) {
    474453                ipc_answer_0(rid, ENOTDIR);
    475454                goto out;
    476455        }
    477        
     456
    478457out_with_answer:
    479        
    480458        if (rc == EOK) {
    481                 if (lflag & L_OPEN)
    482                         rc = ops->node_open(cur);
    483                
    484                 ipc_answer_5(rid, rc, fs_handle, dev_handle,
     459                ipc_answer_5(rid, EOK, fs_handle, dev_handle,
    485460                    ops->index_get(cur), ops->size_get(cur),
    486461                    ops->lnkcnt_get(cur));
    487         } else
     462        } else {
    488463                ipc_answer_0(rid, rc);
    489        
     464        }
     465
    490466out:
    491        
    492467        if (par)
    493468                (void) ops->node_put(par);
    494        
    495469        if (cur)
    496470                (void) ops->node_put(cur);
    497        
    498471        if (tmp)
    499472                (void) ops->node_put(tmp);
     
    505478        dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
    506479        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
    507        
    508480        fs_node_t *fn;
    509         int rc = ops->node_get(&fn, dev_handle, index);
     481        int rc;
     482
     483        rc = ops->node_get(&fn, dev_handle, index);
    510484        on_error(rc, answer_and_return(rid, rc));
    511        
     485
    512486        ipc_callid_t callid;
    513487        size_t size;
    514         if ((!async_data_read_receive(&callid, &size)) ||
    515             (size != sizeof(struct stat))) {
    516                 ops->node_put(fn);
     488        if (!async_data_read_receive(&callid, &size) ||
     489            size != sizeof(struct stat)) {
    517490                ipc_answer_0(callid, EINVAL);
    518491                ipc_answer_0(rid, EINVAL);
    519492                return;
    520493        }
    521        
     494
    522495        struct stat stat;
    523496        memset(&stat, 0, sizeof(struct stat));
     
    526499        stat.dev_handle = dev_handle;
    527500        stat.index = index;
    528         stat.lnkcnt = ops->lnkcnt_get(fn);
     501        stat.lnkcnt = ops->lnkcnt_get(fn); 
    529502        stat.is_file = ops->is_file(fn);
    530         stat.is_directory = ops->is_directory(fn);
    531503        stat.size = ops->size_get(fn);
    532         stat.device = ops->device_get(fn);
    533        
    534         ops->node_put(fn);
    535        
     504
    536505        async_data_read_finalize(callid, &stat, sizeof(struct stat));
    537506        ipc_answer_0(rid, EOK);
     
    540509/** Open VFS triplet.
    541510 *
    542  * @param ops     libfs operations structure with function pointers to
    543  *                file system implementation
    544  * @param rid     Request ID of the VFS_OUT_OPEN_NODE request.
    545  * @param request VFS_OUT_OPEN_NODE request data itself.
     511 * @param ops       libfs operations structure with function pointers to
     512 *                  file system implementation
     513 * @param rid       Request ID of the VFS_OUT_OPEN_NODE request.
     514 * @param request   VFS_OUT_OPEN_NODE request data itself.
    546515 *
    547516 */
     
    562531        }
    563532       
    564         rc = ops->node_open(fn);
    565         ipc_answer_3(rid, rc, ops->size_get(fn), ops->lnkcnt_get(fn),
     533        ipc_answer_3(rid, EOK, ops->size_get(fn), ops->lnkcnt_get(fn),
    566534            (ops->is_file(fn) ? L_FILE : 0) | (ops->is_directory(fn) ? L_DIRECTORY : 0));
    567535       
Note: See TracChangeset for help on using the changeset viewer.