Changeset 1313ee9 in mainline for uspace/lib


Ignore:
Timestamp:
2009-12-13T15:17:08Z (16 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
963dd91
Parents:
fc6dd18
Message:

introduce device namespaces

  • add support for explicit open in libfs (needed by devfs, but also possibly for other filesystems which need to track some stateful information)
  • extend libfs to be more generic, make proper adjustments to libc, tmpfs and fat
  • various updates to make use of the device namespaces
  • code cleanup
Location:
uspace/lib
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/generic/devmap.c

    rfc6dd18 r1313ee9  
    3535#include <async.h>
    3636#include <errno.h>
     37#include <malloc.h>
     38#include <bool.h>
    3739
    3840static int devmap_phone_driver = -1;
     
    105107        aid_t req = async_send_2(phone, DEVMAP_DRIVER_REGISTER, 0, 0, &answer);
    106108       
    107         ipcarg_t retval = async_data_write_start(phone, name, str_size(name) + 1);
    108        
     109        ipcarg_t retval = async_data_write_start(phone, name, str_size(name));
    109110        if (retval != EOK) {
    110111                async_wait_for(req, NULL);
     
    126127/** Register new device.
    127128 *
    128  * @param name   Device name.
    129  * @param handle Output: Handle to the created instance of device.
     129 * @param namespace Namespace name.
     130 * @param fqdn      Fully qualified device name.
     131 * @param handle    Output: Handle to the created instance of device.
    130132 *
    131133 */
    132 int devmap_device_register(const char *name, dev_handle_t *handle)
     134int devmap_device_register(const char *fqdn, dev_handle_t *handle)
    133135{
    134136        int phone = devmap_get_phone(DEVMAP_DRIVER, IPC_FLAG_BLOCKING);
     
    143145            &answer);
    144146       
    145         ipcarg_t retval = async_data_write_start(phone, name, str_size(name) + 1);
    146        
     147        ipcarg_t retval = async_data_write_start(phone, fqdn, str_size(fqdn));
    147148        if (retval != EOK) {
    148149                async_wait_for(req, NULL);
     
    167168}
    168169
    169 int devmap_device_get_handle(const char *name, dev_handle_t *handle, unsigned int flags)
     170int devmap_device_get_handle(const char *fqdn, dev_handle_t *handle, unsigned int flags)
    170171{
    171172        int phone = devmap_get_phone(DEVMAP_CLIENT, flags);
     
    180181            &answer);
    181182       
    182         ipcarg_t retval = async_data_write_start(phone, name, str_size(name) + 1);
    183        
     183        ipcarg_t retval = async_data_write_start(phone, fqdn, str_size(fqdn));
    184184        if (retval != EOK) {
    185185                async_wait_for(req, NULL);
     
    202202       
    203203        return retval;
     204}
     205
     206int devmap_namespace_get_handle(const char *name, dev_handle_t *handle, unsigned int flags)
     207{
     208        int phone = devmap_get_phone(DEVMAP_CLIENT, flags);
     209       
     210        if (phone < 0)
     211                return phone;
     212       
     213        async_serialize_start();
     214       
     215        ipc_call_t answer;
     216        aid_t req = async_send_2(phone, DEVMAP_NAMESPACE_GET_HANDLE, flags, 0,
     217            &answer);
     218       
     219        ipcarg_t retval = async_data_write_start(phone, name, str_size(name));
     220        if (retval != EOK) {
     221                async_wait_for(req, NULL);
     222                async_serialize_end();
     223                return retval;
     224        }
     225       
     226        async_wait_for(req, &retval);
     227       
     228        async_serialize_end();
     229       
     230        if (retval != EOK) {
     231                if (handle != NULL)
     232                        *handle = (dev_handle_t) -1;
     233                return retval;
     234        }
     235       
     236        if (handle != NULL)
     237                *handle = (dev_handle_t) IPC_GET_ARG1(answer);
     238       
     239        return retval;
     240}
     241
     242devmap_handle_type_t devmap_handle_probe(dev_handle_t handle)
     243{
     244        int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING);
     245       
     246        if (phone < 0)
     247                return phone;
     248       
     249        ipcarg_t type;
     250        int retval = async_req_1_1(phone, DEVMAP_HANDLE_PROBE, handle, &type);
     251        if (retval != EOK)
     252                return DEV_HANDLE_NONE;
     253       
     254        return (devmap_handle_type_t) type;
    204255}
    205256
     
    227278       
    228279        ipcarg_t null_id;
    229         int retval = async_req_0_1(phone, DEVMAP_DEVICE_NULL_CREATE, &null_id);
     280        int retval = async_req_0_1(phone, DEVMAP_NULL_CREATE, &null_id);
    230281        if (retval != EOK)
    231282                return -1;
     
    241292                return;
    242293       
    243         async_req_1_0(phone, DEVMAP_DEVICE_NULL_DESTROY, (ipcarg_t) null_id);
    244 }
    245 
    246 ipcarg_t devmap_device_get_count(void)
    247 {
    248         int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING);
    249        
    250         if (phone < 0)
    251                 return 0;
    252        
     294        async_req_1_0(phone, DEVMAP_NULL_DESTROY, (ipcarg_t) null_id);
     295}
     296
     297static size_t devmap_count_namespaces_internal(int phone)
     298{
    253299        ipcarg_t count;
    254         int retval = async_req_0_1(phone, DEVMAP_DEVICE_GET_COUNT, &count);
     300        int retval = async_req_0_1(phone, DEVMAP_GET_NAMESPACE_COUNT, &count);
    255301        if (retval != EOK)
    256302                return 0;
     
    259305}
    260306
    261 ipcarg_t devmap_device_get_devices(ipcarg_t count, dev_desc_t *data)
    262 {
    263         int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING);
    264        
    265         if (phone < 0)
    266                 return 0;
    267        
    268         async_serialize_start();
    269        
    270         ipc_call_t answer;
    271         aid_t req = async_send_0(phone, DEVMAP_DEVICE_GET_DEVICES, &answer);
    272        
    273         ipcarg_t retval = async_data_read_start(phone, data, count * sizeof(dev_desc_t));
    274        
    275         if (retval != EOK) {
    276                 async_wait_for(req, NULL);
    277                 async_serialize_end();
    278                 return 0;
    279         }
    280        
    281         async_wait_for(req, &retval);
    282        
    283         async_serialize_end();
    284        
     307static size_t devmap_count_devices_internal(int phone, dev_handle_t ns_handle)
     308{
     309        ipcarg_t count;
     310        int retval = async_req_1_1(phone, DEVMAP_GET_DEVICE_COUNT, ns_handle, &count);
    285311        if (retval != EOK)
    286312                return 0;
    287313       
    288         return IPC_GET_ARG1(answer);
    289 }
     314        return count;
     315}
     316
     317size_t devmap_count_namespaces(void)
     318{
     319        int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING);
     320       
     321        if (phone < 0)
     322                return 0;
     323       
     324        return devmap_count_namespaces_internal(phone);
     325}
     326
     327size_t devmap_count_devices(dev_handle_t ns_handle)
     328{
     329        int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING);
     330       
     331        if (phone < 0)
     332                return 0;
     333       
     334        return devmap_count_devices_internal(phone, ns_handle);
     335}
     336
     337size_t devmap_get_namespaces(dev_desc_t **data)
     338{
     339        int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING);
     340       
     341        if (phone < 0)
     342                return 0;
     343       
     344        /* Loop until namespaces read succesful */
     345        while (true) {
     346                size_t count = devmap_count_namespaces_internal(phone);
     347                if (count == 0)
     348                        return 0;
     349               
     350                dev_desc_t *devs = (dev_desc_t *) calloc(count, sizeof(dev_desc_t));
     351                if (devs == NULL)
     352                        return 0;
     353               
     354                async_serialize_start();
     355               
     356                ipc_call_t answer;
     357                aid_t req = async_send_0(phone, DEVMAP_GET_NAMESPACES, &answer);
     358               
     359                int rc = async_data_read_start(phone, devs, count * sizeof(dev_desc_t));
     360                if (rc == EOVERFLOW) {
     361                        /*
     362                         * Number of namespaces has changed since
     363                         * the last call of DEVMAP_DEVICE_GET_NAMESPACE_COUNT
     364                         */
     365                        async_serialize_end();
     366                        free(devs);
     367                        continue;
     368                }
     369               
     370                if (rc != EOK) {
     371                        async_wait_for(req, NULL);
     372                        async_serialize_end();
     373                        free(devs);
     374                        return 0;
     375                }
     376               
     377                ipcarg_t retval;
     378                async_wait_for(req, &retval);
     379                async_serialize_end();
     380               
     381                if (retval != EOK)
     382                        return 0;
     383               
     384                *data = devs;
     385                return count;
     386        }
     387}
     388
     389size_t devmap_get_devices(dev_handle_t ns_handle, dev_desc_t **data)
     390{
     391        int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING);
     392       
     393        if (phone < 0)
     394                return 0;
     395       
     396        /* Loop until namespaces read succesful */
     397        while (true) {
     398                size_t count = devmap_count_devices_internal(phone, ns_handle);
     399                if (count == 0)
     400                        return 0;
     401               
     402                dev_desc_t *devs = (dev_desc_t *) calloc(count, sizeof(dev_desc_t));
     403                if (devs == NULL)
     404                        return 0;
     405               
     406                async_serialize_start();
     407               
     408                ipc_call_t answer;
     409                aid_t req = async_send_1(phone, DEVMAP_GET_DEVICES, ns_handle, &answer);
     410               
     411                int rc = async_data_read_start(phone, devs, count * sizeof(dev_desc_t));
     412                if (rc == EOVERFLOW) {
     413                        /*
     414                         * Number of devices has changed since
     415                         * the last call of DEVMAP_DEVICE_GET_DEVICE_COUNT
     416                         */
     417                        async_serialize_end();
     418                        free(devs);
     419                        continue;
     420                }
     421               
     422                if (rc != EOK) {
     423                        async_wait_for(req, NULL);
     424                        async_serialize_end();
     425                        free(devs);
     426                        return 0;
     427                }
     428               
     429                ipcarg_t retval;
     430                async_wait_for(req, &retval);
     431                async_serialize_end();
     432               
     433                if (retval != EOK)
     434                        return 0;
     435               
     436                *data = devs;
     437                return count;
     438        }
     439}
  • uspace/lib/libc/generic/vfs/vfs.c

    rfc6dd18 r1313ee9  
    117117}
    118118
    119 int mount(const char *fs_name, const char *mp, const char *dev,
     119int mount(const char *fs_name, const char *mp, const char *fqdn,
    120120    const char *opts, unsigned int flags)
    121121{
     
    126126        dev_handle_t dev_handle;
    127127       
    128         res = devmap_device_get_handle(dev, &dev_handle, flags);
     128        res = devmap_device_get_handle(fqdn, &dev_handle, flags);
    129129        if (res != EOK)
    130130                return res;
     
    703703        rc = fstat(fildes, &stat);
    704704
    705         if (!stat.devfs_stat.device)
     705        if (!stat.device)
    706706                return -1;
    707707       
    708         return devmap_device_connect(stat.devfs_stat.device, 0);
     708        return devmap_device_connect(stat.device, 0);
    709709}
    710710
  • uspace/lib/libc/include/devmap.h

    rfc6dd18 r1313ee9  
    3838#include <ipc/devmap.h>
    3939#include <async.h>
     40#include <bool.h>
    4041
    4142extern int devmap_get_phone(devmap_interface_t, unsigned int);
     
    4647
    4748extern int devmap_device_get_handle(const char *, dev_handle_t *, unsigned int);
     49extern int devmap_namespace_get_handle(const char *, dev_handle_t *, unsigned int);
     50extern devmap_handle_type_t devmap_handle_probe(dev_handle_t);
     51
    4852extern int devmap_device_connect(dev_handle_t, unsigned int);
    4953
     
    5155extern void devmap_null_destroy(int);
    5256
    53 extern ipcarg_t devmap_device_get_count(void);
    54 extern ipcarg_t devmap_device_get_devices(ipcarg_t, dev_desc_t *);
     57extern size_t devmap_count_namespaces(void);
     58extern size_t devmap_count_devices(dev_handle_t);
     59
     60extern size_t devmap_get_namespaces(dev_desc_t **);
     61extern size_t devmap_get_devices(dev_handle_t, dev_desc_t **);
    5562
    5663#endif
  • uspace/lib/libc/include/ipc/devmap.h

    rfc6dd18 r1313ee9  
    4343
    4444typedef enum {
     45        DEV_HANDLE_NONE,
     46        DEV_HANDLE_NAMESPACE,
     47        DEV_HANDLE_DEVICE
     48} devmap_handle_type_t;
     49
     50typedef enum {
    4551        DEVMAP_DRIVER_REGISTER = IPC_FIRST_USER_METHOD,
    4652        DEVMAP_DRIVER_UNREGISTER,
    4753        DEVMAP_DEVICE_REGISTER,
    4854        DEVMAP_DEVICE_UNREGISTER,
    49         DEVMAP_DEVICE_GET_NAME,
    5055        DEVMAP_DEVICE_GET_HANDLE,
    51         DEVMAP_DEVICE_NULL_CREATE,
    52         DEVMAP_DEVICE_NULL_DESTROY,
    53         DEVMAP_DEVICE_GET_COUNT,
    54         DEVMAP_DEVICE_GET_DEVICES
     56        DEVMAP_NAMESPACE_GET_HANDLE,
     57        DEVMAP_HANDLE_PROBE,
     58        DEVMAP_NULL_CREATE,
     59        DEVMAP_NULL_DESTROY,
     60        DEVMAP_GET_NAMESPACE_COUNT,
     61        DEVMAP_GET_DEVICE_COUNT,
     62        DEVMAP_GET_NAMESPACES,
     63        DEVMAP_GET_DEVICES
    5564} devmap_request_t;
    5665
  • uspace/lib/libc/include/sys/stat.h

    rfc6dd18 r1313ee9  
    4242
    4343struct stat {
    44         fs_handle_t     fs_handle;
    45         dev_handle_t    dev_handle;
    46         fs_index_t      index;
    47         unsigned        lnkcnt;
    48         bool            is_file;
    49         off_t           size;
    50         union {
    51                 struct {
    52                         dev_handle_t    device;
    53                 } devfs_stat;
    54         };
     44        fs_handle_t fs_handle;
     45        dev_handle_t dev_handle;
     46        fs_index_t index;
     47        unsigned int lnkcnt;
     48        bool is_file;
     49        bool is_directory;
     50        off_t size;
     51        dev_handle_t device;
    5552};
    5653
  • uspace/lib/libfs/libfs.c

    rfc6dd18 r1313ee9  
    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       
  • uspace/lib/libfs/libfs.h

    rfc6dd18 r1313ee9  
    6464        int (* match)(fs_node_t **, fs_node_t *, const char *);
    6565        int (* node_get)(fs_node_t **, dev_handle_t, fs_index_t);
     66        int (* node_open)(fs_node_t *);
    6667        int (* node_put)(fs_node_t *);
    6768        int (* create)(fs_node_t **, dev_handle_t, int);
     
    7677        fs_index_t (* index_get)(fs_node_t *);
    7778        size_t (* size_get)(fs_node_t *);
    78         unsigned (* lnkcnt_get)(fs_node_t *);
     79        unsigned int (* lnkcnt_get)(fs_node_t *);
    7980        char (* plb_get_char)(unsigned pos);
    8081        bool (* is_directory)(fs_node_t *);
    8182        bool (* is_file)(fs_node_t *);
     83        dev_handle_t (* device_get)(fs_node_t *);
    8284} libfs_ops_t;
    8385
Note: See TracChangeset for help on using the changeset viewer.