Changeset cf95bc0 in mainline


Ignore:
Timestamp:
2009-05-09T21:56:50Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d4a172b
Parents:
4f46695e
Message:

Streamline TMPFS and fix its design so that it properly supports hardlinks.
libfs operation unlink() is now passed also the name of the component being
unlinked.

Location:
uspace
Files:
6 edited

Legend:

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

    r4f46695e rcf95bc0  
    291291        if (lflag & L_UNLINK) {
    292292                unsigned old_lnkcnt = ops->lnkcnt_get(cur);
    293                 int res = ops->unlink(par, cur);
     293                int res = ops->unlink(par, cur, component);
    294294                ipc_answer_5(rid, (ipcarg_t)res, fs_handle, dev_handle,
    295295                    ops->index_get(cur), ops->size_get(cur), old_lnkcnt);
  • uspace/lib/libfs/libfs.h

    r4f46695e rcf95bc0  
    5353        int (* destroy)(fs_node_t *);
    5454        int (* link)(fs_node_t *, fs_node_t *, const char *);
    55         int (* unlink)(fs_node_t *, fs_node_t *);
     55        int (* unlink)(fs_node_t *, fs_node_t *, const char *);
    5656        fs_index_t (* index_get)(fs_node_t *);
    5757        size_t (* size_get)(fs_node_t *);
  • uspace/srv/fs/fat/fat_ops.c

    r4f46695e rcf95bc0  
    242242static int fat_destroy_node(fs_node_t *);
    243243static int fat_link(fs_node_t *, fs_node_t *, const char *);
    244 static int fat_unlink(fs_node_t *, fs_node_t *);
     244static int fat_unlink(fs_node_t *, fs_node_t *, const char *);
    245245static fs_node_t *fat_match(fs_node_t *, const char *);
    246246static fs_index_t fat_index_get(fs_node_t *);
     
    544544}
    545545
    546 int fat_unlink(fs_node_t *pfn, fs_node_t *cfn)
     546int fat_unlink(fs_node_t *pfn, fs_node_t *cfn, const char *nm)
    547547{
    548548        fat_node_t *parentp = FAT_NODE(pfn);
  • uspace/srv/fs/tmpfs/tmpfs.h

    r4f46695e rcf95bc0  
    4545#endif
    4646
    47 #define TMPFS_NODE(node)        ((node) ? (tmpfs_dentry_t *)(node)->data : NULL)
     47#define TMPFS_NODE(node)        ((node) ? (tmpfs_node_t *)(node)->data : NULL)
    4848#define FS_NODE(node)           ((node) ? (node)->bp : NULL)
    4949
     
    5454} tmpfs_dentry_type_t;
    5555
     56/* forward declaration */
     57struct tmpfs_node;
     58
    5659typedef struct tmpfs_dentry {
     60        link_t link;            /**< Linkage for the list of siblings. */
     61        struct tmpfs_node *node;/**< Back pointer to TMPFS node. */
     62        char *name;             /**< Name of dentry. */
     63} tmpfs_dentry_t;
     64
     65typedef struct tmpfs_node {
    5766        fs_node_t *bp;          /**< Back pointer to the FS node. */
    5867        fs_index_t index;       /**< TMPFS node index. */
    5968        dev_handle_t dev_handle;/**< Device handle. */
    60         link_t dh_link;         /**< Dentries hash table link. */
    61         struct tmpfs_dentry *sibling;
    62         struct tmpfs_dentry *child;
    63         hash_table_t names;     /**< All names linking to this TMPFS node. */
     69        link_t nh_link;         /**< Nodes hash table link. */
    6470        tmpfs_dentry_type_t type;
    6571        unsigned lnkcnt;        /**< Link count. */
    6672        size_t size;            /**< File size if type is TMPFS_FILE. */
    6773        void *data;             /**< File content's if type is TMPFS_FILE. */
    68 } tmpfs_dentry_t;
     74        link_t cs_head;         /**< Head of child's siblings list. */
     75} tmpfs_node_t;
    6976
    7077extern fs_reg_t tmpfs_reg;
  • uspace/srv/fs/tmpfs/tmpfs_dump.c

    r4f46695e rcf95bc0  
    6565                char *fname;
    6666                fs_node_t *fn;
    67                 tmpfs_dentry_t *nodep;
     67                tmpfs_node_t *nodep;
    6868                uint32_t size;
    6969               
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    r4f46695e rcf95bc0  
    5555#define max(a, b)               ((a) > (b) ? (a) : (b))
    5656
    57 #define DENTRIES_BUCKETS        256
    58 
    59 #define NAMES_BUCKETS           4
     57#define NODES_BUCKETS   256
    6058
    6159/** All root nodes have index 0. */
     
    7472static fs_node_t *tmpfs_create_node(dev_handle_t, int);
    7573static int tmpfs_link_node(fs_node_t *, fs_node_t *, const char *);
    76 static int tmpfs_unlink_node(fs_node_t *, fs_node_t *);
     74static int tmpfs_unlink_node(fs_node_t *, fs_node_t *, const char *);
    7775static int tmpfs_destroy_node(fs_node_t *);
    7876
     
    9593static bool tmpfs_has_children(fs_node_t *fn)
    9694{
    97         return TMPFS_NODE(fn)->child != NULL;
     95        return !list_empty(&TMPFS_NODE(fn)->cs_head);
    9896}
    9997
     
    137135};
    138136
    139 /** Hash table of all directory entries. */
    140 hash_table_t dentries;
    141 
    142 #define DENTRIES_KEY_INDEX      0
    143 #define DENTRIES_KEY_DEV        1
    144 
    145 /* Implementation of hash table interface for the dentries hash table. */
    146 static hash_index_t dentries_hash(unsigned long key[])
    147 {
    148         return key[DENTRIES_KEY_INDEX] % DENTRIES_BUCKETS;
    149 }
    150 
    151 static int dentries_compare(unsigned long key[], hash_count_t keys,
    152     link_t *item)
    153 {
    154         tmpfs_dentry_t *dentry = hash_table_get_instance(item, tmpfs_dentry_t,
    155             dh_link);
    156         return (dentry->index == key[DENTRIES_KEY_INDEX] &&
    157             dentry->dev_handle == key[DENTRIES_KEY_DEV]);
    158 }
    159 
    160 static void dentries_remove_callback(link_t *item)
    161 {
    162 }
    163 
    164 /** TMPFS dentries hash table operations. */
    165 hash_table_operations_t dentries_ops = {
    166         .hash = dentries_hash,
    167         .compare = dentries_compare,
    168         .remove_callback = dentries_remove_callback
     137/** Hash table of all TMPFS nodes. */
     138hash_table_t nodes;
     139
     140#define NODES_KEY_INDEX 0
     141#define NODES_KEY_DEV   1
     142
     143/* Implementation of hash table interface for the nodes hash table. */
     144static hash_index_t nodes_hash(unsigned long key[])
     145{
     146        return key[NODES_KEY_INDEX] % NODES_BUCKETS;
     147}
     148
     149static int nodes_compare(unsigned long key[], hash_count_t keys, link_t *item)
     150{
     151        tmpfs_node_t *nodep = hash_table_get_instance(item, tmpfs_node_t,
     152            nh_link);
     153        return (nodep->index == key[NODES_KEY_INDEX] &&
     154            nodep->dev_handle == key[NODES_KEY_DEV]);
     155}
     156
     157static void nodes_remove_callback(link_t *item)
     158{
     159}
     160
     161/** TMPFS nodes hash table operations. */
     162hash_table_operations_t nodes_ops = {
     163        .hash = nodes_hash,
     164        .compare = nodes_compare,
     165        .remove_callback = nodes_remove_callback
    169166};
    170167
    171 typedef struct {
    172         char *name;
    173         tmpfs_dentry_t *parent;
    174         link_t link;
    175 } tmpfs_name_t;
    176 
    177 /* Implementation of hash table interface for the names hash table. */
    178 static hash_index_t names_hash(unsigned long *key)
    179 {
    180         tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) *key;
    181         return dentry->index % NAMES_BUCKETS;
    182 }
    183 
    184 static int names_compare(unsigned long *key, hash_count_t keys, link_t *item)
    185 {
    186         tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) *key;
    187         tmpfs_name_t *namep = hash_table_get_instance(item, tmpfs_name_t,
    188             link);
    189         return dentry == namep->parent;
    190 }
    191 
    192 static void names_remove_callback(link_t *item)
    193 {
    194         tmpfs_name_t *namep = hash_table_get_instance(item, tmpfs_name_t,
    195             link);
    196         free(namep->name);
    197         free(namep);
    198 }
    199 
    200 /** TMPFS node names hash table operations. */
    201 static hash_table_operations_t names_ops = {
    202         .hash = names_hash,
    203         .compare = names_compare,
    204         .remove_callback = names_remove_callback
    205 };
    206 
    207 static void tmpfs_name_initialize(tmpfs_name_t *namep)
    208 {
    209         namep->name = NULL;
    210         namep->parent = NULL;
    211         link_initialize(&namep->link);
    212 }
    213 
    214 static bool tmpfs_dentry_initialize(tmpfs_dentry_t *dentry)
    215 {
    216         dentry->bp = NULL;
    217         dentry->index = 0;
    218         dentry->dev_handle = 0;
    219         dentry->sibling = NULL;
    220         dentry->child = NULL;
    221         dentry->type = TMPFS_NONE;
    222         dentry->lnkcnt = 0;
    223         dentry->size = 0;
    224         dentry->data = NULL;
    225         link_initialize(&dentry->dh_link);
    226         return (bool)hash_table_create(&dentry->names, NAMES_BUCKETS, 1,
    227             &names_ops);
     168static void tmpfs_node_initialize(tmpfs_node_t *nodep)
     169{
     170        nodep->bp = NULL;
     171        nodep->index = 0;
     172        nodep->dev_handle = 0;
     173        nodep->type = TMPFS_NONE;
     174        nodep->lnkcnt = 0;
     175        nodep->size = 0;
     176        nodep->data = NULL;
     177        link_initialize(&nodep->nh_link);
     178        list_initialize(&nodep->cs_head);
     179}
     180
     181static void tmpfs_dentry_initialize(tmpfs_dentry_t *dentryp)
     182{
     183        link_initialize(&dentryp->link);
     184        dentryp->name = NULL;
     185        dentryp->node = NULL;
    228186}
    229187
    230188bool tmpfs_init(void)
    231189{
    232         if (!hash_table_create(&dentries, DENTRIES_BUCKETS, 2, &dentries_ops))
     190        if (!hash_table_create(&nodes, NODES_BUCKETS, 2, &nodes_ops))
    233191                return false;
    234192       
     
    247205}
    248206
    249 /** Compare one component of path to a directory entry.
    250  *
    251  * @param parentp       Pointer to node from which we descended.
    252  * @param childp        Pointer to node to compare the path component with.
    253  * @param component     Array of characters holding component name.
    254  *
    255  * @return              True on match, false otherwise.
    256  */
    257 static bool
    258 tmpfs_match_one(tmpfs_dentry_t *parentp, tmpfs_dentry_t *childp,
    259     const char *component)
    260 {
    261         unsigned long key = (unsigned long) parentp;
    262         link_t *hlp = hash_table_find(&childp->names, &key);
    263         assert(hlp);
    264         tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t, link);
    265         return !str_cmp(namep->name, component);
    266 }
    267 
    268207fs_node_t *tmpfs_match(fs_node_t *pfn, const char *component)
    269208{
    270         tmpfs_dentry_t *parentp = TMPFS_NODE(pfn);
    271         tmpfs_dentry_t *childp = parentp->child;
    272 
    273         while (childp && !tmpfs_match_one(parentp, childp, component))
    274                 childp = childp->sibling;
    275 
    276         return FS_NODE(childp);
     209        tmpfs_node_t *parentp = TMPFS_NODE(pfn);
     210        link_t *lnk;
     211
     212        for (lnk = parentp->cs_head.next; lnk != &parentp->cs_head;
     213            lnk = lnk->next) {
     214                tmpfs_dentry_t *dentryp = list_get_instance(lnk, tmpfs_dentry_t,
     215                    link);
     216                if (!str_cmp(dentryp->name, component))
     217                        return FS_NODE(dentryp->node);
     218        }
     219
     220        return NULL;
    277221}
    278222
     
    280224{
    281225        unsigned long key[] = {
    282                 [DENTRIES_KEY_INDEX] = index,
    283                 [DENTRIES_KEY_DEV] = dev_handle
     226                [NODES_KEY_INDEX] = index,
     227                [NODES_KEY_DEV] = dev_handle
    284228        };
    285         link_t *lnk = hash_table_find(&dentries, key);
     229        link_t *lnk = hash_table_find(&nodes, key);
    286230        if (!lnk)
    287231                return NULL;
    288         return FS_NODE(hash_table_get_instance(lnk, tmpfs_dentry_t, dh_link));
     232        return FS_NODE(hash_table_get_instance(lnk, tmpfs_node_t, nh_link));
    289233}
    290234
     
    298242        assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY));
    299243
    300         fs_node_t *fn = malloc(sizeof(fs_node_t));
    301         if (!fn)
     244        tmpfs_node_t *nodep = malloc(sizeof(tmpfs_node_t));
     245        if (!nodep)
    302246                return NULL;
    303        
    304         tmpfs_dentry_t *node = malloc(sizeof(tmpfs_dentry_t));
    305         if (!node) {
    306                 free(fn);
     247        tmpfs_node_initialize(nodep);
     248        nodep->bp = malloc(sizeof(fs_node_t));
     249        if (!nodep->bp) {
     250                free(nodep);
    307251                return NULL;
    308252        }
    309         if (!tmpfs_dentry_initialize(node)) {
    310                 free(fn);
    311                 free(node);
    312                 return NULL;
    313         }
    314         fn->data = node;
    315         node->bp = fn;  /* establish the back pointer */
     253        nodep->bp->data = nodep;        /* link the FS and TMPFS nodes */
    316254        if (!tmpfs_root_get(dev_handle))
    317                 node->index = TMPFS_SOME_ROOT;
     255                nodep->index = TMPFS_SOME_ROOT;
    318256        else
    319                 node->index = tmpfs_next_index++;
    320         node->dev_handle = dev_handle;
     257                nodep->index = tmpfs_next_index++;
     258        nodep->dev_handle = dev_handle;
    321259        if (lflag & L_DIRECTORY)
    322                 node->type = TMPFS_DIRECTORY;
     260                nodep->type = TMPFS_DIRECTORY;
    323261        else
    324                 node->type = TMPFS_FILE;
    325 
    326         /* Insert the new node into the dentry hash table. */
     262                nodep->type = TMPFS_FILE;
     263
     264        /* Insert the new node into the nodes hash table. */
    327265        unsigned long key[] = {
    328                 [DENTRIES_KEY_INDEX] = node->index,
    329                 [DENTRIES_KEY_DEV] = node->dev_handle
     266                [NODES_KEY_INDEX] = nodep->index,
     267                [NODES_KEY_DEV] = nodep->dev_handle
    330268        };
    331         hash_table_insert(&dentries, key, &node->dh_link);
    332         return fn;
     269        hash_table_insert(&nodes, key, &nodep->nh_link);
     270        return FS_NODE(nodep);
    333271}
    334272
    335273int tmpfs_link_node(fs_node_t *pfn, fs_node_t *cfn, const char *nm)
    336274{
    337         tmpfs_dentry_t *parentp = TMPFS_NODE(pfn);
    338         tmpfs_dentry_t *childp = TMPFS_NODE(cfn);
     275        tmpfs_node_t *parentp = TMPFS_NODE(pfn);
     276        tmpfs_node_t *childp = TMPFS_NODE(cfn);
     277        tmpfs_dentry_t *dentryp;
     278        link_t *lnk;
    339279
    340280        assert(parentp->type == TMPFS_DIRECTORY);
    341281
    342         tmpfs_name_t *namep = malloc(sizeof(tmpfs_name_t));
    343         if (!namep)
     282        /* Check for duplicit entries. */
     283        for (lnk = parentp->cs_head.next; lnk != &parentp->cs_head;
     284            lnk = lnk->next) {
     285                dentryp = list_get_instance(lnk, tmpfs_dentry_t, link);
     286                if (!str_cmp(dentryp->name, nm))
     287                        return EEXIST;
     288        }
     289
     290        /* Allocate and initialize the dentry. */
     291        dentryp = malloc(sizeof(tmpfs_dentry_t));
     292        if (!dentryp)
    344293                return ENOMEM;
    345         tmpfs_name_initialize(namep);
     294        tmpfs_dentry_initialize(dentryp);
     295
     296        /* Populate and link the new dentry. */
    346297        size_t size = str_size(nm);
    347         namep->name = malloc(size + 1);
    348         if (!namep->name) {
    349                 free(namep);
     298        dentryp->name = malloc(size + 1);
     299        if (!dentryp->name) {
     300                free(dentryp);
    350301                return ENOMEM;
    351302        }
    352         str_cpy(namep->name, size + 1, nm);
    353         namep->parent = parentp;
    354        
     303        str_cpy(dentryp->name, size + 1, nm);
     304        dentryp->node = childp;
    355305        childp->lnkcnt++;
    356 
    357         unsigned long key = (unsigned long) parentp;
    358         hash_table_insert(&childp->names, &key, &namep->link);
    359 
    360         /* Insert the new node into the namespace. */
    361         if (parentp->child) {
    362                 tmpfs_dentry_t *tmp = parentp->child;
    363                 while (tmp->sibling)
    364                         tmp = tmp->sibling;
    365                 tmp->sibling = childp;
    366         } else {
    367                 parentp->child = childp;
    368         }
     306        list_append(&dentryp->link, &parentp->cs_head);
    369307
    370308        return EOK;
    371309}
    372310
    373 int tmpfs_unlink_node(fs_node_t *pfn, fs_node_t *cfn)
    374 {
    375         tmpfs_dentry_t *parentp = TMPFS_NODE(pfn);
    376         tmpfs_dentry_t *childp = TMPFS_NODE(cfn);
     311int tmpfs_unlink_node(fs_node_t *pfn, fs_node_t *cfn, const char *nm)
     312{
     313        tmpfs_node_t *parentp = TMPFS_NODE(pfn);
     314        tmpfs_node_t *childp = NULL;
     315        tmpfs_dentry_t *dentryp;
     316        link_t *lnk;
    377317
    378318        if (!parentp)
    379319                return EBUSY;
    380 
    381         if (childp->child)
     320       
     321        for (lnk = parentp->cs_head.next; lnk != &parentp->cs_head;
     322            lnk = lnk->next) {
     323                dentryp = list_get_instance(lnk, tmpfs_dentry_t, link);
     324                if (!str_cmp(dentryp->name, nm)) {
     325                        childp = dentryp->node;
     326                        assert(FS_NODE(childp) == cfn);
     327                        break;
     328                }       
     329        }
     330
     331        if (!childp)
     332                return ENOENT;
     333               
     334        if ((childp->lnkcnt == 1) && !list_empty(&childp->cs_head))
    382335                return ENOTEMPTY;
    383336
    384         if (parentp->child == childp) {
    385                 parentp->child = childp->sibling;
    386         } else {
    387                 /* TODO: consider doubly linked list for organizing siblings. */
    388                 tmpfs_dentry_t *tmp = parentp->child;
    389                 while (tmp->sibling != childp)
    390                         tmp = tmp->sibling;
    391                 tmp->sibling = childp->sibling;
    392         }
    393         childp->sibling = NULL;
    394 
    395         unsigned long key = (unsigned long) parentp;
    396         hash_table_remove(&childp->names, &key, 1);
    397 
     337        list_remove(&dentryp->link);
     338        free(dentryp);
    398339        childp->lnkcnt--;
    399340
     
    403344int tmpfs_destroy_node(fs_node_t *fn)
    404345{
    405         tmpfs_dentry_t *dentry = TMPFS_NODE(fn);
     346        tmpfs_node_t *nodep = TMPFS_NODE(fn);
    406347       
    407         assert(!dentry->lnkcnt);
    408         assert(!dentry->child);
    409         assert(!dentry->sibling);
     348        assert(!nodep->lnkcnt);
     349        assert(list_empty(&nodep->cs_head));
    410350
    411351        unsigned long key[] = {
    412                 [DENTRIES_KEY_INDEX] = dentry->index,
    413                 [DENTRIES_KEY_DEV] = dentry->dev_handle
     352                [NODES_KEY_INDEX] = nodep->index,
     353                [NODES_KEY_DEV] = nodep->dev_handle
    414354        };
    415         hash_table_remove(&dentries, key, 2);
    416 
    417         hash_table_destroy(&dentry->names);
    418 
    419         if (dentry->type == TMPFS_FILE)
    420                 free(dentry->data);
    421         free(dentry->bp);
    422         free(dentry);
     355        hash_table_remove(&nodes, key, 2);
     356
     357        if (nodep->type == TMPFS_FILE)
     358                free(nodep->data);
     359        free(nodep->bp);
     360        free(nodep);
    423361        return EOK;
    424362}
     
    456394        }
    457395
    458         tmpfs_dentry_t *root = TMPFS_NODE(tmpfs_root_get(dev_handle));
     396        tmpfs_node_t *rootp = TMPFS_NODE(tmpfs_root_get(dev_handle));
    459397        if (str_cmp(opts, "restore") == 0) {
    460398                if (tmpfs_restore(dev_handle))
    461                         ipc_answer_3(rid, EOK, root->index, root->size,
    462                             root->lnkcnt);
     399                        ipc_answer_3(rid, EOK, rootp->index, rootp->size,
     400                            rootp->lnkcnt);
    463401                else
    464402                        ipc_answer_0(rid, ELIMIT);
    465403        } else {
    466                 ipc_answer_3(rid, EOK, root->index, root->size, root->lnkcnt);
     404                ipc_answer_3(rid, EOK, rootp->index, rootp->size,
     405                    rootp->lnkcnt);
    467406        }
    468407}
     
    490429
    491430        /*
    492          * Lookup the respective dentry.
     431         * Lookup the respective TMPFS node.
    493432         */
    494433        link_t *hlp;
    495434        unsigned long key[] = {
    496                 [DENTRIES_KEY_INDEX] = index,
    497                 [DENTRIES_KEY_DEV] = dev_handle,
     435                [NODES_KEY_INDEX] = index,
     436                [NODES_KEY_DEV] = dev_handle,
    498437        };
    499         hlp = hash_table_find(&dentries, key);
     438        hlp = hash_table_find(&nodes, key);
    500439        if (!hlp) {
    501440                ipc_answer_0(rid, ENOENT);
    502441                return;
    503442        }
    504         tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t,
    505             dh_link);
     443        tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,
     444            nh_link);
    506445
    507446        /*
     
    517456
    518457        size_t bytes;
    519         if (dentry->type == TMPFS_FILE) {
    520                 bytes = max(0, min(dentry->size - pos, size));
    521                 (void) ipc_data_read_finalize(callid, dentry->data + pos,
     458        if (nodep->type == TMPFS_FILE) {
     459                bytes = max(0, min(nodep->size - pos, size));
     460                (void) ipc_data_read_finalize(callid, nodep->data + pos,
    522461                    bytes);
    523462        } else {
     463                tmpfs_dentry_t *dentryp;
     464                link_t *lnk;
    524465                int i;
    525                 tmpfs_dentry_t *cur;
    526466               
    527                 assert(dentry->type == TMPFS_DIRECTORY);
     467                assert(nodep->type == TMPFS_DIRECTORY);
    528468               
    529469                /*
     
    532472                 * hash table.
    533473                 */
    534                 for (i = 0, cur = dentry->child; i < pos && cur; i++,
    535                     cur = cur->sibling)
     474                for (i = 0, lnk = nodep->cs_head.next;
     475                    i < pos && lnk != &nodep->cs_head;
     476                    i++, lnk = lnk->next)
    536477                        ;
    537478
    538                 if (!cur) {
     479                if (lnk == &nodep->cs_head) {
    539480                        ipc_answer_0(callid, ENOENT);
    540481                        ipc_answer_1(rid, ENOENT, 0);
     
    542483                }
    543484
    544                 unsigned long key = (unsigned long) dentry;
    545                 link_t *hlp = hash_table_find(&cur->names, &key);
    546                 assert(hlp);
    547                 tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t,
    548                     link);
    549 
    550                 (void) ipc_data_read_finalize(callid, namep->name,
    551                     str_size(namep->name) + 1);
     485                dentryp = list_get_instance(lnk, tmpfs_dentry_t, link);
     486
     487                (void) ipc_data_read_finalize(callid, dentryp->name,
     488                    str_size(dentryp->name) + 1);
    552489                bytes = 1;
    553490        }
     
    566503
    567504        /*
    568          * Lookup the respective dentry.
     505         * Lookup the respective TMPFS node.
    569506         */
    570507        link_t *hlp;
    571508        unsigned long key[] = {
    572                 [DENTRIES_KEY_INDEX] = index,
    573                 [DENTRIES_KEY_DEV] = dev_handle
     509                [NODES_KEY_INDEX] = index,
     510                [NODES_KEY_DEV] = dev_handle
    574511        };
    575         hlp = hash_table_find(&dentries, key);
     512        hlp = hash_table_find(&nodes, key);
    576513        if (!hlp) {
    577514                ipc_answer_0(rid, ENOENT);
    578515                return;
    579516        }
    580         tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t,
    581             dh_link);
     517        tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,
     518            nh_link);
    582519
    583520        /*
     
    595532         * Check whether the file needs to grow.
    596533         */
    597         if (pos + size <= dentry->size) {
     534        if (pos + size <= nodep->size) {
    598535                /* The file size is not changing. */
    599                 (void) ipc_data_write_finalize(callid, dentry->data + pos, size);
    600                 ipc_answer_2(rid, EOK, size, dentry->size);
    601                 return;
    602         }
    603         size_t delta = (pos + size) - dentry->size;
     536                (void) ipc_data_write_finalize(callid, nodep->data + pos, size);
     537                ipc_answer_2(rid, EOK, size, nodep->size);
     538                return;
     539        }
     540        size_t delta = (pos + size) - nodep->size;
    604541        /*
    605542         * At this point, we are deliberately extremely straightforward and
     
    609546         * possible.
    610547         */
    611         void *newdata = realloc(dentry->data, dentry->size + delta);
     548        void *newdata = realloc(nodep->data, nodep->size + delta);
    612549        if (!newdata) {
    613550                ipc_answer_0(callid, ENOMEM);
    614                 ipc_answer_2(rid, EOK, 0, dentry->size);
     551                ipc_answer_2(rid, EOK, 0, nodep->size);
    615552                return;
    616553        }
    617554        /* Clear any newly allocated memory in order to emulate gaps. */
    618         memset(newdata + dentry->size, 0, delta);
    619         dentry->size += delta;
    620         dentry->data = newdata;
    621         (void) ipc_data_write_finalize(callid, dentry->data + pos, size);
    622         ipc_answer_2(rid, EOK, size, dentry->size);
     555        memset(newdata + nodep->size, 0, delta);
     556        nodep->size += delta;
     557        nodep->data = newdata;
     558        (void) ipc_data_write_finalize(callid, nodep->data + pos, size);
     559        ipc_answer_2(rid, EOK, size, nodep->size);
    623560}
    624561
     
    630567
    631568        /*
    632          * Lookup the respective dentry.
     569         * Lookup the respective TMPFS node.
    633570         */
    634571        link_t *hlp;
    635572        unsigned long key[] = {
    636                 [DENTRIES_KEY_INDEX] = index,
    637                 [DENTRIES_KEY_DEV] = dev_handle
     573                [NODES_KEY_INDEX] = index,
     574                [NODES_KEY_DEV] = dev_handle
    638575        };
    639         hlp = hash_table_find(&dentries, key);
     576        hlp = hash_table_find(&nodes, key);
    640577        if (!hlp) {
    641578                ipc_answer_0(rid, ENOENT);
    642579                return;
    643580        }
    644         tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t,
    645             dh_link);
    646 
    647         if (size == dentry->size) {
     581        tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,
     582            nh_link);
     583
     584        if (size == nodep->size) {
    648585                ipc_answer_0(rid, EOK);
    649586                return;
    650587        }
    651588
    652         void *newdata = realloc(dentry->data, size);
     589        void *newdata = realloc(nodep->data, size);
    653590        if (!newdata) {
    654591                ipc_answer_0(rid, ENOMEM);
    655592                return;
    656593        }
    657         if (size > dentry->size) {
    658                 size_t delta = size - dentry->size;
    659                 memset(newdata + dentry->size, 0, delta);
    660         }
    661         dentry->size = size;
    662         dentry->data = newdata;
     594        if (size > nodep->size) {
     595                size_t delta = size - nodep->size;
     596                memset(newdata + nodep->size, 0, delta);
     597        }
     598        nodep->size = size;
     599        nodep->data = newdata;
    663600        ipc_answer_0(rid, EOK);
    664601}
     
    672609        link_t *hlp;
    673610        unsigned long key[] = {
    674                 [DENTRIES_KEY_INDEX] = index,
    675                 [DENTRIES_KEY_DEV] = dev_handle
     611                [NODES_KEY_INDEX] = index,
     612                [NODES_KEY_DEV] = dev_handle
    676613        };
    677         hlp = hash_table_find(&dentries, key);
     614        hlp = hash_table_find(&nodes, key);
    678615        if (!hlp) {
    679616                ipc_answer_0(rid, ENOENT);
    680617                return;
    681618        }
    682         tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t,
    683             dh_link);
    684         rc = tmpfs_destroy_node(FS_NODE(dentry));
     619        tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,
     620            nh_link);
     621        rc = tmpfs_destroy_node(FS_NODE(nodep));
    685622        ipc_answer_0(rid, rc);
    686623}
Note: See TracChangeset for help on using the changeset viewer.