From: Julian Stecklina <julian.stecklina@cyberus-technology.de>
Port romfs from to the new initrd_fs_detect API. There are no
functional changes.
Signed-off-by: Julian Stecklina <julian.stecklina@cyberus-technology.de>
---
fs/romfs/Makefile | 4 ++++
fs/romfs/initrd.c | 22 ++++++++++++++++++++++
init/do_mounts_rd.c | 14 --------------
3 files changed, 26 insertions(+), 14 deletions(-)
diff --git a/fs/romfs/Makefile b/fs/romfs/Makefile
index 844928f1571160abed9d5aff54152b5508eaf7be..eb15dc3a78721d7f650560a404a92706260e9b63 100644
--- a/fs/romfs/Makefile
+++ b/fs/romfs/Makefile
@@ -11,3 +11,7 @@ ifneq ($(CONFIG_MMU),y)
romfs-$(CONFIG_ROMFS_ON_MTD) += mmap-nommu.o
endif
+# If we are built-in, we provide support for romfs on initrds.
+ifeq ($(CONFIG_ROMFS_FS),y)
+romfs-y += initrd.o
+endif
diff --git a/fs/romfs/initrd.c b/fs/romfs/initrd.c
new file mode 100644
index 0000000000000000000000000000000000000000..0ec7b4c9d1f79fac892b7fb1d8e17122092008a8
--- /dev/null
+++ b/fs/romfs/initrd.c
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/fs.h>
+#include <linux/initrd.h>
+#include <linux/magic.h>
+#include <linux/romfs_fs.h>
+
+static size_t __init detect_romfs(void *block_data)
+{
+ struct romfs_super_block *romfsb
+ = (struct romfs_super_block *)block_data;
+ BUILD_BUG_ON(sizeof(*romfsb) > BLOCK_SIZE);
+
+ /* The definitions of ROMSB_WORD* already handle endianness. */
+ if (romfsb->word0 != ROMSB_WORD0 ||
+ romfsb->word1 != ROMSB_WORD1)
+ return 0;
+
+ return be32_to_cpu(romfsb->size);
+}
+
+initrd_fs_detect(detect_romfs, 0);
diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c
index cdc39baaf3a1a65daad5fe6571a82faf3fc95b62..9f9a04cce505e532d444e2aef77037bc2b01da08 100644
--- a/init/do_mounts_rd.c
+++ b/init/do_mounts_rd.c
@@ -2,7 +2,6 @@
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/ext2_fs.h>
-#include <linux/romfs_fs.h>
#include <linux/initrd.h>
#include <linux/string.h>
@@ -42,7 +41,6 @@ static int __init crd_load(decompress_fn deco);
*
* We currently check for the following magic numbers:
* ext2
- * romfs
* squashfs
* gzip
* bzip2
@@ -56,7 +54,6 @@ identify_ramdisk_image(struct file *file, loff_t pos,
decompress_fn *decompressor)
{
const int size = BLOCK_SIZE;
- struct romfs_super_block *romfsb;
struct squashfs_super_block *squashfsb;
int nblocks = -1;
@@ -70,7 +67,6 @@ identify_ramdisk_image(struct file *file, loff_t pos,
if (!buf)
return -ENOMEM;
- romfsb = (struct romfs_super_block *) buf;
squashfsb = (struct squashfs_super_block *) buf;
memset(buf, 0xe5, size);
@@ -92,16 +88,6 @@ identify_ramdisk_image(struct file *file, loff_t pos,
goto done;
}
- /* romfs is at block zero too */
- if (romfsb->word0 == ROMSB_WORD0 &&
- romfsb->word1 == ROMSB_WORD1) {
- printk(KERN_NOTICE
- "RAMDISK: romfs filesystem found at block %d\n",
- start_block);
- nblocks = (ntohl(romfsb->size)+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
- goto done;
- }
-
/* squashfs is at block zero too */
if (le32_to_cpu(squashfsb->s_magic) == SQUASHFS_MAGIC) {
printk(KERN_NOTICE
--
2.47.0
Hi Julian,
kernel test robot noticed the following build errors:
[auto build test ERROR on 88d324e69ea9f3ae1c1905ea75d717c08bdb8e15]
url: https://github.com/intel-lab-lkp/linux/commits/Julian-Stecklina-via-B4-Relay/initrd-remove-ASCII-spinner/20250323-043649
base: 88d324e69ea9f3ae1c1905ea75d717c08bdb8e15
patch link: https://lore.kernel.org/r/20250322-initrd-erofs-v2-6-d66ee4a2c756%40cyberus-technology.de
patch subject: [PATCH v2 6/9] fs: romfs: register an initrd fs detector
config: i386-buildonly-randconfig-002-20250323 (https://download.01.org/0day-ci/archive/20250323/202503230701.JV9cV28A-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250323/202503230701.JV9cV28A-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202503230701.JV9cV28A-lkp@intel.com/
All error/warnings (new ones prefixed by >>):
>> fs/romfs/initrd.c:22:33: error: macro "initrd_fs_detect" passed 2 arguments, but takes just 1
22 | initrd_fs_detect(detect_romfs, 0);
| ^
In file included from fs/romfs/initrd.c:4:
include/linux/initrd.h:63: note: macro "initrd_fs_detect" defined here
63 | #define initrd_fs_detect(detectfn)
|
>> fs/romfs/initrd.c:22:1: warning: data definition has no type or storage class
22 | initrd_fs_detect(detect_romfs, 0);
| ^~~~~~~~~~~~~~~~
>> fs/romfs/initrd.c:22:1: error: type defaults to 'int' in declaration of 'initrd_fs_detect' [-Werror=implicit-int]
>> fs/romfs/initrd.c:8:22: warning: 'detect_romfs' defined but not used [-Wunused-function]
8 | static size_t __init detect_romfs(void *block_data)
| ^~~~~~~~~~~~
cc1: some warnings being treated as errors
vim +/initrd_fs_detect +22 fs/romfs/initrd.c
2
3 #include <linux/fs.h>
> 4 #include <linux/initrd.h>
5 #include <linux/magic.h>
6 #include <linux/romfs_fs.h>
7
> 8 static size_t __init detect_romfs(void *block_data)
9 {
10 struct romfs_super_block *romfsb
11 = (struct romfs_super_block *)block_data;
12 BUILD_BUG_ON(sizeof(*romfsb) > BLOCK_SIZE);
13
14 /* The definitions of ROMSB_WORD* already handle endianness. */
15 if (romfsb->word0 != ROMSB_WORD0 ||
16 romfsb->word1 != ROMSB_WORD1)
17 return 0;
18
19 return be32_to_cpu(romfsb->size);
20 }
21
> 22 initrd_fs_detect(detect_romfs, 0);
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
© 2016 - 2026 Red Hat, Inc.