]> git.sven.stormbind.net Git - sven/exfat-utils.git/blobdiff - libexfat/utils.c
Imported Upstream version 0.9.6
[sven/exfat-utils.git] / libexfat / utils.c
index 39fdd483a288b53981a9c2f1d72f791e061c8004..31b7e8cce38b9d91d1a5a9de0009734b648802ce 100644 (file)
@@ -41,7 +41,9 @@ void exfat_stat(const struct exfat* ef, const struct exfat_node* node,
                CLUSTER_SIZE(*ef->sb) / 512;
        stbuf->st_mtime = node->mtime;
        stbuf->st_atime = node->atime;
-       stbuf->st_ctime = 0; /* unapplicable */
+       /* set ctime to mtime to ensure we don't break programs that rely on ctime
+          (e.g. rsync) */
+       stbuf->st_ctime = node->mtime;
 }
 
 #define SEC_IN_MIN 60ll
@@ -258,14 +260,20 @@ void exfat_humanize_bytes(uint64_t value, struct exfat_human_bytes* hb)
        size_t i;
        const char* units[] = {"bytes", "KB", "MB", "GB", "TB", "PB"};
        uint64_t divisor = 1;
+       uint64_t temp = 0;
 
-       for (i = 0; i < sizeof(units) / sizeof(units[0]) - 1; i++)
+       for (i = 0; i < sizeof(units) / sizeof(units[0]) - 1; i++, divisor *= 1024)
        {
-               if ((value + divisor / 2) / divisor < 1024)
+               temp = (value + divisor / 2) / divisor;
+
+               if (temp == 0)
+                       break;
+               if (temp / 1024 * 1024 == temp)
+                       continue;
+               if (temp < 10240)
                        break;
-               divisor *= 1024;
        }
-       hb->value = (value + divisor / 2) / divisor;
+       hb->value = temp;
        hb->unit = units[i];
 }