Changeset 3298ddc in mainline


Ignore:
Timestamp:
2008-03-06T22:33:27Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d5d9c53
Parents:
739d00a
Message:

Support for multiple TMPFS node names.

Location:
uspace
Files:
4 edited

Legend:

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

    r739d00a r3298ddc  
    176176
    177177                /* match the component */
    178                 while (tmp && !ops->match(tmp, component))
     178                while (tmp && !ops->match(cur, tmp, component))
    179179                        tmp = ops->sibling_get(tmp);
    180180
  • uspace/lib/libfs/libfs.h

    r739d00a r3298ddc  
    4343
    4444typedef struct {
    45         bool (* match)(void *, const char *);
     45        bool (* match)(void *, void *, const char *);
    4646        void * (* create)(int);
    4747        void (* destroy)(void *);
  • uspace/srv/fs/tmpfs/tmpfs.h

    r739d00a r3298ddc  
    4848        struct tmpfs_dentry *sibling;
    4949        struct tmpfs_dentry *child;
    50         char *name;
     50        hash_table_t names;     /**< All names linking to this TMPFS node. */
    5151        enum {
    5252                TMPFS_NONE,
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    r739d00a r3298ddc  
    5757#define DENTRIES_BUCKETS        256
    5858
     59#define NAMES_BUCKETS           4
     60
    5961/*
    6062 * For now, we don't distinguish between different dev_handles/instances. All
     
    6870
    6971/* Forward declarations of static functions. */
    70 static bool tmpfs_match(void *, const char *);
     72static bool tmpfs_match(void *, void *, const char *);
    7173static void *tmpfs_create_node(int);
    7274static bool tmpfs_link_node(void *, void *, const char *);
     
    141143hash_table_t dentries;
    142144
    143 /* Implementation of hash table interface. */
     145/* Implementation of hash table interface for the dentries hash table. */
    144146static hash_index_t dentries_hash(unsigned long *key)
    145147{
     
    168170unsigned tmpfs_next_index = 1;
    169171
    170 static void tmpfs_dentry_initialize(tmpfs_dentry_t *dentry)
     172typedef struct {
     173        char *name;
     174        tmpfs_dentry_t *parent;
     175        link_t link;
     176} tmpfs_name_t;
     177
     178/* Implementation of hash table interface for the names hash table. */
     179static hash_index_t names_hash(unsigned long *key)
     180{
     181        tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) *key;
     182        return dentry->index % NAMES_BUCKETS;
     183}
     184
     185static int names_compare(unsigned long *key, hash_count_t keys, link_t *item)
     186{
     187        tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) *key;
     188        tmpfs_name_t *namep = hash_table_get_instance(item, tmpfs_name_t,
     189            link);
     190        return dentry == namep->parent;
     191}
     192
     193static void names_remove_callback(link_t *item)
     194{
     195        tmpfs_name_t *namep = hash_table_get_instance(item, tmpfs_name_t,
     196            link);
     197        free(namep->name);
     198        free(namep);
     199}
     200
     201/** TMPFS node names hash table operations. */
     202static hash_table_operations_t names_ops = {
     203        .hash = names_hash,
     204        .compare = names_compare,
     205        .remove_callback = names_remove_callback
     206};
     207
     208static void tmpfs_name_initialize(tmpfs_name_t *namep)
     209{
     210        namep->name = NULL;
     211        namep->parent = NULL;
     212        link_initialize(&namep->link);
     213}
     214
     215static bool tmpfs_dentry_initialize(tmpfs_dentry_t *dentry)
    171216{
    172217        dentry->index = 0;
    173218        dentry->sibling = NULL;
    174219        dentry->child = NULL;
    175         dentry->name = NULL;
    176220        dentry->type = TMPFS_NONE;
    177221        dentry->lnkcnt = 0;
     
    179223        dentry->data = NULL;
    180224        link_initialize(&dentry->dh_link);
     225        return (bool)hash_table_create(&dentry->names, NAMES_BUCKETS, 1,
     226            &names_ops);
    181227}
    182228
     
    186232                return false;
    187233        root = (tmpfs_dentry_t *) tmpfs_create_node(L_DIRECTORY);
     234        if (!root) {
     235                hash_table_destroy(&dentries);
     236                return false;
     237        }
    188238        root->lnkcnt = 1;
    189         return root != NULL;
     239        return true;
    190240}
    191241
    192242/** Compare one component of path to a directory entry.
    193243 *
    194  * @param nodep         Node to compare the path component with.
     244 * @param prnt          Node from which we descended.
     245 * @param chld          Node to compare the path component with.
    195246 * @param component     Array of characters holding component name.
    196247 *
    197248 * @return              True on match, false otherwise.
    198249 */
    199 bool tmpfs_match(void *nodep, const char *component)
    200 {
    201         tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) nodep;
    202 
    203         return !strcmp(dentry->name, component);
     250bool tmpfs_match(void *prnt, void *chld, const char *component)
     251{
     252        tmpfs_dentry_t *parentp = (tmpfs_dentry_t *) prnt;
     253        tmpfs_dentry_t *childp = (tmpfs_dentry_t *) chld;
     254
     255        unsigned long key = (unsigned long) parentp;
     256        link_t *hlp = hash_table_find(&childp->names, &key);
     257        assert(hlp);
     258        tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t, link);
     259
     260        return !strcmp(namep->name, component);
    204261}
    205262
     
    212269                return NULL;
    213270
    214         tmpfs_dentry_initialize(node);
     271        if (!tmpfs_dentry_initialize(node)) {
     272                free(node);
     273                return NULL;
     274        }
    215275        node->index = tmpfs_next_index++;
    216276        if (lflag & L_DIRECTORY)
     
    231291        assert(parentp->type == TMPFS_DIRECTORY);
    232292
     293        tmpfs_name_t *namep = malloc(sizeof(tmpfs_name_t));
     294        if (!namep)
     295                return false;
     296        tmpfs_name_initialize(namep);
    233297        size_t len = strlen(nm);
    234         char *name = malloc(len + 1);
    235         if (!name)
     298        namep->name = malloc(len + 1);
     299        if (!namep->name) {
     300                free(namep);
    236301                return false;
     302        }
     303        strcpy(namep->name, nm);
     304        namep->parent = parentp;
    237305       
    238306        childp->lnkcnt++;
    239        
    240         strcpy(name, nm);
    241         childp->name = name;
     307
     308        unsigned long key = (unsigned long) parentp;
     309        hash_table_insert(&childp->names, &key, &namep->link);
    242310
    243311        /* Insert the new node into the namespace. */
     
    276344        childp->sibling = NULL;
    277345
    278         free(childp->name);
    279         childp->name = NULL;
     346        unsigned long key = (unsigned long) parentp;
     347        hash_table_remove(&childp->names, &key, 1);
    280348
    281349        childp->lnkcnt--;
     
    294362        unsigned long index = dentry->index;
    295363        hash_table_remove(&dentries, &index, 1);
     364
     365        hash_table_destroy(&dentry->names);
    296366
    297367        if (dentry->type == TMPFS_FILE)
     
    365435                }
    366436
    367                 (void) ipc_data_read_finalize(callid, cur->name,
    368                     strlen(cur->name) + 1);
     437                unsigned long key = (unsigned long) dentry;
     438                link_t *hlp = hash_table_find(&cur->names, &key);
     439                assert(hlp);
     440                tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t,
     441                    link);
     442
     443                (void) ipc_data_read_finalize(callid, namep->name,
     444                    strlen(namep->name) + 1);
    369445                bytes = 1;
    370446        }
Note: See TracChangeset for help on using the changeset viewer.