Changeset 25c60f4 in mainline for uspace/srv/fs/exfat/exfat_bitmap.c


Ignore:
Timestamp:
2011-08-14T09:32:44Z (13 years ago)
Author:
Oleg Romanenko <romanenko.oleg@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f061de75
Parents:
5d5863c
Message:

exFAT: implement bitmap_is_free, bitmap_clear_cluster

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/exfat/exfat_bitmap.c

    r5d5863c r25c60f4  
    5252    exfat_cluster_t clst)
    5353{
    54         /* TODO */
    55         return EOK;
    56 }
    57 
    58 int bitmap_set_cluster(exfat_bs_t *bs, devmap_handle_t devmap_handle,
    59     exfat_cluster_t firstc)
    60 {
    6154        fs_node_t *fn;
    6255        block_t *b=NULL;
     
    6457        uint8_t *bitmap;
    6558        int rc;
    66 
    67         firstc -= EXFAT_CLST_FIRST;
    68        
    69         /* rc = exfat_node_get(&fn, devmap_handle, EXFAT_BITMAP_IDX); */
     59        bool alloc;
     60
     61        clst -= EXFAT_CLST_FIRST;
     62       
    7063        rc = exfat_bitmap_get(&fn, devmap_handle);
    7164        if (rc != EOK)
     
    7366        bitmapp = EXFAT_NODE(fn);
    7467       
    75         aoff64_t offset = firstc / 8;
     68        aoff64_t offset = clst / 8;
    7669        rc = exfat_block_get(&b, bs, bitmapp, offset / BPS(bs), BLOCK_FLAGS_NONE);
    7770        if (rc != EOK) {
     
    8073        }
    8174        bitmap = (uint8_t *)b->data;
    82         bitmap[offset % BPS(bs)] |= (1 << (firstc % 8));
     75        alloc = bitmap[offset % BPS(bs)] & (1 << (clst % 8));
     76
     77        rc = block_put(b);
     78        if (rc != EOK) {
     79                (void) exfat_node_put(fn);
     80                return rc;
     81        }
     82        rc = exfat_node_put(fn);
     83        if (rc != EOK)
     84                return rc;
     85
     86        if (alloc)
     87                return ENOENT;
     88
     89        return EOK;
     90}
     91
     92int bitmap_set_cluster(exfat_bs_t *bs, devmap_handle_t devmap_handle,
     93    exfat_cluster_t clst)
     94{
     95        fs_node_t *fn;
     96        block_t *b=NULL;
     97        exfat_node_t *bitmapp;
     98        uint8_t *bitmap;
     99        int rc;
     100
     101        clst -= EXFAT_CLST_FIRST;
     102       
     103        rc = exfat_bitmap_get(&fn, devmap_handle);
     104        if (rc != EOK)
     105                return rc;
     106        bitmapp = EXFAT_NODE(fn);
     107       
     108        aoff64_t offset = clst / 8;
     109        rc = exfat_block_get(&b, bs, bitmapp, offset / BPS(bs), BLOCK_FLAGS_NONE);
     110        if (rc != EOK) {
     111                (void) exfat_node_put(fn);
     112                return rc;
     113        }
     114        bitmap = (uint8_t *)b->data;
     115        bitmap[offset % BPS(bs)] |= (1 << (clst % 8));
    83116
    84117        b->dirty = true;
     
    93126
    94127int bitmap_clear_cluster(exfat_bs_t *bs, devmap_handle_t devmap_handle,
    95     exfat_cluster_t firstc)
    96 {
    97         /* TODO */
    98         return EOK;
     128    exfat_cluster_t clst)
     129{
     130        fs_node_t *fn;
     131        block_t *b=NULL;
     132        exfat_node_t *bitmapp;
     133        uint8_t *bitmap;
     134        int rc;
     135
     136        clst -= EXFAT_CLST_FIRST;
     137       
     138        rc = exfat_bitmap_get(&fn, devmap_handle);
     139        if (rc != EOK)
     140                return rc;
     141        bitmapp = EXFAT_NODE(fn);
     142       
     143        aoff64_t offset = clst / 8;
     144        rc = exfat_block_get(&b, bs, bitmapp, offset / BPS(bs), BLOCK_FLAGS_NONE);
     145        if (rc != EOK) {
     146                (void) exfat_node_put(fn);
     147                return rc;
     148        }
     149        bitmap = (uint8_t *)b->data;
     150        bitmap[offset % BPS(bs)] &= ~(1 << (clst % 8));
     151
     152        b->dirty = true;
     153        rc = block_put(b);
     154        if (rc != EOK) {
     155                (void) exfat_node_put(fn);
     156                return rc;
     157        }
     158       
     159        return exfat_node_put(fn);
    99160}
    100161
Note: See TracChangeset for help on using the changeset viewer.