Ignore:
File:
1 edited

Legend:

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

    r44ecf89 r1558d85  
    5555#include <assert.h>
    5656#include <fibril_synch.h>
    57 #include <sys/mman.h>
    5857#include <align.h>
    5958#include <malloc.h>
    60 #include <str.h>
    6159
    6260#define FAT_NODE(node)  ((node) ? (fat_node_t *) (node)->data : NULL)
     
    9189static bool fat_is_file(fs_node_t *node);
    9290static service_id_t fat_service_get(fs_node_t *node);
     91static int fat_size_block(service_id_t, uint32_t *);
     92static int fat_total_block_count(service_id_t, uint64_t *);
     93static int fat_free_block_count(service_id_t, uint64_t *);
    9394
    9495/*
     
    149150static int fat_node_fini_by_service_id(service_id_t service_id)
    150151{
    151         fat_node_t *nodep;
    152152        int rc;
    153153
     
    160160restart:
    161161        fibril_mutex_lock(&ffn_mutex);
    162         list_foreach(ffn_list, lnk) {
    163                 nodep = list_get_instance(lnk, fat_node_t, ffn_link);
     162        list_foreach(ffn_list, ffn_link, fat_node_t, nodep) {
    164163                if (!fibril_mutex_trylock(&nodep->lock)) {
    165164                        fibril_mutex_unlock(&ffn_mutex);
     
    843842}
    844843
     844int fat_size_block(service_id_t service_id, uint32_t *size)
     845{
     846        fat_bs_t *bs;
     847
     848        bs = block_bb_get(service_id);
     849        *size = BPC(bs);
     850
     851        return EOK;
     852}
     853
     854int fat_total_block_count(service_id_t service_id, uint64_t *count)
     855{
     856        fat_bs_t *bs;
     857       
     858        bs = block_bb_get(service_id);
     859        *count = (SPC(bs)) ? TS(bs) / SPC(bs) : 0;
     860
     861        return EOK;
     862}
     863
     864int fat_free_block_count(service_id_t service_id, uint64_t *count)
     865{
     866        fat_bs_t *bs;
     867        fat_cluster_t e0;
     868        uint64_t block_count;
     869        int rc;
     870        uint32_t cluster_no, clusters;
     871
     872        block_count = 0;
     873        bs = block_bb_get(service_id);
     874        clusters = (SPC(bs)) ? TS(bs) / SPC(bs) : 0;
     875        for (cluster_no = 0; cluster_no < clusters; cluster_no++) {
     876                rc = fat_get_cluster(bs, service_id, FAT1, cluster_no, &e0);
     877                if (rc != EOK)
     878                        return EIO;
     879
     880                if (e0 == FAT_CLST_RES0)
     881                        block_count++;
     882        }
     883        *count = block_count;
     884       
     885        return EOK;
     886}
     887
    845888/** libfs operations */
    846889libfs_ops_t fat_libfs_ops = {
     
    860903        .is_directory = fat_is_directory,
    861904        .is_file = fat_is_file,
    862         .service_get = fat_service_get
     905        .service_get = fat_service_get,
     906        .size_block = fat_size_block,
     907        .total_block_count = fat_total_block_count,
     908        .free_block_count = fat_free_block_count
    863909};
    864910
     
    883929        /* Parse mount options. */
    884930        char *mntopts = (char *) opts;
    885         char *saveptr;
    886931        char *opt;
    887         while ((opt = strtok_r(mntopts, " ,", &saveptr)) != NULL) {
     932        while ((opt = str_tok(mntopts, " ,", &mntopts)) != NULL) {
    888933                if (str_cmp(opt, "wtcache") == 0)
    889934                        cmode = CACHE_MODE_WT;
    890935                else if (str_cmp(opt, "nolfn") == 0)
    891936                        instance->lfn_enabled = false;
    892                 mntopts = NULL;
    893937        }
    894938
    895939        /* initialize libblock */
    896         rc = block_init(EXCHANGE_SERIALIZE, service_id, BS_SIZE);
     940        rc = block_init(service_id, BS_SIZE);
    897941        if (rc != EOK) {
    898942                free(instance);
Note: See TracChangeset for help on using the changeset viewer.