OSDN Git Service

Add a function that prints basic information about FS to stdout.
authorrelan <relan@users.noreply.github.com>
Tue, 9 Nov 2010 19:02:51 +0000 (19:02 +0000)
committerrelan <relan@users.noreply.github.com>
Mon, 24 Aug 2015 05:26:12 +0000 (08:26 +0300)
libexfat/exfat.h
libexfat/utils.c

index 177bde2..2407c60 100644 (file)
@@ -154,6 +154,8 @@ le16_t exfat_calc_checksum(const struct exfat_entry_meta1* meta1,
                const struct exfat_entry_meta2* meta2, const le16_t* name);
 le16_t exfat_calc_name_hash(const struct exfat* ef, const le16_t* name);
 void exfat_humanize_bytes(uint64_t value, struct exfat_human_bytes* hb);
+void exfat_print_info(const struct exfat_super_block* sb,
+               uint32_t free_clusters);
 
 int utf16_to_utf8(char* output, const le16_t* input, size_t outsize,
                size_t insize);
index edb45aa..332dc76 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "exfat.h"
 #include <string.h>
+#include <stdio.h>
+#include <inttypes.h>
 #define _XOPEN_SOURCE /* for timezone in Linux */
 #include <time.h>
 
@@ -244,3 +246,24 @@ void exfat_humanize_bytes(uint64_t value, struct exfat_human_bytes* hb)
        hb->value = (value + divisor / 2) / divisor;
        hb->unit = units[i];
 }
+
+void exfat_print_info(const struct exfat_super_block* sb,
+               uint32_t free_clusters)
+{
+       struct exfat_human_bytes hb;
+       off_t total_space = (off_t) le64_to_cpu(sb->block_count) * BLOCK_SIZE(*sb);
+       off_t avail_space = (off_t) free_clusters * CLUSTER_SIZE(*sb);
+
+       printf("File system version           %hhu.%hhu\n",
+                       sb->version.major, sb->version.minor);
+       exfat_humanize_bytes(BLOCK_SIZE(*sb), &hb);
+       printf("Block size             %8"PRIu64" %s\n", hb.value, hb.unit);
+       exfat_humanize_bytes(CLUSTER_SIZE(*sb), &hb);
+       printf("Cluster size           %8"PRIu64" %s\n", hb.value, hb.unit);
+       exfat_humanize_bytes(total_space, &hb);
+       printf("Volume size            %8"PRIu64" %s\n", hb.value, hb.unit);
+       exfat_humanize_bytes(total_space - avail_space, &hb);
+       printf("Used space             %8"PRIu64" %s\n", hb.value, hb.unit);
+       exfat_humanize_bytes(avail_space, &hb);
+       printf("Available space        %8"PRIu64" %s\n", hb.value, hb.unit);
+}