Changeset cb682eb in mainline for uspace/srv/fs/fat/fat_fat.c


Ignore:
Timestamp:
2008-10-27T12:45:08Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0ec862d
Parents:
e17d986
Message:

Pass the buffer holding the boot sector to the internal functions so that it
doesn't have to be block_get()'ed in each function. The idea is that the boot
block should be read by the top-level functions in fat_ops.c and passed down the
call chain.

File:
1 edited

Legend:

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

    re17d986 rcb682eb  
    4747
    4848block_t *
    49 _fat_block_get(dev_handle_t dev_handle, fat_cluster_t firstc, off_t offset)
    50 {
    51         block_t *bb;
     49_fat_block_get(fat_bs_t *bs, dev_handle_t dev_handle, fat_cluster_t firstc,
     50    off_t offset)
     51{
    5252        block_t *b;
    5353        unsigned bps;
     
    6363        unsigned i;
    6464
    65         bb = block_get(dev_handle, BS_BLOCK, BS_SIZE);
    66         bps = uint16_t_le2host(FAT_BS(bb)->bps);
    67         spc = FAT_BS(bb)->spc;
    68         rscnt = uint16_t_le2host(FAT_BS(bb)->rscnt);
    69         fatcnt = FAT_BS(bb)->fatcnt;
    70         rde = uint16_t_le2host(FAT_BS(bb)->root_ent_max);
    71         sf = uint16_t_le2host(FAT_BS(bb)->sec_per_fat);
    72         block_put(bb);
     65        bps = uint16_t_le2host(bs->bps);
     66        spc = bs->spc;
     67        rscnt = uint16_t_le2host(bs->rscnt);
     68        fatcnt = bs->fatcnt;
     69        rde = uint16_t_le2host(bs->root_ent_max);
     70        sf = uint16_t_le2host(bs->sec_per_fat);
    7371
    7472        rds = (sizeof(fat_dentry_t) * rde) / bps;
     
    107105/** Return number of blocks allocated to a file.
    108106 *
     107 * @param bs            Buffer holding the boot sector for the file.
    109108 * @param dev_handle    Device handle of the device with the file.
    110109 * @param firstc        First cluster of the file.
     
    115114 */
    116115uint16_t
    117 _fat_blcks_get(dev_handle_t dev_handle, fat_cluster_t firstc,
     116_fat_blcks_get(fat_bs_t *bs, dev_handle_t dev_handle, fat_cluster_t firstc,
    118117    fat_cluster_t *lastc)
    119118{
    120         block_t *bb;
    121119        block_t *b;
    122120        unsigned bps;
     
    126124        fat_cluster_t clst = firstc;
    127125
    128         bb = block_get(dev_handle, BS_BLOCK, BS_SIZE);
    129         bps = uint16_t_le2host(FAT_BS(bb)->bps);
    130         spc = FAT_BS(bb)->spc;
    131         rscnt = uint16_t_le2host(FAT_BS(bb)->rscnt);
    132         block_put(bb);
     126        bps = uint16_t_le2host(bs->bps);
     127        spc = bs->spc;
     128        rscnt = uint16_t_le2host(bs->rscnt);
    133129
    134130        if (firstc == FAT_CLST_RES0) {
     
    161157}
    162158
    163 uint16_t fat_bps_get(dev_handle_t dev_handle)
    164 {
    165         block_t *bb;
    166         uint16_t bps;
    167        
    168         bb = block_get(dev_handle, BS_BLOCK, BS_SIZE);
    169         assert(bb != NULL);
    170         bps = uint16_t_le2host(FAT_BS(bb)->bps);
    171         block_put(bb);
    172 
    173         return bps;
    174 }
    175 
    176159/** Fill the gap between EOF and a new file position.
    177160 *
     161 * @param bs            Buffer holding the boot sector for nodep.
    178162 * @param nodep         FAT node with the gap.
    179163 * @param mcl           First cluster in an independent cluster chain that will
     
    183167 * @param pos           Position in the last node block.
    184168 */
    185 void fat_fill_gap(fat_node_t *nodep, fat_cluster_t mcl, off_t pos)
     169void fat_fill_gap(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl, off_t pos)
    186170{
    187171        uint16_t bps;
    188172        unsigned spc;
    189         block_t *bb, *b;
     173        block_t *b;
    190174        off_t o, boundary;
    191175
    192         bb = block_get(nodep->idx->dev_handle, BS_BLOCK, BS_SIZE);
    193         bps = uint16_t_le2host(FAT_BS(bb)->bps);
    194         spc = FAT_BS(bb)->spc;
    195         block_put(bb);
     176        bps = uint16_t_le2host(bs->bps);
     177        spc = bs->spc;
    196178       
    197179        boundary = ROUND_UP(nodep->size, bps * spc);
     
    200182        for (o = nodep->size - 1; o < pos && o < boundary;
    201183            o = ALIGN_DOWN(o + bps, bps)) {
    202                 b = fat_block_get(nodep, o / bps);
     184                b = fat_block_get(bs, nodep, o / bps);
    203185                memset(b->data + o % bps, 0, bps - o % bps);
    204186                b->dirty = true;                /* need to sync node */
     
    211193        /* zero out the initial part of the new cluster chain */
    212194        for (o = boundary; o < pos; o += bps) {
    213                 b = _fat_block_get(nodep->idx->dev_handle, mcl,
     195                b = _fat_block_get(bs, nodep->idx->dev_handle, mcl,
    214196                    (o - boundary) / bps);
    215197                memset(b->data, 0, min(bps, pos - o));
     
    220202
    221203void
    222 fat_mark_cluster(dev_handle_t dev_handle, unsigned fatno, fat_cluster_t clst,
    223     fat_cluster_t value)
    224 {
    225         block_t *bb, *blk;
     204fat_mark_cluster(fat_bs_t *bs, dev_handle_t dev_handle, unsigned fatno,
     205    fat_cluster_t clst, fat_cluster_t value)
     206{
     207        block_t *b;
    226208        uint16_t bps;
    227209        uint16_t rscnt;
    228210        uint16_t sf;
    229         uint8_t fatcnt;
    230211        fat_cluster_t *cp;
    231212
    232         bb = block_get(dev_handle, BS_BLOCK, BS_SIZE);
    233         bps = uint16_t_le2host(FAT_BS(bb)->bps);
    234         rscnt = uint16_t_le2host(FAT_BS(bb)->rscnt);
    235         sf = uint16_t_le2host(FAT_BS(bb)->sec_per_fat);
    236         fatcnt = FAT_BS(bb)->fatcnt;
    237         block_put(bb);
    238 
    239         assert(fatno < fatcnt);
    240         blk = block_get(dev_handle, rscnt + sf * fatno +
     213        bps = uint16_t_le2host(bs->bps);
     214        rscnt = uint16_t_le2host(bs->rscnt);
     215        sf = uint16_t_le2host(bs->sec_per_fat);
     216
     217        assert(fatno < bs->fatcnt);
     218        b = block_get(dev_handle, rscnt + sf * fatno +
    241219            (clst * sizeof(fat_cluster_t)) / bps, bps);
    242         cp = (fat_cluster_t *)blk->data + clst % (bps / sizeof(fat_cluster_t));
     220        cp = (fat_cluster_t *)b->data + clst % (bps / sizeof(fat_cluster_t));
    243221        *cp = host2uint16_t_le(value);
    244         blk->dirty = true;              /* need to sync block */
    245         block_put(blk);
    246 }
    247 
    248 void fat_alloc_shadow_clusters(dev_handle_t dev_handle, fat_cluster_t *lifo,
    249     unsigned nclsts)
    250 {
    251         uint8_t fatcnt;
     222        b->dirty = true;                /* need to sync block */
     223        block_put(b);
     224}
     225
     226void fat_alloc_shadow_clusters(fat_bs_t *bs, dev_handle_t dev_handle,
     227    fat_cluster_t *lifo, unsigned nclsts)
     228{
    252229        uint8_t fatno;
    253230        unsigned c;
    254         block_t *bb;
    255 
    256         bb = block_get(dev_handle, BS_BLOCK, BS_SIZE);
    257         fatcnt = FAT_BS(bb)->fatcnt;
    258         block_put(bb);
    259        
    260         for (fatno = FAT1 + 1; fatno < fatcnt; fatno++) {
     231
     232        for (fatno = FAT1 + 1; fatno < bs->fatcnt; fatno++) {
    261233                for (c = 0; c < nclsts; c++) {
    262                         fat_mark_cluster(dev_handle, fatno, lifo[c],
     234                        fat_mark_cluster(bs, dev_handle, fatno, lifo[c],
    263235                            c == 0 ? FAT_CLST_LAST1 : lifo[c - 1]);
    264236                }
     
    267239
    268240int
    269 fat_alloc_clusters(dev_handle_t dev_handle, unsigned nclsts, fat_cluster_t *mcl,
    270     fat_cluster_t *lcl)
     241fat_alloc_clusters(fat_bs_t *bs, dev_handle_t dev_handle, unsigned nclsts,
     242    fat_cluster_t *mcl, fat_cluster_t *lcl)
    271243{
    272244        uint16_t bps;
    273245        uint16_t rscnt;
    274246        uint16_t sf;
    275         block_t *bb, *blk;
     247        block_t *blk;
    276248        fat_cluster_t *lifo;    /* stack for storing free cluster numbers */
    277249        unsigned found = 0;     /* top of the free cluster number stack */
     
    282254                return ENOMEM;
    283255       
    284         bb = block_get(dev_handle, BS_BLOCK, BS_SIZE);
    285         bps = uint16_t_le2host(FAT_BS(bb)->bps);
    286         rscnt = uint16_t_le2host(FAT_BS(bb)->rscnt);
    287         sf = uint16_t_le2host(FAT_BS(bb)->sec_per_fat);
    288         block_put(bb);
     256        bps = uint16_t_le2host(bs->bps);
     257        rscnt = uint16_t_le2host(bs->rscnt);
     258        sf = uint16_t_le2host(bs->sec_per_fat);
    289259       
    290260        /*
     
    309279                                        block_put(blk);
    310280                                        /* update the shadow copies of FAT */
    311                                         fat_alloc_shadow_clusters(dev_handle,
    312                                             lifo, nclsts);
     281                                        fat_alloc_shadow_clusters(bs,
     282                                            dev_handle, lifo, nclsts);
    313283                                        *mcl = lifo[found - 1];
    314284                                        *lcl = lifo[0];
     
    325295         * we have allocated so far.
    326296         */
    327         while (found--)
    328                 fat_mark_cluster(dev_handle, FAT1, lifo[found], FAT_CLST_RES0);
     297        while (found--) {
     298                fat_mark_cluster(bs, dev_handle, FAT1, lifo[found],
     299                    FAT_CLST_RES0);
     300        }
    329301       
    330302        free(lifo);
     
    332304}
    333305
    334 void fat_append_clusters(fat_node_t *nodep, fat_cluster_t mcl)
    335 {
    336         block_t *bb;
     306void fat_append_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl)
     307{
     308        dev_handle_t dev_handle = nodep->idx->dev_handle;
    337309        fat_cluster_t lcl;
    338         uint8_t fatcnt, fatno;
    339 
    340         if (_fat_blcks_get(nodep->idx->dev_handle, nodep->firstc, &lcl) == 0) {
     310        uint8_t fatno;
     311
     312        if (_fat_blcks_get(bs, dev_handle, nodep->firstc, &lcl) == 0) {
    341313                nodep->firstc = host2uint16_t_le(mcl);
    342314                nodep->dirty = true;            /* need to sync node */
     
    344316        }
    345317
    346         bb = block_get(nodep->idx->dev_handle, BS_BLOCK, BS_SIZE);
    347         fatcnt = FAT_BS(bb)->fatcnt;
    348         block_put(bb);
    349 
    350         for (fatno = FAT1; fatno < fatcnt; fatno++)
    351                 fat_mark_cluster(nodep->idx->dev_handle, fatno, lcl, mcl);
     318        for (fatno = FAT1; fatno < bs->fatcnt; fatno++)
     319                fat_mark_cluster(bs, nodep->idx->dev_handle, fatno, lcl, mcl);
    352320}
    353321
Note: See TracChangeset for help on using the changeset viewer.