Skip to content

Commit a7a8f4a

Browse files
djfunrichardweinberger
authored andcommitted
ubifs: add option to specify version for new file systems
Instead of creating ubifs file systems with UBIFS_FORMAT_VERSION by default, add a module parameter ubifs.default_version to allow the user to specify the desired version. Valid values are 4 to UBIFS_FORMAT_VERSION (currently 5). This way, one can for example create a file system with version 4 on kernel 4.19 which can still be mounted rw when downgrading to kernel 4.9. Signed-off-by: Martin Kaistra <[email protected]> Signed-off-by: Richard Weinberger <[email protected]>
1 parent 92ed301 commit a7a8f4a

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

fs/ubifs/sb.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ static int create_default_filesystem(struct ubifs_info *c)
174174
tmp64 = (long long)max_buds * c->leb_size;
175175
if (big_lpt)
176176
sup_flags |= UBIFS_FLG_BIGLPT;
177-
sup_flags |= UBIFS_FLG_DOUBLE_HASH;
177+
if (ubifs_default_version > 4)
178+
sup_flags |= UBIFS_FLG_DOUBLE_HASH;
178179

179180
if (ubifs_authenticated(c)) {
180181
sup_flags |= UBIFS_FLG_AUTHENTICATION;
@@ -200,7 +201,7 @@ static int create_default_filesystem(struct ubifs_info *c)
200201
sup->jhead_cnt = cpu_to_le32(DEFAULT_JHEADS_CNT);
201202
sup->fanout = cpu_to_le32(DEFAULT_FANOUT);
202203
sup->lsave_cnt = cpu_to_le32(c->lsave_cnt);
203-
sup->fmt_version = cpu_to_le32(UBIFS_FORMAT_VERSION);
204+
sup->fmt_version = cpu_to_le32(ubifs_default_version);
204205
sup->time_gran = cpu_to_le32(DEFAULT_TIME_GRAN);
205206
if (c->mount_opts.override_compr)
206207
sup->default_compr = cpu_to_le16(c->mount_opts.compr_type);

fs/ubifs/super.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@
2626
#include <linux/writeback.h>
2727
#include "ubifs.h"
2828

29+
static int ubifs_default_version_set(const char *val, const struct kernel_param *kp)
30+
{
31+
int n = 0, ret;
32+
33+
ret = kstrtoint(val, 10, &n);
34+
if (ret != 0 || n < 4 || n > UBIFS_FORMAT_VERSION)
35+
return -EINVAL;
36+
return param_set_int(val, kp);
37+
}
38+
39+
static const struct kernel_param_ops ubifs_default_version_ops = {
40+
.set = ubifs_default_version_set,
41+
.get = param_get_int,
42+
};
43+
44+
int ubifs_default_version = UBIFS_FORMAT_VERSION;
45+
module_param_cb(default_version, &ubifs_default_version_ops, &ubifs_default_version, 0600);
46+
2947
/*
3048
* Maximum amount of memory we may 'kmalloc()' without worrying that we are
3149
* allocating too much.

fs/ubifs/ubifs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,7 @@ extern const struct file_operations ubifs_dir_operations;
15041504
extern const struct inode_operations ubifs_dir_inode_operations;
15051505
extern const struct inode_operations ubifs_symlink_inode_operations;
15061506
extern struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT];
1507+
extern int ubifs_default_version;
15071508

15081509
/* auth.c */
15091510
static inline int ubifs_authenticated(const struct ubifs_info *c)

0 commit comments

Comments
 (0)