OSDN Git Service

Implement dynamic calculation of free clusters count.
authorrelan <relan@users.noreply.github.com>
Mon, 15 Feb 2010 19:22:23 +0000 (19:22 +0000)
committerrelan <relan@users.noreply.github.com>
Mon, 24 Aug 2015 05:26:12 +0000 (08:26 +0300)
Now df utility behaves properly.

fuse/main.c
libexfat/cluster.c
libexfat/exfat.h

index 409e503..931daad 100644 (file)
@@ -229,7 +229,8 @@ static int fuse_exfat_statfs(const char* path, struct statvfs* sfs)
        sfs->f_bsize = BLOCK_SIZE(*ef.sb);
        sfs->f_frsize = CLUSTER_SIZE(*ef.sb);
        sfs->f_blocks = block_count;
-       sfs->f_bavail = block_count - ef.sb->allocated_percent * block_count / 100;
+       sfs->f_bavail = (fsblkcnt_t) exfat_count_free_clusters(&ef) *
+                       (CLUSTER_SIZE(*ef.sb) / BLOCK_SIZE(*ef.sb));
        sfs->f_bfree = sfs->f_bavail;
        sfs->f_namemax = EXFAT_NAME_MAX;
 
index 2951dfa..b53c31f 100644 (file)
@@ -379,3 +379,14 @@ int exfat_truncate(struct exfat* ef, struct exfat_node* node, uint64_t size)
        node->flags |= EXFAT_ATTRIB_DIRTY;
        return 0;
 }
+
+uint32_t exfat_count_free_clusters(struct exfat* ef)
+{
+       uint32_t free_clusters = 0;
+       uint32_t i;
+
+       for (i = 0; i < ef->cmap.size; i++)
+               if (BMAP_GET(ef->cmap.chunk, i) == 0)
+                       free_clusters++;
+       return free_clusters;
+}
index 95575c5..a93c18d 100644 (file)
@@ -130,6 +130,7 @@ cluster_t exfat_advance_cluster(const struct exfat* ef,
                struct exfat_node* node, uint32_t count);
 void exfat_flush_cmap(struct exfat* ef);
 int exfat_truncate(struct exfat* ef, struct exfat_node* node, uint64_t size);
+uint32_t exfat_count_free_clusters(struct exfat* ef);
 
 void exfat_stat(const struct exfat* ef, const struct exfat_node* node,
                struct stat* stbuf);