Changeset 4573a79 in mainline


Ignore:
Timestamp:
2008-05-08T21:29:24Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2c4bbcde
Parents:
4797132
Message:

New first bits of fat_node_get().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/fat/fat_ops.c

    r4797132 r4573a79  
    122122#define FAT_CLST_LAST8  0xffff
    123123
    124 static block_t *fat_block_get(fat_node_t *nodep, off_t offset)
     124#define fat_block_get(np, off) \
     125    _fat_block_get((np)->idx->dev_handle, (np)->firstc, (off))
     126
     127static block_t *
     128_fat_block_get(dev_handle_t dev_handle, fat_cluster_t fc, off_t offset)
    125129{
    126130        block_t *bb;
     
    135139        unsigned ssa;           /* size of the system area */
    136140        unsigned clusters;
    137         fat_cluster_t clst = nodep->firstc;
     141        fat_cluster_t clst = fc;
    138142        unsigned i;
    139143
    140         bb = block_get(nodep->idx->dev_handle, BS_BLOCK);
     144        bb = block_get(dev_handle, BS_BLOCK);
    141145        bps = uint16_t_le2host(FAT_BS(bb)->bps);
    142146        spc = FAT_BS(bb)->spc;
     
    151155        ssa = rscnt + fatcnt * sf + rds;
    152156
    153         if (nodep->idx->index == FAT_CLST_RES1) {
     157        if (fc == FAT_CLST_RES1) {
    154158                /* root directory special case */
    155159                assert(offset < rds);
    156                 b = block_get(nodep->idx->dev_handle,
    157                     rscnt + fatcnt * sf + offset);
     160                b = block_get(dev_handle, rscnt + fatcnt * sf + offset);
    158161                return b;
    159162        }
     
    168171                fidx = clst % (bps / sizeof(fat_cluster_t));
    169172                /* read FAT1 */
    170                 b = block_get(nodep->idx->dev_handle, rscnt + fsec);
     173                b = block_get(dev_handle, rscnt + fsec);
    171174                clst = uint16_t_le2host(((fat_cluster_t *)b->data)[fidx]);
    172175                assert(clst != FAT_CLST_BAD);
     
    175178        }
    176179
    177         b = block_get(nodep->idx->dev_handle, ssa +
    178             (clst - FAT_CLST_FIRST) * spc + offset % spc);
     180        b = block_get(dev_handle, ssa + (clst - FAT_CLST_FIRST) * spc +
     181            offset % spc);
    179182
    180183        return b;
     
    242245
    243246/** Instantiate a FAT in-core node. */
    244 static void *
    245 fat_node_get(dev_handle_t dev_handle, fs_index_t index)
    246 {
    247         return NULL;    /* TODO */
     247static void *fat_node_get(dev_handle_t dev_handle, fs_index_t index)
     248{
     249        fat_idx_t *idx;
     250        block_t *b;
     251        fat_dentry_t *d;
     252        fat_node_t *nodep;
     253        unsigned bps;
     254        unsigned dps;
     255
     256        idx = fat_idx_get_by_index(dev_handle, index);
     257        if (!idx)
     258                return NULL;
     259
     260        if (idx->nodep) {
     261                /*
     262                 * We are lucky.
     263                 * The node is already instantiated in memory.
     264                 */
     265                idx->nodep->refcnt++;
     266                return idx->nodep;
     267        }
     268
     269        /*
     270         * We must instantiate the node from the file system.
     271         */
     272       
     273        assert(idx->pfc);
     274
     275        nodep = (fat_node_t *)malloc(sizeof(fat_node_t));
     276        if (!nodep)
     277                return NULL;
     278        fat_node_initialize(nodep);
     279
     280        bps = fat_bps_get(dev_handle);
     281        dps = bps / sizeof(fat_dentry_t);
     282
     283        b = _fat_block_get(dev_handle, idx->pfc,
     284            (idx->pdi * sizeof(fat_dentry_t)) / bps);
     285
     286        assert(b);
     287
     288        d = ((fat_dentry_t *)b->data) + (idx->pdi % dps);
     289        /* XXX */
    248290}
    249291
     
    399441static void *fat_root_get(dev_handle_t dev_handle)
    400442{
    401         return fat_node_get(dev_handle, FAT_CLST_RES1);
     443        return fat_node_get(dev_handle, 0);     /* TODO */
    402444}
    403445
Note: See TracChangeset for help on using the changeset viewer.