From a3612b81fe0c172bc4fe7e2cf468f195bd785222 Mon Sep 17 00:00:00 2001 From: Libor Bukata Date: Wed, 24 Jan 2018 17:10:09 +0100 Subject: Added the support for lz4hc, deflate, and 842 compression algorithms in zramctl utility. Signed-off-by: Libor Bukata --- sys-utils/zramctl.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'sys-utils/zramctl.c') diff --git a/sys-utils/zramctl.c b/sys-utils/zramctl.c index fb64150d6..68cac761c 100644 --- a/sys-utils/zramctl.c +++ b/sys-utils/zramctl.c @@ -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': -- cgit v1.2.3-55-g7522