X-Git-Url: http://git.sven.stormbind.net/?p=sven%2Fexfat-utils.git;a=blobdiff_plain;f=libexfat%2Futils.c;h=31b7e8cce38b9d91d1a5a9de0009734b648802ce;hp=39fdd483a288b53981a9c2f1d72f791e061c8004;hb=dbe4348df2ba88986e13163ef13d09fb7247589d;hpb=4cb393cfd9b0ab69392612521ee3dbe481ec492d diff --git a/libexfat/utils.c b/libexfat/utils.c index 39fdd48..31b7e8c 100644 --- a/libexfat/utils.c +++ b/libexfat/utils.c @@ -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]; }