From 1ed058f107e53602a6f87af0035f0ce11522c184 Mon Sep 17 00:00:00 2001 From: Teemu Toivola Date: Wed, 21 Mar 2018 17:11:30 +0200 Subject: [PATCH] add exbibyte support --- CHANGES | 2 +- README.md | 2 +- src/misc.c | 14 ++++++++------ src/misc.h | 2 +- tests/misc_tests.c | 12 ++++++++++++ 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/CHANGES b/CHANGES index 12b76af..9b39a33 100644 --- a/CHANGES +++ b/CHANGES @@ -6,7 +6,7 @@ - Full data import from 1.x version database format including reconstructed yearly data - Add yearly and 5 minute resolution statistics - - Add pebibyte support + - Add pebibyte and exbibyte support - Add options the configure the length of each list output - Add hourly list output as alternative - Remove weekly output diff --git a/README.md b/README.md index e186bed..3ba9a9e 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ durations. Yearly and five-minute resolution statistics are now included. * only fatal errors will cause the daemon to exit directly * most vnstat (console output) features * all vnstati (image output) features - * pebibyte support + * pebibyte and exbibyte support ##### Removed features diff --git a/src/misc.c b/src/misc.c index 9658420..89ef3e8 100644 --- a/src/misc.c +++ b/src/misc.c @@ -226,8 +226,9 @@ char *gettrafficrate(const uint64_t bytes, const time_t interval, const int len) const char *getunitprefix(const int index) { - static const char *unitprefix[] = { "na", "B", "KiB", "MiB", "GiB", "TiB", "PiB", /* IEC - 1024^n */ - "B", "KB", "MB", "GB", "TB", "PB" }; /* JEDEC - 1024^n */ + static const char *unitprefix[] = { "na", + "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", /* IEC - 1024^n */ + "B", "KB", "MB", "GB", "TB", "PB", "EB" }; /* JEDEC - 1024^n */ if (index>UNITPREFIXCOUNT) { return unitprefix[0]; @@ -238,10 +239,11 @@ const char *getunitprefix(const int index) const char *getrateunitprefix(const int unitmode, const int index) { - static const char *rateunitprefix[] = { "na", "B/s", "KiB/s", "MiB/s", "GiB/s", "TiB/s", "PiB/s", /* IEC - 1024^n */ - "B/s", "KB/s", "MB/s", "GB/s", "TB/s", "PB/s", /* JEDEC - 1024^n */ - "bit/s", "Kibit/s", "Mibit/s", "Gibit/s", "Tibit/s", "Pibit/s", /* IEC - 1024^n */ - "bit/s", "kbit/s", "Mbit/s", "Gbit/s", "Tbit/s", "Pbit/s" }; /* SI - 1000^n */ + static const char *rateunitprefix[] = { "na", + "B/s", "KiB/s", "MiB/s", "GiB/s", "TiB/s", "PiB/s", "EiB/s", /* IEC - 1024^n */ + "B/s", "KB/s", "MB/s", "GB/s", "TB/s", "PB/s", "EB/s", /* JEDEC - 1024^n */ + "bit/s", "Kibit/s", "Mibit/s", "Gibit/s", "Tibit/s", "Pibit/s", "Eibit/s", /* IEC - 1024^n */ + "bit/s", "kbit/s", "Mbit/s", "Gbit/s", "Tbit/s", "Pbit/s", "Ebit/s" }; /* SI - 1000^n */ if (index>UNITPREFIXCOUNT) { return rateunitprefix[0]; diff --git a/src/misc.h b/src/misc.h index 1215bb0..4dcb338 100644 --- a/src/misc.h +++ b/src/misc.h @@ -1,7 +1,7 @@ #ifndef MISC_H #define MISC_H -#define UNITPREFIXCOUNT 6 +#define UNITPREFIXCOUNT 7 int spacecheck(const char *path); void sighandler(int sig); diff --git a/tests/misc_tests.c b/tests/misc_tests.c index 16eedad..1d510ec 100644 --- a/tests/misc_tests.c +++ b/tests/misc_tests.c @@ -90,6 +90,7 @@ START_TEST(getvalue_normal) ck_assert_str_eq(getvalue(1073741824, 0, 1), "1.00 GiB"); ck_assert_str_eq(getvalue(1099511627776ULL, 0, 1), "1.00 TiB"); ck_assert_str_eq(getvalue(1125899906842624ULL, 0, 1), "1.00 PiB"); + ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, 1), "1.00 EiB"); cfg.unitmode = 1; ck_assert_str_eq(getvalue(100, 0, 1), "100 B"); ck_assert_str_eq(getvalue(1024, 0, 1), "1.00 KB"); @@ -97,6 +98,7 @@ START_TEST(getvalue_normal) ck_assert_str_eq(getvalue(1073741824, 0, 1), "1.00 GB"); ck_assert_str_eq(getvalue(1099511627776ULL, 0, 1), "1.00 TB"); ck_assert_str_eq(getvalue(1125899906842624ULL, 0, 1), "1.00 PB"); + ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, 1), "1.00 EB"); } END_TEST @@ -110,6 +112,7 @@ START_TEST(getvalue_estimate) ck_assert_str_eq(getvalue(1073741824, 0, 2), "1.00 GiB"); ck_assert_str_eq(getvalue(1099511627776ULL, 0, 2), "1.00 TiB"); ck_assert_str_eq(getvalue(1125899906842624ULL, 0, 2), "1.00 PiB"); + ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, 2), "1.00 EiB"); cfg.unitmode = 1; ck_assert_str_eq(getvalue(100, 0, 2), "100 B"); ck_assert_str_eq(getvalue(1024, 0, 2), "1 KB"); @@ -117,6 +120,7 @@ START_TEST(getvalue_estimate) ck_assert_str_eq(getvalue(1073741824, 0, 2), "1.00 GB"); ck_assert_str_eq(getvalue(1099511627776ULL, 0, 2), "1.00 TB"); ck_assert_str_eq(getvalue(1125899906842624ULL, 0, 2), "1.00 PB"); + ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, 2), "1.00 EB"); } END_TEST @@ -130,6 +134,7 @@ START_TEST(getvalue_imagescale) ck_assert_str_eq(getvalue(1073741824, 0, 3), "1 GiB"); ck_assert_str_eq(getvalue(1099511627776ULL, 0,3), "1 TiB"); ck_assert_str_eq(getvalue(1125899906842624ULL, 0, 3), "1 PiB"); + ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, 3), "1 EiB"); cfg.unitmode = 1; ck_assert_str_eq(getvalue(100, 0, 3), "100 B"); ck_assert_str_eq(getvalue(1024, 0, 3), "1 KB"); @@ -137,6 +142,7 @@ START_TEST(getvalue_imagescale) ck_assert_str_eq(getvalue(1073741824, 0, 3), "1 GB"); ck_assert_str_eq(getvalue(1099511627776ULL, 0, 3), "1 TB"); ck_assert_str_eq(getvalue(1125899906842624ULL, 0, 3), "1 PB"); + ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, 3), "1 EB"); } END_TEST @@ -192,6 +198,7 @@ START_TEST(gettrafficrate_bytes) ck_assert_str_eq(gettrafficrate(1073741824, 1, 0), "1.00 GiB/s"); ck_assert_str_eq(gettrafficrate(1099511627776ULL, 1, 0), "1.00 TiB/s"); ck_assert_str_eq(gettrafficrate(1125899906842624ULL, 1, 0), "1.00 PiB/s"); + ck_assert_str_eq(gettrafficrate(1152921504606846976ULL, 1, 0), "1.00 EiB/s"); cfg.unitmode = 1; ck_assert_str_eq(gettrafficrate(900, 1, 0), "900 B/s"); ck_assert_str_eq(gettrafficrate(102400, 1, 0), "100.00 KB/s"); @@ -199,6 +206,7 @@ START_TEST(gettrafficrate_bytes) ck_assert_str_eq(gettrafficrate(1073741824, 1, 0), "1.00 GB/s"); ck_assert_str_eq(gettrafficrate(1099511627776ULL, 1, 0), "1.00 TB/s"); ck_assert_str_eq(gettrafficrate(1125899906842624ULL, 1, 0), "1.00 PB/s"); + ck_assert_str_eq(gettrafficrate(1152921504606846976ULL, 1, 0), "1.00 EB/s"); } END_TEST @@ -215,6 +223,7 @@ START_TEST(gettrafficrate_bits) ck_assert_str_eq(gettrafficrate(1073741824, 1, 0), "8.59 Gbit/s"); ck_assert_str_eq(gettrafficrate(1099511627776ULL, 1, 0), "8.80 Tbit/s"); ck_assert_str_eq(gettrafficrate(1125899906842624ULL, 1, 0), "9.01 Pbit/s"); + ck_assert_str_eq(gettrafficrate(1152921504606846976ULL, 1, 0), "9.22 Ebit/s"); cfg.unitmode = 1; ck_assert_str_eq(gettrafficrate(100, 1, 0), "800 bit/s"); ck_assert_str_eq(gettrafficrate(102400, 1, 0), "819.20 kbit/s"); @@ -222,6 +231,7 @@ START_TEST(gettrafficrate_bits) ck_assert_str_eq(gettrafficrate(1073741824, 1, 0), "8.59 Gbit/s"); ck_assert_str_eq(gettrafficrate(1099511627776ULL, 1, 0), "8.80 Tbit/s"); ck_assert_str_eq(gettrafficrate(1125899906842624ULL, 1, 0), "9.01 Pbit/s"); + ck_assert_str_eq(gettrafficrate(1152921504606846976ULL, 1, 0), "9.22 Ebit/s"); cfg.rateunitmode = 0; cfg.unitmode = 0; @@ -231,6 +241,7 @@ START_TEST(gettrafficrate_bits) ck_assert_str_eq(gettrafficrate(1073741824, 1, 0), "8.00 Gibit/s"); ck_assert_str_eq(gettrafficrate(1099511627776ULL, 1, 0), "8.00 Tibit/s"); ck_assert_str_eq(gettrafficrate(1125899906842624ULL, 1, 0), "8.00 Pibit/s"); + ck_assert_str_eq(gettrafficrate(1152921504606846976ULL, 1, 0), "8.00 Eibit/s"); cfg.unitmode = 1; ck_assert_str_eq(gettrafficrate(100, 1, 0), "800 bit/s"); ck_assert_str_eq(gettrafficrate(102400, 1, 0), "800.00 Kibit/s"); @@ -238,6 +249,7 @@ START_TEST(gettrafficrate_bits) ck_assert_str_eq(gettrafficrate(1073741824, 1, 0), "8.00 Gibit/s"); ck_assert_str_eq(gettrafficrate(1099511627776ULL, 1, 0), "8.00 Tibit/s"); ck_assert_str_eq(gettrafficrate(1125899906842624ULL, 1, 0), "8.00 Pibit/s"); + ck_assert_str_eq(gettrafficrate(1152921504606846976ULL, 1, 0), "8.00 Eibit/s"); } END_TEST -- 2.40.0