]> granicus.if.org Git - vnstat/commitdiff
add exbibyte support
authorTeemu Toivola <git@humdi.net>
Wed, 21 Mar 2018 15:11:30 +0000 (17:11 +0200)
committerTeemu Toivola <git@humdi.net>
Wed, 21 Mar 2018 15:11:30 +0000 (17:11 +0200)
CHANGES
README.md
src/misc.c
src/misc.h
tests/misc_tests.c

diff --git a/CHANGES b/CHANGES
index 12b76afc39ef7fcad4aefcbf2163bf56efecb63a..9b39a3369e1bb4600b29b5a84b0bd7d134e1a542 100644 (file)
--- 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
index e186bed2e7a80f5989fdd6017b2d2a31614bf6f7..3ba9a9edfa6c0c6233e0e0648aa548469b469557 100644 (file)
--- 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
 
index 9658420da90c4e58958e2ab35046b9f0f2886a8d..89ef3e8bbd201b62b4a943f96288f5c91144a2d3 100644 (file)
@@ -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];
index 1215bb09a498bf303167e3fdcb34819476364f10..4dcb3389c15115b8ced8a8916566b03063adcb63 100644 (file)
@@ -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);
index 16eedad08c103ffd7ec79047bae6d08ec79f4117..1d510ec1d5fbcdaae0826cb9db51b72dc90cf76a 100644 (file)
@@ -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