Changeset 869e546 in mainline for uspace/srv/fs/fat/fat_ops.c


Ignore:
Timestamp:
2008-04-20T22:37:13Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
297f1197
Parents:
34f62f8
Message:

Introduce the foundation for unique and stable FAT VFS node indices.

The first two reserved FAT entries are physically present in each FAT, so fix
the code to be aware of this.

File:
1 edited

Legend:

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

    r34f62f8 r869e546  
    5454#define FIN_KEY_INDEX           1
    5555
    56 /** Futex protecting both fin_hash and ffn_head. */
    57 futex_t fin_futex = FUTEX_INITIALIZER;
    58 
    5956/** Hash table of FAT in-core nodes. */
    6057hash_table_t fin_hash;
     
    116113}
    117114
     115static fat_idx_t *fat_idx_map(fat_cluster_t pfc, unsigned pdi)
     116{
     117        return NULL;    /* TODO */
     118}
    118119
    119120#define FAT_BS(b)               ((fat_bs_t *)((b)->data))
    120121
     122#define FAT_CLST_RES0   0x0000
     123#define FAT_CLST_RES1   0x0001  /* internally used to mark root directory */
    121124#define FAT_CLST_FIRST  0x0002
    122125#define FAT_CLST_BAD    0xfff7
     
    124127#define FAT_CLST_LAST8  0xffff
    125128
    126 /** Convert cluster number to an index within a FAT.
    127  *
    128  * Format Identifier and cluster numbering is considered.
    129  */
    130 #define C2FAT_IDX(c)    (1 + (c) - FAT_CLST_FIRST)
    131 
    132 static block_t *fat_block_get(dev_handle_t dev_handle, fs_index_t index,
    133     off_t offset)
     129static block_t *fat_block_get(fat_node_t *nodep, off_t offset)
    134130{
    135131        block_t *bb;
     
    144140        unsigned ssa;           /* size of the system area */
    145141        unsigned clusters;
    146         unsigned clst = index;
     142        fat_cluster_t clst = nodep->firstc;
    147143        unsigned i;
    148144
    149         bb = block_get(dev_handle, BS_BLOCK);
     145        bb = block_get(nodep->idx->dev_handle, BS_BLOCK);
    150146        bps = uint16_t_le2host(FAT_BS(bb)->bps);
    151147        spc = FAT_BS(bb)->spc;
     
    160156        ssa = rscnt + fatcnt * sf + rds;
    161157
    162         if (!index) {
     158        if (nodep->idx->index == FAT_CLST_RES1) {
    163159                /* root directory special case */
    164160                assert(offset < rds);
    165                 b = block_get(dev_handle, rscnt + fatcnt * sf + offset);
     161                b = block_get(nodep->idx->dev_handle,
     162                    rscnt + fatcnt * sf + offset);
    166163                return b;
    167164        }
     
    173170
    174171                assert(clst >= FAT_CLST_FIRST && clst < FAT_CLST_BAD);
    175                 fsec = (C2FAT_IDX(clst) * sizeof(uint16_t)) / bps;
    176                 fidx = C2FAT_IDX(clst) % (bps / sizeof(uint16_t));
     172                fsec = (clst * sizeof(fat_cluster_t)) / bps;
     173                fidx = clst % (bps / sizeof(fat_cluster_t));
    177174                /* read FAT1 */
    178                 b = block_get(dev_handle, rscnt + fsec);
    179                 clst = uint16_t_le2host(((uint16_t *)b->data)[fidx]);
     175                b = block_get(nodep->idx->dev_handle, rscnt + fsec);
     176                clst = uint16_t_le2host(((fat_cluster_t *)b->data)[fidx]);
    180177                assert(clst != FAT_CLST_BAD);
    181178                assert(clst < FAT_CLST_LAST1);
     
    183180        }
    184181
    185         b = block_get(dev_handle, ssa + (clst - FAT_CLST_FIRST) * spc +
    186             offset % spc);
     182        b = block_get(nodep->idx->dev_handle, ssa +
     183            (clst - FAT_CLST_FIRST) * spc + offset % spc);
    187184
    188185        return b;
     
    191188static void fat_node_initialize(fat_node_t *node)
    192189{
    193         futex_initialize(&node->lock, 1);
     190        node->idx = NULL;
    194191        node->type = 0;
    195         node->index = 0;
    196         node->pindex = 0;
    197         node->dev_handle = 0;
    198192        link_initialize(&node->fin_link);
    199193        link_initialize(&node->ffn_link);
     
    295289        block_t *b;
    296290
    297         bps = fat_bps_get(parentp->dev_handle);
     291        bps = fat_bps_get(parentp->idx->dev_handle);
    298292        dps = bps / sizeof(fat_dentry_t);
    299293        blocks = parentp->size / bps + (parentp->size % bps != 0);
     
    301295                unsigned dentries;
    302296               
    303                 b = fat_block_get(parentp->dev_handle, parentp->index, i);
     297                b = fat_block_get(parentp, i);
    304298                dentries = (i == blocks - 1) ?
    305299                    parentp->size % sizeof(fat_dentry_t) :
     
    320314                        if (strcmp(name, component) == 0) {
    321315                                /* hit */
    322                                 void *node = fat_node_get(parentp->dev_handle,
    323                                     (fs_index_t)uint16_t_le2host(d->firstc));
     316                                fat_idx_t *idx = fat_idx_map(parentp->firstc,
     317                                    i * dps + j);
     318                                void *node = fat_node_get(idx->dev_handle,
     319                                    idx->index);
    324320                                block_put(b);
    325321                                return node;
     
    337333        if (!fnodep)
    338334                return 0;
    339         return fnodep->index;
     335        return fnodep->idx->index;
    340336}
    341337
     
    362358                return false;
    363359
    364         bps = fat_bps_get(nodep->dev_handle);
     360        bps = fat_bps_get(nodep->idx->dev_handle);
    365361        dps = bps / sizeof(fat_dentry_t);
    366362
     
    371367                fat_dentry_t *d;
    372368       
    373                 b = fat_block_get(nodep->dev_handle, nodep->index, i);
     369                b = fat_block_get(nodep, i);
    374370                dentries = (i == blocks - 1) ?
    375371                    nodep->size % sizeof(fat_dentry_t) :
     
    399395static void *fat_root_get(dev_handle_t dev_handle)
    400396{
    401         return fat_node_get(dev_handle, 0);     
     397        return fat_node_get(dev_handle, FAT_CLST_RES1);
    402398}
    403399
Note: See TracChangeset for help on using the changeset viewer.