Changeset 758f8d5 in mainline for uspace/srv/fs/exfat/exfat_ops.c


Ignore:
Timestamp:
2013-09-11T21:53:36Z (11 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e1ec5a2
Parents:
1e371cf (diff), 9dbdda9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge the df branch

File:
1 edited

Legend:

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

    r1e371cf r758f8d5  
    8989static bool exfat_is_file(fs_node_t *node);
    9090static service_id_t exfat_service_get(fs_node_t *node);
     91static int exfat_size_block(service_id_t, uint32_t *);
     92static int exfat_total_block_count(service_id_t, uint64_t *);
     93static int exfat_free_block_count(service_id_t, uint64_t *);
    9194
    9295/*
     
    910913}
    911914
     915int exfat_size_block(service_id_t service_id, uint32_t *size)
     916{
     917        exfat_bs_t *bs;
     918        bs = block_bb_get(service_id);
     919        *size = BPC(bs);
     920
     921        return EOK;
     922}
     923
     924int exfat_total_block_count(service_id_t service_id, uint64_t *count)
     925{
     926        exfat_bs_t *bs;
     927        bs = block_bb_get(service_id);
     928        *count = DATA_CNT(bs);
     929       
     930        return EOK;
     931}
     932
     933int exfat_free_block_count(service_id_t service_id, uint64_t *count)
     934{
     935        fs_node_t *node;
     936        exfat_node_t *bmap_node;
     937        exfat_bs_t *bs;
     938        uint64_t free_block_count = 0;
     939        uint64_t block_count;
     940        unsigned sector;
     941        int rc;
     942
     943        rc = exfat_total_block_count(service_id, &block_count);
     944        if (rc != EOK)
     945                goto exit;
     946
     947        bs = block_bb_get(service_id);
     948        node = NULL;
     949        rc = exfat_bitmap_get(&node, service_id);
     950        if (rc != EOK)
     951                goto exit;
     952
     953        bmap_node = (exfat_node_t *) node->data;
     954
     955        unsigned const bmap_sectors = ROUND_UP(bmap_node->size, BPS(bs)) /
     956            BPS(bs);
     957
     958        for (sector = 0; sector < bmap_sectors; ++sector) {
     959
     960                block_t *block;
     961                uint8_t *bitmap;
     962                unsigned bit;
     963
     964                rc = exfat_block_get(&block, bs, bmap_node, sector,
     965                    BLOCK_FLAGS_NONE);
     966                if (rc != EOK) {
     967                        free_block_count = 0;
     968                        goto exit;
     969                }
     970
     971                bitmap = (uint8_t *) block->data;
     972
     973                for (bit = 0; bit < BPS(bs) * 8 && block_count > 0;
     974                    ++bit, --block_count) {
     975                        if (!(bitmap[bit / 8] & (1 << (bit % 8))))
     976                                ++free_block_count;
     977                }
     978
     979                block_put(block);
     980
     981                if (block_count == 0) {
     982                        /* Reached the end of the bitmap */
     983                        goto exit;
     984                }
     985        }
     986
     987exit:
     988        exfat_node_put(node);
     989        *count = free_block_count;
     990        return rc;
     991}
    912992
    913993/** libfs operations */
     
    9281008        .is_directory = exfat_is_directory,
    9291009        .is_file = exfat_is_file,
    930         .service_get = exfat_service_get
     1010        .service_get = exfat_service_get,
     1011        .size_block = exfat_size_block,
     1012        .total_block_count = exfat_total_block_count,
     1013        .free_block_count = exfat_free_block_count
    9311014};
    9321015
Note: See TracChangeset for help on using the changeset viewer.