Ignore:
File:
1 edited

Legend:

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

    r2463df9 rfeeac0d  
    5858#include <assert.h>
    5959#include <fibril_synch.h>
     60#include <sys/mman.h>
    6061#include <align.h>
    6162#include <malloc.h>
     
    8889static bool exfat_is_file(fs_node_t *node);
    8990static service_id_t exfat_service_get(fs_node_t *node);
    90 static int exfat_size_block(service_id_t, uint32_t *);
    91 static int exfat_total_block_count(service_id_t, uint64_t *);
    92 static int exfat_free_block_count(service_id_t, uint64_t *);
    9391
    9492/*
     
    912910}
    913911
    914 int exfat_size_block(service_id_t service_id, uint32_t *size)
    915 {
    916         exfat_bs_t *bs;
    917         bs = block_bb_get(service_id);
    918         *size = BPC(bs);
    919 
    920         return EOK;
    921 }
    922 
    923 int exfat_total_block_count(service_id_t service_id, uint64_t *count)
    924 {
    925         exfat_bs_t *bs;
    926         bs = block_bb_get(service_id);
    927         *count = DATA_CNT(bs);
    928        
    929         return EOK;
    930 }
    931 
    932 int exfat_free_block_count(service_id_t service_id, uint64_t *count)
    933 {
    934         fs_node_t *node;
    935         exfat_node_t *bmap_node;
    936         exfat_bs_t *bs;
    937         uint64_t free_block_count = 0;
    938         uint64_t block_count;
    939         unsigned sector;
    940         int rc;
    941 
    942         rc = exfat_total_block_count(service_id, &block_count);
    943         if (rc != EOK)
    944                 goto exit;
    945 
    946         bs = block_bb_get(service_id);
    947         node = NULL;
    948         rc = exfat_bitmap_get(&node, service_id);
    949         if (rc != EOK)
    950                 goto exit;
    951 
    952         bmap_node = (exfat_node_t *) node->data;
    953 
    954         unsigned const bmap_sectors = ROUND_UP(bmap_node->size, BPS(bs)) /
    955             BPS(bs);
    956 
    957         for (sector = 0; sector < bmap_sectors; ++sector) {
    958 
    959                 block_t *block;
    960                 uint8_t *bitmap;
    961                 unsigned bit;
    962 
    963                 rc = exfat_block_get(&block, bs, bmap_node, sector,
    964                     BLOCK_FLAGS_NONE);
    965                 if (rc != EOK) {
    966                         free_block_count = 0;
    967                         goto exit;
    968                 }
    969 
    970                 bitmap = (uint8_t *) block->data;
    971 
    972                 for (bit = 0; bit < BPS(bs) * 8 && block_count > 0;
    973                     ++bit, --block_count) {
    974                         if (!(bitmap[bit / 8] & (1 << (bit % 8))))
    975                                 ++free_block_count;
    976                 }
    977 
    978                 block_put(block);
    979 
    980                 if (block_count == 0) {
    981                         /* Reached the end of the bitmap */
    982                         goto exit;
    983                 }
    984         }
    985 
    986 exit:
    987         exfat_node_put(node);
    988         *count = free_block_count;
    989         return rc;
    990 }
    991912
    992913/** libfs operations */
     
    1007928        .is_directory = exfat_is_directory,
    1008929        .is_file = exfat_is_file,
    1009         .service_get = exfat_service_get,
    1010         .size_block = exfat_size_block,
    1011         .total_block_count = exfat_total_block_count,
    1012         .free_block_count = exfat_free_block_count
     930        .service_get = exfat_service_get
    1013931};
    1014932
Note: See TracChangeset for help on using the changeset viewer.