kernel: backport upstream ubifs default compression selection fix
[openwrt/openwrt.git] / target / linux / generic / backport-4.19 / 500-v4.20-ubifs-Fix-default-compression-selection-in-ubifs.patch
1 From d62e98ed1efcaa94caa004f622944afdce5f1c3c Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Sun, 9 Dec 2018 18:12:13 +0100
4 Subject: [PATCH] ubifs: Fix default compression selection in ubifs
5
6 When ubifs is build without the LZO compressor and no compressor is
7 given the creation of the default file system will fail. before
8 selection the LZO compressor check if it is present and if not fall back
9 to the zlib or none.
10
11 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
12 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
13 Signed-off-by: Richard Weinberger <richard@nod.at>
14 ---
15 fs/ubifs/sb.c | 13 ++++++++++++-
16 1 file changed, 12 insertions(+), 1 deletion(-)
17
18 --- a/fs/ubifs/sb.c
19 +++ b/fs/ubifs/sb.c
20 @@ -63,6 +63,17 @@
21 /* Default time granularity in nanoseconds */
22 #define DEFAULT_TIME_GRAN 1000000000
23
24 +static int get_default_compressor(struct ubifs_info *c)
25 +{
26 + if (ubifs_compr_present(c, UBIFS_COMPR_LZO))
27 + return UBIFS_COMPR_LZO;
28 +
29 + if (ubifs_compr_present(c, UBIFS_COMPR_ZLIB))
30 + return UBIFS_COMPR_ZLIB;
31 +
32 + return UBIFS_COMPR_NONE;
33 +}
34 +
35 /**
36 * create_default_filesystem - format empty UBI volume.
37 * @c: UBIFS file-system description object
38 @@ -186,7 +197,7 @@ static int create_default_filesystem(str
39 if (c->mount_opts.override_compr)
40 sup->default_compr = cpu_to_le16(c->mount_opts.compr_type);
41 else
42 - sup->default_compr = cpu_to_le16(UBIFS_COMPR_LZO);
43 + sup->default_compr = cpu_to_le16(get_default_compressor(c));
44
45 generate_random_uuid(sup->uuid);
46