From: Julian Stecklina via B4 Relay <devnull+julian.stecklina.cyberus-technology.de@kernel.org>
To: Christoph Hellwig <hch@lst.de>, Al Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Gao Xiang <xiang@kernel.org>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-erofs@lists.ozlabs.org,
Julian Stecklina <julian.stecklina@cyberus-technology.de>
Subject: [PATCH v2 7/9] fs: squashfs: register an initrd fs detector
Date: Sat, 22 Mar 2025 21:34:19 +0100 [thread overview]
Message-ID: <20250322-initrd-erofs-v2-7-d66ee4a2c756@cyberus-technology.de> (raw)
In-Reply-To: <20250322-initrd-erofs-v2-0-d66ee4a2c756@cyberus-technology.de>
From: Julian Stecklina <julian.stecklina@cyberus-technology.de>
Port squashfs from to the new initrd_fs_detect API. There are no
functional changes.
Signed-off-by: Julian Stecklina <julian.stecklina@cyberus-technology.de>
---
fs/squashfs/Makefile | 5 +++++
fs/squashfs/initrd.c | 23 +++++++++++++++++++++++
init/do_mounts_rd.c | 14 --------------
3 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/fs/squashfs/Makefile b/fs/squashfs/Makefile
index 477c89a519ee8825e4dfc88f76e09fd733e90625..fa64f0b9a45e52e9b3e78bd16446474c0b3dc158 100644
--- a/fs/squashfs/Makefile
+++ b/fs/squashfs/Makefile
@@ -17,3 +17,8 @@ squashfs-$(CONFIG_SQUASHFS_LZO) += lzo_wrapper.o
squashfs-$(CONFIG_SQUASHFS_XZ) += xz_wrapper.o
squashfs-$(CONFIG_SQUASHFS_ZLIB) += zlib_wrapper.o
squashfs-$(CONFIG_SQUASHFS_ZSTD) += zstd_wrapper.o
+
+# If we are built-in, we provide support for squashfs on initrds.
+ifeq ($(CONFIG_SQUASHFS),y)
+squashfs-y += initrd.o
+endif
diff --git a/fs/squashfs/initrd.c b/fs/squashfs/initrd.c
new file mode 100644
index 0000000000000000000000000000000000000000..bb99fc40083c6c5fdf47b2e28bcdc525d36520b4
--- /dev/null
+++ b/fs/squashfs/initrd.c
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/initrd.h>
+#include <linux/fs.h>
+#include <linux/magic.h>
+
+#include "squashfs_fs.h"
+
+static size_t __init detect_squashfs(void *block_data)
+{
+ struct squashfs_super_block *squashfsb
+ = (struct squashfs_super_block *)block_data;
+ BUILD_BUG_ON(sizeof(*squashfsb) > BLOCK_SIZE);
+
+ /* squashfs is at block zero too */
+ if (le32_to_cpu(squashfsb->s_magic) != SQUASHFS_MAGIC)
+ return 0;
+
+
+ return le64_to_cpu(squashfsb->bytes_used);
+}
+
+initrd_fs_detect(detect_squashfs, 0);
diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c
index 9f9a04cce505e532d444e2aef77037bc2b01da08..2a6cb08d0b4872ef8e861a813ef89dc1e9a150af 100644
--- a/init/do_mounts_rd.c
+++ b/init/do_mounts_rd.c
@@ -8,7 +8,6 @@
#include <linux/slab.h>
#include "do_mounts.h"
-#include "../fs/squashfs/squashfs_fs.h"
#include <linux/decompress/generic.h>
@@ -41,7 +40,6 @@ static int __init crd_load(decompress_fn deco);
*
* We currently check for the following magic numbers:
* ext2
- * squashfs
* gzip
* bzip2
* lzma
@@ -55,7 +53,6 @@ identify_ramdisk_image(struct file *file, loff_t pos,
{
const int size = BLOCK_SIZE;
- struct squashfs_super_block *squashfsb;
int nblocks = -1;
unsigned char *buf;
const char *compress_name;
@@ -67,7 +64,6 @@ identify_ramdisk_image(struct file *file, loff_t pos,
if (!buf)
return -ENOMEM;
- squashfsb = (struct squashfs_super_block *) buf;
memset(buf, 0xe5, size);
/*
@@ -88,16 +84,6 @@ identify_ramdisk_image(struct file *file, loff_t pos,
goto done;
}
- /* squashfs is at block zero too */
- if (le32_to_cpu(squashfsb->s_magic) == SQUASHFS_MAGIC) {
- printk(KERN_NOTICE
- "RAMDISK: squashfs filesystem found at block %d\n",
- start_block);
- nblocks = (le64_to_cpu(squashfsb->bytes_used) + BLOCK_SIZE - 1)
- >> BLOCK_SIZE_BITS;
- goto done;
- }
-
/*
* Read block 1 to test for ext2 superblock
*/
--
2.47.0
next prev parent reply other threads:[~2025-03-22 20:35 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-22 20:34 [PATCH v2 0/9] initrd: cleanup and erofs support Julian Stecklina via B4 Relay
2025-03-22 20:34 ` [PATCH v2 1/9] initrd: remove ASCII spinner Julian Stecklina via B4 Relay
2025-03-25 6:42 ` David Disseldorp
2025-03-22 20:34 ` [PATCH v2 2/9] initrd: fix double fput for truncated ramdisks Julian Stecklina via B4 Relay
2025-03-22 20:34 ` [PATCH v2 3/9] initrd: add a generic mechanism to add fs detectors Julian Stecklina via B4 Relay
2025-03-24 9:35 ` Julian Stecklina
2025-03-22 20:34 ` [PATCH v2 4/9] fs: minix: register an initrd fs detector Julian Stecklina via B4 Relay
2025-03-22 23:26 ` kernel test robot
2025-03-22 20:34 ` [PATCH v2 5/9] fs: cramfs: " Julian Stecklina via B4 Relay
2025-03-22 20:34 ` [PATCH v2 6/9] fs: romfs: " Julian Stecklina via B4 Relay
2025-03-22 23:26 ` kernel test robot
2025-03-22 20:34 ` Julian Stecklina via B4 Relay [this message]
2025-03-22 20:34 ` [PATCH v2 8/9] fs: ext2, ext4: " Julian Stecklina via B4 Relay
2025-03-22 23:36 ` kernel test robot
2025-03-22 20:34 ` [PATCH v2 9/9] fs: erofs: " Julian Stecklina via B4 Relay
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250322-initrd-erofs-v2-7-d66ee4a2c756@cyberus-technology.de \
--to=devnull+julian.stecklina.cyberus-technology.de@kernel.org \
--cc=brauner@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=hch@lst.de \
--cc=julian.stecklina@cyberus-technology.de \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
--cc=xiang@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®