Skip to contentSkip to conversation

mkfs.f2fs: support -C [no]hashonly to control linear lookup fallback

PATCH Superseded Chao Yu via Linux-f2fs-devel 2 participants 4 messages Jul 25, 2025 Library code

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mkfs.f2fs: support -C [no]hashonly to control linear lookup fallback

It provides a way to disable linear lookup fallback during mkfs.

Behavior summary:
Android Distro
By default disabled enabled
Tune w/ [no]hashonly no yes

Android case:

1.1) Disable linear lookup:
mkfs.f2fs -f -g android -O casefold -C utf8:hashonly /dev/vdb dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 2 : 2]

1.2) Enable linear lookup:
mkfs.f2fs -f -g android -O casefold -C utf8:nohashonly /dev/vdb dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 2 : 2]

1.3) By default:
mkfs.f2fs -f -g android -O casefold -C utf8 /dev/vdb dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 2 : 2]

Distro case:

2.1) Disable linear lookup:
mkfs.f2fs -f -O casefold -C utf8:hashonly /dev/vdb dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 2 : 2]

2.2) Enable linear lookup:
mkfs.f2fs -f -O casefold -C utf8:nohashonly /dev/vdb dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 0 : 0]

2.3) By default:
mkfs.f2fs -f -O casefold -C utf8 /dev/vdb
dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 0 : 0]

---
v2:
- disable linear lookup by default for Android case

 include/f2fs_fs.h       |  3 ++-
 lib/libf2fs.c           |  1 +
 man/mkfs.f2fs.8         | 10 ++++++++--
 mkfs/f2fs_format.c      |  3 +++
 mkfs/f2fs_format_main.c |  3 ++-
 5 files changed, 16 insertions(+), 4 deletions(-)
include/f2fs_fs.h +2 -1
index f7268d1..a8da8fa 100644
@@ -1478,7 +1478,8 @@ enum {
 
 /* feature list in Android */
 enum {
-	F2FS_FEATURE_NAT_BITS = 0x0001,
+	F2FS_FEATURE_NAT_BITS		= 0x0001,
+	F2FS_FEATURE_LINEAR_LOOKUP	= 0x0002,
 };
 
 /* nolinear lookup tune */
lib/libf2fs.c +1 -0
index 2f012c8..0e3e62a 100644
@@ -1424,6 +1424,7 @@ static const struct enc_flags {
 	char *param;
 } encoding_flags[] = {
 	{ F2FS_ENC_STRICT_MODE_FL, "strict" },
+	{ F2FS_ENC_NO_COMPAT_FALLBACK_FL, "hashonly"}
 };
 
 /* Return a positive number < 0xff indicating the encoding magic number
man/mkfs.f2fs.8 +8 -2
index 8b3b0cc..8cb7d32 100644
@@ -232,9 +232,15 @@ Use UTF-8 for casefolding.
 .I flags:
 .RS 1.2i
 .TP 1.2i
-.B strict
+.B [no]strict
 This flag specifies that invalid strings should be rejected by the filesystem.
-Default is disabled.
+For android case, it will disable linear lookup by default.
+.RE
+.RS 1.2i
+.TP 1.2i
+.B [no]hashonly
+This flag specifies that there is no linear lookup fallback during lookup.
+By default, linear lookup fallback is enabled.
 .RE
 .RE
 .TP
mkfs/f2fs_format.c +3 -0
index 2680bd3..a45bbcb 100644
@@ -671,6 +671,9 @@ static int f2fs_prepare_super_block(void)
 	memcpy(sb->init_version, c.version, VERSION_LEN);
 
 	if (c.feature & F2FS_FEATURE_CASEFOLD) {
+		if (!(c.s_encoding_flags & F2FS_ENC_NO_COMPAT_FALLBACK_FL) &&
+			(c.disabled_feature & F2FS_FEATURE_LINEAR_LOOKUP))
+			c.s_encoding_flags |= F2FS_ENC_NO_COMPAT_FALLBACK_FL;
 		set_sb(s_encoding, c.s_encoding);
 		set_sb(s_encoding_flags, c.s_encoding_flags);
 	}
mkfs/f2fs_format_main.c +2 -1
index f0bec4f..8f8e975 100644
@@ -143,7 +143,8 @@ static void add_default_options(void)
 		force_overwrite = 1;
 		c.wanted_sector_size = F2FS_BLKSIZE;
 		c.root_uid = c.root_gid = 0;
-		c.disabled_feature |= F2FS_FEATURE_NAT_BITS;
+		c.disabled_feature |= F2FS_FEATURE_NAT_BITS |
+					F2FS_FEATURE_LINEAR_LOOKUP;
 
 		/* RO doesn't need any other features */
 		if (c.feature & F2FS_FEATURE_RO)
Signature · 8 lines
2.49.0



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#1 lore raw

Chao Yu via Linux-f2fs-devel <[email protected]>

Quoted 15 lines · 于2025年7月25日周五 09:03写道:

It provides a way to disable linear lookup fallback during mkfs.

Behavior summary:

                        Android         Distro
By default              disabled        enabled
Tune w/ [no]hashonly    no              yes

Android case:

1.1) Disable linear lookup:
mkfs.f2fs -f -g android -O casefold -C utf8:hashonly /dev/vdb dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 2 : 2]

Quoted 4 lines

1.2) Enable linear lookup:
mkfs.f2fs -f -g android -O casefold -C utf8:nohashonly /dev/vdb dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 2 : 2]

Hi Chao,
Seems like a typo here? should be:
s_encoding_flags [0x 0 : 0] ?
thanks!

Quoted 115 lines

1.3) By default:
mkfs.f2fs -f -g android -O casefold -C utf8 /dev/vdb dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 2 : 2]

Distro case:

2.1) Disable linear lookup:
mkfs.f2fs -f -O casefold -C utf8:hashonly /dev/vdb dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 2 : 2]

2.2) Enable linear lookup:
mkfs.f2fs -f -O casefold -C utf8:nohashonly /dev/vdb dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 0 : 0]

2.3) By default:
mkfs.f2fs -f -O casefold -C utf8 /dev/vdb
dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 0 : 0]

---
v2:
- disable linear lookup by default for Android case

 include/f2fs_fs.h       |  3 ++-
 lib/libf2fs.c           |  1 +
 man/mkfs.f2fs.8         | 10 ++++++++--
 mkfs/f2fs_format.c      |  3 +++
 mkfs/f2fs_format_main.c |  3 ++-
 5 files changed, 16 insertions(+), 4 deletions(-)
include/f2fs_fs.h +2 -1
index f7268d1..a8da8fa 100644
@@ -1478,7 +1478,8 @@ enum {
 
 /* feature list in Android */
 enum {
-       F2FS_FEATURE_NAT_BITS = 0x0001,
+       F2FS_FEATURE_NAT_BITS           = 0x0001,
+       F2FS_FEATURE_LINEAR_LOOKUP      = 0x0002,
 };
 
 /* nolinear lookup tune */
lib/libf2fs.c +1 -0
index 2f012c8..0e3e62a 100644
@@ -1424,6 +1424,7 @@ static const struct enc_flags {
        char *param;
 } encoding_flags[] = {
        { F2FS_ENC_STRICT_MODE_FL, "strict" },
+       { F2FS_ENC_NO_COMPAT_FALLBACK_FL, "hashonly"}
 };
 
 /* Return a positive number < 0xff indicating the encoding magic number
man/mkfs.f2fs.8 +8 -2
index 8b3b0cc..8cb7d32 100644
@@ -232,9 +232,15 @@ Use UTF-8 for casefolding.
 .I flags:
 .RS 1.2i
 .TP 1.2i
-.B strict
+.B [no]strict
 This flag specifies that invalid strings should be rejected by the filesystem.
-Default is disabled.
+For android case, it will disable linear lookup by default.
+.RE
+.RS 1.2i
+.TP 1.2i
+.B [no]hashonly
+This flag specifies that there is no linear lookup fallback during lookup.
+By default, linear lookup fallback is enabled.
 .RE
 .RE
 .TP
mkfs/f2fs_format.c +3 -0
index 2680bd3..a45bbcb 100644
@@ -671,6 +671,9 @@ static int f2fs_prepare_super_block(void)
        memcpy(sb->init_version, c.version, VERSION_LEN);
 
        if (c.feature & F2FS_FEATURE_CASEFOLD) {
+               if (!(c.s_encoding_flags & F2FS_ENC_NO_COMPAT_FALLBACK_FL) &&
+                       (c.disabled_feature & F2FS_FEATURE_LINEAR_LOOKUP))
+                       c.s_encoding_flags |= F2FS_ENC_NO_COMPAT_FALLBACK_FL;
                set_sb(s_encoding, c.s_encoding);
                set_sb(s_encoding_flags, c.s_encoding_flags);
        }
mkfs/f2fs_format_main.c +2 -2
index f0bec4f..8f8e975 100644
@@ -143,7 +143,8 @@ static void add_default_options(void)
                force_overwrite = 1;
                c.wanted_sector_size = F2FS_BLKSIZE;
                c.root_uid = c.root_gid = 0;
-               c.disabled_feature |= F2FS_FEATURE_NAT_BITS;
+               c.disabled_feature |= F2FS_FEATURE_NAT_BITS |
+                                       F2FS_FEATURE_LINEAR_LOOKUP;
 
                /* RO doesn't need any other features */
                if (c.feature & F2FS_FEATURE_RO)
--

2.49.0

Quoted 4 lines

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#2 lore raw
Quoted 17 lines · Zhiguo Niu

Chao Yu via Linux-f2fs-devel <[email protected]>

Quoted 15 lines · 于2025年7月25日周五 09:03写道:

It provides a way to disable linear lookup fallback during mkfs.

Behavior summary:
Android Distro

By default              disabled        enabled
Tune w/ [no]hashonly    no              yes

Android case:

1.1) Disable linear lookup:
mkfs.f2fs -f -g android -O casefold -C utf8:hashonly /dev/vdb dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 2 : 2]

Quoted 6 lines
Quoted 4 lines

1.2) Enable linear lookup:
mkfs.f2fs -f -g android -O casefold -C utf8:nohashonly /dev/vdb dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 2 : 2]

Hi Chao,
Seems like a typo here? should be:

Zhiguo,

Not a typo, it's intentional, see above behavior summary.

But after rethinking about this, I guess it will be good to honor 'nohashonly' for Android case like Distro case.

Anyway, let me update the patch.

Thanks,

Quoted 117 lines

s_encoding_flags [0x 0 : 0] ?
thanks!

Quoted 115 lines

1.3) By default:
mkfs.f2fs -f -g android -O casefold -C utf8 /dev/vdb dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 2 : 2]

Distro case:

2.1) Disable linear lookup:
mkfs.f2fs -f -O casefold -C utf8:hashonly /dev/vdb dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 2 : 2]

2.2) Enable linear lookup:
mkfs.f2fs -f -O casefold -C utf8:nohashonly /dev/vdb dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 0 : 0]

2.3) By default:
mkfs.f2fs -f -O casefold -C utf8 /dev/vdb
dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 0 : 0]

---
v2:
- disable linear lookup by default for Android case

  include/f2fs_fs.h       |  3 ++-
  lib/libf2fs.c           |  1 +
  man/mkfs.f2fs.8         | 10 ++++++++--
  mkfs/f2fs_format.c      |  3 +++
  mkfs/f2fs_format_main.c |  3 ++-
  5 files changed, 16 insertions(+), 4 deletions(-)
include/f2fs_fs.h +2 -1
index f7268d1..a8da8fa 100644
@@ -1478,7 +1478,8 @@ enum {
 
  /* feature list in Android */
  enum {
-       F2FS_FEATURE_NAT_BITS = 0x0001,
+       F2FS_FEATURE_NAT_BITS           = 0x0001,
+       F2FS_FEATURE_LINEAR_LOOKUP      = 0x0002,
  };
 
  /* nolinear lookup tune */
lib/libf2fs.c +1 -0
index 2f012c8..0e3e62a 100644
@@ -1424,6 +1424,7 @@ static const struct enc_flags {
         char *param;
  } encoding_flags[] = {
         { F2FS_ENC_STRICT_MODE_FL, "strict" },
+       { F2FS_ENC_NO_COMPAT_FALLBACK_FL, "hashonly"}
  };
 
  /* Return a positive number < 0xff indicating the encoding magic number
man/mkfs.f2fs.8 +8 -2
index 8b3b0cc..8cb7d32 100644
@@ -232,9 +232,15 @@ Use UTF-8 for casefolding.
  .I flags:
  .RS 1.2i
  .TP 1.2i
-.B strict
+.B [no]strict
  This flag specifies that invalid strings should be rejected by the filesystem.
-Default is disabled.
+For android case, it will disable linear lookup by default.
+.RE
+.RS 1.2i
+.TP 1.2i
+.B [no]hashonly
+This flag specifies that there is no linear lookup fallback during lookup.
+By default, linear lookup fallback is enabled.
  .RE
  .RE
  .TP
mkfs/f2fs_format.c +3 -0
index 2680bd3..a45bbcb 100644
@@ -671,6 +671,9 @@ static int f2fs_prepare_super_block(void)
         memcpy(sb->init_version, c.version, VERSION_LEN);
 
         if (c.feature & F2FS_FEATURE_CASEFOLD) {
+               if (!(c.s_encoding_flags & F2FS_ENC_NO_COMPAT_FALLBACK_FL) &&
+                       (c.disabled_feature & F2FS_FEATURE_LINEAR_LOOKUP))
+                       c.s_encoding_flags |= F2FS_ENC_NO_COMPAT_FALLBACK_FL;
                 set_sb(s_encoding, c.s_encoding);
                 set_sb(s_encoding_flags, c.s_encoding_flags);
         }
mkfs/f2fs_format_main.c +2 -2
index f0bec4f..8f8e975 100644
@@ -143,7 +143,8 @@ static void add_default_options(void)
                 force_overwrite = 1;
                 c.wanted_sector_size = F2FS_BLKSIZE;
                 c.root_uid = c.root_gid = 0;
-               c.disabled_feature |= F2FS_FEATURE_NAT_BITS;
+               c.disabled_feature |= F2FS_FEATURE_NAT_BITS |
+                                       F2FS_FEATURE_LINEAR_LOOKUP;
 
                 /* RO doesn't need any other features */
                 if (c.feature & F2FS_FEATURE_RO)
--

2.49.0

Quoted 4 lines
Quoted 4 lines

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#3 lore raw
Quoted 23 lines · Chao Yu <[email protected]> 于2025年7月25日周五 10:45写道:
Quoted 21 lines · Zhiguo Niu

Chao Yu via Linux-f2fs-devel <[email protected]>

Quoted 19 lines · 于2025年7月25日周五 09:03写道:

It provides a way to disable linear lookup fallback during mkfs.

Behavior summary:
Android Distro

By default              disabled        enabled
Tune w/ [no]hashonly    no              yes

Android case:

1.1) Disable linear lookup:
mkfs.f2fs -f -g android -O casefold -C utf8:hashonly /dev/vdb dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 2 : 2]

1.2) Enable linear lookup:
mkfs.f2fs -f -g android -O casefold -C utf8:nohashonly /dev/vdb dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 2 : 2]

Quoted 7 lines
Quoted 2 lines

Hi Chao,
Seems like a typo here? should be:

Zhiguo,

Not a typo, it's intentional, see above behavior summary.

Hi Chao,
Ah, I got it after checking again.^^

Quoted 4 lines

But after rethinking about this, I guess it will be good to honor 'nohashonly' for Android case like Distro case.

Anyway, let me update the patch.

Thanks for this and explanation.

Quoted 120 lines

Thanks,

Quoted 117 lines

s_encoding_flags [0x 0 : 0] ?
thanks!

Quoted 115 lines

1.3) By default:
mkfs.f2fs -f -g android -O casefold -C utf8 /dev/vdb dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 2 : 2]

Distro case:

2.1) Disable linear lookup:
mkfs.f2fs -f -O casefold -C utf8:hashonly /dev/vdb dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 2 : 2]

2.2) Enable linear lookup:
mkfs.f2fs -f -O casefold -C utf8:nohashonly /dev/vdb dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 0 : 0]

2.3) By default:
mkfs.f2fs -f -O casefold -C utf8 /dev/vdb
dump.f2fs -d3 /dev/vdb |grep s_encoding_flags
s_encoding_flags [0x 0 : 0]

---
v2:
- disable linear lookup by default for Android case

  include/f2fs_fs.h       |  3 ++-
  lib/libf2fs.c           |  1 +
  man/mkfs.f2fs.8         | 10 ++++++++--
  mkfs/f2fs_format.c      |  3 +++
  mkfs/f2fs_format_main.c |  3 ++-
  5 files changed, 16 insertions(+), 4 deletions(-)
include/f2fs_fs.h +2 -1
index f7268d1..a8da8fa 100644
@@ -1478,7 +1478,8 @@ enum {
 
  /* feature list in Android */
  enum {
-       F2FS_FEATURE_NAT_BITS = 0x0001,
+       F2FS_FEATURE_NAT_BITS           = 0x0001,
+       F2FS_FEATURE_LINEAR_LOOKUP      = 0x0002,
  };
 
  /* nolinear lookup tune */
lib/libf2fs.c +1 -0
index 2f012c8..0e3e62a 100644
@@ -1424,6 +1424,7 @@ static const struct enc_flags {
         char *param;
  } encoding_flags[] = {
         { F2FS_ENC_STRICT_MODE_FL, "strict" },
+       { F2FS_ENC_NO_COMPAT_FALLBACK_FL, "hashonly"}
  };
 
  /* Return a positive number < 0xff indicating the encoding magic number
man/mkfs.f2fs.8 +8 -2
index 8b3b0cc..8cb7d32 100644
@@ -232,9 +232,15 @@ Use UTF-8 for casefolding.
  .I flags:
  .RS 1.2i
  .TP 1.2i
-.B strict
+.B [no]strict
  This flag specifies that invalid strings should be rejected by the filesystem.
-Default is disabled.
+For android case, it will disable linear lookup by default.
+.RE
+.RS 1.2i
+.TP 1.2i
+.B [no]hashonly
+This flag specifies that there is no linear lookup fallback during lookup.
+By default, linear lookup fallback is enabled.
  .RE
  .RE
  .TP
mkfs/f2fs_format.c +3 -0
index 2680bd3..a45bbcb 100644
@@ -671,6 +671,9 @@ static int f2fs_prepare_super_block(void)
         memcpy(sb->init_version, c.version, VERSION_LEN);
 
         if (c.feature & F2FS_FEATURE_CASEFOLD) {
+               if (!(c.s_encoding_flags & F2FS_ENC_NO_COMPAT_FALLBACK_FL) &&
+                       (c.disabled_feature & F2FS_FEATURE_LINEAR_LOOKUP))
+                       c.s_encoding_flags |= F2FS_ENC_NO_COMPAT_FALLBACK_FL;
                 set_sb(s_encoding, c.s_encoding);
                 set_sb(s_encoding_flags, c.s_encoding_flags);
         }
mkfs/f2fs_format_main.c +2 -2
index f0bec4f..8f8e975 100644
@@ -143,7 +143,8 @@ static void add_default_options(void)
                 force_overwrite = 1;
                 c.wanted_sector_size = F2FS_BLKSIZE;
                 c.root_uid = c.root_gid = 0;
-               c.disabled_feature |= F2FS_FEATURE_NAT_BITS;
+               c.disabled_feature |= F2FS_FEATURE_NAT_BITS |
+                                       F2FS_FEATURE_LINEAR_LOOKUP;
 
                 /* RO doesn't need any other features */
                 if (c.feature & F2FS_FEATURE_RO)
--

2.49.0

Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel