Changeset b6035ba in mainline


Ignore:
Timestamp:
2009-05-05T22:09:13Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
770d281
Parents:
c852f4be
Message:

Introduce the concept of FS nodes. A FS node is a typed abstraction of
file-system-specific node type. It replaces the void * in libfs interfaces
and is suitable for holding various information such as mount point data.

Location:
uspace
Files:
7 edited

Legend:

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

    rc852f4be rb6035ba  
    149149                last += PLB_SIZE;
    150150
    151         void *par = NULL;
    152         void *cur = ops->root_get(dev_handle);
    153         void *tmp = NULL;
     151        fs_node_t *par = NULL;
     152        fs_node_t *cur = ops->root_get(dev_handle);
     153        fs_node_t *tmp = NULL;
    154154
    155155        if (ops->plb_get_char(next) == '/')
     
    190190                                        goto out;
    191191                                }
    192                                 void *nodep;
     192                                fs_node_t *fn;
    193193                                if (lflag & L_CREATE)
    194                                         nodep = ops->create(dev_handle, lflag);
     194                                        fn = ops->create(dev_handle, lflag);
    195195                                else
    196                                         nodep = ops->node_get(dev_handle,
     196                                        fn = ops->node_get(dev_handle,
    197197                                            index);
    198                                 if (nodep) {
     198                                if (fn) {
    199199                                        int rc;
    200200
    201                                         rc = ops->link(cur, nodep, component);
     201                                        rc = ops->link(cur, fn, component);
    202202                                        if (rc != EOK) {
    203203                                                if (lflag & L_CREATE) {
    204                                                         (void)ops->destroy(
    205                                                             nodep);
     204                                                        (void)ops->destroy(fn);
    206205                                                }
    207206                                                ipc_answer_0(rid, rc);
     
    209208                                                ipc_answer_5(rid, EOK,
    210209                                                    fs_handle, dev_handle,
    211                                                     ops->index_get(nodep),
    212                                                     ops->size_get(nodep),
    213                                                     ops->lnkcnt_get(nodep));
    214                                                 ops->node_put(nodep);
     210                                                    ops->index_get(fn),
     211                                                    ops->size_get(fn),
     212                                                    ops->lnkcnt_get(fn));
     213                                                ops->node_put(fn);
    215214                                        }
    216215                                } else {
     
    264263                        component[len] = '\0';
    265264                               
    266                         void *nodep;
     265                        fs_node_t *fn;
    267266                        if (lflag & L_CREATE)
    268                                 nodep = ops->create(dev_handle, lflag);
     267                                fn = ops->create(dev_handle, lflag);
    269268                        else
    270                                 nodep = ops->node_get(dev_handle, index);
    271                         if (nodep) {
     269                                fn = ops->node_get(dev_handle, index);
     270                        if (fn) {
    272271                                int rc;
    273272
    274                                 rc = ops->link(cur, nodep, component);
     273                                rc = ops->link(cur, fn, component);
    275274                                if (rc != EOK) {
    276275                                        if (lflag & L_CREATE)
    277                                                 (void)ops->destroy(nodep);
     276                                                (void)ops->destroy(fn);
    278277                                        ipc_answer_0(rid, rc);
    279278                                } else {
    280279                                        ipc_answer_5(rid, EOK,
    281280                                            fs_handle, dev_handle,
    282                                             ops->index_get(nodep),
    283                                             ops->size_get(nodep),
    284                                             ops->lnkcnt_get(nodep));
    285                                         ops->node_put(nodep);
     281                                            ops->index_get(fn),
     282                                            ops->size_get(fn),
     283                                            ops->lnkcnt_get(fn));
     284                                        ops->node_put(fn);
    286285                                }
    287286                        } else {
  • uspace/lib/libfs/libfs.h

    rc852f4be rb6035ba  
    4343
    4444typedef struct {
    45         void * (* match)(void *, const char *);
    46         void * (* node_get)(dev_handle_t, fs_index_t);
    47         void (* node_put)(void *);
    48         void * (* create)(dev_handle_t, int);
    49         int (* destroy)(void *);
    50         int (* link)(void *, void *, const char *);
    51         int (* unlink)(void *, void *);
    52         fs_index_t (* index_get)(void *);
    53         size_t (* size_get)(void *);
    54         unsigned (* lnkcnt_get)(void *);
    55         bool (* has_children)(void *);
    56         void *(* root_get)(dev_handle_t);
     45        void *data;     /**< Data of the file system implementation. */
     46} fs_node_t;
     47
     48typedef struct {
     49        fs_node_t * (* match)(fs_node_t *, const char *);
     50        fs_node_t * (* node_get)(dev_handle_t, fs_index_t);
     51        void (* node_put)(fs_node_t *);
     52        fs_node_t * (* create)(dev_handle_t, int);
     53        int (* destroy)(fs_node_t *);
     54        int (* link)(fs_node_t *, fs_node_t *, const char *);
     55        int (* unlink)(fs_node_t *, fs_node_t *);
     56        fs_index_t (* index_get)(fs_node_t *);
     57        size_t (* size_get)(fs_node_t *);
     58        unsigned (* lnkcnt_get)(fs_node_t *);
     59        bool (* has_children)(fs_node_t *);
     60        fs_node_t *(* root_get)(dev_handle_t);
    5761        char (* plb_get_char)(unsigned pos);   
    58         bool (* is_directory)(void *);
    59         bool (* is_file)(void *);
     62        bool (* is_directory)(fs_node_t *);
     63        bool (* is_file)(fs_node_t *);
    6064} libfs_ops_t;
    6165
  • uspace/srv/fs/fat/fat.h

    rc852f4be rb6035ba  
    179179/** FAT in-core node. */
    180180typedef struct fat_node {
     181        /** Back pointer to the FS node. */
     182        fs_node_t               *bp;
     183       
    181184        futex_t                 lock;
    182185        fat_node_type_t         type;
  • uspace/srv/fs/fat/fat_ops.c

    rc852f4be rb6035ba  
    5656#include <align.h>
    5757
     58#define FAT_NODE(node)  ((node) ? (fat_node_t *) (node)->data : NULL)
     59#define FS_NODE(node)   ((node) ? (node)->bp : NULL)
     60
    5861/** Futex protecting the list of cached free FAT nodes. */
    5962static futex_t ffn_futex = FUTEX_INITIALIZER;
     
    6568{
    6669        futex_initialize(&node->lock, 1);
     70        node->bp = NULL;
    6771        node->idx = NULL;
    6872        node->type = 0;
     
    109113static fat_node_t *fat_node_get_new(void)
    110114{
     115        fs_node_t *fn;
    111116        fat_node_t *nodep;
    112117
     
    130135                futex_up(&nodep->lock);
    131136                futex_up(&idxp_tmp->lock);
     137                fn = FS_NODE(nodep);
    132138        } else {
    133139skip_cache:
    134140                /* Try to allocate a new node structure. */
    135141                futex_up(&ffn_futex);
     142                fn = (fs_node_t *)malloc(sizeof(fs_node_t));
     143                if (!fn)
     144                        return NULL;
    136145                nodep = (fat_node_t *)malloc(sizeof(fat_node_t));
    137                 if (!nodep)
     146                if (!nodep) {
     147                        free(fn);
    138148                        return NULL;
     149                }
    139150        }
    140151        fat_node_initialize(nodep);
     152        fn->data = nodep;
     153        nodep->bp = fn;
    141154       
    142155        return nodep;
     
    147160 * @param idxp          Locked index structure.
    148161 */
    149 static void *fat_node_get_core(fat_idx_t *idxp)
     162static fat_node_t *fat_node_get_core(fat_idx_t *idxp)
    150163{
    151164        block_t *b;
     
    224237 * Forward declarations of FAT libfs operations.
    225238 */
    226 static void *fat_node_get(dev_handle_t, fs_index_t);
    227 static void fat_node_put(void *);
    228 static void *fat_create_node(dev_handle_t, int);
    229 static int fat_destroy_node(void *);
    230 static int fat_link(void *, void *, const char *);
    231 static int fat_unlink(void *, void *);
    232 static void *fat_match(void *, const char *);
    233 static fs_index_t fat_index_get(void *);
    234 static size_t fat_size_get(void *);
    235 static unsigned fat_lnkcnt_get(void *);
    236 static bool fat_has_children(void *);
    237 static void *fat_root_get(dev_handle_t);
     239static fs_node_t *fat_node_get(dev_handle_t, fs_index_t);
     240static void fat_node_put(fs_node_t *);
     241static fs_node_t *fat_create_node(dev_handle_t, int);
     242static int fat_destroy_node(fs_node_t *);
     243static int fat_link(fs_node_t *, fs_node_t *, const char *);
     244static int fat_unlink(fs_node_t *, fs_node_t *);
     245static fs_node_t *fat_match(fs_node_t *, const char *);
     246static fs_index_t fat_index_get(fs_node_t *);
     247static size_t fat_size_get(fs_node_t *);
     248static unsigned fat_lnkcnt_get(fs_node_t *);
     249static bool fat_has_children(fs_node_t *);
     250static fs_node_t *fat_root_get(dev_handle_t);
    238251static char fat_plb_get_char(unsigned);
    239 static bool fat_is_directory(void *);
    240 static bool fat_is_file(void *node);
     252static bool fat_is_directory(fs_node_t *);
     253static bool fat_is_file(fs_node_t *node);
    241254
    242255/*
     
    245258
    246259/** Instantiate a FAT in-core node. */
    247 void *fat_node_get(dev_handle_t dev_handle, fs_index_t index)
    248 {
    249         void *node;
     260fs_node_t *fat_node_get(dev_handle_t dev_handle, fs_index_t index)
     261{
     262        fat_node_t *nodep;
    250263        fat_idx_t *idxp;
    251264
     
    254267                return NULL;
    255268        /* idxp->lock held */
    256         node = fat_node_get_core(idxp);
     269        nodep = fat_node_get_core(idxp);
    257270        futex_up(&idxp->lock);
    258         return node;
    259 }
    260 
    261 void fat_node_put(void *node)
    262 {
    263         fat_node_t *nodep = (fat_node_t *)node;
     271        return FS_NODE(nodep);
     272}
     273
     274void fat_node_put(fs_node_t *fn)
     275{
     276        fat_node_t *nodep = FAT_NODE(fn);
    264277        bool destroy = false;
    265278
     
    281294        }
    282295        futex_up(&nodep->lock);
    283         if (destroy)
    284                 free(node);
    285 }
    286 
    287 void *fat_create_node(dev_handle_t dev_handle, int flags)
     296        if (destroy) {
     297                free(nodep->bp);
     298                free(nodep);
     299        }
     300}
     301
     302fs_node_t *fat_create_node(dev_handle_t dev_handle, int flags)
    288303{
    289304        fat_idx_t *idxp;
     
    311326        if (!idxp) {
    312327                fat_free_clusters(bs, dev_handle, mcl);
    313                 fat_node_put(nodep);
     328                fat_node_put(FS_NODE(nodep));
    314329                return NULL;
    315330        }
     
    346361
    347362        futex_up(&idxp->lock);
    348         return nodep;
    349 }
    350 
    351 int fat_destroy_node(void *node)
    352 {
    353         fat_node_t *nodep = (fat_node_t *)node;
     363        return FS_NODE(nodep);
     364}
     365
     366int fat_destroy_node(fs_node_t *fn)
     367{
     368        fat_node_t *nodep = FAT_NODE(fn);
    354369        fat_bs_t *bs;
    355370
     
    365380         * The node may not have any children.
    366381         */
    367         assert(fat_has_children(node) == false);
     382        assert(fat_has_children(fn) == false);
    368383
    369384        bs = block_bb_get(nodep->idx->dev_handle);
     
    375390
    376391        fat_idx_destroy(nodep->idx);
     392        free(nodep->bp);
    377393        free(nodep);
    378394        return EOK;
    379395}
    380396
    381 int fat_link(void *prnt, void *chld, const char *name)
    382 {
    383         fat_node_t *parentp = (fat_node_t *)prnt;
    384         fat_node_t *childp = (fat_node_t *)chld;
     397int fat_link(fs_node_t *pfn, fs_node_t *cfn, const char *name)
     398{
     399        fat_node_t *parentp = FAT_NODE(pfn);
     400        fat_node_t *childp = FAT_NODE(cfn);
    385401        fat_dentry_t *d;
    386402        fat_bs_t *bs;
     
    528544}
    529545
    530 int fat_unlink(void *prnt, void *chld)
    531 {
    532         fat_node_t *parentp = (fat_node_t *)prnt;
    533         fat_node_t *childp = (fat_node_t *)chld;
     546int fat_unlink(fs_node_t *pfn, fs_node_t *cfn)
     547{
     548        fat_node_t *parentp = FAT_NODE(pfn);
     549        fat_node_t *childp = FAT_NODE(cfn);
    534550        fat_bs_t *bs;
    535551        fat_dentry_t *d;
     
    568584}
    569585
    570 void *fat_match(void *prnt, const char *component)
     586fs_node_t *fat_match(fs_node_t *pfn, const char *component)
    571587{
    572588        fat_bs_t *bs;
    573         fat_node_t *parentp = (fat_node_t *)prnt;
     589        fat_node_t *parentp = FAT_NODE(pfn);
    574590        char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1];
    575591        unsigned i, j;
     
    604620                        if (fat_dentry_namecmp(name, component) == 0) {
    605621                                /* hit */
    606                                 void *node;
     622                                fat_node_t *nodep;
    607623                                /*
    608624                                 * Assume tree hierarchy for locking.  We
     
    623639                                        return NULL;
    624640                                }
    625                                 node = fat_node_get_core(idx);
     641                                nodep = fat_node_get_core(idx);
    626642                                futex_up(&idx->lock);
    627643                                block_put(b);
    628                                 return node;
     644                                return FS_NODE(nodep);
    629645                        }
    630646                }
     
    636652}
    637653
    638 fs_index_t fat_index_get(void *node)
    639 {
    640         fat_node_t *fnodep = (fat_node_t *)node;
    641         if (!fnodep)
    642                 return 0;
    643         return fnodep->idx->index;
    644 }
    645 
    646 size_t fat_size_get(void *node)
    647 {
    648         return ((fat_node_t *)node)->size;
    649 }
    650 
    651 unsigned fat_lnkcnt_get(void *node)
    652 {
    653         return ((fat_node_t *)node)->lnkcnt;
    654 }
    655 
    656 bool fat_has_children(void *node)
     654fs_index_t fat_index_get(fs_node_t *fn)
     655{
     656        return FAT_NODE(fn)->idx->index;
     657}
     658
     659size_t fat_size_get(fs_node_t *fn)
     660{
     661        return FAT_NODE(fn)->size;
     662}
     663
     664unsigned fat_lnkcnt_get(fs_node_t *fn)
     665{
     666        return FAT_NODE(fn)->lnkcnt;
     667}
     668
     669bool fat_has_children(fs_node_t *fn)
    657670{
    658671        fat_bs_t *bs;
    659         fat_node_t *nodep = (fat_node_t *)node;
     672        fat_node_t *nodep = FAT_NODE(fn);
    660673        unsigned bps;
    661674        unsigned dps;
     
    705718}
    706719
    707 void *fat_root_get(dev_handle_t dev_handle)
     720fs_node_t *fat_root_get(dev_handle_t dev_handle)
    708721{
    709722        return fat_node_get(dev_handle, 0);
     
    715728}
    716729
    717 bool fat_is_directory(void *node)
    718 {
    719         return ((fat_node_t *)node)->type == FAT_DIRECTORY;
    720 }
    721 
    722 bool fat_is_file(void *node)
    723 {
    724         return ((fat_node_t *)node)->type == FAT_FILE;
     730bool fat_is_directory(fs_node_t *fn)
     731{
     732        return FAT_NODE(fn)->type == FAT_DIRECTORY;
     733}
     734
     735bool fat_is_file(fs_node_t *fn)
     736{
     737        return FAT_NODE(fn)->type == FAT_FILE;
    725738}
    726739
     
    822835
    823836        /* Initialize the root node. */
    824         fat_node_t *rootp = (fat_node_t *)malloc(sizeof(fat_node_t));
    825         if (!rootp) {
     837        fs_node_t *rfn = (fs_node_t *)malloc(sizeof(fs_node_t));
     838        if (!rfn) {
    826839                block_fini(dev_handle);
    827840                fat_idx_fini_by_dev_handle(dev_handle);
     
    829842                return;
    830843        }
     844        fat_node_t *rootp = (fat_node_t *)malloc(sizeof(fat_node_t));
     845        if (!rootp) {
     846                free(rfn);
     847                block_fini(dev_handle);
     848                fat_idx_fini_by_dev_handle(dev_handle);
     849                ipc_answer_0(rid, ENOMEM);
     850                return;
     851        }
    831852        fat_node_initialize(rootp);
    832853
    833854        fat_idx_t *ridxp = fat_idx_get_by_pos(dev_handle, FAT_CLST_ROOTPAR, 0);
    834855        if (!ridxp) {
     856                free(rfn);
     857                free(rootp);
    835858                block_fini(dev_handle);
    836                 free(rootp);
    837859                fat_idx_fini_by_dev_handle(dev_handle);
    838860                ipc_answer_0(rid, ENOMEM);
     
    849871        rootp->idx = ridxp;
    850872        ridxp->nodep = rootp;
     873        rootp->bp = rfn;
     874        rfn->data = rootp;
    851875       
    852876        futex_up(&ridxp->lock);
     
    870894        fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
    871895        off_t pos = (off_t)IPC_GET_ARG3(*request);
    872         fat_node_t *nodep = (fat_node_t *)fat_node_get(dev_handle, index);
     896        fs_node_t *fn = fat_node_get(dev_handle, index);
     897        fat_node_t *nodep;
    873898        fat_bs_t *bs;
    874899        uint16_t bps;
     
    876901        block_t *b;
    877902
    878         if (!nodep) {
     903        if (!fn) {
    879904                ipc_answer_0(rid, ENOENT);
    880905                return;
    881906        }
     907        nodep = FAT_NODE(fn);
    882908
    883909        ipc_callid_t callid;
    884910        size_t len;
    885911        if (!ipc_data_read_receive(&callid, &len)) {
    886                 fat_node_put(nodep);
     912                fat_node_put(fn);
    887913                ipc_answer_0(callid, EINVAL);
    888914                ipc_answer_0(rid, EINVAL);
     
    955981                }
    956982miss:
    957                 fat_node_put(nodep);
     983                fat_node_put(fn);
    958984                ipc_answer_0(callid, ENOENT);
    959985                ipc_answer_1(rid, ENOENT, 0);
     
    964990        }
    965991
    966         fat_node_put(nodep);
     992        fat_node_put(fn);
    967993        ipc_answer_1(rid, EOK, (ipcarg_t)bytes);
    968994}
     
    973999        fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
    9741000        off_t pos = (off_t)IPC_GET_ARG3(*request);
    975         fat_node_t *nodep = (fat_node_t *)fat_node_get(dev_handle, index);
     1001        fs_node_t *fn = fat_node_get(dev_handle, index);
     1002        fat_node_t *nodep;
    9761003        fat_bs_t *bs;
    9771004        size_t bytes;
     
    9831010        int flags = BLOCK_FLAGS_NONE;
    9841011       
    985         if (!nodep) {
     1012        if (!fn) {
    9861013                ipc_answer_0(rid, ENOENT);
    9871014                return;
    9881015        }
     1016        nodep = FAT_NODE(fn);
    9891017       
    9901018        ipc_callid_t callid;
    9911019        size_t len;
    9921020        if (!ipc_data_write_receive(&callid, &len)) {
    993                 fat_node_put(nodep);
     1021                fat_node_put(fn);
    9941022                ipc_answer_0(callid, EINVAL);
    9951023                ipc_answer_0(rid, EINVAL);
     
    10321060                }
    10331061                ipc_answer_2(rid, EOK, bytes, nodep->size);     
    1034                 fat_node_put(nodep);
     1062                fat_node_put(fn);
    10351063                return;
    10361064        } else {
     
    10481076                if (status != EOK) {
    10491077                        /* could not allocate a chain of nclsts clusters */
    1050                         fat_node_put(nodep);
     1078                        fat_node_put(fn);
    10511079                        ipc_answer_0(callid, status);
    10521080                        ipc_answer_0(rid, status);
     
    10691097                nodep->dirty = true;            /* need to sync node */
    10701098                ipc_answer_2(rid, EOK, bytes, nodep->size);
    1071                 fat_node_put(nodep);
     1099                fat_node_put(fn);
    10721100                return;
    10731101        }
     
    10791107        fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
    10801108        size_t size = (off_t)IPC_GET_ARG3(*request);
    1081         fat_node_t *nodep = (fat_node_t *)fat_node_get(dev_handle, index);
     1109        fs_node_t *fn = fat_node_get(dev_handle, index);
     1110        fat_node_t *nodep;
    10821111        fat_bs_t *bs;
    10831112        uint16_t bps;
     
    10861115        int rc;
    10871116
    1088         if (!nodep) {
     1117        if (!fn) {
    10891118                ipc_answer_0(rid, ENOENT);
    10901119                return;
    10911120        }
     1121        nodep = FAT_NODE(fn);
    10921122
    10931123        bs = block_bb_get(dev_handle);
     
    11271157                rc = EOK;       
    11281158        }
    1129         fat_node_put(nodep);
     1159        fat_node_put(fn);
    11301160        ipc_answer_0(rid, rc);
    11311161        return;
     
    11381168        int rc;
    11391169
    1140         fat_node_t *nodep = fat_node_get(dev_handle, index);
    1141         if (!nodep) {
     1170        fs_node_t *fn = fat_node_get(dev_handle, index);
     1171        if (!fn) {
    11421172                ipc_answer_0(rid, ENOENT);
    11431173                return;
    11441174        }
    11451175
    1146         rc = fat_destroy_node(nodep);
     1176        rc = fat_destroy_node(fn);
    11471177        ipc_answer_0(rid, rc);
    11481178}
  • uspace/srv/fs/tmpfs/tmpfs.h

    rc852f4be rb6035ba  
    4545#endif
    4646
     47#define TMPFS_NODE(node)        ((node) ? (tmpfs_dentry_t *)(node)->data : NULL)
     48#define FS_NODE(node)           ((node) ? (node)->bp : NULL)
     49
    4750typedef enum {
    4851        TMPFS_NONE,
     
    5255
    5356typedef struct tmpfs_dentry {
     57        fs_node_t *bp;          /**< Back pointer to the FS node. */
    5458        fs_index_t index;       /**< TMPFS node index. */
    5559        dev_handle_t dev_handle;/**< Device handle. */
  • uspace/srv/fs/tmpfs/tmpfs_dump.c

    rc852f4be rb6035ba  
    5656static bool
    5757tmpfs_restore_recursion(int dev, off_t *bufpos, size_t *buflen, off_t *pos,
    58     tmpfs_dentry_t *parent)
     58    fs_node_t *pfn)
    5959{
    6060        struct rdentry entry;
     
    6464        do {
    6565                char *fname;
    66                 tmpfs_dentry_t *node;
     66                fs_node_t *fn;
     67                tmpfs_dentry_t *nodep;
    6768                uint32_t size;
    6869               
     
    8182                                return false;
    8283                       
    83                         node = (tmpfs_dentry_t *) ops->create(dev, L_FILE);
    84                         if (node == NULL) {
     84                        fn = ops->create(dev, L_FILE);
     85                        if (fn == NULL) {
    8586                                free(fname);
    8687                                return false;
     
    8990                        if (block_read(dev, bufpos, buflen, pos, fname,
    9091                            entry.len, TMPFS_BLOCK_SIZE) != EOK) {
    91                                 ops->destroy((void *) node);
     92                                ops->destroy(fn);
    9293                                free(fname);
    9394                                return false;
     
    9596                        fname[entry.len] = 0;
    9697                       
    97                         rc = ops->link((void *) parent, (void *) node, fname);
     98                        rc = ops->link(pfn, fn, fname);
    9899                        if (rc != EOK) {
    99                                 ops->destroy((void *) node);
     100                                ops->destroy(fn);
    100101                                free(fname);
    101102                                return false;
     
    109110                        size = uint32_t_le2host(size);
    110111                       
    111                         node->data = malloc(size);
    112                         if (node->data == NULL)
     112                        nodep = TMPFS_NODE(fn);
     113                        nodep->data = malloc(size);
     114                        if (nodep->data == NULL)
    113115                                return false;
    114116                       
    115                         node->size = size;
    116                         if (block_read(dev, bufpos, buflen, pos, node->data,
     117                        nodep->size = size;
     118                        if (block_read(dev, bufpos, buflen, pos, nodep->data,
    117119                            size, TMPFS_BLOCK_SIZE) != EOK)
    118120                                return false;
     
    124126                                return false;
    125127                       
    126                         node = (tmpfs_dentry_t *) ops->create(dev, L_DIRECTORY);
    127                         if (node == NULL) {
     128                        fn = ops->create(dev, L_DIRECTORY);
     129                        if (fn == NULL) {
    128130                                free(fname);
    129131                                return false;
     
    132134                        if (block_read(dev, bufpos, buflen, pos, fname,
    133135                            entry.len, TMPFS_BLOCK_SIZE) != EOK) {
    134                                 ops->destroy((void *) node);
     136                                ops->destroy(fn);
    135137                                free(fname);
    136138                                return false;
     
    138140                        fname[entry.len] = 0;
    139141
    140                         rc = ops->link((void *) parent, (void *) node, fname);
     142                        rc = ops->link(pfn, fn, fname);
    141143                        if (rc != EOK) {
    142                                 ops->destroy((void *) node);
     144                                ops->destroy(fn);
    143145                                free(fname);
    144146                                return false;
     
    147149                       
    148150                        if (!tmpfs_restore_recursion(dev, bufpos, buflen, pos,
    149                             node))
     151                            fn))
    150152                                return false;
    151153                       
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    rc852f4be rb6035ba  
    6969
    7070/* Forward declarations of static functions. */
    71 static void *tmpfs_match(void *, const char *);
    72 static void *tmpfs_node_get(dev_handle_t, fs_index_t);
    73 static void tmpfs_node_put(void *);
    74 static void *tmpfs_create_node(dev_handle_t, int);
    75 static int tmpfs_link_node(void *, void *, const char *);
    76 static int tmpfs_unlink_node(void *, void *);
    77 static int tmpfs_destroy_node(void *);
     71static fs_node_t *tmpfs_match(fs_node_t *, const char *);
     72static fs_node_t *tmpfs_node_get(dev_handle_t, fs_index_t);
     73static void tmpfs_node_put(fs_node_t *);
     74static fs_node_t *tmpfs_create_node(dev_handle_t, int);
     75static int tmpfs_link_node(fs_node_t *, fs_node_t *, const char *);
     76static int tmpfs_unlink_node(fs_node_t *, fs_node_t *);
     77static int tmpfs_destroy_node(fs_node_t *);
    7878
    7979/* Implementation of helper functions. */
    80 static fs_index_t tmpfs_index_get(void *nodep)
    81 {
    82         return ((tmpfs_dentry_t *) nodep)->index;
    83 }
    84 
    85 static size_t tmpfs_size_get(void *nodep)
    86 {
    87         return ((tmpfs_dentry_t *) nodep)->size;
    88 }
    89 
    90 static unsigned tmpfs_lnkcnt_get(void *nodep)
    91 {
    92         return ((tmpfs_dentry_t *) nodep)->lnkcnt;
    93 }
    94 
    95 static bool tmpfs_has_children(void *nodep)
    96 {
    97         return ((tmpfs_dentry_t *) nodep)->child != NULL;
    98 }
    99 
    100 static void *tmpfs_root_get(dev_handle_t dev_handle)
     80static fs_index_t tmpfs_index_get(fs_node_t *fn)
     81{
     82        return TMPFS_NODE(fn)->index;
     83}
     84
     85static size_t tmpfs_size_get(fs_node_t *fn)
     86{
     87        return TMPFS_NODE(fn)->size;
     88}
     89
     90static unsigned tmpfs_lnkcnt_get(fs_node_t *fn)
     91{
     92        return TMPFS_NODE(fn)->lnkcnt;
     93}
     94
     95static bool tmpfs_has_children(fs_node_t *fn)
     96{
     97        return TMPFS_NODE(fn)->child != NULL;
     98}
     99
     100static fs_node_t *tmpfs_root_get(dev_handle_t dev_handle)
    101101{
    102102        return tmpfs_node_get(dev_handle, TMPFS_SOME_ROOT);
     
    108108}
    109109
    110 static bool tmpfs_is_directory(void *nodep)
    111 {
    112         return ((tmpfs_dentry_t *) nodep)->type == TMPFS_DIRECTORY;
    113 }
    114 
    115 static bool tmpfs_is_file(void *nodep)
    116 {
    117         return ((tmpfs_dentry_t *) nodep)->type == TMPFS_FILE;
     110static bool tmpfs_is_directory(fs_node_t *fn)
     111{
     112        return TMPFS_NODE(fn)->type == TMPFS_DIRECTORY;
     113}
     114
     115static bool tmpfs_is_file(fs_node_t *fn)
     116{
     117        return TMPFS_NODE(fn)->type == TMPFS_FILE;
    118118}
    119119
     
    214214static bool tmpfs_dentry_initialize(tmpfs_dentry_t *dentry)
    215215{
     216        dentry->bp = NULL;
    216217        dentry->index = 0;
    217218        dentry->dev_handle = 0;
     
    237238static bool tmpfs_instance_init(dev_handle_t dev_handle)
    238239{
    239         tmpfs_dentry_t *root;
     240        fs_node_t *rfn;
    240241       
    241         root = (tmpfs_dentry_t *) tmpfs_create_node(dev_handle, L_DIRECTORY);
    242         if (!root)
     242        rfn = tmpfs_create_node(dev_handle, L_DIRECTORY);
     243        if (!rfn)
    243244                return false;
    244         root->lnkcnt = 0;       /* FS root is not linked */
     245        TMPFS_NODE(rfn)->lnkcnt = 0;    /* FS root is not linked */
    245246        return true;
    246247}
     
    265266}
    266267
    267 void *tmpfs_match(void *prnt, const char *component)
    268 {
    269         tmpfs_dentry_t *parentp = (tmpfs_dentry_t *) prnt;
     268fs_node_t *tmpfs_match(fs_node_t *pfn, const char *component)
     269{
     270        tmpfs_dentry_t *parentp = TMPFS_NODE(pfn);
    270271        tmpfs_dentry_t *childp = parentp->child;
    271272
     
    273274                childp = childp->sibling;
    274275
    275         return (void *) childp;
    276 }
    277 
    278 void *
    279 tmpfs_node_get(dev_handle_t dev_handle, fs_index_t index)
     276        return FS_NODE(childp);
     277}
     278
     279fs_node_t *tmpfs_node_get(dev_handle_t dev_handle, fs_index_t index)
    280280{
    281281        unsigned long key[] = {
     
    286286        if (!lnk)
    287287                return NULL;
    288         return hash_table_get_instance(lnk, tmpfs_dentry_t, dh_link);
    289 }
    290 
    291 void tmpfs_node_put(void *node)
     288        return FS_NODE(hash_table_get_instance(lnk, tmpfs_dentry_t, dh_link));
     289}
     290
     291void tmpfs_node_put(fs_node_t *fn)
    292292{
    293293        /* nothing to do */
    294294}
    295295
    296 void *tmpfs_create_node(dev_handle_t dev_handle, int lflag)
     296fs_node_t *tmpfs_create_node(dev_handle_t dev_handle, int lflag)
    297297{
    298298        assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY));
    299299
     300        fs_node_t *fn = malloc(sizeof(fs_node_t));
     301        if (!fn)
     302                return NULL;
     303       
    300304        tmpfs_dentry_t *node = malloc(sizeof(tmpfs_dentry_t));
    301         if (!node)
     305        if (!node) {
     306                free(fn);
    302307                return NULL;
    303 
     308        }
    304309        if (!tmpfs_dentry_initialize(node)) {
     310                free(fn);
    305311                free(node);
    306312                return NULL;
    307313        }
     314        fn->data = node;
     315        node->bp = fn;  /* establish the back pointer */
    308316        if (!tmpfs_root_get(dev_handle))
    309317                node->index = TMPFS_SOME_ROOT;
     
    322330        };
    323331        hash_table_insert(&dentries, key, &node->dh_link);
    324         return (void *) node;
    325 }
    326 
    327 int tmpfs_link_node(void *prnt, void *chld, const char *nm)
    328 {
    329         tmpfs_dentry_t *parentp = (tmpfs_dentry_t *) prnt;
    330         tmpfs_dentry_t *childp = (tmpfs_dentry_t *) chld;
     332        return fn;
     333}
     334
     335int tmpfs_link_node(fs_node_t *pfn, fs_node_t *cfn, const char *nm)
     336{
     337        tmpfs_dentry_t *parentp = TMPFS_NODE(pfn);
     338        tmpfs_dentry_t *childp = TMPFS_NODE(cfn);
    331339
    332340        assert(parentp->type == TMPFS_DIRECTORY);
     
    363371}
    364372
    365 int tmpfs_unlink_node(void *prnt, void *chld)
    366 {
    367         tmpfs_dentry_t *parentp = (tmpfs_dentry_t *)prnt;
    368         tmpfs_dentry_t *childp = (tmpfs_dentry_t *)chld;
     373int 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);
    369377
    370378        if (!parentp)
     
    393401}
    394402
    395 int tmpfs_destroy_node(void *nodep)
    396 {
    397         tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) nodep;
     403int tmpfs_destroy_node(fs_node_t *fn)
     404{
     405        tmpfs_dentry_t *dentry = TMPFS_NODE(fn);
    398406       
    399407        assert(!dentry->lnkcnt);
     
    411419        if (dentry->type == TMPFS_FILE)
    412420                free(dentry->data);
     421        free(dentry->bp);
    413422        free(dentry);
    414423        return EOK;
     
    447456        }
    448457
    449         tmpfs_dentry_t *root = tmpfs_root_get(dev_handle);
     458        tmpfs_dentry_t *root = TMPFS_NODE(tmpfs_root_get(dev_handle));
    450459        if (str_cmp(opts, "restore") == 0) {
    451460                if (tmpfs_restore(dev_handle))
     
    673682        tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t,
    674683            dh_link);
    675         rc = tmpfs_destroy_node(dentry);
     684        rc = tmpfs_destroy_node(FS_NODE(dentry));
    676685        ipc_answer_0(rid, rc);
    677686}
Note: See TracChangeset for help on using the changeset viewer.