diff options
-rw-r--r-- | fs/btrfs/compression.c | 16 | ||||
-rw-r--r-- | fs/btrfs/compression.h | 1 | ||||
-rw-r--r-- | fs/btrfs/props.c | 6 |
3 files changed, 18 insertions, 5 deletions
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 66e21a4e9ea2..db41315f11eb 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c | |||
@@ -43,6 +43,22 @@ const char* btrfs_compress_type2str(enum btrfs_compression_type type) | |||
43 | return NULL; | 43 | return NULL; |
44 | } | 44 | } |
45 | 45 | ||
46 | bool btrfs_compress_is_valid_type(const char *str, size_t len) | ||
47 | { | ||
48 | int i; | ||
49 | |||
50 | for (i = 1; i < ARRAY_SIZE(btrfs_compress_types); i++) { | ||
51 | size_t comp_len = strlen(btrfs_compress_types[i]); | ||
52 | |||
53 | if (len < comp_len) | ||
54 | continue; | ||
55 | |||
56 | if (!strncmp(btrfs_compress_types[i], str, comp_len)) | ||
57 | return true; | ||
58 | } | ||
59 | return false; | ||
60 | } | ||
61 | |||
46 | static int btrfs_decompress_bio(struct compressed_bio *cb); | 62 | static int btrfs_decompress_bio(struct compressed_bio *cb); |
47 | 63 | ||
48 | static inline int compressed_bio_size(struct btrfs_fs_info *fs_info, | 64 | static inline int compressed_bio_size(struct btrfs_fs_info *fs_info, |
diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index 191e5f4e3523..2035b8eb1290 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h | |||
@@ -173,6 +173,7 @@ extern const struct btrfs_compress_op btrfs_lzo_compress; | |||
173 | extern const struct btrfs_compress_op btrfs_zstd_compress; | 173 | extern const struct btrfs_compress_op btrfs_zstd_compress; |
174 | 174 | ||
175 | const char* btrfs_compress_type2str(enum btrfs_compression_type type); | 175 | const char* btrfs_compress_type2str(enum btrfs_compression_type type); |
176 | bool btrfs_compress_is_valid_type(const char *str, size_t len); | ||
176 | 177 | ||
177 | int btrfs_compress_heuristic(struct inode *inode, u64 start, u64 end); | 178 | int btrfs_compress_heuristic(struct inode *inode, u64 start, u64 end); |
178 | 179 | ||
diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c index a9e2e66152ee..af109c0ba720 100644 --- a/fs/btrfs/props.c +++ b/fs/btrfs/props.c | |||
@@ -257,11 +257,7 @@ static int prop_compression_validate(const char *value, size_t len) | |||
257 | if (!value) | 257 | if (!value) |
258 | return 0; | 258 | return 0; |
259 | 259 | ||
260 | if (!strncmp("lzo", value, 3)) | 260 | if (btrfs_compress_is_valid_type(value, len)) |
261 | return 0; | ||
262 | else if (!strncmp("zlib", value, 4)) | ||
263 | return 0; | ||
264 | else if (!strncmp("zstd", value, 4)) | ||
265 | return 0; | 261 | return 0; |
266 | 262 | ||
267 | return -EINVAL; | 263 | return -EINVAL; |