summaryrefslogtreecommitdiff
path: root/fs/btrfs/compression.c
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2017-09-15 17:36:58 +0200
committerDavid Sterba <dsterba@suse.com>2017-11-01 20:45:34 +0100
commitfa4d885a482ef52ad3efa12a5799a3f6408b0718 (patch)
treeb2c77afc273d184129350162e5b564a545f59916 /fs/btrfs/compression.c
parentf51d2b59120ff364a5e612a594ed358767e1cd09 (diff)
btrfs: allow setting zlib compression level via :9
This is bikeshedding, but it seems people are drastically more likely to understand "zlib:9" as compression level rather than an algorithm version compared to "zlib9". Based on feedback on the mailinglist, the ":9" will be the only accepted syntax. The level must be a single digit. Unrecognized format will result to the default, for forward compatibility in a similar way the compression algorithm specifier was relaxed in commit a7164fa4e055daf6368c ("btrfs: prepare for extensions in compression options"). Signed-off-by: Adam Borowski <kilobyte@angband.pl> Reviewed-by: David Sterba <dsterba@suse.com> [ tighten the accepted format ] Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/compression.c')
-rw-r--r--fs/btrfs/compression.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 3e452525f8ad..083f9c485875 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -1111,8 +1111,9 @@ unsigned int btrfs_compress_str2level(const char *str)
if (strncmp(str, "zlib", 4) != 0)
return 0;
- if ('1' <= str[4] && str[4] <= '9' )
- return str[4] - '0';
+ /* Accepted form: zlib:1 up to zlib:9 and nothing left after the number */
+ if (str[4] == ':' && '1' <= str[5] && str[5] <= '9' && str[6] == 0)
+ return str[5] - '0';
return 0;
}