Changeset ee24574 in mainline for uspace/srv/fs/locfs/locfs_ops.c


Ignore:
Timestamp:
2011-08-18T08:00:42Z (13 years ago)
Author:
Petr Koupy <petr.koupy@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a92cf94f
Parents:
0f963cb (diff), c53a705 (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 libposix changes.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/locfs/locfs_ops.c

    r0f963cb ree24574  
    3232
    3333/**
    34  * @file devfs_ops.c
    35  * @brief Implementation of VFS operations for the devfs file system server.
     34 * @file locfs_ops.c
     35 * @brief Implementation of VFS operations for the locfs file system server.
    3636 */
    3737
     
    4444#include <fibril_synch.h>
    4545#include <adt/hash_table.h>
    46 #include <ipc/devmap.h>
     46#include <ipc/loc.h>
    4747#include <sys/stat.h>
    4848#include <libfs.h>
    4949#include <assert.h>
    50 #include "devfs.h"
    51 #include "devfs_ops.h"
     50#include "locfs.h"
     51#include "locfs_ops.h"
    5252
    5353typedef struct {
    54         devmap_handle_type_t type;
    55         devmap_handle_t handle;
    56 } devfs_node_t;
    57 
    58 /** Opened devices structure */
     54        loc_object_type_t type;
     55        service_id_t service_id;
     56} locfs_node_t;
     57
     58/** Opened services structure */
    5959typedef struct {
    60         devmap_handle_t handle;
     60        service_id_t service_id;
    6161        async_sess_t *sess;       /**< If NULL, the structure is incomplete. */
    6262        size_t refcount;
    6363        link_t link;
    6464        fibril_condvar_t cv;      /**< Broadcast when completed. */
    65 } device_t;
    66 
    67 /** Hash table of opened devices */
    68 static hash_table_t devices;
     65} service_t;
     66
     67/** Hash table of opened services */
     68static hash_table_t services;
    6969
    7070/** Hash table mutex */
    71 static FIBRIL_MUTEX_INITIALIZE(devices_mutex);
    72 
    73 #define DEVICES_KEYS        1
    74 #define DEVICES_KEY_HANDLE  0
    75 #define DEVICES_BUCKETS     256
     71static FIBRIL_MUTEX_INITIALIZE(services_mutex);
     72
     73#define SERVICES_KEYS        1
     74#define SERVICES_KEY_HANDLE  0
     75#define SERVICES_BUCKETS     256
    7676
    7777/* Implementation of hash table interface for the nodes hash table. */
    78 static hash_index_t devices_hash(unsigned long key[])
    79 {
    80         return key[DEVICES_KEY_HANDLE] % DEVICES_BUCKETS;
    81 }
    82 
    83 static int devices_compare(unsigned long key[], hash_count_t keys, link_t *item)
    84 {
    85         device_t *dev = hash_table_get_instance(item, device_t, link);
    86         return (dev->handle == (devmap_handle_t) key[DEVICES_KEY_HANDLE]);
    87 }
    88 
    89 static void devices_remove_callback(link_t *item)
    90 {
    91         free(hash_table_get_instance(item, device_t, link));
    92 }
    93 
    94 static hash_table_operations_t devices_ops = {
    95         .hash = devices_hash,
    96         .compare = devices_compare,
    97         .remove_callback = devices_remove_callback
     78static hash_index_t services_hash(unsigned long key[])
     79{
     80        return key[SERVICES_KEY_HANDLE] % SERVICES_BUCKETS;
     81}
     82
     83static int services_compare(unsigned long key[], hash_count_t keys, link_t *item)
     84{
     85        service_t *dev = hash_table_get_instance(item, service_t, link);
     86        return (dev->service_id == (service_id_t) key[SERVICES_KEY_HANDLE]);
     87}
     88
     89static void services_remove_callback(link_t *item)
     90{
     91        free(hash_table_get_instance(item, service_t, link));
     92}
     93
     94static hash_table_operations_t services_ops = {
     95        .hash = services_hash,
     96        .compare = services_compare,
     97        .remove_callback = services_remove_callback
    9898};
    9999
    100 static int devfs_node_get_internal(fs_node_t **rfn, devmap_handle_type_t type,
    101     devmap_handle_t handle)
    102 {
    103         devfs_node_t *node = (devfs_node_t *) malloc(sizeof(devfs_node_t));
     100static int locfs_node_get_internal(fs_node_t **rfn, loc_object_type_t type,
     101    service_id_t service_id)
     102{
     103        locfs_node_t *node = (locfs_node_t *) malloc(sizeof(locfs_node_t));
    104104        if (node == NULL) {
    105105                *rfn = NULL;
     
    116116        fs_node_initialize(*rfn);
    117117        node->type = type;
    118         node->handle = handle;
     118        node->service_id = service_id;
    119119       
    120120        (*rfn)->data = node;
     
    122122}
    123123
    124 static int devfs_root_get(fs_node_t **rfn, devmap_handle_t devmap_handle)
    125 {
    126         return devfs_node_get_internal(rfn, DEV_HANDLE_NONE, 0);
    127 }
    128 
    129 static int devfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component)
    130 {
    131         devfs_node_t *node = (devfs_node_t *) pfn->data;
     124static int locfs_root_get(fs_node_t **rfn, service_id_t service_id)
     125{
     126        return locfs_node_get_internal(rfn, LOC_OBJECT_NONE, 0);
     127}
     128
     129static int locfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component)
     130{
     131        locfs_node_t *node = (locfs_node_t *) pfn->data;
    132132        int ret;
    133133       
    134         if (node->handle == 0) {
     134        if (node->service_id == 0) {
    135135                /* Root directory */
    136136               
    137                 dev_desc_t *devs;
    138                 size_t count = devmap_get_namespaces(&devs);
     137                loc_sdesc_t *nspaces;
     138                size_t count = loc_get_namespaces(&nspaces);
    139139               
    140140                if (count > 0) {
     
    142142                        for (pos = 0; pos < count; pos++) {
    143143                                /* Ignore root namespace */
    144                                 if (str_cmp(devs[pos].name, "") == 0)
     144                                if (str_cmp(nspaces[pos].name, "") == 0)
    145145                                        continue;
    146146                               
    147                                 if (str_cmp(devs[pos].name, component) == 0) {
    148                                         ret = devfs_node_get_internal(rfn, DEV_HANDLE_NAMESPACE, devs[pos].handle);
    149                                         free(devs);
     147                                if (str_cmp(nspaces[pos].name, component) == 0) {
     148                                        ret = locfs_node_get_internal(rfn, LOC_OBJECT_NAMESPACE, nspaces[pos].id);
     149                                        free(nspaces);
    150150                                        return ret;
    151151                                }
    152152                        }
    153153                       
    154                         free(devs);
     154                        free(nspaces);
    155155                }
    156156               
    157157                /* Search root namespace */
    158                 devmap_handle_t namespace;
    159                 if (devmap_namespace_get_handle("", &namespace, 0) == EOK) {
    160                         count = devmap_get_devices(namespace, &devs);
     158                service_id_t namespace;
     159                loc_sdesc_t *svcs;
     160                if (loc_namespace_get_id("", &namespace, 0) == EOK) {
     161                        count = loc_get_services(namespace, &svcs);
    161162                       
    162163                        if (count > 0) {
    163164                                size_t pos;
    164165                                for (pos = 0; pos < count; pos++) {
    165                                         if (str_cmp(devs[pos].name, component) == 0) {
    166                                                 ret = devfs_node_get_internal(rfn, DEV_HANDLE_DEVICE, devs[pos].handle);
    167                                                 free(devs);
     166                                        if (str_cmp(svcs[pos].name, component) == 0) {
     167                                                ret = locfs_node_get_internal(rfn, LOC_OBJECT_SERVICE, svcs[pos].id);
     168                                                free(svcs);
    168169                                                return ret;
    169170                                        }
    170171                                }
    171172                               
    172                                 free(devs);
     173                                free(svcs);
    173174                        }
    174175                }
     
    178179        }
    179180       
    180         if (node->type == DEV_HANDLE_NAMESPACE) {
     181        if (node->type == LOC_OBJECT_NAMESPACE) {
    181182                /* Namespace directory */
    182183               
    183                 dev_desc_t *devs;
    184                 size_t count = devmap_get_devices(node->handle, &devs);
     184                loc_sdesc_t *svcs;
     185                size_t count = loc_get_services(node->service_id, &svcs);
    185186                if (count > 0) {
    186187                        size_t pos;
    187188                        for (pos = 0; pos < count; pos++) {
    188                                 if (str_cmp(devs[pos].name, component) == 0) {
    189                                         ret = devfs_node_get_internal(rfn, DEV_HANDLE_DEVICE, devs[pos].handle);
    190                                         free(devs);
     189                                if (str_cmp(svcs[pos].name, component) == 0) {
     190                                        ret = locfs_node_get_internal(rfn, LOC_OBJECT_SERVICE, svcs[pos].id);
     191                                        free(svcs);
    191192                                        return ret;
    192193                                }
    193194                        }
    194195                       
    195                         free(devs);
     196                        free(svcs);
    196197                }
    197198               
     
    204205}
    205206
    206 static int devfs_node_get(fs_node_t **rfn, devmap_handle_t devmap_handle, fs_index_t index)
    207 {
    208         return devfs_node_get_internal(rfn, devmap_handle_probe(index), index);
    209 }
    210 
    211 static int devfs_node_open(fs_node_t *fn)
    212 {
    213         devfs_node_t *node = (devfs_node_t *) fn->data;
    214        
    215         if (node->handle == 0) {
     207static int locfs_node_get(fs_node_t **rfn, service_id_t service_id, fs_index_t index)
     208{
     209        return locfs_node_get_internal(rfn, loc_id_probe(index), index);
     210}
     211
     212static int locfs_node_open(fs_node_t *fn)
     213{
     214        locfs_node_t *node = (locfs_node_t *) fn->data;
     215       
     216        if (node->service_id == 0) {
    216217                /* Root directory */
    217218                return EOK;
    218219        }
    219220       
    220         devmap_handle_type_t type = devmap_handle_probe(node->handle);
    221        
    222         if (type == DEV_HANDLE_NAMESPACE) {
     221        loc_object_type_t type = loc_id_probe(node->service_id);
     222       
     223        if (type == LOC_OBJECT_NAMESPACE) {
    223224                /* Namespace directory */
    224225                return EOK;
    225226        }
    226227       
    227         if (type == DEV_HANDLE_DEVICE) {
     228        if (type == LOC_OBJECT_SERVICE) {
    228229                /* Device node */
    229230               
    230231                unsigned long key[] = {
    231                         [DEVICES_KEY_HANDLE] = (unsigned long) node->handle
     232                        [SERVICES_KEY_HANDLE] = (unsigned long) node->service_id
    232233                };
    233234                link_t *lnk;
    234235               
    235                 fibril_mutex_lock(&devices_mutex);
     236                fibril_mutex_lock(&services_mutex);
    236237restart:
    237                 lnk = hash_table_find(&devices, key);
     238                lnk = hash_table_find(&services, key);
    238239                if (lnk == NULL) {
    239                         device_t *dev = (device_t *) malloc(sizeof(device_t));
     240                        service_t *dev = (service_t *) malloc(sizeof(service_t));
    240241                        if (dev == NULL) {
    241                                 fibril_mutex_unlock(&devices_mutex);
     242                                fibril_mutex_unlock(&services_mutex);
    242243                                return ENOMEM;
    243244                        }
    244245                       
    245                         dev->handle = node->handle;
     246                        dev->service_id = node->service_id;
    246247                       
    247248                        /* Mark as incomplete */
     
    255256                         * below.
    256257                         */
    257                         hash_table_insert(&devices, key, &dev->link);
     258                        hash_table_insert(&services, key, &dev->link);
    258259                       
    259260                        /*
    260                          * Drop the mutex to allow recursive devfs requests.
     261                         * Drop the mutex to allow recursive locfs requests.
    261262                         */
    262                         fibril_mutex_unlock(&devices_mutex);
    263                        
    264                         async_sess_t *sess = devmap_device_connect(EXCHANGE_SERIALIZE,
    265                             node->handle, 0);
    266                        
    267                         fibril_mutex_lock(&devices_mutex);
     263                        fibril_mutex_unlock(&services_mutex);
     264                       
     265                        async_sess_t *sess = loc_service_connect(
     266                            EXCHANGE_SERIALIZE, node->service_id, 0);
     267                       
     268                        fibril_mutex_lock(&services_mutex);
    268269                       
    269270                        /*
     
    278279                                 * entry and free the device structure.
    279280                                 */
    280                                 hash_table_remove(&devices, key, DEVICES_KEYS);
    281                                 fibril_mutex_unlock(&devices_mutex);
     281                                hash_table_remove(&services, key, SERVICES_KEYS);
     282                                fibril_mutex_unlock(&services_mutex);
    282283                               
    283284                                return ENOENT;
     
    287288                        dev->sess = sess;
    288289                } else {
    289                         device_t *dev = hash_table_get_instance(lnk, device_t, link);
     290                        service_t *dev = hash_table_get_instance(lnk, service_t, link);
    290291                       
    291292                        if (!dev->sess) {
     
    297298                                 * fibril_condvar_wait().
    298299                                 */
    299                                 fibril_condvar_wait(&dev->cv, &devices_mutex);
     300                                fibril_condvar_wait(&dev->cv, &services_mutex);
    300301                                goto restart;
    301302                        }
     
    304305                }
    305306               
    306                 fibril_mutex_unlock(&devices_mutex);
     307                fibril_mutex_unlock(&services_mutex);
    307308               
    308309                return EOK;
     
    312313}
    313314
    314 static int devfs_node_put(fs_node_t *fn)
     315static int locfs_node_put(fs_node_t *fn)
    315316{
    316317        free(fn->data);
     
    319320}
    320321
    321 static int devfs_create_node(fs_node_t **rfn, devmap_handle_t devmap_handle, int lflag)
     322static int locfs_create_node(fs_node_t **rfn, service_id_t service_id, int lflag)
    322323{
    323324        assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY));
     
    327328}
    328329
    329 static int devfs_destroy_node(fs_node_t *fn)
     330static int locfs_destroy_node(fs_node_t *fn)
    330331{
    331332        return ENOTSUP;
    332333}
    333334
    334 static int devfs_link_node(fs_node_t *pfn, fs_node_t *cfn, const char *nm)
     335static int locfs_link_node(fs_node_t *pfn, fs_node_t *cfn, const char *nm)
    335336{
    336337        return ENOTSUP;
    337338}
    338339
    339 static int devfs_unlink_node(fs_node_t *pfn, fs_node_t *cfn, const char *nm)
     340static int locfs_unlink_node(fs_node_t *pfn, fs_node_t *cfn, const char *nm)
    340341{
    341342        return ENOTSUP;
    342343}
    343344
    344 static int devfs_has_children(bool *has_children, fs_node_t *fn)
    345 {
    346         devfs_node_t *node = (devfs_node_t *) fn->data;
    347        
    348         if (node->handle == 0) {
    349                 size_t count = devmap_count_namespaces();
     345static int locfs_has_children(bool *has_children, fs_node_t *fn)
     346{
     347        locfs_node_t *node = (locfs_node_t *) fn->data;
     348       
     349        if (node->service_id == 0) {
     350                size_t count = loc_count_namespaces();
    350351                if (count > 0) {
    351352                        *has_children = true;
     
    354355               
    355356                /* Root namespace */
    356                 devmap_handle_t namespace;
    357                 if (devmap_namespace_get_handle("", &namespace, 0) == EOK) {
    358                         count = devmap_count_devices(namespace);
     357                service_id_t namespace;
     358                if (loc_namespace_get_id("", &namespace, 0) == EOK) {
     359                        count = loc_count_services(namespace);
    359360                        if (count > 0) {
    360361                                *has_children = true;
     
    367368        }
    368369       
    369         if (node->type == DEV_HANDLE_NAMESPACE) {
    370                 size_t count = devmap_count_devices(node->handle);
     370        if (node->type == LOC_OBJECT_NAMESPACE) {
     371                size_t count = loc_count_services(node->service_id);
    371372                if (count > 0) {
    372373                        *has_children = true;
     
    382383}
    383384
    384 static fs_index_t devfs_index_get(fs_node_t *fn)
    385 {
    386         devfs_node_t *node = (devfs_node_t *) fn->data;
    387         return node->handle;
    388 }
    389 
    390 static aoff64_t devfs_size_get(fs_node_t *fn)
     385static fs_index_t locfs_index_get(fs_node_t *fn)
     386{
     387        locfs_node_t *node = (locfs_node_t *) fn->data;
     388        return node->service_id;
     389}
     390
     391static aoff64_t locfs_size_get(fs_node_t *fn)
    391392{
    392393        return 0;
    393394}
    394395
    395 static unsigned int devfs_lnkcnt_get(fs_node_t *fn)
    396 {
    397         devfs_node_t *node = (devfs_node_t *) fn->data;
    398        
    399         if (node->handle == 0)
     396static unsigned int locfs_lnkcnt_get(fs_node_t *fn)
     397{
     398        locfs_node_t *node = (locfs_node_t *) fn->data;
     399       
     400        if (node->service_id == 0)
    400401                return 0;
    401402       
     
    403404}
    404405
    405 static bool devfs_is_directory(fs_node_t *fn)
    406 {
    407         devfs_node_t *node = (devfs_node_t *) fn->data;
    408        
    409         return ((node->type == DEV_HANDLE_NONE) || (node->type == DEV_HANDLE_NAMESPACE));
    410 }
    411 
    412 static bool devfs_is_file(fs_node_t *fn)
    413 {
    414         devfs_node_t *node = (devfs_node_t *) fn->data;
    415        
    416         return (node->type == DEV_HANDLE_DEVICE);
    417 }
    418 
    419 static devmap_handle_t devfs_device_get(fs_node_t *fn)
    420 {
    421         devfs_node_t *node = (devfs_node_t *) fn->data;
    422        
    423         if (node->type == DEV_HANDLE_DEVICE)
    424                 return node->handle;
     406static bool locfs_is_directory(fs_node_t *fn)
     407{
     408        locfs_node_t *node = (locfs_node_t *) fn->data;
     409       
     410        return ((node->type == LOC_OBJECT_NONE) || (node->type == LOC_OBJECT_NAMESPACE));
     411}
     412
     413static bool locfs_is_file(fs_node_t *fn)
     414{
     415        locfs_node_t *node = (locfs_node_t *) fn->data;
     416       
     417        return (node->type == LOC_OBJECT_SERVICE);
     418}
     419
     420static service_id_t locfs_device_get(fs_node_t *fn)
     421{
     422        locfs_node_t *node = (locfs_node_t *) fn->data;
     423       
     424        if (node->type == LOC_OBJECT_SERVICE)
     425                return node->service_id;
    425426       
    426427        return 0;
     
    428429
    429430/** libfs operations */
    430 libfs_ops_t devfs_libfs_ops = {
    431         .root_get = devfs_root_get,
    432         .match = devfs_match,
    433         .node_get = devfs_node_get,
    434         .node_open = devfs_node_open,
    435         .node_put = devfs_node_put,
    436         .create = devfs_create_node,
    437         .destroy = devfs_destroy_node,
    438         .link = devfs_link_node,
    439         .unlink = devfs_unlink_node,
    440         .has_children = devfs_has_children,
    441         .index_get = devfs_index_get,
    442         .size_get = devfs_size_get,
    443         .lnkcnt_get = devfs_lnkcnt_get,
    444         .is_directory = devfs_is_directory,
    445         .is_file = devfs_is_file,
    446         .device_get = devfs_device_get
     431libfs_ops_t locfs_libfs_ops = {
     432        .root_get = locfs_root_get,
     433        .match = locfs_match,
     434        .node_get = locfs_node_get,
     435        .node_open = locfs_node_open,
     436        .node_put = locfs_node_put,
     437        .create = locfs_create_node,
     438        .destroy = locfs_destroy_node,
     439        .link = locfs_link_node,
     440        .unlink = locfs_unlink_node,
     441        .has_children = locfs_has_children,
     442        .index_get = locfs_index_get,
     443        .size_get = locfs_size_get,
     444        .lnkcnt_get = locfs_lnkcnt_get,
     445        .is_directory = locfs_is_directory,
     446        .is_file = locfs_is_file,
     447        .device_get = locfs_device_get
    447448};
    448449
    449 bool devfs_init(void)
    450 {
    451         if (!hash_table_create(&devices, DEVICES_BUCKETS,
    452             DEVICES_KEYS, &devices_ops))
     450bool locfs_init(void)
     451{
     452        if (!hash_table_create(&services, SERVICES_BUCKETS,
     453            SERVICES_KEYS, &services_ops))
    453454                return false;
    454455       
     
    456457}
    457458
    458 static int devfs_mounted(devmap_handle_t devmap_handle, const char *opts,
     459static int locfs_mounted(service_id_t service_id, const char *opts,
    459460    fs_index_t *index, aoff64_t *size, unsigned *lnkcnt)
    460461{
     
    465466}
    466467
    467 static int devfs_unmounted(devmap_handle_t devmap_handle)
     468static int locfs_unmounted(service_id_t service_id)
    468469{
    469470        return ENOTSUP;
     
    471472
    472473static int
    473 devfs_read(devmap_handle_t devmap_handle, fs_index_t index, aoff64_t pos,
     474locfs_read(service_id_t service_id, fs_index_t index, aoff64_t pos,
    474475    size_t *rbytes)
    475476{
     
    482483                }
    483484               
    484                 dev_desc_t *desc;
    485                 size_t count = devmap_get_namespaces(&desc);
     485                loc_sdesc_t *desc;
     486                size_t count = loc_get_namespaces(&desc);
    486487               
    487488                /* Get rid of root namespace */
     
    507508               
    508509                /* Search root namespace */
    509                 devmap_handle_t namespace;
    510                 if (devmap_namespace_get_handle("", &namespace, 0) == EOK) {
    511                         count = devmap_get_devices(namespace, &desc);
     510                service_id_t namespace;
     511                if (loc_namespace_get_id("", &namespace, 0) == EOK) {
     512                        count = loc_get_services(namespace, &desc);
    512513                       
    513514                        if (pos < count) {
     
    525526        }
    526527       
    527         devmap_handle_type_t type = devmap_handle_probe(index);
    528        
    529         if (type == DEV_HANDLE_NAMESPACE) {
     528        loc_object_type_t type = loc_id_probe(index);
     529       
     530        if (type == LOC_OBJECT_NAMESPACE) {
    530531                /* Namespace directory */
    531532                ipc_callid_t callid;
     
    536537                }
    537538               
    538                 dev_desc_t *desc;
    539                 size_t count = devmap_get_devices(index, &desc);
     539                loc_sdesc_t *desc;
     540                size_t count = loc_get_services(index, &desc);
    540541               
    541542                if (pos < count) {
     
    551552        }
    552553       
    553         if (type == DEV_HANDLE_DEVICE) {
     554        if (type == LOC_OBJECT_SERVICE) {
    554555                /* Device node */
    555556               
    556557                unsigned long key[] = {
    557                         [DEVICES_KEY_HANDLE] = (unsigned long) index
     558                        [SERVICES_KEY_HANDLE] = (unsigned long) index
    558559                };
    559560               
    560                 fibril_mutex_lock(&devices_mutex);
    561                 link_t *lnk = hash_table_find(&devices, key);
     561                fibril_mutex_lock(&services_mutex);
     562                link_t *lnk = hash_table_find(&services, key);
    562563                if (lnk == NULL) {
    563                         fibril_mutex_unlock(&devices_mutex);
     564                        fibril_mutex_unlock(&services_mutex);
    564565                        return ENOENT;
    565566                }
    566567               
    567                 device_t *dev = hash_table_get_instance(lnk, device_t, link);
     568                service_t *dev = hash_table_get_instance(lnk, service_t, link);
    568569                assert(dev->sess);
    569570               
    570571                ipc_callid_t callid;
    571572                if (!async_data_read_receive(&callid, NULL)) {
    572                         fibril_mutex_unlock(&devices_mutex);
     573                        fibril_mutex_unlock(&services_mutex);
    573574                        async_answer_0(callid, EINVAL);
    574575                        return EINVAL;
     
    579580               
    580581                ipc_call_t answer;
    581                 aid_t msg = async_send_4(exch, VFS_OUT_READ, devmap_handle,
     582                aid_t msg = async_send_4(exch, VFS_OUT_READ, service_id,
    582583                    index, LOWER32(pos), UPPER32(pos), &answer);
    583584               
     
    587588                async_exchange_end(exch);
    588589               
    589                 fibril_mutex_unlock(&devices_mutex);
     590                fibril_mutex_unlock(&services_mutex);
    590591               
    591592                /* Wait for reply from the driver. */
     
    601602
    602603static int
    603 devfs_write(devmap_handle_t devmap_handle, fs_index_t index, aoff64_t pos,
     604locfs_write(service_id_t service_id, fs_index_t index, aoff64_t pos,
    604605    size_t *wbytes, aoff64_t *nsize)
    605606{
     
    607608                return ENOTSUP;
    608609       
    609         devmap_handle_type_t type = devmap_handle_probe(index);
    610        
    611         if (type == DEV_HANDLE_NAMESPACE) {
     610        loc_object_type_t type = loc_id_probe(index);
     611       
     612        if (type == LOC_OBJECT_NAMESPACE) {
    612613                /* Namespace directory */
    613614                return ENOTSUP;
    614615        }
    615616       
    616         if (type == DEV_HANDLE_DEVICE) {
     617        if (type == LOC_OBJECT_SERVICE) {
    617618                /* Device node */
    618619                unsigned long key[] = {
    619                         [DEVICES_KEY_HANDLE] = (unsigned long) index
     620                        [SERVICES_KEY_HANDLE] = (unsigned long) index
    620621                };
    621622               
    622                 fibril_mutex_lock(&devices_mutex);
    623                 link_t *lnk = hash_table_find(&devices, key);
     623                fibril_mutex_lock(&services_mutex);
     624                link_t *lnk = hash_table_find(&services, key);
    624625                if (lnk == NULL) {
    625                         fibril_mutex_unlock(&devices_mutex);
     626                        fibril_mutex_unlock(&services_mutex);
    626627                        return ENOENT;
    627628                }
    628629               
    629                 device_t *dev = hash_table_get_instance(lnk, device_t, link);
     630                service_t *dev = hash_table_get_instance(lnk, service_t, link);
    630631                assert(dev->sess);
    631632               
    632633                ipc_callid_t callid;
    633634                if (!async_data_write_receive(&callid, NULL)) {
    634                         fibril_mutex_unlock(&devices_mutex);
     635                        fibril_mutex_unlock(&services_mutex);
    635636                        async_answer_0(callid, EINVAL);
    636637                        return EINVAL;
     
    641642               
    642643                ipc_call_t answer;
    643                 aid_t msg = async_send_4(exch, VFS_OUT_WRITE, devmap_handle,
     644                aid_t msg = async_send_4(exch, VFS_OUT_WRITE, service_id,
    644645                    index, LOWER32(pos), UPPER32(pos), &answer);
    645646               
     
    649650                async_exchange_end(exch);
    650651               
    651                 fibril_mutex_unlock(&devices_mutex);
     652                fibril_mutex_unlock(&services_mutex);
    652653               
    653654                /* Wait for reply from the driver. */
     
    664665
    665666static int
    666 devfs_truncate(devmap_handle_t devmap_handle, fs_index_t index, aoff64_t size)
     667locfs_truncate(service_id_t service_id, fs_index_t index, aoff64_t size)
    667668{
    668669        return ENOTSUP;
    669670}
    670671
    671 static int devfs_close(devmap_handle_t devmap_handle, fs_index_t index)
     672static int locfs_close(service_id_t service_id, fs_index_t index)
    672673{
    673674        if (index == 0)
    674675                return EOK;
    675676       
    676         devmap_handle_type_t type = devmap_handle_probe(index);
    677        
    678         if (type == DEV_HANDLE_NAMESPACE) {
     677        loc_object_type_t type = loc_id_probe(index);
     678       
     679        if (type == LOC_OBJECT_NAMESPACE) {
    679680                /* Namespace directory */
    680681                return EOK;
    681682        }
    682683       
    683         if (type == DEV_HANDLE_DEVICE) {
     684        if (type == LOC_OBJECT_SERVICE) {
    684685                unsigned long key[] = {
    685                         [DEVICES_KEY_HANDLE] = (unsigned long) index
     686                        [SERVICES_KEY_HANDLE] = (unsigned long) index
    686687                };
    687688               
    688                 fibril_mutex_lock(&devices_mutex);
    689                 link_t *lnk = hash_table_find(&devices, key);
     689                fibril_mutex_lock(&services_mutex);
     690                link_t *lnk = hash_table_find(&services, key);
    690691                if (lnk == NULL) {
    691                         fibril_mutex_unlock(&devices_mutex);
     692                        fibril_mutex_unlock(&services_mutex);
    692693                        return ENOENT;
    693694                }
    694695               
    695                 device_t *dev = hash_table_get_instance(lnk, device_t, link);
     696                service_t *dev = hash_table_get_instance(lnk, service_t, link);
    696697                assert(dev->sess);
    697698                dev->refcount--;
     
    699700                if (dev->refcount == 0) {
    700701                        async_hangup(dev->sess);
    701                         hash_table_remove(&devices, key, DEVICES_KEYS);
    702                 }
    703                
    704                 fibril_mutex_unlock(&devices_mutex);
     702                        hash_table_remove(&services, key, SERVICES_KEYS);
     703                }
     704               
     705                fibril_mutex_unlock(&services_mutex);
    705706               
    706707                return EOK;
     
    710711}
    711712
    712 static int devfs_sync(devmap_handle_t devmap_handle, fs_index_t index)
     713static int locfs_sync(service_id_t service_id, fs_index_t index)
    713714{
    714715        if (index == 0)
    715716                return EOK;
    716717       
    717         devmap_handle_type_t type = devmap_handle_probe(index);
    718        
    719         if (type == DEV_HANDLE_NAMESPACE) {
     718        loc_object_type_t type = loc_id_probe(index);
     719       
     720        if (type == LOC_OBJECT_NAMESPACE) {
    720721                /* Namespace directory */
    721722                return EOK;
    722723        }
    723724       
    724         if (type == DEV_HANDLE_DEVICE) {
     725        if (type == LOC_OBJECT_SERVICE) {
    725726                unsigned long key[] = {
    726                         [DEVICES_KEY_HANDLE] = (unsigned long) index
     727                        [SERVICES_KEY_HANDLE] = (unsigned long) index
    727728                };
    728729               
    729                 fibril_mutex_lock(&devices_mutex);
    730                 link_t *lnk = hash_table_find(&devices, key);
     730                fibril_mutex_lock(&services_mutex);
     731                link_t *lnk = hash_table_find(&services, key);
    731732                if (lnk == NULL) {
    732                         fibril_mutex_unlock(&devices_mutex);
     733                        fibril_mutex_unlock(&services_mutex);
    733734                        return ENOENT;
    734735                }
    735736               
    736                 device_t *dev = hash_table_get_instance(lnk, device_t, link);
     737                service_t *dev = hash_table_get_instance(lnk, service_t, link);
    737738                assert(dev->sess);
    738739               
     
    741742               
    742743                ipc_call_t answer;
    743                 aid_t msg = async_send_2(exch, VFS_OUT_SYNC, devmap_handle,
     744                aid_t msg = async_send_2(exch, VFS_OUT_SYNC, service_id,
    744745                    index, &answer);
    745746               
    746747                async_exchange_end(exch);
    747748               
    748                 fibril_mutex_unlock(&devices_mutex);
     749                fibril_mutex_unlock(&services_mutex);
    749750               
    750751                /* Wait for reply from the driver */
     
    758759}
    759760
    760 static int devfs_destroy(devmap_handle_t devmap_handle, fs_index_t index)
     761static int locfs_destroy(service_id_t service_id, fs_index_t index)
    761762{
    762763        return ENOTSUP;
    763764}
    764765
    765 vfs_out_ops_t devfs_ops = {
    766         .mounted = devfs_mounted,
    767         .unmounted = devfs_unmounted,
    768         .read = devfs_read,
    769         .write = devfs_write,
    770         .truncate = devfs_truncate,
    771         .close = devfs_close,
    772         .destroy = devfs_destroy,
    773         .sync = devfs_sync,
     766vfs_out_ops_t locfs_ops = {
     767        .mounted = locfs_mounted,
     768        .unmounted = locfs_unmounted,
     769        .read = locfs_read,
     770        .write = locfs_write,
     771        .truncate = locfs_truncate,
     772        .close = locfs_close,
     773        .destroy = locfs_destroy,
     774        .sync = locfs_sync,
    774775};
    775776
Note: See TracChangeset for help on using the changeset viewer.