[RFC PATCH v2 08/18] befs: Allow to use native UTF-8 mode

From: Pali Rohár
Date: Mon Dec 26 2022 - 09:23:18 EST


befs driver already has a code which avoids usage of NLS when befs_sb->nls
is not set.

But befs_fill_super() always set befs_sb->nls, so activating native UTF-8
is not possible.

Fix it by not setting befs_sb->nls when iocharset is set to utf8. So now
after this cgange mount option iocharset=utf8 activates usage of native
UTF-8 code path in befs driver.

Signed-off-by: Pali Rohár <pali@xxxxxxxxxx>
---
fs/befs/linuxvfs.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
index 8d2954e3afd6..e5400123d33f 100644
--- a/fs/befs/linuxvfs.c
+++ b/fs/befs/linuxvfs.c
@@ -769,6 +769,7 @@ static int befs_show_options(struct seq_file *m, struct dentry *root)
{
struct befs_sb_info *befs_sb = BEFS_SB(root->d_sb);
struct befs_mount_options *opts = &befs_sb->mount_opts;
+ struct nls_table *nls = befs_sb->nls;

if (!uid_eq(opts->uid, GLOBAL_ROOT_UID))
seq_printf(m, ",uid=%u",
@@ -776,8 +777,10 @@ static int befs_show_options(struct seq_file *m, struct dentry *root)
if (!gid_eq(opts->gid, GLOBAL_ROOT_GID))
seq_printf(m, ",gid=%u",
from_kgid_munged(&init_user_ns, opts->gid));
- if (opts->iocharset)
- seq_printf(m, ",iocharset=%s", opts->iocharset);
+ if (nls)
+ seq_printf(m, ",iocharset=%s", nls->charset);
+ else
+ seq_puts(m, ",iocharset=utf8");
if (opts->debug)
seq_puts(m, ",debug");
return 0;
@@ -815,6 +818,7 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
const unsigned long sb_block = 0;
const off_t x86_sb_off = 512;
int blocksize;
+ const char *p;

sb->s_fs_info = kzalloc(sizeof(*befs_sb), GFP_KERNEL);
if (sb->s_fs_info == NULL)
@@ -907,8 +911,11 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
goto unacquire_priv_sbp;
}

+ p = befs_sb->mount_opts.iocharset ? befs_sb->mount_opts.iocharset : CONFIG_NLS_DEFAULT;
+ if (strcmp(p, "utf8") == 0) {
+ befs_debug(sb, "Using native UTF-8 without nls");
/* load nls library */
- if (befs_sb->mount_opts.iocharset) {
+ } else if (befs_sb->mount_opts.iocharset) {
befs_debug(sb, "Loading nls: %s",
befs_sb->mount_opts.iocharset);
befs_sb->nls = load_nls(befs_sb->mount_opts.iocharset);
--
2.20.1