Skip to contentSkip to conversation

Introduce EROFS support

PATCH Superseded Gao Xiang 5 participants 15 messages May 17, 2024 – May 20, 2024 Kbuild

v14 of 15 Superseded Latest is v15 →

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

v14 cover Introduce EROFS support

[ This is a RESEND version of v13 due to a mis-fix. ]

Hi folks,

EROFS [1] is a lightweight read-only filesystem designed for performance which has already been shipped in most Linux distributions as well as widely used in several scenarios, such as Android system partitions, container images, and rootfs for embedded devices.

This patch brings EROFS uncompressed support together with related tests. Now, it's possible to boot directly through GRUB with an EROFS rootfs.

EROFS compressed files will be supported later since it has more work to polish.

[1] https://erofs.docs.kernel.org

v12: https://lore.kernel.org/grub-devel/[email protected]
changelog since v12:
- Address ALIGN_UP_OVF() suggested by Daniel:
https://lore.kernel.org/grub-devel/[email protected]

Tested-by Link (Commit 1): https://lists.gnu.org/archive/html/grub-devel/2024-05/msg00001.html
Reviewed-by Link (Commit 2): https://lists.gnu.org/archive/html/grub-devel/2024-04/msg00101.html
Reviewed-by Link (Commit 2): https://lore.kernel.org/grub-devel/[email protected]/

Gao Xiang (1):
safemath: Add ALIGN_UP_OVF() that checks for {over,under}flow

Yifan Zhao (2):
fs/erofs: Add support for EROFS
fs/erofs: Add tests for EROFS in grub-fs-tester

 .gitignore                   |    1 +
 INSTALL                      |    8 +-
 Makefile.util.def            |    7 +
 docs/grub.texi               |    3 +-
 grub-core/Makefile.core.def  |    5 +
 grub-core/fs/erofs.c         | 1000 ++++++++++++++++++++++++++++++++++
 include/grub/safemath.h      |   16 +
 tests/erofs_test.in          |   20 +
 tests/util/grub-fs-tester.in |   32 +-
 9 files changed, 1080 insertions(+), 12 deletions(-)
 create mode 100644 grub-core/fs/erofs.c
 create mode 100644 tests/erofs_test.in

Interdiff against v12:

grub-core/fs/erofs.c +1 -3
index 630f95e75..46cfc2e5c 100644
@@ -405,10 +405,8 @@ erofs_map_blocks_chunkmode (grub_fshelp_node_t node,
   if (grub_add (pos, erofs_inode_xattr_ibody_size (node), &pos))
     return grub_error (GRUB_ERR_OUT_OF_RANGE, "chunkmap position overflow when adding xattr size");
 
-  /* pos = ALIGN_UP(pos, unit) */
-  if (grub_add (pos, unit - 1, &pos))
+  if (ALIGN_UP_OVF (pos, unit, &pos))
     return grub_error (GRUB_ERR_OUT_OF_RANGE, "position overflow when seeking at the start of chunkmap");
-  pos &= ~(unit - 1);
 
   /* No overflow for multiplication as chunkbits >= 9 and sizeof(unit) <= 8. */
   if (grub_add (pos, chunknr * unit, &pos))
include/grub/safemath.h +16 -0
index fbd9b5925..baaea0ef4 100644
@@ -32,6 +32,22 @@
 
 #define grub_cast(a, res)	grub_add ((a), 0, (res))
 
+#define ALIGN_UP_OVF(v, align, res) 			\
+({							\
+  bool __failed;					\
+  typeof(v) a;						\
+							\
+  __failed = grub_sub ((typeof(v))(align), 1, &a);	\
+  if (__failed == false)				\
+    {							\
+    __failed = grub_add (v, a, res);			\
+    if (__failed == false)				\
+      {							\
+        *(res) &= ~a;					\
+      }							\
+    }							\
+__failed;})
+
 #else
 #error gcc 5.1 or newer or clang 8.0 or newer is required
 #endif
Signature · 7 lines
2.39.3


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
author
#1 lore raw

PATCH v14 1/3 safemath: Add ALIGN_UP_OVF() that checks for {over, under}flow

The following EROFS patch will use this helper to handle overflow ALIGN_UP() cases.

---
 include/grub/safemath.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
include/grub/safemath.h +16 -0
index fbd9b5925..baaea0ef4 100644
@@ -32,6 +32,22 @@
 
 #define grub_cast(a, res)	grub_add ((a), 0, (res))
 
+#define ALIGN_UP_OVF(v, align, res) 			\
+({							\
+  bool __failed;					\
+  typeof(v) a;						\
+							\
+  __failed = grub_sub ((typeof(v))(align), 1, &a);	\
+  if (__failed == false)				\
+    {							\
+    __failed = grub_add (v, a, res);			\
+    if (__failed == false)				\
+      {							\
+        *(res) &= ~a;					\
+      }							\
+    }							\
+__failed;})
+
 #else
 #error gcc 5.1 or newer or clang 8.0 or newer is required
 #endif
Signature · 7 lines
2.39.3


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#2 lore raw

Re: [PATCH v14 1/3] safemath: Add ALIGN_UP_OVF() that checks for {over, under}flow

I think that given that align is a non zero const we can trust it.

Le ven. 17 mai 2024, 15:56, Gao Xiang <[email protected]> a écrit :

Quoted 36 lines

The following EROFS patch will use this helper to handle overflow ALIGN_UP() cases.

---
 include/grub/safemath.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
include/grub/safemath.h +16 -1
index fbd9b5925..baaea0ef4 100644
@@ -32,6 +32,22 @@
 
 #define grub_cast(a, res)      grub_add ((a), 0, (res))
 
+#define ALIGN_UP_OVF(v, align, res)                    \
+({                                                     \
+  bool __failed;                                       \
+  typeof(v) a;                                         \
+                                                       \
+  __failed = grub_sub ((typeof(v))(align), 1, &a);     \
+  if (__failed == false)                               \
+    {                                                  \
+    __failed = grub_add (v, a, res);                   \
+    if (__failed == false)                             \
+      {                                                        \
+        *(res) &= ~a;                                  \
+      }                                                        \
+    }                                                  \
+__failed;})
+
 #else
 #error gcc 5.1 or newer or clang 8.0 or newer is required
 #endif
--
Quoted 3 lines

2.39.3

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

author
#3 lore raw

Re: [PATCH v14 1/3] safemath: Add ALIGN_UP_OVF() that checks for {over,under}flow

Hi Vladimir,

Quoted 1 line · Vladimir 'phcoder' Serbinenko

I think that given that align is a non zero const we can trust it.

From the EROFS specific cases, they are always non-zero values, So I agree with you on this..

Yet Daniel said ".. Be careful with underflows too." in
https://lore.kernel.org/r/[email protected]
although I'm not quite sure but I guess like this.

Also as a generic helper, I think align could be zero if it's a variable..

Anyway, either way works for EROFS. I just try my best to do
what I could do for this first series for upstreaming and we could move forward to the next step..

Thanks,
Gao Xiang

Quoted 32 lines

Le ven. 17 mai 2024, 15:56, Gao Xiang <[email protected] <mailto:[email protected]>> a écrit :

    The following EROFS patch will use this helper to handle overflow
    ALIGN_UP() cases.

    Signed-off-by: Gao Xiang <[email protected] <mailto:[email protected]>>
    ---
      include/grub/safemath.h | 16 ++++++++++++++++
      1 file changed, 16 insertions(+)

    diff --git a/include/grub/safemath.h b/include/grub/safemath.h
    index fbd9b5925..baaea0ef4 100644
    --- a/include/grub/safemath.h
    +++ b/include/grub/safemath.h
    @@ -32,6 +32,22 @@

      #define grub_cast(a, res)      grub_add ((a), 0, (res))

    +#define ALIGN_UP_OVF(v, align, res)                    \
    +({                                                     \
    +  bool __failed;                                       \
    +  typeof(v) a;                                         \
    +                                                       \
    +  __failed = grub_sub ((typeof(v))(align), 1, &a);     \
    +  if (__failed == false)                               \
    +    {                                                  \
    +    __failed = grub_add (v, a, res);                   \
    +    if (__failed == false)                             \
    +      {                                                        \
    +        *(res) &= ~a;                                  \
    +      }                                                        \
Quoted 9 lines
    +    }                                                  \
    +__failed;})
    +
      #else
      #error gcc 5.1 or newer or clang 8.0 or newer is required
      #endif
    -- 
    2.39.3

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#4 lore raw

Re: [PATCH v14 1/3] safemath: Add ALIGN_UP_OVF() that checks for {over, under}flow

Le ven. 17 mai 2024, 21:26, Gao Xiang <[email protected]> a écrit :

Quoted 8 lines

Hi Vladimir,

Quoted 1 line · Vladimir 'phcoder' Serbinenko

I think that given that align is a non zero const we can trust it.

From the EROFS specific cases, they are always non-zero values,
So I agree with you on this..

Quoted 7 lines

Yet Daniel said ".. Be careful with underflows too." in
https://lore.kernel.org/r/[email protected]
although I'm not quite sure but I guess like this.

Also as a generic helper, I think align could be zero if it's a variable..

It's rare for align to be a variable and then additional checks are needed that align is a power of 2. And power of 2 is never zero. This check is better done on the caller side. You just need a comment specify that it's caller responsibility to check it.

Quoted 9 lines

Anyway, either way works for EROFS. I just try my best to do
what I could do for this first series for upstreaming and we could move forward to the next step..

Thanks,
Gao Xiang

Quoted 1 line
Quoted 43 lines
Quoted 1 line

Le ven. 17 mai 2024, 15:56, Gao Xiang <[email protected]

Quoted 5 lines · <mailto:[email protected]>> a écrit :

The following EROFS patch will use this helper to handle overflow ALIGN_UP() cases.

[email protected]>>

Quoted 34 lines

---
include/grub/safemath.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)

diff --git a/include/grub/safemath.h b/include/grub/safemath.h index fbd9b5925..baaea0ef4 100644
--- a/include/grub/safemath.h
+++ b/include/grub/safemath.h
@@ -32,6 +32,22 @@

#define grub_cast(a, res) grub_add ((a), 0, (res))

+#define ALIGN_UP_OVF(v, align, res) \
+({ \
+ bool __failed; \
+ typeof(v) a; \
+ \
+ __failed = grub_sub ((typeof(v))(align), 1, &a); \
+ if (__failed == false) \
+ { \
+ __failed = grub_add (v, a, res); \
+ if (__failed == false) \
+ { \
+ *(res) &= ~a; \
+ } \
+ } \
+__failed;})
+
#else
#error gcc 5.1 or newer or clang 8.0 or newer is required #endif
--
2.39.3

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

author
#5 lore raw

Re: [PATCH v14 1/3] safemath: Add ALIGN_UP_OVF() that checks for {over,under}flow

Quoted 16 lines · Vladimir 'phcoder' Serbinenko

Le ven. 17 mai 2024, 21:26, Gao Xiang <[email protected] <mailto:[email protected]>> a écrit :

Hi Vladimir,

On 2024/5/18 00:38, Vladimir 'phcoder' Serbinenko wrote:
> I think that given that align is a non zero const we can trust it.

 From the EROFS specific cases, they are always non-zero values,
So I agree with you on this..

Yet Daniel said ".. Be careful with underflows too." in
https://lore.kernel.org/r/[email protected] <https://lore.kernel.org/r/[email protected]>
although I'm not quite sure but I guess like this.

Quoted 5 lines

Also as a generic helper, I think align could be zero if it's a variable..

It's rare for align to be a variable and then additional checks are needed that align is a power of 2. And power of 2 is never zero. This check is better done on the caller side. You just need a comment specify that it's caller responsibility to check it.

I'd like to know Daniel's comment about this first, there are already too many comments out of nits. I'm fine with updating such nits but I would like to confirm _which comment_ I should follow for upstreaming.

Thanks,
Gao Xiang

Quoted 9 lines

Anyway, either way works for EROFS.   I just try my best to do what I could do for this first series for upstreaming and we could move forward to the next step..

Thanks,
Gao Xiang

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

author
#6 lore raw

Re: [PATCH v14 1/3] safemath: Add ALIGN_UP_OVF() that checks for {over,under}flow

Hi Daniel,

There is too many comments on this minor stuff, would you mind giving some hints of your perference so I could have a chance to finish this stuff?

https://lore.kernel.org/grub-devel/CAEaD8JNwa8W=3LvaVeDG0hByz10+XHEDwCsV8TQe5md_13s2jg@mail.gmail.com/
https://lore.kernel.org/grub-devel/[email protected]/

Thanks in advance.

Thanks,
Gao Xiang

Quoted 25 lines · Gao Xiang
Quoted 16 lines · Vladimir 'phcoder' Serbinenko

Le ven. 17 mai 2024, 21:26, Gao Xiang <[email protected] <mailto:[email protected]>> a écrit :

    Hi Vladimir,

    On 2024/5/18 00:38, Vladimir 'phcoder' Serbinenko wrote:
     > I think that given that align is a non zero const we can trust it.

      From the EROFS specific cases, they are always non-zero values, So I agree with you on this..

    Yet Daniel said ".. Be careful with underflows too." in
    https://lore.kernel.org/r/[email protected] <https://lore.kernel.org/r/[email protected]>
    although I'm not quite sure but I guess like this.

Quoted 5 lines

    Also as a generic helper, I think align could be zero if it's a variable..

It's rare for align to be a variable and then additional checks are needed that align is a power of 2. And power of 2 is never zero. This check is better done on the caller side. You just need a comment specify that it's caller responsibility to check it.

Quoted 17 lines

I'd like to know Daniel's comment about this first, there are already too many comments out of nits.  I'm fine with updating such nits but I would like to confirm _which comment_ I should follow for upstreaming.

Thanks,
Gao Xiang

Quoted 9 lines

    Anyway, either way works for EROFS.   I just try my best to do what I could do for this first series for upstreaming and we could move forward to the next step..

    Thanks,
    Gao Xiang

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

author
#7 lore raw

PATCH v14 1/3 safemath: Add ALIGN_UP_OVF() that checks for {over, under}flow

The following EROFS patch will use this helper to handle overflow ALIGN_UP() cases.

---
Hi Daniel,

I've also made another patch to conform Vladimir's and Boyang's comments as much as I can.

Thanks,
Gao Xiang

 include/grub/safemath.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
include/grub/safemath.h +16 -0
index fbd9b5925..bb8a5b39c 100644
@@ -32,6 +32,22 @@
 
 #define grub_cast(a, res)	grub_add ((a), 0, (res))
 
+/*
+ * It's caller's responsibility that `align` should not equal to 0 and
+ * it must be a power of 2.
+ */
+#define ALIGN_UP_OVF(v, align, res) 			\
+({							\
+  bool __failed;					\
+  typeof(v) __a = ((typeof(v))(align) - 1);		\
+							\
+  __failed = grub_add (v, __a, res);			\
+  if (__failed == false)				\
+    {							\
+      *(res) &= ~__a;					\
+    }							\
+__failed;})
+
 #else
 #error gcc 5.1 or newer or clang 8.0 or newer is required
 #endif
Signature · 7 lines
2.39.3


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Reviewed-by Daniel Kiper on v14 1/3
#8 lore raw

Re: [PATCH v14 NEW ALT 1/3] safemath: Add ALIGN_UP_OVF() that checks for {over,under}flow

Quoted 4 lines · Gao Xiang

The following EROFS patch will use this helper to handle overflow ALIGN_UP() cases.

I think Vladimir is right.

Please post v15 an I will merge it this week.

Thank you for adding EROFS support!

Daniel

Quoted 29 lines

---
Hi Daniel,

I've also made another patch to conform Vladimir's and Boyang's comments as much as I can.

Thanks,
Gao Xiang

 include/grub/safemath.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
include/grub/safemath.h +9 -0
index fbd9b5925..bb8a5b39c 100644
@@ -32,6 +32,22 @@
 
 #define grub_cast(a, res)	grub_add ((a), 0, (res))
 
+/*
+ * It's caller's responsibility that `align` should not equal to 0 and
+ * it must be a power of 2.
+ */
+#define ALIGN_UP_OVF(v, align, res) 			\
+({							\
+  bool __failed;					\
+  typeof(v) __a = ((typeof(v))(align) - 1);		\
+							\

include/grub/safemath.h line 53

Quoted 10 lines
include/grub/safemath.h +7 -0
+  __failed = grub_add (v, __a, res);			\
+  if (__failed == false)				\
+    {							\
+      *(res) &= ~__a;					\
+    }							\
+__failed;})
+
 #else
 #error gcc 5.1 or newer or clang 8.0 or newer is required
 #endif

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

author
#9 lore raw

Re: [PATCH v14 NEW ALT 1/3] safemath: Add ALIGN_UP_OVF() that checks for {over,under}flow

Hi Daniel and all,

Quoted 7 lines · Daniel Kiper
Quoted 4 lines · Gao Xiang

The following EROFS patch will use this helper to handle overflow ALIGN_UP() cases.

I think Vladimir is right.

Thanks for your confirmation! :-)

Quoted 4 lines

Please post v15 an I will merge it this week.

Okay, let me sort out a new version soon.

Quoted 2 lines

Thank you for adding EROFS support!

Thank you all for taking so much time on this stuffs too, thanks again!

Thanks,
Gao Xiang

Quoted 3 lines

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#10 lore raw

Re: [PATCH v14 1/3] safemath: Add ALIGN_UP_OVF() that checks for {over, under}flow

In reply to Gao Xiang

Hi,

Quoted 13 lines · Gao Xiang

The following EROFS patch will use this helper to handle overflow ALIGN_UP() cases.

---
  include/grub/safemath.h | 16 ++++++++++++++++
  1 file changed, 16 insertions(+)
include/grub/safemath.h +0 -0
index fbd9b5925..baaea0ef4 100644

include/grub/safemath.h line 38

Quoted 7 lines
include/grub/safemath.h +4 -0
@@ -32,6 +32,22 @@
 
  #define grub_cast(a, res)	grub_add ((a), 0, (res))
 
+#define ALIGN_UP_OVF(v, align, res) 			\
+({							\
+  bool __failed;					\
+  typeof(v) a;						\

I think "a" should be changed to some unique name like "__a", because variable shadowing might occur:

int a = 10, b = 4;
if (!ALIGN_UP_OVF(a, b, &a)) { // "a" is shadowed
printf("a=%d\n", a);
}

The uniqueness of variable name can reduce the possibility of variable shadowing, but it will not eliminate the pitfall.
https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html

The ultimate solution would be a macro-like "static inline" function, but I'm not sure whether a inline function is appropriate in grub headers.

include/grub/safemath.h line 40

Quoted 2 lines
include/grub/safemath.h +2 -0
+							\
+  __failed = grub_sub ((typeof(v))(align), 1, &a);	\

The cast "(typeof(v))" is unnecessary and it will silently ignore overflow/underflow.

Zhang Boyang

include/grub/safemath.h line 53

Quoted 13 lines
include/grub/safemath.h +10 -0
+  if (__failed == false)				\
+    {							\
+    __failed = grub_add (v, a, res);			\
+    if (__failed == false)				\
+      {							\
+        *(res) &= ~a;					\
+      }							\
+    }							\
+__failed;})
+
  #else
  #error gcc 5.1 or newer or clang 8.0 or newer is required
  #endif

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#11 lore raw

Re: [PATCH v14 1/3] safemath: Add ALIGN_UP_OVF() that checks for {over, under}flow

Hi,

Quoted 29 lines · Zhang Boyang

Hi,

Quoted 13 lines · Gao Xiang

The following EROFS patch will use this helper to handle overflow ALIGN_UP() cases.

---
  include/grub/safemath.h | 16 ++++++++++++++++

  1 file changed, 16 insertions(+)
include/grub/safemath.h +0 -0
index fbd9b5925..baaea0ef4 100644

include/grub/safemath.h line 36

Quoted 5 lines
include/grub/safemath.h +4 -0
@@ -32,6 +32,22 @@
   #define grub_cast(a, res)    grub_add ((a), 0, (res))
+#define ALIGN_UP_OVF(v, align, res)             \
+({                            \
+  bool __failed;                    \
+  typeof(v) a;                        \

I think "a" should be changed to some unique name like "__a", because variable shadowing might occur:

int a = 10, b = 4;
if (!ALIGN_UP_OVF(a, b, &a)) { // "a" is shadowed
  printf("a=%d\n", a);
}

Quoted 5 lines

The uniqueness of variable name can reduce the possibility of variable shadowing, but it will not eliminate the pitfall.
https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html

The ultimate solution would be a macro-like "static inline" function, but I'm not sure whether a inline function is appropriate in grub headers.

Oh, sorry, I'm wrong. This marco can't be a inline function because function signature requires specific types to be given to a variable, which will eliminate the efforts of overflow macros.

By the way, I think it would be better to write a comment about "align should not equal to 0 and it must be a power of 2"

Zhang Boyang

Quoted 7 lines

include/grub/safemath.h line 40

Quoted 2 lines
include/grub/safemath.h +2 -0
+                            \
+  __failed = grub_sub ((typeof(v))(align), 1, &a);    \

The cast "(typeof(v))" is unnecessary and it will silently ignore overflow/underflow.

Zhang Boyang

Quoted 13 lines

include/grub/safemath.h line 53

Quoted 13 lines
include/grub/safemath.h +10 -0
+  if (__failed == false)                \
+    {                            \
+    __failed = grub_add (v, a, res);            \
+    if (__failed == false)                \
+      {                            \
+        *(res) &= ~a;                    \
+      }                            \
+    }                            \
+__failed;})
+
   #else
   #error gcc 5.1 or newer or clang 8.0 or newer is required
   #endif

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

author
#12 lore raw

PATCH v14 2/3 fs/erofs: Add support for EROFS

In reply to Gao Xiang

From: Yifan Zhao <[email protected]>

EROFS [1] is a lightweight read-only filesystem designed for performance which has already been shipped in most Linux distributions as well as widely used in several scenarios, such as Android system partitions, container images, and rootfs for embedded devices.

This patch brings EROFS uncompressed support. Now, it's possible to boot directly through GRUB with an EROFS rootfs.

EROFS compressed files will be supported later since it has more work to polish.

[1] https://erofs.docs.kernel.org

---
 INSTALL                     |    8 +-
 Makefile.util.def           |    1 +
 docs/grub.texi              |    3 +-
 grub-core/Makefile.core.def |    5 +
 grub-core/fs/erofs.c        | 1000 +++++++++++++++++++++++++++++++++++
 5 files changed, 1012 insertions(+), 5 deletions(-)
 create mode 100644 grub-core/fs/erofs.c
INSTALL +4 -4
index 8d9207c84..84030c9f4 100644
@@ -77,15 +77,15 @@ Prerequisites for make-check:
 
 * If running a Linux kernel the following modules must be loaded:
   - fuse, loop
-  - btrfs, ext4, f2fs, fat, hfs, hfsplus, jfs, mac-roman, minix, nilfs2,
+  - btrfs, erofs, ext4, f2fs, fat, hfs, hfsplus, jfs, mac-roman, minix, nilfs2,
     reiserfs, udf, xfs
   - On newer kernels, the exfat kernel modules may be used instead of the
     exfat FUSE filesystem
 * The following are Debian named packages required mostly for the full
   suite of filesystem testing (but some are needed by other tests as well):
-  - btrfs-progs, dosfstools, e2fsprogs, exfat-utils, f2fs-tools, genromfs,
-    hfsprogs, jfsutils, nilfs-tools, ntfs-3g, reiserfsprogs, squashfs-tools,
-    reiserfsprogs, udftools, xfsprogs, zfs-fuse
+  - btrfs-progs, dosfstools, e2fsprogs, erofs-utils, exfat-utils, f2fs-tools,
+    genromfs, hfsprogs, jfsutils, nilfs-tools, ntfs-3g, reiserfsprogs,
+    squashfs-tools, reiserfsprogs, udftools, xfsprogs, zfs-fuse
   - exfat-fuse, if not using the exfat kernel module
   - gzip, lzop, xz-utils
   - attr, cpio, g++, gawk, parted, recode, tar, util-linux
Makefile.util.def +1 -0
index 9432365a9..8d3bc107f 100644
@@ -98,6 +98,7 @@ library = {
   common = grub-core/fs/cpio_be.c;
   common = grub-core/fs/odc.c;
   common = grub-core/fs/newc.c;
+  common = grub-core/fs/erofs.c;
   common = grub-core/fs/ext2.c;
   common = grub-core/fs/fat.c;
   common = grub-core/fs/exfat.c;
docs/grub.texi +2 -1
index d32266f69..b198d963d 100644
@@ -353,6 +353,7 @@ blocklist notation. The currently supported filesystem types are @dfn{Amiga
 Fast FileSystem (AFFS)}, @dfn{AtheOS fs}, @dfn{BeFS},
 @dfn{BtrFS} (including raid0, raid1, raid10, gzip and lzo),
 @dfn{cpio} (little- and big-endian bin, odc and newc variants),
+@dfn{EROFS} (only uncompressed support for now),
 @dfn{Linux ext2/ext3/ext4}, @dfn{DOS FAT12/FAT16/FAT32},
 @dfn{exFAT}, @dfn{F2FS}, @dfn{HFS}, @dfn{HFS+},
 @dfn{ISO9660} (including Joliet, Rock-ridge and multi-chunk files),
@@ -6276,7 +6277,7 @@ assumed to be encoded in UTF-8.
 NTFS, JFS, UDF, HFS+, exFAT, long filenames in FAT, Joliet part of
 ISO9660 are treated as UTF-16 as per specification. AFS and BFS are read
 as UTF-8, again according to specification. BtrFS, cpio, tar, squash4, minix,
-minix2, minix3, ROMFS, ReiserFS, XFS, ext2, ext3, ext4, FAT (short names),
+minix2, minix3, ROMFS, ReiserFS, XFS, EROFS, ext2, ext3, ext4, FAT (short names),
 F2FS, RockRidge part of ISO9660, nilfs2, UFS1, UFS2 and ZFS are assumed
 to be UTF-8. This might be false on systems configured with legacy charset
 but as long as the charset used is superset of ASCII you should be able to
grub-core/Makefile.core.def +5 -0
index 8e1b1d9f3..7fa9446bd 100644
@@ -1442,6 +1442,11 @@ module = {
   common = fs/odc.c;
 };
 
+module = {
+  name = erofs;
+  common = fs/erofs.c;
+};
+
 module = {
   name = ext2;
   common = fs/ext2.c;
grub-core/fs/erofs.c new file +1000 -0

1,000 lines not on this page · raw message

Signature · 7 lines
2.39.3


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
author
#13 lore raw

PATCH v14 3/3 fs/erofs: Add tests for EROFS in grub-fs-tester

In reply to Gao Xiang

From: Yifan Zhao <[email protected]>

In this patch, three tests of EROFS are introduced and they cover compact, extended and chunk-based inodes, respectively.

---
 .gitignore                   |  1 +
 Makefile.util.def            |  6 ++++++
 tests/erofs_test.in          | 20 ++++++++++++++++++++
 tests/util/grub-fs-tester.in | 32 +++++++++++++++++++++++++-------
 4 files changed, 52 insertions(+), 7 deletions(-)
 create mode 100644 tests/erofs_test.in
.gitignore +1 -0
index 11fcecf5c..4c1f91db8 100644
@@ -104,6 +104,7 @@ widthspec.bin
 /docs/version-dev.texi
 /docs/version.texi
 /ehci_test
+/erofs_test
 /example_grub_script_test
 /example_scripted_test
 /example_unit_test
Makefile.util.def +6 -0
index 8d3bc107f..0f74a1680 100644
@@ -764,6 +764,12 @@ script = {
   dependencies = 'garbage-gen$(BUILD_EXEEXT)';
 };
 
+script = {
+  testcase = native;
+  name = erofs_test;
+  common = tests/erofs_test.in;
+};
+
 script = {
   testcase = native;
   name = ext234_test;
tests/erofs_test.in new file +20 -0
new file mode 100644
index 000000000..51111627a
@@ -0,0 +1,20 @@
+#!@BUILD_SHEBANG@
+
+set -e
+
+if [ "x$EUID" = "x" ] ; then
+  EUID=`id -u`
+fi
+
+if [ "$EUID" != 0 ] ; then
+   exit 99
+fi
+
+if ! which mkfs.erofs >/dev/null 2>&1; then
+   echo "mkfs.erofs not installed; cannot test erofs."
+   exit 99
+fi
+
+"@builddir@/grub-fs-tester" erofs_compact
+"@builddir@/grub-fs-tester" erofs_extended
+"@builddir@/grub-fs-tester" erofs_chunk
tests/util/grub-fs-tester.in +25 -7
index ea8b2d1f6..df5dc7542 100644
@@ -227,6 +227,10 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do
 	xsquash*)
 	    MINBLKSIZE=4096
 	    MAXBLKSIZE=1048576;;
+	x"erofs_"*)
+		MINBLKSIZE=4096
+		MAXBLKSIZE=4096
+		;;
 	xxfs|xf2fs)
 	    MINBLKSIZE=$SECSIZE
 	    # OS Limitation: GNU/Linux doesn't accept > 4096
@@ -382,8 +386,8 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do
 		    FSLABEL="g;/_é䏌䐓䏕䎛䎾䏴кит u"
 		    #FSLABEL="g;/_é莭莽😁кит u"
 		    ;;
-		# FS LIMITATION: reiserfs, extN and jfs label is at most 16 UTF-8 characters
-		x"reiserfs_old" | x"reiserfs" | x"ext"* | x"lvm"* | x"luks"* | x"mdraid"* | x"jfs" | x"jfs_caseins")
+		# FS LIMITATION: reiserfs, extN, jfs and erofs label is at most 16 UTF-8 characters
+		x"reiserfs_old" | x"reiserfs" | x"ext"* | x"lvm"* | x"luks"* | x"mdraid"* | x"jfs" | x"jfs_caseins" | x"erofs_"*)
 		    FSLABEL="g;/éт 莭😁";;
 		# FS LIMITATION: No underscore, space, semicolon, slash or international characters in UFS* in label. Limited to 32 UTF-8 characters
 		x"ufs1" | x"ufs1_sun" | x"ufs2")
@@ -661,7 +665,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do
 		x"tarfs" | x"cpio_"*| x"ziso9660" | x"romfs" | x"squash4_"*\
 		    | x"iso9660" | xjoliet | xrockridge | xrockridge_joliet \
 		    | x"iso9660_1999" | xjoliet_1999 | xrockridge_1999 \
-		    | xrockridge_joliet_1999)
+		    | xrockridge_joliet_1999 | x"erofs_"*)
 		    MNTPOINTRW="$MASTER"
 		    MNTPOINTRO="$MASTER"
 		    mkdir -p "$MASTER";;
@@ -805,7 +809,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do
 		    sleep 1
 		    "zfs" create "$FSLABEL"/"grub fs"
 		    sleep 1;;
-		x"tarfs" | x"cpio_"* | x"iso9660" | xjoliet | xrockridge | xrockridge_joliet | x"iso9660_1999" | xjoliet_1999 | xrockridge_1999 | xrockridge_joliet_1999 | x"ziso9660" | x"romfs" | x"squash4_"*)
+		x"tarfs" | x"cpio_"* | x"iso9660" | xjoliet | xrockridge | xrockridge_joliet | x"iso9660_1999" | xjoliet_1999 | xrockridge_1999 | xrockridge_joliet_1999 | x"ziso9660" | x"romfs" | x"squash4_"* | x"erofs_"*)
 		    INSTDEVICE=/dev/null;;
 		x"reiserfs")
 		    "mkfs.reiserfs" --format=3.6 -b $BLKSIZE -l "$FSLABEL" -q "${MOUNTDEVICE}" ;;
@@ -990,7 +994,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do
 		x"zfs"*)
 		    OSDIR="grub fs/"
 		    GRUBDIR="($GRUBDEVICE)/grub fs@";;
-		x"tarfs" | x"cpio_"* | x"iso9660" | xjoliet | xrockridge | xrockridge_joliet | x"iso9660_1999" | xjoliet_1999 | xrockridge_1999 | xrockridge_joliet_1999 | x"ziso9660" | x"romfs" | x"squash4_"* | xafs)
+		x"tarfs" | x"cpio_"* | x"iso9660" | xjoliet | xrockridge | xrockridge_joliet | x"iso9660_1999" | xjoliet_1999 | xrockridge_1999 | xrockridge_joliet_1999 | x"ziso9660" | x"romfs" | x"squash4_"* | xafs | x"erofs_"*)
 		    ;;
 		*)
 		    if ! mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRW" -o ${MOUNTOPTS}${SELINUXOPTS}rw  ; then
@@ -1116,6 +1120,18 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do
 		xsquash4_*)
 		    echo mksquashfs "$MASTER" "${FSIMAGEP}0.img" -always-use-fragments -comp "${fs/squash4_/}" -b $BLKSIZE
 		    mksquashfs "$MASTER" "${FSIMAGEP}0.img" -always-use-fragments -comp "${fs/squash4_/}" -b $BLKSIZE ;;
+		x"erofs_compact")
+			echo mkfs.erofs -Eforce-inode-compact -L "$FSLABEL" "${FSIMAGEP}0.img" "$MNTPOINTRW"
+			mkfs.erofs -Eforce-inode-compact -L "$FSLABEL" "${FSIMAGEP}0.img" "$MNTPOINTRW"
+			;;
+		x"erofs_extended")
+			echo mkfs.erofs -Eforce-inode-extended -L "$FSLABEL" "${FSIMAGEP}0.img" "$MNTPOINTRW"
+			mkfs.erofs -Eforce-inode-extended -L "$FSLABEL" "${FSIMAGEP}0.img" "$MNTPOINTRW"
+			;;
+		x"erofs_chunk")
+			echo mkfs.erofs --chunksize=1048576 -L "$FSLABEL" "${FSIMAGEP}0.img" "$MNTPOINTRW"
+			mkfs.erofs --chunksize=1048576 -L "$FSLABEL" "${FSIMAGEP}0.img" "$MNTPOINTRW"
+			;;
 		x"bfs")
 		    sleep 1
 		    fusermount -u "$MNTPOINTRW"
@@ -1187,6 +1203,8 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do
 		    ;;
 		xsquash4_*)
 		    ;;
+		x"erofs_"*)
+		    ;;
 		xlvm*)
 		    vgchange -a y grub_test
 		    sleep 1
@@ -1624,7 +1642,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do
 			sleep 1;
 		    done
 		    sleep 5;;
-		x"tarfs" | x"cpio_"* | xrockridge | xjoliet | xrockridge_joliet | x"ziso9660" | x"romfs" | x"squash4_"* | xiso9660 | xiso9660_1999 | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999)
+		x"tarfs" | x"cpio_"* | xrockridge | xjoliet | xrockridge_joliet | x"ziso9660" | x"romfs" | x"squash4_"* | xiso9660 | xiso9660_1999 | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999 | x"erofs_"*)
 		    rm -rf "$MNTPOINTRW";;
 		x"afs")
 		    rm -rf "$MNTPOINTRO"
@@ -1651,7 +1669,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do
 		    ;;
 	    esac
 	    case x"$fs" in
-		x"tarfs" | x"cpio_"* | x"iso9660" | xrockridge | xjoliet | xrockridge_joliet | x"ziso9660" | x"romfs" | x"squash4_"* | x"iso9660_1999" | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999) ;;
+		x"tarfs" | x"cpio_"* | x"iso9660" | xrockridge | xjoliet | xrockridge_joliet | x"ziso9660" | x"romfs" | x"squash4_"* | x"iso9660_1999" | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999 | x"erofs_"*) ;;
 		*)
 		    for lodev in $LODEVICES; do
 			while ! losetup -d "$lodev"; do
Signature · 7 lines
2.39.3


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#14 lore raw
In reply to Gao Xiang

Reran v14, and it still correctly passes the fs-tester and correctly boots the EROFS kernel image.

Thanks,

Yifan Zhao

Quoted 82 lines · Gao Xiang

[ This is a RESEND version of v13 due to a mis-fix. ]

Hi folks,

EROFS [1] is a lightweight read-only filesystem designed for performance which has already been shipped in most Linux distributions as well as widely used in several scenarios, such as Android system partitions, container images, and rootfs for embedded devices.

This patch brings EROFS uncompressed support together with related tests. Now, it's possible to boot directly through GRUB with an EROFS rootfs.

EROFS compressed files will be supported later since it has more work to polish.

[1] https://erofs.docs.kernel.org

v12: https://lore.kernel.org/grub-devel/[email protected]
changelog since v12:
- Address ALIGN_UP_OVF() suggested by Daniel:
https://lore.kernel.org/grub-devel/[email protected]

Tested-by Link (Commit 1): https://lists.gnu.org/archive/html/grub-devel/2024-05/msg00001.html
Reviewed-by Link (Commit 2): https://lists.gnu.org/archive/html/grub-devel/2024-04/msg00101.html
Reviewed-by Link (Commit 2): https://lore.kernel.org/grub-devel/[email protected]/

Gao Xiang (1):
safemath: Add ALIGN_UP_OVF() that checks for {over,under}flow

Yifan Zhao (2):
fs/erofs: Add support for EROFS fs/erofs: Add tests for EROFS in grub-fs-tester

  .gitignore                   |    1 +
  INSTALL                      |    8 +-
  Makefile.util.def            |    7 +
  docs/grub.texi               |    3 +-
  grub-core/Makefile.core.def  |    5 +
  grub-core/fs/erofs.c         | 1000 ++++++++++++++++++++++++++++++++++
  include/grub/safemath.h      |   16 +
  tests/erofs_test.in          |   20 +
  tests/util/grub-fs-tester.in |   32 +-
  9 files changed, 1080 insertions(+), 12 deletions(-)

create mode 100644 grub-core/fs/erofs.c
create mode 100644 tests/erofs_test.in

Interdiff against v12:

grub-core/fs/erofs.c +1 -3
index 630f95e75..46cfc2e5c 100644
@@ -405,10 +405,8 @@ erofs_map_blocks_chunkmode (grub_fshelp_node_t node,
    if (grub_add (pos, erofs_inode_xattr_ibody_size (node), &pos))
      return grub_error (GRUB_ERR_OUT_OF_RANGE, "chunkmap position overflow when adding xattr size");
 
-  /* pos = ALIGN_UP(pos, unit) */
-  if (grub_add (pos, unit - 1, &pos))
+  if (ALIGN_UP_OVF (pos, unit, &pos))
      return grub_error (GRUB_ERR_OUT_OF_RANGE, "position overflow when seeking at the start of chunkmap");
-  pos &= ~(unit - 1);
 
    /* No overflow for multiplication as chunkbits >= 9 and sizeof(unit) <= 8. */
    if (grub_add (pos, chunknr * unit, &pos))
include/grub/safemath.h +9 -0
index fbd9b5925..baaea0ef4 100644
@@ -32,6 +32,22 @@
 
  #define grub_cast(a, res)	grub_add ((a), 0, (res))
 
+#define ALIGN_UP_OVF(v, align, res) 			\
+({							\
+  bool __failed;					\
+  typeof(v) a;						\
+							\
+  __failed = grub_sub ((typeof(v))(align), 1, &a);	\
+  if (__failed == false)				\
+    {							\
+    __failed = grub_add (v, a, res);			\

include/grub/safemath.h line 53

Quoted 10 lines
include/grub/safemath.h +7 -0
+    if (__failed == false)				\
+      {							\
+        *(res) &= ~a;					\
+      }							\
+    }							\
+__failed;})
+
  #else
  #error gcc 5.1 or newer or clang 8.0 or newer is required
  #endif

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel