summaryrefslogtreecommitdiffstats
path: root/sys-utils/zramctl.c
diff options
context:
space:
mode:
authorLibor Bukata2018-01-24 17:10:09 +0100
committerLibor Bukata2018-01-24 17:10:09 +0100
commita3612b81fe0c172bc4fe7e2cf468f195bd785222 (patch)
tree2b958a0d4622229cebdaa19f7597ebb365f613d8 /sys-utils/zramctl.c
parentcal: do not set months_in_row with -3 option (diff)
downloadkernel-qcow2-util-linux-a3612b81fe0c172bc4fe7e2cf468f195bd785222.tar.gz
kernel-qcow2-util-linux-a3612b81fe0c172bc4fe7e2cf468f195bd785222.tar.xz
kernel-qcow2-util-linux-a3612b81fe0c172bc4fe7e2cf468f195bd785222.zip
Added the support for lz4hc, deflate, and 842
compression algorithms in zramctl utility. Signed-off-by: Libor Bukata <lbukata@gmail.com>
Diffstat (limited to 'sys-utils/zramctl.c')
-rw-r--r--sys-utils/zramctl.c30
1 files changed, 16 insertions, 14 deletions
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':