Changeset 2c4bbcde in mainline


Ignore:
Timestamp:
2008-05-11T11:16:41Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5d12283
Parents:
4573a79
Message:

More bits of fat_node_get().
Still needs to do some locking.

Location:
uspace/srv/fs/fat
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/fat/fat.h

    r4573a79 r2c4bbcde  
    206206         */
    207207        fat_cluster_t           firstc;
    208         /** FAT in-core node hash table link. */
    209         link_t                  fin_link;
    210208        /** FAT in-core node free list link. */
    211209        link_t                  ffn_link;
  • uspace/srv/fs/fat/fat_ops.c

    r4573a79 r2c4bbcde  
    5151#define BS_BLOCK                0
    5252
    53 #define FIN_KEY_DEV_HANDLE      0
    54 #define FIN_KEY_INDEX           1
    55 
    56 /** Hash table of FAT in-core nodes. */
    57 hash_table_t fin_hash;
    58 
    59 /** List of free FAT in-core nodes. */
    60 link_t ffn_head;
     53/** List of free FAT nodes that still contain valid data. */
     54LIST_INITIALIZE(ffn_head);
    6155
    6256#define FAT_NAME_LEN            8
     
    126120
    127121static block_t *
    128 _fat_block_get(dev_handle_t dev_handle, fat_cluster_t fc, off_t offset)
     122_fat_block_get(dev_handle_t dev_handle, fat_cluster_t firstc, off_t offset)
    129123{
    130124        block_t *bb;
     
    139133        unsigned ssa;           /* size of the system area */
    140134        unsigned clusters;
    141         fat_cluster_t clst = fc;
     135        fat_cluster_t clst = firstc;
    142136        unsigned i;
    143137
     
    155149        ssa = rscnt + fatcnt * sf + rds;
    156150
    157         if (fc == FAT_CLST_RES1) {
     151        if (firstc == FAT_CLST_RES1) {
    158152                /* root directory special case */
    159153                assert(offset < rds);
     
    188182        node->idx = NULL;
    189183        node->type = 0;
    190         link_initialize(&node->fin_link);
    191184        link_initialize(&node->ffn_link);
    192185        node->size = 0;
     
    239232}
    240233
    241 static void fat_sync_node(fat_node_t *node)
     234static void fat_node_sync(fat_node_t *node)
    242235{
    243236        /* TODO */
     
    273266        assert(idx->pfc);
    274267
    275         nodep = (fat_node_t *)malloc(sizeof(fat_node_t));
    276         if (!nodep)
    277                 return NULL;
     268        if (!list_empty(&ffn_head)) {
     269                /* Try to use a cached unused node structure. */
     270                nodep = list_get_instance(ffn_head.next, fat_node_t, ffn_link);
     271                if (nodep->dirty)
     272                        fat_node_sync(nodep);
     273                list_remove(&nodep->ffn_link);
     274                nodep->idx->nodep = NULL;
     275        } else {
     276                /* Try to allocate a new node structure. */
     277                nodep = (fat_node_t *)malloc(sizeof(fat_node_t));
     278                if (!nodep)
     279                        return NULL;
     280        }
    278281        fat_node_initialize(nodep);
    279282
     
    281284        dps = bps / sizeof(fat_dentry_t);
    282285
     286        /* Read the block that contains the dentry of interest. */
    283287        b = _fat_block_get(dev_handle, idx->pfc,
    284288            (idx->pdi * sizeof(fat_dentry_t)) / bps);
    285 
    286289        assert(b);
    287290
    288291        d = ((fat_dentry_t *)b->data) + (idx->pdi % dps);
    289         /* XXX */
     292        if (d->attr & FAT_ATTR_SUBDIR) {
     293                /*
     294                 * The only directory which does not have this bit set is the
     295                 * root directory itself. The root directory node is handled
     296                 * and initialized elsewhere.
     297                 */
     298                nodep->type = FAT_DIRECTORY;
     299        } else {
     300                nodep->type = FAT_FILE;
     301        }
     302        nodep->firstc = uint16_t_le2host(d->firstc);
     303        nodep->size = uint32_t_le2host(d->size);
     304        nodep->lnkcnt = 1;
     305        nodep->refcnt = 1;
     306
     307        block_put(b);
     308
     309        /* Link the idx structure with the node structure. */
     310        nodep->idx = idx;
     311        idx->nodep = nodep;
     312
     313        return nodep;
    290314}
    291315
     
    441465static void *fat_root_get(dev_handle_t dev_handle)
    442466{
    443         return fat_node_get(dev_handle, 0);     /* TODO */
     467        return NULL;    /* TODO */
    444468}
    445469
Note: See TracChangeset for help on using the changeset viewer.