Changeset 5eb5dcf in mainline for uspace/lib/libfs/libfs.c


Ignore:
Timestamp:
2010-01-06T20:56:04Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fccc236
Parents:
002252a (diff), eca2435 (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/lib/libfs/libfs.c

    r002252a r5eb5dcf  
    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 commonod to all FS implementations.
    35  */
    36 
    37 #include "libfs.h" 
     34 * Glue code which is common to all FS implementations.
     35 */
     36
     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.
     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 *
    7879 */
    7980int fs_register(int vfs_phone, fs_reg_t *reg, vfs_info_t *info,
     
    8788        ipc_call_t answer;
    8889        aid_t req = async_send_0(vfs_phone, VFS_IN_REGISTER, &answer);
    89 
     90       
    9091        /*
    9192         * Send our VFS info structure to VFS.
     
    9697                return rc;
    9798        }
    98 
     99       
    99100        /*
    100101         * Ask VFS for callback connection.
    101102         */
    102103        ipc_connect_to_me(vfs_phone, 0, 0, 0, &reg->vfs_phonehash);
    103 
     104       
    104105        /*
    105106         * Allocate piece of address space for PLB.
     
    110111                return ENOMEM;
    111112        }
    112 
     113       
    113114        /*
    114115         * Request sharing the Path Lookup Buffer with VFS.
     
    136137         */
    137138        async_set_client_connection(conn);
    138 
     139       
    139140        return IPC_GET_RETVAL(answer);
    140141}
     
    154155        int res;
    155156        ipcarg_t rc;
    156 
     157       
    157158        ipc_call_t call;
    158159        ipc_callid_t callid;
    159 
    160         /* accept the phone */
     160       
     161        /* Accept the phone */
    161162        callid = async_get_call(&call);
    162163        int mountee_phone = (int)IPC_GET_ARG1(call);
    163164        if ((IPC_GET_METHOD(call) != IPC_M_CONNECTION_CLONE) ||
    164             mountee_phone < 0) {
     165            (mountee_phone < 0)) {
    165166                ipc_answer_0(callid, EINVAL);
    166167                ipc_answer_0(rid, EINVAL);
    167168                return;
    168169        }
    169         ipc_answer_0(callid, EOK);      /* acknowledge the mountee_phone */
     170       
     171        /* Acknowledge the mountee_phone */
     172        ipc_answer_0(callid, EOK);
    170173       
    171174        res = async_data_write_receive(&callid, NULL);
     
    176179                return;
    177180        }
    178 
     181       
    179182        fs_node_t *fn;
    180183        res = ops->node_get(&fn, mp_dev_handle, mp_fs_index);
    181         if (res != EOK || !fn) {
     184        if ((res != EOK) || (!fn)) {
    182185                ipc_hangup(mountee_phone);
    183186                ipc_answer_0(callid, combine_rc(res, ENOENT));
     
    185188                return;
    186189        }
    187 
     190       
    188191        if (fn->mp_data.mp_active) {
    189192                ipc_hangup(mountee_phone);
     
    193196                return;
    194197        }
    195 
     198       
    196199        rc = async_req_0_0(mountee_phone, IPC_M_CONNECT_ME);
    197200        if (rc != EOK) {
     
    215218                fn->mp_data.phone = mountee_phone;
    216219        }
     220       
    217221        /*
    218222         * Do not release the FS node so that it stays in memory.
     
    238242    ipc_call_t *request)
    239243{
    240         unsigned first = IPC_GET_ARG1(*request);
    241         unsigned last = IPC_GET_ARG2(*request);
    242         unsigned next = first;
     244        unsigned int first = IPC_GET_ARG1(*request);
     245        unsigned int last = IPC_GET_ARG2(*request);
     246        unsigned int next = first;
    243247        dev_handle_t dev_handle = IPC_GET_ARG3(*request);
    244248        int lflag = IPC_GET_ARG4(*request);
    245         fs_index_t index = IPC_GET_ARG5(*request); /* when L_LINK specified */
     249        fs_index_t index = IPC_GET_ARG5(*request);
    246250        char component[NAME_MAX + 1];
    247251        int len;
    248252        int rc;
    249 
     253       
    250254        if (last < next)
    251255                last += PLB_SIZE;
    252 
     256       
    253257        fs_node_t *par = NULL;
    254258        fs_node_t *cur = NULL;
    255259        fs_node_t *tmp = NULL;
    256 
     260       
    257261        rc = ops->root_get(&cur, dev_handle);
    258262        on_error(rc, goto out_with_answer);
    259 
     263       
    260264        if (cur->mp_data.mp_active) {
    261265                ipc_forward_slow(rid, cur->mp_data.phone, VFS_OUT_LOOKUP,
     
    265269                return;
    266270        }
    267 
     271       
     272        /* Eat slash */
    268273        if (ops->plb_get_char(next) == '/')
    269                 next++;         /* eat slash */
     274                next++;
    270275       
    271276        while (next <= last) {
    272277                bool has_children;
    273 
     278               
    274279                rc = ops->has_children(&has_children, cur);
    275280                on_error(rc, goto out_with_answer);
    276281                if (!has_children)
    277282                        break;
    278 
    279                 /* collect the component */
     283               
     284                /* Collect the component */
    280285                len = 0;
    281                 while ((next <= last) &&  (ops->plb_get_char(next) != '/')) {
     286                while ((next <= last) && (ops->plb_get_char(next) != '/')) {
    282287                        if (len + 1 == NAME_MAX) {
    283                                 /* component length overflow */
     288                                /* Component length overflow */
    284289                                ipc_answer_0(rid, ENAMETOOLONG);
    285290                                goto out;
    286291                        }
    287292                        component[len++] = ops->plb_get_char(next);
    288                         next++; /* process next character */
     293                        /* Process next character */
     294                        next++;
    289295                }
    290 
     296               
    291297                assert(len);
    292298                component[len] = '\0';
    293                 next++;         /* eat slash */
    294 
    295                 /* match the component */
     299                /* Eat slash */
     300                next++;
     301               
     302                /* Match the component */
    296303                rc = ops->match(&tmp, cur, component);
    297304                on_error(rc, goto out_with_answer);
    298 
    299                 if (tmp && tmp->mp_data.mp_active) {
     305               
     306                if ((tmp) && (tmp->mp_data.mp_active)) {
    300307                        if (next > last)
    301308                                next = last = first;
    302309                        else
    303310                                next--;
    304                                
     311                       
    305312                        ipc_forward_slow(rid, tmp->mp_data.phone,
    306313                            VFS_OUT_LOOKUP, next, last, tmp->mp_data.dev_handle,
     
    312319                        return;
    313320                }
    314 
    315                 /* handle miss: match amongst siblings */
     321               
     322                /* Handle miss: match amongst siblings */
    316323                if (!tmp) {
    317324                        if (next <= last) {
    318                                 /* there are unprocessed components */
     325                                /* There are unprocessed components */
    319326                                ipc_answer_0(rid, ENOENT);
    320327                                goto out;
    321328                        }
    322                         /* miss in the last component */
    323                         if (lflag & (L_CREATE | L_LINK)) {
    324                                 /* request to create a new link */
     329                       
     330                        /* Miss in the last component */
     331                        if (lflag & (L_CREATE | L_LINK)) {
     332                                /* Request to create a new link */
    325333                                if (!ops->is_directory(cur)) {
    326334                                        ipc_answer_0(rid, ENOTDIR);
    327335                                        goto out;
    328336                                }
     337                               
    329338                                fs_node_t *fn;
    330339                                if (lflag & L_CREATE)
     
    335344                                            index);
    336345                                on_error(rc, goto out_with_answer);
     346                               
    337347                                if (fn) {
    338348                                        rc = ops->link(cur, fn, component);
     
    349359                                                (void) ops->node_put(fn);
    350360                                        }
    351                                 } else {
     361                                } else
    352362                                        ipc_answer_0(rid, ENOSPC);
    353                                 }
     363                               
    354364                                goto out;
    355                         }
     365                        }
     366                       
    356367                        ipc_answer_0(rid, ENOENT);
    357368                        goto out;
    358369                }
    359 
     370               
    360371                if (par) {
    361372                        rc = ops->node_put(par);
    362373                        on_error(rc, goto out_with_answer);
    363374                }
    364 
    365                 /* descend one level */
     375               
     376                /* Descend one level */
    366377                par = cur;
    367378                cur = tmp;
    368379                tmp = NULL;
    369380        }
    370 
    371         /* handle miss: excessive components */
     381       
     382        /* Handle miss: excessive components */
    372383        if (next <= last) {
    373384                bool has_children;
    374 
    375385                rc = ops->has_children(&has_children, cur);
    376386                on_error(rc, goto out_with_answer);
     387               
    377388                if (has_children)
    378389                        goto skip_miss;
    379 
     390               
    380391                if (lflag & (L_CREATE | L_LINK)) {
    381392                        if (!ops->is_directory(cur)) {
     
    383394                                goto out;
    384395                        }
    385 
    386                         /* collect next component */
     396                       
     397                        /* Collect next component */
    387398                        len = 0;
    388399                        while (next <= last) {
    389400                                if (ops->plb_get_char(next) == '/') {
    390                                         /* more than one component */
     401                                        /* More than one component */
    391402                                        ipc_answer_0(rid, ENOENT);
    392403                                        goto out;
    393404                                }
     405                               
    394406                                if (len + 1 == NAME_MAX) {
    395                                         /* component length overflow */
     407                                        /* Component length overflow */
    396408                                        ipc_answer_0(rid, ENAMETOOLONG);
    397409                                        goto out;
    398410                                }
     411                               
    399412                                component[len++] = ops->plb_get_char(next);
    400                                 next++; /* process next character */
     413                                /* Process next character */
     414                                next++;
    401415                        }
     416                       
    402417                        assert(len);
    403418                        component[len] = '\0';
    404                                
     419                       
    405420                        fs_node_t *fn;
    406421                        if (lflag & L_CREATE)
     
    409424                                rc = ops->node_get(&fn, dev_handle, index);
    410425                        on_error(rc, goto out_with_answer);
     426                       
    411427                        if (fn) {
    412428                                rc = ops->link(cur, fn, component);
     
    423439                                        (void) ops->node_put(fn);
    424440                                }
    425                         } else {
     441                        } else
    426442                                ipc_answer_0(rid, ENOSPC);
    427                         }
     443                       
    428444                        goto out;
    429445                }
     446               
    430447                ipc_answer_0(rid, ENOENT);
    431448                goto out;
    432449        }
     450       
    433451skip_miss:
    434 
    435         /* handle hit */
     452       
     453        /* Handle hit */
    436454        if (lflag & L_UNLINK) {
    437                 unsigned old_lnkcnt = ops->lnkcnt_get(cur);
     455                unsigned int old_lnkcnt = ops->lnkcnt_get(cur);
    438456                rc = ops->unlink(par, cur, component);
    439                 ipc_answer_5(rid, (ipcarg_t)rc, fs_handle, dev_handle,
     457                ipc_answer_5(rid, (ipcarg_t) rc, fs_handle, dev_handle,
    440458                    ops->index_get(cur), ops->size_get(cur), old_lnkcnt);
    441459                goto out;
    442460        }
     461       
    443462        if (((lflag & (L_CREATE | L_EXCLUSIVE)) == (L_CREATE | L_EXCLUSIVE)) ||
    444463            (lflag & L_LINK)) {
     
    446465                goto out;
    447466        }
     467       
    448468        if ((lflag & L_FILE) && (ops->is_directory(cur))) {
    449469                ipc_answer_0(rid, EISDIR);
    450470                goto out;
    451471        }
     472       
    452473        if ((lflag & L_DIRECTORY) && (ops->is_file(cur))) {
    453474                ipc_answer_0(rid, ENOTDIR);
    454475                goto out;
    455476        }
    456 
     477       
    457478out_with_answer:
     479       
    458480        if (rc == EOK) {
    459                 ipc_answer_5(rid, EOK, fs_handle, dev_handle,
     481                if (lflag & L_OPEN)
     482                        rc = ops->node_open(cur);
     483               
     484                ipc_answer_5(rid, rc, fs_handle, dev_handle,
    460485                    ops->index_get(cur), ops->size_get(cur),
    461486                    ops->lnkcnt_get(cur));
    462         } else {
     487        } else
    463488                ipc_answer_0(rid, rc);
    464         }
    465 
     489       
    466490out:
     491       
    467492        if (par)
    468493                (void) ops->node_put(par);
     494       
    469495        if (cur)
    470496                (void) ops->node_put(cur);
     497       
    471498        if (tmp)
    472499                (void) ops->node_put(tmp);
     
    478505        dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
    479506        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
     507       
    480508        fs_node_t *fn;
    481         int rc;
    482 
    483         rc = ops->node_get(&fn, dev_handle, index);
     509        int rc = ops->node_get(&fn, dev_handle, index);
    484510        on_error(rc, answer_and_return(rid, rc));
    485 
     511       
    486512        ipc_callid_t callid;
    487513        size_t size;
    488         if (!async_data_read_receive(&callid, &size) ||
    489             size != sizeof(struct stat)) {
     514        if ((!async_data_read_receive(&callid, &size)) ||
     515            (size != sizeof(struct stat))) {
     516                ops->node_put(fn);
    490517                ipc_answer_0(callid, EINVAL);
    491518                ipc_answer_0(rid, EINVAL);
    492519                return;
    493520        }
    494 
     521       
    495522        struct stat stat;
    496523        memset(&stat, 0, sizeof(struct stat));
     
    499526        stat.dev_handle = dev_handle;
    500527        stat.index = index;
    501         stat.lnkcnt = ops->lnkcnt_get(fn); 
     528        stat.lnkcnt = ops->lnkcnt_get(fn);
    502529        stat.is_file = ops->is_file(fn);
     530        stat.is_directory = ops->is_directory(fn);
    503531        stat.size = ops->size_get(fn);
    504 
     532        stat.device = ops->device_get(fn);
     533       
     534        ops->node_put(fn);
     535       
    505536        async_data_read_finalize(callid, &stat, sizeof(struct stat));
    506537        ipc_answer_0(rid, EOK);
     
    509540/** Open VFS triplet.
    510541 *
    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.
     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.
    515546 *
    516547 */
     
    531562        }
    532563       
    533         ipc_answer_3(rid, EOK, ops->size_get(fn), ops->lnkcnt_get(fn),
     564        rc = ops->node_open(fn);
     565        ipc_answer_3(rid, rc, ops->size_get(fn), ops->lnkcnt_get(fn),
    534566            (ops->is_file(fn) ? L_FILE : 0) | (ops->is_directory(fn) ? L_DIRECTORY : 0));
    535567       
Note: See TracChangeset for help on using the changeset viewer.