<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jun 1, 2023 at 2:46 AM Gao Xiang <<a href="mailto:hsiangkao@linux.alibaba.com">hsiangkao@linux.alibaba.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Previously PAGE_SIZE was actually unset for most cases so that it was<br>
always hard-coded 4096.<br>
<br>
In order to set EROFS_MAX_BLOCK_SIZE correctly, let's detect the real<br>
page size when configuring.<br>
<br>
Cc: Kelvin Zhang <<a href="mailto:zhangkelvin@google.com" target="_blank">zhangkelvin@google.com</a>><br>
Signed-off-by: Gao Xiang <<a href="mailto:hsiangkao@linux.alibaba.com" target="_blank">hsiangkao@linux.alibaba.com</a>><br>
---<br>
 <a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a>             | 38 ++++++++++++++++++++++++++++++++++++++<br>
 include/erofs/internal.h |  8 +++-----<br>
 lib/namei.c              |  2 +-<br>
 mkfs/main.c              |  4 ++--<br>
 4 files changed, 44 insertions(+), 8 deletions(-)<br>
<br>
diff --git a/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a> b/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
index 4dbe86f..2ade490 100644<br>
--- a/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
+++ b/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
@@ -59,6 +59,8 @@ AC_DEFUN([EROFS_UTILS_PARSE_DIRECTORY],<br>
  fi<br>
 ])<br>
<br>
+AC_ARG_VAR([MAX_BLOCK_SIZE], [The maximum block size which erofs-utils supports])<br>
+<br>
 AC_ARG_ENABLE([debug],<br>
     [AS_HELP_STRING([--enable-debug],<br>
                     [enable debugging mode @<:@default=no@:>@])],<br>
@@ -202,6 +204,35 @@ AC_CHECK_FUNCS(m4_flatten([<br>
        tmpfile64<br>
        utimensat]))<br>
<br>
+# Detect maximum block size if necessary<br>
+AS_IF([test "x$MAX_BLOCK_SIZE" = "x"], [<br>
+  AC_CACHE_CHECK([sysconf (_SC_PAGESIZE)], [erofs_cv_max_block_size],<br>
+               AC_RUN_IFELSE([AC_LANG_PROGRAM(<br>
+[[<br>
+#include <unistd.h><br>
+#include <stdio.h><br>
+]],<br>
+[[<br>
+    int result;<br>
+    FILE *f;<br>
+<br>
+    result = sysconf(_SC_PAGESIZE);<br>
+    if (result < 0)<br>
+       return 1;<br>
+<br>
+    f = fopen("conftest.out", "w");<br>
+    if (!f)<br>
+       return 1;<br>
+<br>
+    fprintf(f, "%d", result);<br>
+    fclose(f);<br>
+    return 0;<br>
+]])],<br>
+                             [erofs_cv_max_block_size=`cat conftest.out`],<br>
+                             [],<br>
+                             []))<br>
+], [erofs_cv_max_block_size=$MAX_BLOCK_SIZE])<br>
+<br>
 # Configure debug mode<br>
 AS_IF([test "x$enable_debug" != "xno"], [], [<br>
   dnl Turn off all assert checking.<br>
@@ -367,6 +398,13 @@ if test "x${have_liblzma}" = "xyes"; then<br>
   AC_SUBST([liblzma_CFLAGS])<br>
 fi<br>
<br>
+# Dump maximum block size<br>
+AS_IF([test "x$erofs_cv_max_block_size" = "x"],<br>
+      [$erofs_cv_max_block_size = 4096], [])<br>
+<br>
+AC_DEFINE_UNQUOTED([EROFS_MAX_BLOCK_SIZE], [$erofs_cv_max_block_size],<br>
+                  [The maximum block size which erofs-utils supports])<br>
+<br>
 AC_CONFIG_FILES([Makefile<br>
                 man/Makefile<br>
                 lib/Makefile<br>
diff --git a/include/erofs/internal.h b/include/erofs/internal.h<br>
index b3d04be..ee301e0 100644<br>
--- a/include/erofs/internal.h<br>
+++ b/include/erofs/internal.h<br>
@@ -27,15 +27,13 @@ typedef unsigned short umode_t;<br>
 #define PATH_MAX        4096    /* # chars in a path name including nul */<br>
 #endif<br>
<br>
-#ifndef PAGE_SHIFT<br>
-#define PAGE_SHIFT             (12)<br>
-#endif<br>
-<br>
 #ifndef PAGE_SIZE<br>
-#define PAGE_SIZE              (1U << PAGE_SHIFT)<br>
+#define PAGE_SIZE              4096<br>
 #endif<br>
<br>
+#ifndef EROFS_MAX_BLOCK_SIZE<br>
 #define EROFS_MAX_BLOCK_SIZE   PAGE_SIZE<br>
+#endif<br>
<br>
 #define EROFS_ISLOTBITS                5<br>
 #define EROFS_SLOTSIZE         (1U << EROFS_ISLOTBITS)<br>
diff --git a/lib/namei.c b/lib/namei.c<br>
index 3d0cf93..3751741 100644<br>
--- a/lib/namei.c<br>
+++ b/lib/namei.c<br>
@@ -137,7 +137,7 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi)<br>
                vi->u.chunkbits = sbi.blkszbits +<br>
                        (vi->u.chunkformat & EROFS_CHUNK_FORMAT_BLKBITS_MASK);<br>
        } else if (erofs_inode_is_data_compressed(vi->datalayout)) {<br>
-               if (erofs_blksiz() != PAGE_SIZE)<br>
+               if (erofs_blksiz() != EROFS_MAX_BLOCK_SIZE)<br>
                        return -EOPNOTSUPP;<br>
                return z_erofs_fill_inode(vi);<br>
        }<br>
diff --git a/mkfs/main.c b/mkfs/main.c<br>
index 3ec4903..a6a2d0e 100644<br>
--- a/mkfs/main.c<br>
+++ b/mkfs/main.c<br>
@@ -532,7 +532,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])<br>
                cfg.c_dbg_lvl = EROFS_ERR;<br>
                cfg.c_showprogress = false;<br>
        }<br>
-       if (cfg.c_compr_alg[0] && erofs_blksiz() != PAGE_SIZE) {<br>
+       if (cfg.c_compr_alg[0] && erofs_blksiz() != EROFS_MAX_BLOCK_SIZE) {<br>
                erofs_err("compression is unsupported for now with block size %u",<br>
                          erofs_blksiz());<br>
                return -EINVAL;<br>
@@ -670,7 +670,7 @@ static void erofs_mkfs_default_options(void)<br>
 {<br>
        cfg.c_showprogress = true;<br>
        cfg.c_legacy_compress = false;<br>
-       sbi.blkszbits = ilog2(PAGE_SIZE);<br>
+       sbi.blkszbits = ilog2(EROFS_MAX_BLOCK_SIZE);<br>
        sbi.feature_incompat = EROFS_FEATURE_INCOMPAT_LZ4_0PADDING;<br>
        sbi.feature_compat = EROFS_FEATURE_COMPAT_SB_CHKSUM |<br>
                             EROFS_FEATURE_COMPAT_MTIME;<br>
-- <br>
2.24.4<br>
<br>
</blockquote></div><div><br></div>Overall it looks good to me. Do we still need the PAGE_SIZE macro then?<br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr">Sincerely,<div><br></div><div>Kelvin Zhang</div></div></div></div>