]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
Added the support for lz4hc, deflate, and 842
authorLibor Bukata <lbukata@gmail.com>
Wed, 24 Jan 2018 16:10:09 +0000 (17:10 +0100)
committerLibor Bukata <lbukata@gmail.com>
Wed, 24 Jan 2018 16:10:09 +0000 (17:10 +0100)
compression algorithms in zramctl utility.

Signed-off-by: Libor Bukata <lbukata@gmail.com>
sys-utils/zramctl.8
sys-utils/zramctl.c

index 9ca2983b95e7658ac667df739d2e4e3405447e0a..679a8a175704cc1873e327929ce7bdf3fb8d283b 100644 (file)
@@ -44,7 +44,7 @@ query the status of used zram devices.
 If no option is given, all non-zero size zram devices are shown.
 .SH OPTIONS
 .TP
-.BR \-a , " \-\-algorithm lzo" | lz4
+.BR \-a , " \-\-algorithm lzo" | lz4 | lz4hc | deflate | 842
 Set the compression algorithm to be used for compressing data in the zram device.
 .TP
 .BR \-f , " \-\-find"
index fb64150d61249d8faafa6ce698ae9f825f490978..68cac761cb4c68f741b282f0a3a956e8ee740abf 100644 (file)
@@ -422,16 +422,21 @@ static void fill_table_row(struct libscols_table *tb, struct zram *z)
                case COL_ALGORITHM:
                {
                        char *alg = sysfs_strdup(sysfs, "comp_algorithm");
-                       if (!alg)
-                               break;
-                       if (strstr(alg, "[lzo]") == NULL) {
-                               if (strstr(alg, "[lz4]") == NULL)
-                                       ;
-                               else
-                                       str = xstrdup("lz4");
-                       } else
-                               str = xstrdup("lzo");
-                       free(alg);
+
+                       if (alg != NULL)        {
+
+                               char* left_br = strrchr(alg, '[');
+                               char* right_br = strrchr(alg, ']');
+
+                               if (left_br != NULL && right_br != NULL
+                                               && right_br-left_br > 1)        {
+                                       str = xmalloc(right_br-left_br);
+                                       strncpy(str, left_br+1, right_br-left_br-1);
+                                       str[right_br-left_br-1] = '\0';
+                               }
+
+                               free(alg);
+                       }
                        break;
                }
                case COL_MOUNTPOINT:
@@ -539,7 +544,7 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_("Set up and control zram devices.\n"), out);
 
        fputs(USAGE_OPTIONS, out);
-       fputs(_(" -a, --algorithm lzo|lz4   compression algorithm to use\n"), out);
+       fputs(_(" -a, --algorithm lzo|lz4|lz4hc|deflate|842   compression algorithm to use\n"), out);
        fputs(_(" -b, --bytes               print sizes in bytes rather than in human readable format\n"), out);
        fputs(_(" -f, --find                find a free device\n"), out);
        fputs(_(" -n, --noheadings          don't print headings\n"), out);
@@ -611,9 +616,6 @@ int main(int argc, char **argv)
 
                switch (c) {
                case 'a':
-                       if (strcmp(optarg,"lzo") && strcmp(optarg,"lz4"))
-                               errx(EXIT_FAILURE, _("unsupported algorithm: %s"),
-                                            optarg);
                        algorithm = optarg;
                        break;
                case 'b':