Ignore:
File:
1 edited

Legend:

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

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