From patchwork Sat Mar 22 20:34:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Stecklina X-Patchwork-Id: 14026400 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 877128BF8; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742675715; cv=none; b=LjJAD12r2YZlm9S8UXtpKnb0RvwMpKwyeJHV05g5VfpUj7wagCrEDM8sSqO/SVpVsNfo5DlfFVZBYG+a48/cbllRMoVTOdMLsoQaQkaKpg5mDrjhOEqHtdCy5cZwi2LmFwuEFlrY1dAGilOMFoFDgBHHefrNTMrtnGRuRv2Q/pM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742675715; c=relaxed/simple; bh=gINZ0Aw8Hylr726Wuv3Tb5zHE90wq70NebX4Kb1KIYg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=R/H1z7ohJVoMNsGxeTqoRnq3DbcywSI2zE6MgrIKX76ZSnN2zmmAQJCnODMhSNPR0OB1ix+hwN/nJQ+VPwiJzovutfu9SlQCcwVNngmAUwm3C30OQWXRd1AyAuYG3VSp81nePDQzaQN8mphXRrIDnIMcWsUMAj+mKEacE4Mcns8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ym5YgecI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ym5YgecI" Received: by smtp.kernel.org (Postfix) with ESMTPS id ED851C4CEE9; Sat, 22 Mar 2025 20:35:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742675715; bh=gINZ0Aw8Hylr726Wuv3Tb5zHE90wq70NebX4Kb1KIYg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Ym5YgecIPYw5eJfx+kMkQLnilWlWcqki58e2BiXmYlEiKRuh5FYyoqddx6+kcQTac OWxuTSsmGQqcR09FuuHnwDww4UJbOFl+K/GJbOTi6BQar/Itk5AaPsSVgeExEYGJML yCC4BjGXgLijc1Fi91VfMQhbF6ndgZiGcBouG2r5DwpLcH+b1vkYs4/5dwiMc/5izA pWUGB3uWI8yHodlIHxBlAWLfSnO3Nb0D6OtNwKbk+ZAJ1Tg++L99PGSqT01MRelcS9 hcTU9zo5+3saHvlsCIxRdmvn2XwCgXam6IXqCaIfi6Ux6oEAHnd+1T4Ct4t08cA3q0 y7lHKG7UIrCrg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4EC7C36008; Sat, 22 Mar 2025 20:35:14 +0000 (UTC) Date: Sat, 22 Mar 2025 21:34:13 +0100 Subject: [PATCH v2 1/9] initrd: remove ASCII spinner Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250322-initrd-erofs-v2-1-d66ee4a2c756@cyberus-technology.de> References: <20250322-initrd-erofs-v2-0-d66ee4a2c756@cyberus-technology.de> In-Reply-To: <20250322-initrd-erofs-v2-0-d66ee4a2c756@cyberus-technology.de> To: Christoph Hellwig , Al Viro , Christian Brauner Cc: Linus Torvalds , Greg Kroah-Hartman , "Rafael J. Wysocki" , Gao Xiang , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-erofs@lists.ozlabs.org, Julian Stecklina X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1742675713; l=1419; i=julian.stecklina@cyberus-technology.de; s=20250320; h=from:subject:message-id; bh=xaOtsZSXLvGxcDVIZd0k1LuXf7yoO5wFbuBG8A93PMw=; b=Q/f0Rz5QFOyX0GFtzyWhjf7NZaw5DwLqmAK+UT+Lih/KQRXWu2ZWjHPR87PxJ073JhZ6qoeo1 dSKgyuoEHDHC8bSj5x2zOKyRbhADY7Q0NrHhkpa8NkAZjxmafF66erV X-Developer-Key: i=julian.stecklina@cyberus-technology.de; a=ed25519; pk=m051/8gQfs5AmkACfykwRcD6CUr2T7DQ9OA5eBgyy7c= X-Endpoint-Received: by B4 Relay for julian.stecklina@cyberus-technology.de/20250320 with auth_id=363 X-Original-From: Julian Stecklina Reply-To: julian.stecklina@cyberus-technology.de From: Julian Stecklina From: Julian Stecklina Writing the ASCII spinner probably costs more cycles than copying the block of data on some output devices if you output to serial and in all other cases it rotates at lightspeed in 2025. Signed-off-by: Julian Stecklina Reviewed-by: David Disseldorp --- init/do_mounts_rd.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c index ac021ae6e6fa78c7b7828a78ab2fa3af3611bef3..473f4f9417e157118b9a6e582607435484d53d63 100644 --- a/init/do_mounts_rd.c +++ b/init/do_mounts_rd.c @@ -189,11 +189,7 @@ int __init rd_load_image(char *from) unsigned long rd_blocks, devblocks; int nblocks, i; char *buf = NULL; - unsigned short rotate = 0; decompress_fn decompressor = NULL; -#if !defined(CONFIG_S390) - char rotator[4] = { '|' , '/' , '-' , '\\' }; -#endif out_file = filp_open("/dev/ram", O_RDWR, 0); if (IS_ERR(out_file)) @@ -249,18 +245,11 @@ int __init rd_load_image(char *from) for (i = 0; i < nblocks; i++) { if (i && (i % devblocks == 0)) { pr_cont("done disk #1.\n"); - rotate = 0; fput(in_file); break; } kernel_read(in_file, buf, BLOCK_SIZE, &in_pos); kernel_write(out_file, buf, BLOCK_SIZE, &out_pos); -#if !defined(CONFIG_S390) - if (!(i % 16)) { - pr_cont("%c\b", rotator[rotate & 0x3]); - rotate++; - } -#endif } pr_cont("done.\n"); From patchwork Sat Mar 22 20:34:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Stecklina X-Patchwork-Id: 14026401 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9703F21D001; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742675715; cv=none; b=S6qmGBhbx5IVYvLNQSLjGsKMxsf5ESJ1Lmv/BsJCKFUFU7eCxyc7v+jHDPhkzYiXPGRusyGRL7q3vOK0SWsHum5TUSRi4JsHR9kEF9n/t1b+CMEGhqY+Xv3SVEnBNcau7v72D+uIJ/st4lkeBVJcLfIeNpJ4Ve3qmfDpYD3Pxqc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742675715; c=relaxed/simple; bh=Yaohu7isWY3gNZXnBO5AmDueX4y+9dG81g5HOyB+u24=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VaK/AaXFwboVztLhXCL0UTmEXU25YuTFZs20dDS/TrYekAbVOAMV6MH5KMFri41Pc8dINueJ3Ei6t1xu9nhHJnxPMfWzEigI3Cre5LFQnxA9PFF+F8SQSWOz7gOugvRcjdVKUm42FQnteTlv2onjVT93/q0kurnUetkD8gjulPI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pnww6gE5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pnww6gE5" Received: by smtp.kernel.org (Postfix) with ESMTPS id 0E5A1C4CEEC; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742675715; bh=Yaohu7isWY3gNZXnBO5AmDueX4y+9dG81g5HOyB+u24=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=pnww6gE5HsT8SEInP30wiYL7hXXdFdj066RG4AJGdqd/KJ7ySk4RQlTiueXfBwhCK 0y3zwSqNLFfbX1qza6Wg78nxcmxdyLL3DZ1IJWgyJpwJ8YEox47J3mPYQfCREnsR87 vU9KdPm4ZGx3MUk0ovQ9mTGKbzvQVyNModWhPBlDm3c71qBJz7tUdVBO4EzoUj0wuT 6wg/nTO5Ju/uEvfAOC/CYKoaXt2ZwX5U30pVYyJ3Us3A4DMKmCaeIbTM5QIAc1uJ11 uXEIPL0f+jJnbdjFYsIPXgYBjYf3J4J5iyvvBL2kPCo4lcNYvPd25Ue/veRnZps5FN 6Lzpt2ZLaF/NA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8BF6C3600B; Sat, 22 Mar 2025 20:35:14 +0000 (UTC) Date: Sat, 22 Mar 2025 21:34:14 +0100 Subject: [PATCH v2 2/9] initrd: fix double fput for truncated ramdisks Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250322-initrd-erofs-v2-2-d66ee4a2c756@cyberus-technology.de> References: <20250322-initrd-erofs-v2-0-d66ee4a2c756@cyberus-technology.de> In-Reply-To: <20250322-initrd-erofs-v2-0-d66ee4a2c756@cyberus-technology.de> To: Christoph Hellwig , Al Viro , Christian Brauner Cc: Linus Torvalds , Greg Kroah-Hartman , "Rafael J. Wysocki" , Gao Xiang , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-erofs@lists.ozlabs.org, Julian Stecklina X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1742675713; l=1599; i=julian.stecklina@cyberus-technology.de; s=20250320; h=from:subject:message-id; bh=k4g6SAXWuxXSYv2iKkbm/npvjC9+dlFx9G1/+9RZN20=; b=rNJ683tIeaNnaJuuNqFjmoLWib1cKLA5DiGdVBrmkGkeiuHZxssO5pP0xtDM/im05voR1Nb/7 4LsMkMemF0TAw9Mnp7ACjJIxCYIyVq4DeGqjSHbewp8eywATzHjpEsz X-Developer-Key: i=julian.stecklina@cyberus-technology.de; a=ed25519; pk=m051/8gQfs5AmkACfykwRcD6CUr2T7DQ9OA5eBgyy7c= X-Endpoint-Received: by B4 Relay for julian.stecklina@cyberus-technology.de/20250320 with auth_id=363 X-Original-From: Julian Stecklina Reply-To: julian.stecklina@cyberus-technology.de From: Julian Stecklina From: Julian Stecklina When you actually take the exit via devblocks == 0, the code will do fput(in_file) twice. This was introduced when the APIs where switched to the file-based APIs. Remove more of the multi-floppy support from the olden days. Fixes: bef173299613 ("initrd: switch initrd loading to struct file based APIs") Signed-off-by: Julian Stecklina --- init/do_mounts_rd.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c index 473f4f9417e157118b9a6e582607435484d53d63..d026df401afa0b7458ab1f266b21830aab974b92 100644 --- a/init/do_mounts_rd.c +++ b/init/do_mounts_rd.c @@ -234,20 +234,20 @@ int __init rd_load_image(char *from) goto done; } + if (devblocks < nblocks) { + printk(KERN_ERR "RAMDISK: looks truncated: (%luKiB vs %dKiB) - continuing anyway\n", + devblocks, nblocks); + nblocks = devblocks; + } + buf = kmalloc(BLOCK_SIZE, GFP_KERNEL); if (!buf) { printk(KERN_ERR "RAMDISK: could not allocate buffer\n"); goto done; } - printk(KERN_NOTICE "RAMDISK: Loading %dKiB [%ld disk%s] into ram disk... ", - nblocks, ((nblocks-1)/devblocks)+1, nblocks>devblocks ? "s" : ""); + printk(KERN_NOTICE "RAMDISK: Loading %dKiB into ram disk... ", nblocks); for (i = 0; i < nblocks; i++) { - if (i && (i % devblocks == 0)) { - pr_cont("done disk #1.\n"); - fput(in_file); - break; - } kernel_read(in_file, buf, BLOCK_SIZE, &in_pos); kernel_write(out_file, buf, BLOCK_SIZE, &out_pos); } From patchwork Sat Mar 22 20:34:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Stecklina X-Patchwork-Id: 14026403 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97098224236; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742675715; cv=none; b=EgzSzcfcSddxcJZ6YAQPdJ03pVHVcoVy9HoXdOdGJhSYKFWQp/K6IBWe2d1mq+VPgwjAdK3QHAqqY/xVmU0DYwTKc6TgWTGKnhGVVvt9eUSe8cz2OpdKGpt9s1WtCEy+ad+hoO2wdp9Y2+7IGpUJDVop6tm8tkG9+cxh+GfdN1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742675715; c=relaxed/simple; bh=TDhbyo9F/ZSQ2RUuUaTZZ0o9x6DAYOKYzNLlrAq8L1I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=htkxyKwrU3TzPgfUWP9/qRLGQ2dQY5WkWHvmc9Ak9nrJvs1BpZQ7oyY6PLPZnRY+zp+UoAZnsELvy4BMcnguzmOL3WdOprGmgFJ2W5B4rR88Y7CFWonnl+HTneolcgCaOI5xjf1uQhGGIHMeCwNtwjmF5tkzjnK7TKzL4Z/B0Xs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q/LalmDt; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="q/LalmDt" Received: by smtp.kernel.org (Postfix) with ESMTPS id 2C191C4CEF0; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742675715; bh=TDhbyo9F/ZSQ2RUuUaTZZ0o9x6DAYOKYzNLlrAq8L1I=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=q/LalmDtJOUAJrZHrgHxJkI2oI09js3AZcqdeCniUFAecfSyWNCit8xl6Gnwf105n 9SchH1kvzhhghyYBJYt7i86OHBq6i/rk+MFsh/lSdEplNrDm37JTWV6OvN8XY2dUpd boDRzh6n0bTigRewigYWSR9Bv9Bd7UdU+FcERoZZ6qJKjQW8rLu2mLLuwjNSsc38eg cQ419jrRsQo3YkOtDb3ZV72NDNuJBjH4rNUrFSGYZLQKoliY+Sm9j+ScDmFiMhb+zf H/Qngo6n++qHSxGPo6UGJ7o6bMET9oSN2dxow/lwAtliJdJv4b4tAEJ8hgVnrPMn3C powEUC9VQS67g== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CEBEC35FFC; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) Date: Sat, 22 Mar 2025 21:34:15 +0100 Subject: [PATCH v2 3/9] initrd: add a generic mechanism to add fs detectors Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250322-initrd-erofs-v2-3-d66ee4a2c756@cyberus-technology.de> References: <20250322-initrd-erofs-v2-0-d66ee4a2c756@cyberus-technology.de> In-Reply-To: <20250322-initrd-erofs-v2-0-d66ee4a2c756@cyberus-technology.de> To: Christoph Hellwig , Al Viro , Christian Brauner Cc: Linus Torvalds , Greg Kroah-Hartman , "Rafael J. Wysocki" , Gao Xiang , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-erofs@lists.ozlabs.org, Julian Stecklina X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1742675713; l=5291; i=julian.stecklina@cyberus-technology.de; s=20250320; h=from:subject:message-id; bh=55Wh0MWl4j4HdLagTcgFYbNKFaTKj1GqG+lEyJb27TU=; b=OGbHoFniZHWRPY2giReYmVqjd13V7KvnyKGwIuoxXzLG+X8S0AOkCmqZtNSa/bEz/ox8kmn5P 3SEJs2yPUFYAnv2JT9E89Ihwls7xnW3A4QYDVuDzcQopJf7R7NZH9fE X-Developer-Key: i=julian.stecklina@cyberus-technology.de; a=ed25519; pk=m051/8gQfs5AmkACfykwRcD6CUr2T7DQ9OA5eBgyy7c= X-Endpoint-Received: by B4 Relay for julian.stecklina@cyberus-technology.de/20250320 with auth_id=363 X-Original-From: Julian Stecklina Reply-To: julian.stecklina@cyberus-technology.de From: Julian Stecklina From: Julian Stecklina So far all filesystems that are supported as initrd have their filesystem detection code implemented in init/do_mounts_rd.c. A better approach is to let filesystem implementations register a detection hook. This allows the filesystem detection code to live with the rest of the filesystem implementation. We could have done a more flexible mechanism than passing a block of data, but this simple solution works for all filesystems and keeps the boilerplate low. The following patches will convert each of the filesystems. Suggested-by: Al Viro Signed-off-by: Julian Stecklina --- include/asm-generic/vmlinux.lds.h | 6 ++++++ include/linux/initrd.h | 37 +++++++++++++++++++++++++++++++++++++ init/do_mounts_rd.c | 28 +++++++++++++++++++++++++++- 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 0d5b186abee86d27f3b02a49299155453a8c8e9e..d0816e6c41a9bbedf8f5a68c33b6f3e18014019a 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -968,8 +968,13 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG) KEEP(*(.init.ramfs)) \ . = ALIGN(8); \ KEEP(*(.init.ramfs.info)) + +#define INITRD_FS_DETECT() \ + . = ALIGN(16); \ + BOUNDED_SECTION(_initrd_fs_detect) #else #define INIT_RAM_FS +#define INITRD_FS_DETECT() #endif /* @@ -1170,6 +1175,7 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG) INIT_CALLS \ CON_INITCALL \ INIT_RAM_FS \ + INITRD_FS_DETECT() \ } #define BSS_SECTION(sbss_align, bss_align, stop_align) \ diff --git a/include/linux/initrd.h b/include/linux/initrd.h index f1a1f4c92ded3921bf56d53bee3e20b549d851fb..25463ce9c26ad4e4e9d3b333aa9f5596585c1762 100644 --- a/include/linux/initrd.h +++ b/include/linux/initrd.h @@ -3,6 +3,9 @@ #ifndef __LINUX_INITRD_H #define __LINUX_INITRD_H +#include +#include + #define INITRD_MINOR 250 /* shouldn't collide with /dev/ram* too soon ... */ /* starting block # of image */ @@ -18,12 +21,46 @@ extern int initrd_below_start_ok; extern unsigned long initrd_start, initrd_end; extern void free_initrd_mem(unsigned long, unsigned long); +struct file; + #ifdef CONFIG_BLK_DEV_INITRD extern void __init reserve_initrd_mem(void); extern void wait_for_initramfs(void); + +/* + * Detect a filesystem on the initrd. You get 1 KiB (BLOCK_SIZE) of + * data to work with. The offset of the block is specified in + * initrd_fs_detect(). + * + * @block_data: A pointer to BLOCK_SIZE of data + * + * Returns the size of the filesystem in bytes or 0, if the filesystem + * was not detected. + */ +typedef size_t initrd_fs_detect_fn(void * const block_data); + +struct initrd_detect_fs { + initrd_fs_detect_fn *detect_fn; + loff_t detect_byte_offset; +}; + +extern struct initrd_detect_fs __start_initrd_fs_detect[]; +extern struct initrd_detect_fs __stop_initrd_fs_detect[]; + +/* + * Add a filesystem detector for initrds. See the documentation of + * initrd_fs_detect_fn above. + */ +#define initrd_fs_detect(fn, byte_offset) \ + static const struct initrd_detect_fs __initrd_fs_detect_ ## fn \ + __used __section("_initrd_fs_detect") = \ + { .detect_fn = fn, .detect_byte_offset = byte_offset} + #else static inline void __init reserve_initrd_mem(void) {} static inline void wait_for_initramfs(void) {} + +#define initrd_fs_detect(detectfn) #endif extern phys_addr_t phys_initrd_start; diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c index d026df401afa0b7458ab1f266b21830aab974b92..56c1fa935c7ee780870142923046a3d2fd2d6d96 100644 --- a/init/do_mounts_rd.c +++ b/init/do_mounts_rd.c @@ -58,7 +58,7 @@ static int __init identify_ramdisk_image(struct file *file, loff_t pos, decompress_fn *decompressor) { - const int size = 512; + const int size = BLOCK_SIZE; struct minix_super_block *minixsb; struct romfs_super_block *romfsb; struct cramfs_super *cramfsb; @@ -68,6 +68,7 @@ identify_ramdisk_image(struct file *file, loff_t pos, const char *compress_name; unsigned long n; int start_block = rd_image_start; + struct initrd_detect_fs *detect_fs; buf = kmalloc(size, GFP_KERNEL); if (!buf) @@ -165,6 +166,31 @@ identify_ramdisk_image(struct file *file, loff_t pos, goto done; } + /* Try to find a filesystem in the initrd */ + for (detect_fs = __start_initrd_fs_detect; + detect_fs < __stop_initrd_fs_detect; + detect_fs++ + ) { + size_t fs_size; + + pos = (start_block * BLOCK_SIZE) + detect_fs->detect_byte_offset; + kernel_read(file, buf, size, &pos); + + fs_size = detect_fs->detect_fn(buf); + + if (fs_size == 0) + continue; + + nblocks = (fs_size + BLOCK_SIZE + 1) + >> BLOCK_SIZE_BITS; + + printk(KERN_NOTICE + "RAMDISK: filesystem found (%d blocks)\n", + nblocks); + + goto done; + } + printk(KERN_NOTICE "RAMDISK: Couldn't find valid RAM disk image starting at %d.\n", start_block); From patchwork Sat Mar 22 20:34:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Stecklina X-Patchwork-Id: 14026402 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96FDD145A03; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742675715; cv=none; b=nNZ935CtIShf1d8X7c3h00tEjwIkN5d53fIjLGCvA312lhTXcqs95DoIeaBzTvms5S8whVDkkKR/qEdn2Xpe5+VII7yIPh8BnBfNfJgm53m+92erDE+1jel3YAxFlpTETroM0HX8x14/8HoPoZHbcf2PttfjD7pR/gkmkkR2GV4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742675715; c=relaxed/simple; bh=b7JI85xRpP1bLGtHtYPbhcaoaNVuyWClE1wqc+y12dg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qqDJxayjJ2vIH3zjhbYiY8HjqTo0MO9qLvmVUu6VGEwazHCekGTDshxMdMN8Tfk7TtbiSIaheH46pTfFG2WZd1mrFt2nJebjWYlBlNevfBOLV7ggFbAQ+w0Bh0yaU05gEtTx6fwB+9/58I5uUFsKD6pXHAd/RYqbrANBi3v3/Xs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PkiUbIiy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PkiUbIiy" Received: by smtp.kernel.org (Postfix) with ESMTPS id 3FF10C4CEF6; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742675715; bh=b7JI85xRpP1bLGtHtYPbhcaoaNVuyWClE1wqc+y12dg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=PkiUbIiy1F2jWy+vsjaTli7aXJSmRUSTgsE/+oz0WOxvw1B9SJ0HJ0aGgf8Vklwok Y2bgLnUq0VjBg1xW4Ev0ft7/b2kmMn01iYcJ0t3XSbdyFE417lRSKSAZQSm+fx+k83 jzx5kztieVfWl0Vt+I/Rl1DdW/EfLQhUc4dtr+iEl17fHmXQh8TBFxE65bwIvemvuS ayaDlnkjPZvzUQMNIEK62OfLhNdMZhoJAlgir1qbhZAeMbp9+XgTnr235+BHtOc7GZ Klzpfv1rBY7w5ASRpLOgtJdi1KnzdSFu6KaH0WS3m0NRdTyigI+faaitaRPIJZyio1 jadKyrHtHRzWg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3321AC3600A; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) Date: Sat, 22 Mar 2025 21:34:16 +0100 Subject: [PATCH v2 4/9] fs: minix: register an initrd fs detector Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250322-initrd-erofs-v2-4-d66ee4a2c756@cyberus-technology.de> References: <20250322-initrd-erofs-v2-0-d66ee4a2c756@cyberus-technology.de> In-Reply-To: <20250322-initrd-erofs-v2-0-d66ee4a2c756@cyberus-technology.de> To: Christoph Hellwig , Al Viro , Christian Brauner Cc: Linus Torvalds , Greg Kroah-Hartman , "Rafael J. Wysocki" , Gao Xiang , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-erofs@lists.ozlabs.org, Julian Stecklina X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1742675713; l=3689; i=julian.stecklina@cyberus-technology.de; s=20250320; h=from:subject:message-id; bh=3zpODlrg8j0+m1aMvTBZ6a+FkLj5kE2s9qVHm6gavTI=; b=RK7CpwXGolb7amFsuhped3Wg2O4qk4HHkEiGLZYmGhlRWSGT/c3+VOQSXeOamqt73w1pTHf3Y GLNFj/9f0xZBXTeTlTZiA+v9cdaZ2Z+AAbSKnSXLqW7gkN2jrLUNoqM X-Developer-Key: i=julian.stecklina@cyberus-technology.de; a=ed25519; pk=m051/8gQfs5AmkACfykwRcD6CUr2T7DQ9OA5eBgyy7c= X-Endpoint-Received: by B4 Relay for julian.stecklina@cyberus-technology.de/20250320 with auth_id=363 X-Original-From: Julian Stecklina Reply-To: julian.stecklina@cyberus-technology.de From: Julian Stecklina From: Julian Stecklina Port minix to the new initrd_fs_detect API. There are no functional changes. This code only supports the minix filesystem v1. This means 64 MiB filesystem size limit. This would be a good candidate to drop support for. Signed-off-by: Julian Stecklina --- fs/minix/Makefile | 5 +++++ fs/minix/initrd.c | 23 +++++++++++++++++++++++ init/do_mounts_rd.c | 16 +--------------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/fs/minix/Makefile b/fs/minix/Makefile index a2d3ab58d1873eeada679a33a65b6cd0c421b3ad..cdd6a1a5b57a0205a1946faa676994c367380c97 100644 --- a/fs/minix/Makefile +++ b/fs/minix/Makefile @@ -6,3 +6,8 @@ obj-$(CONFIG_MINIX_FS) += minix.o minix-objs := bitmap.o itree_v1.o itree_v2.o namei.o inode.o file.o dir.o + +# If we are built-in, we provide support for minix filesystem on initrds. +ifeq ($(CONFIG_MINIX_FS),y) +minix-objs += initrd.o +endif diff --git a/fs/minix/initrd.c b/fs/minix/initrd.c new file mode 100644 index 0000000000000000000000000000000000000000..18b39b9afe9994ec3dd9770eb516f9c25c183140 --- /dev/null +++ b/fs/minix/initrd.c @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include + +static size_t __init detect_minixfs(void *block_data) +{ + struct minix_super_block *minixsb = + (struct minix_super_block *)block_data; + BUILD_BUG_ON(sizeof(*minixsb) > BLOCK_SIZE); + + if (minixsb->s_magic != MINIX_SUPER_MAGIC && + minixsb->s_magic != MINIX_SUPER_MAGIC2) + return 0; + + + return minixsb->s_nzones + << (minixsb->s_log_zone_size + BLOCK_SIZE_BITS); +} + +initrd_fs_detect(detect_minixfs, BLOCK_SIZE); diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c index 56c1fa935c7ee780870142923046a3d2fd2d6d96..f7e5d4ccf029b2707bc8524ecdbe200c8b305b00 100644 --- a/init/do_mounts_rd.c +++ b/init/do_mounts_rd.c @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include #include -#include #include #include #include @@ -42,7 +41,6 @@ static int __init crd_load(decompress_fn deco); * numbers could not be found. * * We currently check for the following magic numbers: - * minix * ext2 * romfs * cramfs @@ -59,7 +57,6 @@ identify_ramdisk_image(struct file *file, loff_t pos, decompress_fn *decompressor) { const int size = BLOCK_SIZE; - struct minix_super_block *minixsb; struct romfs_super_block *romfsb; struct cramfs_super *cramfsb; struct squashfs_super_block *squashfsb; @@ -74,7 +71,6 @@ identify_ramdisk_image(struct file *file, loff_t pos, if (!buf) return -ENOMEM; - minixsb = (struct minix_super_block *) buf; romfsb = (struct romfs_super_block *) buf; cramfsb = (struct cramfs_super *) buf; squashfsb = (struct squashfs_super_block *) buf; @@ -141,21 +137,11 @@ identify_ramdisk_image(struct file *file, loff_t pos, } /* - * Read block 1 to test for minix and ext2 superblock + * Read block 1 to test for ext2 superblock */ pos = (start_block + 1) * BLOCK_SIZE; kernel_read(file, buf, size, &pos); - /* Try minix */ - if (minixsb->s_magic == MINIX_SUPER_MAGIC || - minixsb->s_magic == MINIX_SUPER_MAGIC2) { - printk(KERN_NOTICE - "RAMDISK: Minix filesystem found at block %d\n", - start_block); - nblocks = minixsb->s_nzones << minixsb->s_log_zone_size; - goto done; - } - /* Try ext2 */ n = ext2_image_size(buf); if (n) { From patchwork Sat Mar 22 20:34:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Stecklina X-Patchwork-Id: 14026408 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC6BF235360; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742675715; cv=none; b=NWBEj/CtnuQiDvTfwvTDGRMuHlxOoW+a7uLK/5GXSRZTpigKGEVudVueDipoU2edooqPBB0SvQn5tMKvO4dNLr/qtC8MrVn9A3B/He3NYCogZSU4rpOHPJENB0GQ7inVEk8vmYsfmOdTKWdYma39OsNq6jkvMc1GQoamVgzAHaM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742675715; c=relaxed/simple; bh=FrtM44ukRwWbBGgAYIVqwpenB+RHshAApE0vzjyKwU0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CIq/MJY2PKotY7Blg4rrgXQlBBp8QSKtn57e4wOZFYKjcTBQn1Uq/u72U0MxJ1ZPhmq184n4Ic2HEw+OXlf439QV+8BVOZ/zDi4Gi4ZSQXEePBnxkv0S6/cm1C77wUmyS6TCzjNBjVaA0Hcrvji0gz5MrwgN5DjDHYCLthF+kW8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k44MrFzW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="k44MrFzW" Received: by smtp.kernel.org (Postfix) with ESMTPS id 56576C4CEFA; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742675715; bh=FrtM44ukRwWbBGgAYIVqwpenB+RHshAApE0vzjyKwU0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=k44MrFzWcFXtPbIIxLbreLAZYvt5ZAmVfavSYKytxqNbHJv3PayQ3FzHfBmp5wlyD B9KW5JFEyp/ssxR2rwZvXc9qopTGl4JrY9cNdqMCSaAhx1vbWZyF70s8nvmW70Bw6A WvMpiwAwd9UlpnQa/+JXlsB08i20vr3NL/scxkOm2B8xxfWBwA+foet28o/cH1iKDe IaqbychWLWlLmKqXD3x0y7IV/rNUaxXUvQ7ppIUif3cnr0zeyQEw6UwkQFQ0fNH5Lf LLw5WfrUabvo+VdyMszwOEZm2w3ZCJgHJD6qBHgdTuFU5xisv2ff97AcFrP0nq1IZQ hoADOITOYjmCQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B809C36008; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) Date: Sat, 22 Mar 2025 21:34:17 +0100 Subject: [PATCH v2 5/9] fs: cramfs: register an initrd fs detector Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250322-initrd-erofs-v2-5-d66ee4a2c756@cyberus-technology.de> References: <20250322-initrd-erofs-v2-0-d66ee4a2c756@cyberus-technology.de> In-Reply-To: <20250322-initrd-erofs-v2-0-d66ee4a2c756@cyberus-technology.de> To: Christoph Hellwig , Al Viro , Christian Brauner Cc: Linus Torvalds , Greg Kroah-Hartman , "Rafael J. Wysocki" , Gao Xiang , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-erofs@lists.ozlabs.org, Julian Stecklina X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1742675713; l=4205; i=julian.stecklina@cyberus-technology.de; s=20250320; h=from:subject:message-id; bh=T+YHuo2Ev8aOIZof+FXA1HNY64MvcwqvCtTXx1JM/p0=; b=RV3KMe/LiD+IsfUYYqELk6OGsa0r5a2gi+Mp3Mt0zAMlzR7vGEW8+fcQxMvwhUxUdHoEwczYQ s1kE0Q/P68VBeXE1Z9xP0ClFGrMA10OA9KEhkXMn1ftHbf3Zuk1Tjgg X-Developer-Key: i=julian.stecklina@cyberus-technology.de; a=ed25519; pk=m051/8gQfs5AmkACfykwRcD6CUr2T7DQ9OA5eBgyy7c= X-Endpoint-Received: by B4 Relay for julian.stecklina@cyberus-technology.de/20250320 with auth_id=363 X-Original-From: Julian Stecklina Reply-To: julian.stecklina@cyberus-technology.de From: Julian Stecklina From: Julian Stecklina Port cramfs to the new initrd_fs_detect API. There are no functional changes. Signed-off-by: Julian Stecklina --- fs/cramfs/Makefile | 5 +++++ fs/cramfs/initrd.c | 41 +++++++++++++++++++++++++++++++++++++++++ init/do_mounts_rd.c | 28 ++-------------------------- 3 files changed, 48 insertions(+), 26 deletions(-) diff --git a/fs/cramfs/Makefile b/fs/cramfs/Makefile index 8c3ed298241924b0312fb489b1fb54d274d25c22..d10e2b72aae06bf9ac42690e3967cfd90ac34d4f 100644 --- a/fs/cramfs/Makefile +++ b/fs/cramfs/Makefile @@ -6,3 +6,8 @@ obj-$(CONFIG_CRAMFS) += cramfs.o cramfs-objs := inode.o uncompress.o + +# If we are built-in, we provide support for cramfs on initrds. +ifeq ($(CONFIG_CRAMFS),y) +cramfs-objs += initrd.o +endif diff --git a/fs/cramfs/initrd.c b/fs/cramfs/initrd.c new file mode 100644 index 0000000000000000000000000000000000000000..c16df09c118226e6350b9f5877863ef31322ab7b --- /dev/null +++ b/fs/cramfs/initrd.c @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include + +/* + * The filesystem start maybe padded by this many bytes to make space + * for boot loaders. + */ +#define CRAMFS_PAD_OFFSET 512 + +static size_t __init check_cramfs_sb(struct cramfs_super *cramfsb) +{ + if (cramfsb->magic != CRAMFS_MAGIC) + return 0; + + return cramfsb->size; +} + +static size_t __init detect_cramfs(void *block_data) +{ + size_t fssize; + + BUILD_BUG_ON(sizeof(struct cramfs_super) + CRAMFS_PAD_OFFSET + > BLOCK_SIZE); + + fssize = check_cramfs_sb((struct cramfs_super *)block_data); + if (fssize) + return fssize; + + /* + * The header padding doesn't influence the total length of + * the filesystem. + */ + block_data = (char *)block_data + CRAMFS_PAD_OFFSET; + fssize = check_cramfs_sb((struct cramfs_super *)block_data); + return fssize; +} + +initrd_fs_detect(detect_cramfs, 0); diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c index f7e5d4ccf029b2707bc8524ecdbe200c8b305b00..cdc39baaf3a1a65daad5fe6571a82faf3fc95b62 100644 --- a/init/do_mounts_rd.c +++ b/init/do_mounts_rd.c @@ -3,7 +3,7 @@ #include #include #include -#include + #include #include #include @@ -43,7 +43,6 @@ static int __init crd_load(decompress_fn deco); * We currently check for the following magic numbers: * ext2 * romfs - * cramfs * squashfs * gzip * bzip2 @@ -58,7 +57,7 @@ identify_ramdisk_image(struct file *file, loff_t pos, { const int size = BLOCK_SIZE; struct romfs_super_block *romfsb; - struct cramfs_super *cramfsb; + struct squashfs_super_block *squashfsb; int nblocks = -1; unsigned char *buf; @@ -72,7 +71,6 @@ identify_ramdisk_image(struct file *file, loff_t pos, return -ENOMEM; romfsb = (struct romfs_super_block *) buf; - cramfsb = (struct cramfs_super *) buf; squashfsb = (struct squashfs_super_block *) buf; memset(buf, 0xe5, size); @@ -104,14 +102,6 @@ identify_ramdisk_image(struct file *file, loff_t pos, goto done; } - if (cramfsb->magic == CRAMFS_MAGIC) { - printk(KERN_NOTICE - "RAMDISK: cramfs filesystem found at block %d\n", - start_block); - nblocks = (cramfsb->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 @@ -122,20 +112,6 @@ identify_ramdisk_image(struct file *file, loff_t pos, goto done; } - /* - * Read 512 bytes further to check if cramfs is padded - */ - pos = start_block * BLOCK_SIZE + 0x200; - kernel_read(file, buf, size, &pos); - - if (cramfsb->magic == CRAMFS_MAGIC) { - printk(KERN_NOTICE - "RAMDISK: cramfs filesystem found at block %d\n", - start_block); - nblocks = (cramfsb->size + BLOCK_SIZE - 1) >> BLOCK_SIZE_BITS; - goto done; - } - /* * Read block 1 to test for ext2 superblock */ From patchwork Sat Mar 22 20:34:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Stecklina X-Patchwork-Id: 14026404 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB0FF23535C; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742675715; cv=none; b=kI9kz4q4U391GbNCf/T+2yz3LrktfFVTErgMjD2dPeFsjlTiuhjU/DtAZmHSRDoifMLTSD9fMXGEpyE5MyCLa2hxy0yJ9Tswp/OHlwssgac9RCqbni7uGxpb5N7tHhNwjbK7cVPV+tNoPS5nqSDdXqUI2A2Gou+MaU8O1JYcm48= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742675715; c=relaxed/simple; bh=WxuPWwzWQb6OHqAvqAIEXUyCRmvLthXZsVF3HZREUFs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Jqs/Ns2KNXjnIBnKtVE9oE1Bhqnbxd1Q4W4GXNwxjRfd+8Suhac+7x0hDqpzY9y0O3iJQGpOwjjJtWrEIipne+swPWWFp3TJ9VaQ83s5036iXYpVsE4NNpQF6bVe0E5D9x9Dx+qztP6AshlmmiZw9N+IG3wIUOuDRq7TWJIV4y4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oXfCiNhP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oXfCiNhP" Received: by smtp.kernel.org (Postfix) with ESMTPS id 6B947C4CEFD; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742675715; bh=WxuPWwzWQb6OHqAvqAIEXUyCRmvLthXZsVF3HZREUFs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=oXfCiNhP3/PFBFCePwmcQkQjbUbkzbCpLxSUtIZB/l2qkM/BghyAMKt00hsqBJRPl NZGX9ezmHU04ao2mu8uowtv/4s1bFGoR2pJ1r+6hWhX4++T7MYf2Rr4ASycPod+YaQ jTwJ5GVQjGmxTl8/dwFns9bRFOW3A8CHDB3BQ79z25cDnSMZKTvdkZnJS3PmkD4yMc 9R4jBBl/ZMBMD0BDypQSa+itA7eG01zPjwIpSN7N+cf84bY4Qeen+wtJZMdpbYg1f+ rVJop+DdLD8jgFB2y/3USfjraPlGpG88pLV4/MP0LODoOfxYBmDH2ZZU9xrKVjh+x7 N7l7rQycJBXqg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61DFFC3600B; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) Date: Sat, 22 Mar 2025 21:34:18 +0100 Subject: [PATCH v2 6/9] fs: romfs: register an initrd fs detector Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250322-initrd-erofs-v2-6-d66ee4a2c756@cyberus-technology.de> References: <20250322-initrd-erofs-v2-0-d66ee4a2c756@cyberus-technology.de> In-Reply-To: <20250322-initrd-erofs-v2-0-d66ee4a2c756@cyberus-technology.de> To: Christoph Hellwig , Al Viro , Christian Brauner Cc: Linus Torvalds , Greg Kroah-Hartman , "Rafael J. Wysocki" , Gao Xiang , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-erofs@lists.ozlabs.org, Julian Stecklina X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1742675713; l=3189; i=julian.stecklina@cyberus-technology.de; s=20250320; h=from:subject:message-id; bh=DjTVlMjJ9fly1JjbbQ1cABQpspedV4SfXIZDQ9hYyJw=; b=bYQM009Se+/99LClCNXj1HPpoPjNjrjKzdTybPVuJsdmCzDLeuSC5fNA+iESxAR+1ZgnWKYDX Ev6I3qHnmlqAj9w8p+pdBCatDMx3r8QKy5KB7shQWM2fafgd9gjbT/5 X-Developer-Key: i=julian.stecklina@cyberus-technology.de; a=ed25519; pk=m051/8gQfs5AmkACfykwRcD6CUr2T7DQ9OA5eBgyy7c= X-Endpoint-Received: by B4 Relay for julian.stecklina@cyberus-technology.de/20250320 with auth_id=363 X-Original-From: Julian Stecklina Reply-To: julian.stecklina@cyberus-technology.de From: Julian Stecklina From: Julian Stecklina Port romfs from to the new initrd_fs_detect API. There are no functional changes. Signed-off-by: Julian Stecklina --- 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 +#include +#include +#include + +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 #include #include -#include #include #include @@ -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 From patchwork Sat Mar 22 20:34:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Stecklina X-Patchwork-Id: 14026406 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C7B17235355; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742675715; cv=none; b=ieVwaalQxsX+15KOS5+Rdj4iKOZg97R+ds2VutNYN+DBs9wHpFCnKyDXpnyswTZ6ej6XXDvDujOQNhB2eT46cHXSLeEqb0C9H0GWFFtcDo0GnKXuNgXmSXRlx5UkINkU3PO00Ucjb6CGYFyqCWFDL4fOk5ryuYe4PJnpE7ULjt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742675715; c=relaxed/simple; bh=CGLJl1zEmiCISwzcev9qeEVvn+4xnW6/oap/uXff3ko=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=I70F26dpodX1veivBjU/t62+W0BOXyh+30eqYUCyTzmee/RgxGHjsWw2Bp8NetgVzbZKznx81xhlXX9YtdEAYJpf2sHyU2lLsIM1D9OeU3YyRZ+o2kHzvys7qC7xqMSAzXwZqOC7f4g2OhhIjfUzKhDX2Xcc1IJJN6JUTNPW/7w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=R/wc4fVk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="R/wc4fVk" Received: by smtp.kernel.org (Postfix) with ESMTPS id 7E4A6C4CEFF; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742675715; bh=CGLJl1zEmiCISwzcev9qeEVvn+4xnW6/oap/uXff3ko=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=R/wc4fVkDIP+pjdeKOjGNRZlhkfRErVXjcoSVJkAhNbpwZ7QyIZbx7sZkeWvbAKai qNNZJNjqbFbJwBxL17trCKvX4uSpPJ7FY4XcWNwa5Bt69/64flpcJJii0vwObyEGUO hXiat1wm3Xg47MSjjy81dVhNZFqjdoyqVnPhgS8fJ9nvnQogvvoV685Y+VEgaH7F85 Xc3nguWyTFepgiPs+xAypo+L1hJNwOdh4iEA/AnGdbvegrCmOlUGQBappo7Nv0Js4w W5pJHoaxRrkwp23ExdBNbxOAUxhSWDL5PjCsne5KyKh97YafvB2z5LqqEh8+w3b81e wXKu7gJ3DSVAw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7241DC35FFC; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) Date: Sat, 22 Mar 2025 21:34:19 +0100 Subject: [PATCH v2 7/9] fs: squashfs: register an initrd fs detector Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250322-initrd-erofs-v2-7-d66ee4a2c756@cyberus-technology.de> References: <20250322-initrd-erofs-v2-0-d66ee4a2c756@cyberus-technology.de> In-Reply-To: <20250322-initrd-erofs-v2-0-d66ee4a2c756@cyberus-technology.de> To: Christoph Hellwig , Al Viro , Christian Brauner Cc: Linus Torvalds , Greg Kroah-Hartman , "Rafael J. Wysocki" , Gao Xiang , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-erofs@lists.ozlabs.org, Julian Stecklina X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1742675713; l=3201; i=julian.stecklina@cyberus-technology.de; s=20250320; h=from:subject:message-id; bh=zysxuXEy456UHMgFgfSEAGox0ynSn0NVemXDz0PKiSU=; b=nZrNbSLcFivZ71KUl0X/nNQRHCoVKonroEdGfu+uTmwQBjJeOyVqHGkumj6SPGTNn0sy1YrD3 ejVMVfXX5AHAbW52Bbp6N3qM1+EdspO5bbB9w5pauYrKxkHm/r0zGG2 X-Developer-Key: i=julian.stecklina@cyberus-technology.de; a=ed25519; pk=m051/8gQfs5AmkACfykwRcD6CUr2T7DQ9OA5eBgyy7c= X-Endpoint-Received: by B4 Relay for julian.stecklina@cyberus-technology.de/20250320 with auth_id=363 X-Original-From: Julian Stecklina Reply-To: julian.stecklina@cyberus-technology.de From: Julian Stecklina From: Julian Stecklina Port squashfs from to the new initrd_fs_detect API. There are no functional changes. Signed-off-by: Julian Stecklina --- 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 +#include +#include + +#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 #include "do_mounts.h" -#include "../fs/squashfs/squashfs_fs.h" #include @@ -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 */ From patchwork Sat Mar 22 20:34:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Stecklina X-Patchwork-Id: 14026405 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC3EC23535D; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742675715; cv=none; b=gKBynM5uhN+laPhFJhzxgDVMwZNGXF1/Z4QenS8seslq0FRNSD53PazO9cniPSQt4JbugETmeXdKoWMNsh3VMVbjdLm6EVbnmbwzwnJ4fmkxqx/w4cU0r3r+D47bsfkaPeBAWLvVPz5X2RQiQyO4GAXQVH5yuZKMXGI/Iqdx1S4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742675715; c=relaxed/simple; bh=qlYnspgvq4aayarEVcEiEabLCbx6xRYkDWQEk4WspNA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QiTiHXMlAyaFdSZyFZkCoreBAqVsRYrXHI1GFFoqwdR0ys5HFUFHiJaLHzGoHXI0yogWMGpM3qhZdnUPSdPa92rp8x5vd8RASugFqndyUnTMdKO4a9pPf17HiYAWPHRA+X6Dmn8fvxBaEMFgC0/JdYoTiIeSOQCyv+RKTU5xjDI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eJfYfbPo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eJfYfbPo" Received: by smtp.kernel.org (Postfix) with ESMTPS id 8B99FC113CF; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742675715; bh=qlYnspgvq4aayarEVcEiEabLCbx6xRYkDWQEk4WspNA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=eJfYfbPo+BZJFO9jFoPzDBYrkzPsHCEFgP7PrKjVBtSNsv0FIy7ms/A2f6J3Z4dNm gT/20YuneiiNIS13XA/fCJvIJ2tSeCYmsPSg62QllK8MxzHZVqweoIvwyJCnmY22Da s7sZQmcA0/ZJNLSpF8cjU5DYFjO5Yt/YofdS9reJYgf3Cav8arEliufA3oXaY5kotC 7xd4rdmBtX/woAHpZsWYiwIagjvH5zJIKZWr3217oxHd3oyWlevzanN1hr1+LQ7NZw BopzREDJFX6SO9R0lqyNHbu2ojhdCz/8ioOS/SkKgx88T8zmLEhVYZVzRgi9wi0fDI NVaB7+GFGlVUQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82135C3600B; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) Date: Sat, 22 Mar 2025 21:34:20 +0100 Subject: [PATCH v2 8/9] fs: ext2, ext4: register an initrd fs detector Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250322-initrd-erofs-v2-8-d66ee4a2c756@cyberus-technology.de> References: <20250322-initrd-erofs-v2-0-d66ee4a2c756@cyberus-technology.de> In-Reply-To: <20250322-initrd-erofs-v2-0-d66ee4a2c756@cyberus-technology.de> To: Christoph Hellwig , Al Viro , Christian Brauner Cc: Linus Torvalds , Greg Kroah-Hartman , "Rafael J. Wysocki" , Gao Xiang , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-erofs@lists.ozlabs.org, Julian Stecklina X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1742675713; l=4918; i=julian.stecklina@cyberus-technology.de; s=20250320; h=from:subject:message-id; bh=LdAKuZmUbrCiaWrR+heLI+KjXz18b4SY7NnyYc6FMGI=; b=YFZIJjXxsx7J3kcAizftmxjRIVimZ/jqPa2fg7X4xVMF3sKQ2pEExGPq0hGEBNEjEyJlkcvWA 8IMeR63U5XPCTg3wo7m/f2h+syZWCXdcsZ51TJMQgQPTbzyqG0NGint X-Developer-Key: i=julian.stecklina@cyberus-technology.de; a=ed25519; pk=m051/8gQfs5AmkACfykwRcD6CUr2T7DQ9OA5eBgyy7c= X-Endpoint-Received: by B4 Relay for julian.stecklina@cyberus-technology.de/20250320 with auth_id=363 X-Original-From: Julian Stecklina Reply-To: julian.stecklina@cyberus-technology.de From: Julian Stecklina From: Julian Stecklina Port ext2fs to the new initrd_fs_detect API. There are minor functional changes, because I thought that relying on a 16-bit magic number alone is too error-prone. I also removed ext2_image_size from linux/ext2_fs.h, because the initrd code is the only user. Given that both the ext2 and ext4 module can handle ext2 filesystems, we have to add the code to either module depending on the configuration options. Signed-off-by: Julian Stecklina --- fs/ext2/Makefile | 5 +++++ fs/ext2/initrd.c | 27 +++++++++++++++++++++++++++ fs/ext4/Makefile | 4 ++++ include/linux/ext2_fs.h | 9 --------- init/do_mounts_rd.c | 19 ------------------- 5 files changed, 36 insertions(+), 28 deletions(-) diff --git a/fs/ext2/Makefile b/fs/ext2/Makefile index 8860948ef9ca4e0a9c3f90311c3cecf0c5b70c63..c38a5b209023f93c84e8a6b8995d1db0214bb01a 100644 --- a/fs/ext2/Makefile +++ b/fs/ext2/Makefile @@ -14,3 +14,8 @@ CFLAGS_trace.o := -I$(src) ext2-$(CONFIG_EXT2_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o ext2-$(CONFIG_EXT2_FS_POSIX_ACL) += acl.o ext2-$(CONFIG_EXT2_FS_SECURITY) += xattr_security.o + +# If we are built-in, we provide support for ext2 on initrds. +ifeq ($(CONFIG_EXT2_FS),y) +ext2-y += initrd.o +endif diff --git a/fs/ext2/initrd.c b/fs/ext2/initrd.c new file mode 100644 index 0000000000000000000000000000000000000000..572930512b8b3bee0d733553117a026af6e2f833 --- /dev/null +++ b/fs/ext2/initrd.c @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include + +#include "ext2.h" + +static size_t __init detect_ext2fs(void *block_data) +{ + struct ext2_super_block *ext2sb + = (struct ext2_super_block *)block_data; + BUILD_BUG_ON(sizeof(*ext2sb) > BLOCK_SIZE); + + /* + * The 16-bit magic number is not a lot to reliably detect the + * filesystem. We check the revision as well to decrease the + * chance of false positives. + */ + if (le16_to_cpu(ext2sb->s_magic) != EXT2_SUPER_MAGIC || + le32_to_cpu(ext2sb->s_rev_level) > EXT2_MAX_SUPP_REV) + return 0; + + return le32_to_cpu(ext2sb->s_blocks_count) + << (le32_to_cpu(ext2sb->s_log_block_size) + BLOCK_SIZE_BITS); +} + +initrd_fs_detect(detect_ext2fs, BLOCK_SIZE); diff --git a/fs/ext4/Makefile b/fs/ext4/Makefile index 72206a2926765feba6fc59332ffeca7c03c8677b..907c80c33c8fc1e5dee85f8e862c8b27615f1a04 100644 --- a/fs/ext4/Makefile +++ b/fs/ext4/Makefile @@ -18,3 +18,7 @@ ext4-inode-test-objs += inode-test.o obj-$(CONFIG_EXT4_KUNIT_TESTS) += ext4-inode-test.o ext4-$(CONFIG_FS_VERITY) += verity.o ext4-$(CONFIG_FS_ENCRYPTION) += crypto.o + +ifeq ($(CONFIG_EXT4_FS),y) +ext4-$(CONFIG_EXT4_USE_FOR_EXT2) += ../ext2/initrd.o +endif diff --git a/include/linux/ext2_fs.h b/include/linux/ext2_fs.h index 1fef885690370e5c039871ac8dd99d649d72aa64..0662827c0c69c3b77fb74850e1b0f3626c14c713 100644 --- a/include/linux/ext2_fs.h +++ b/include/linux/ext2_fs.h @@ -31,13 +31,4 @@ #define EXT2_SB_BLOCKS_OFFSET 0x04 #define EXT2_SB_BSIZE_OFFSET 0x18 -static inline u64 ext2_image_size(void *ext2_sb) -{ - __u8 *p = ext2_sb; - if (*(__le16 *)(p + EXT2_SB_MAGIC_OFFSET) != cpu_to_le16(EXT2_SUPER_MAGIC)) - return 0; - return (u64)le32_to_cpup((__le32 *)(p + EXT2_SB_BLOCKS_OFFSET)) << - le32_to_cpup((__le32 *)(p + EXT2_SB_BSIZE_OFFSET)); -} - #endif /* _LINUX_EXT2_FS_H */ diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c index 2a6cb08d0b4872ef8e861a813ef89dc1e9a150af..45d2c5f7da044166524bef808bb97bee46c3324b 100644 --- a/init/do_mounts_rd.c +++ b/init/do_mounts_rd.c @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include #include -#include #include #include @@ -39,7 +38,6 @@ static int __init crd_load(decompress_fn deco); * numbers could not be found. * * We currently check for the following magic numbers: - * ext2 * gzip * bzip2 * lzma @@ -56,7 +54,6 @@ identify_ramdisk_image(struct file *file, loff_t pos, int nblocks = -1; unsigned char *buf; const char *compress_name; - unsigned long n; int start_block = rd_image_start; struct initrd_detect_fs *detect_fs; @@ -84,22 +81,6 @@ identify_ramdisk_image(struct file *file, loff_t pos, goto done; } - /* - * Read block 1 to test for ext2 superblock - */ - pos = (start_block + 1) * BLOCK_SIZE; - kernel_read(file, buf, size, &pos); - - /* Try ext2 */ - n = ext2_image_size(buf); - if (n) { - printk(KERN_NOTICE - "RAMDISK: ext2 filesystem found at block %d\n", - start_block); - nblocks = n; - goto done; - } - /* Try to find a filesystem in the initrd */ for (detect_fs = __start_initrd_fs_detect; detect_fs < __stop_initrd_fs_detect; From patchwork Sat Mar 22 20:34:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Stecklina X-Patchwork-Id: 14026407 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC5FD23535E; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742675715; cv=none; b=BCNSieuudBGqKiPkjhR8QVK5aCYdXlDNAcjOSne7eRxTY1Of/fdyCN4yGDZXOfdoS2ziO3VsPH/P5Q5qsls+nGk8OOqbsw4XkK9kfSQ9H1YXooSfVABFRBJxnX7FeZf4ZDNOLx/MFpRO++Ege7AGuCGdrfMIz1zNBrAy1AUKXhQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742675715; c=relaxed/simple; bh=p8v3JQ4emsUMjjvSBjOOzwZTgB1SvlkW9F+SuuyZM1o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pvAHUSUcJTNGaYAwvqelvHUg2f8WvWhO8FjJ4xT4RT5zsar8qRjEilSZ/eAgvTAu+5QF7WDli3pqBdWm9J9emhBpKaZ+WRRnjIDq8KThg5HXd/NADUvFd0DHO47K/edtQwttQ0gL840BlfTsvplwdg07YAu4j8De6JcDuRkz/A0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KJJeHfYl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KJJeHfYl" Received: by smtp.kernel.org (Postfix) with ESMTPS id A1643C116C6; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742675715; bh=p8v3JQ4emsUMjjvSBjOOzwZTgB1SvlkW9F+SuuyZM1o=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=KJJeHfYl3yzGUIwImmqR8xWDh/xoz41CsGa2N3ZvJ2+Uzr9yIFnrtV8JlkuUcu0YQ Ouy2RN/TdTY0RARXo6QMN15NBmtZcraSr7+++reLI0GQatQ2TyP+c5ShKH7ZlhQLYQ FGjHO4/bBEz4+ZPz1PClqYTh1gnR0t3CyDrJJF6o76jHw8qDRlrbPotMmzleV6W7po rFBm5TmGLxlp3tpY6CgnOUWJAl84hVyGVBOhpURoeF55YpqwGaazTzEakbPTaho18u OPt6mO/stFa+IIWM2wA+mfY/PmSmHIzKhBoWIWvx/pJfMWrCr7lz4PASfk8GEBS5bm gddTVp2bOti0w== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 955E4C36008; Sat, 22 Mar 2025 20:35:15 +0000 (UTC) Date: Sat, 22 Mar 2025 21:34:21 +0100 Subject: [PATCH v2 9/9] fs: erofs: register an initrd fs detector Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250322-initrd-erofs-v2-9-d66ee4a2c756@cyberus-technology.de> References: <20250322-initrd-erofs-v2-0-d66ee4a2c756@cyberus-technology.de> In-Reply-To: <20250322-initrd-erofs-v2-0-d66ee4a2c756@cyberus-technology.de> To: Christoph Hellwig , Al Viro , Christian Brauner Cc: Linus Torvalds , Greg Kroah-Hartman , "Rafael J. Wysocki" , Gao Xiang , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-erofs@lists.ozlabs.org, Julian Stecklina , Niklas Sturm X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1742675713; l=1748; i=julian.stecklina@cyberus-technology.de; s=20250320; h=from:subject:message-id; bh=3yTdTgTHrBXPDCzHQY85SoPI2ekHfJ9SwSVLMJjjpHc=; b=gbKgVEbkExOOnYyBMICxer+0rrpqPN7L6a11TGtSHg9nUJDPcH1Az1Dcltfti9MOJD2CWO7NM iXnPdA1cJA4Ct+v+ehZ5rvSbO6BmO84OPaQLlG31oC9XmPYYKZEvguk X-Developer-Key: i=julian.stecklina@cyberus-technology.de; a=ed25519; pk=m051/8gQfs5AmkACfykwRcD6CUr2T7DQ9OA5eBgyy7c= X-Endpoint-Received: by B4 Relay for julian.stecklina@cyberus-technology.de/20250320 with auth_id=363 X-Original-From: Julian Stecklina Reply-To: julian.stecklina@cyberus-technology.de From: Julian Stecklina From: Julian Stecklina Allow erofs to be used as a filesystem for initrds. It offers similar advantages as squashfs, but with higher performance and arguably nicer tooling. If we support squashfs, there is no reason not to support erofs as well. Suggested-by: Niklas Sturm Signed-off-by: Julian Stecklina --- fs/erofs/Makefile | 5 +++++ fs/erofs/initrd.c | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/fs/erofs/Makefile b/fs/erofs/Makefile index 4331d53c7109550a0518f2ed8df456deecdd2f8c..cea46a51dea2b9e22e4ba1478dd30de3262fe6cb 100644 --- a/fs/erofs/Makefile +++ b/fs/erofs/Makefile @@ -9,3 +9,8 @@ erofs-$(CONFIG_EROFS_FS_ZIP_DEFLATE) += decompressor_deflate.o erofs-$(CONFIG_EROFS_FS_ZIP_ZSTD) += decompressor_zstd.o erofs-$(CONFIG_EROFS_FS_BACKED_BY_FILE) += fileio.o erofs-$(CONFIG_EROFS_FS_ONDEMAND) += fscache.o + +# If we are built-in, we provide support for erofs on initrds. +ifeq ($(CONFIG_EROFS_FS),y) +erofs-objs += initrd.o +endif diff --git a/fs/erofs/initrd.c b/fs/erofs/initrd.c new file mode 100644 index 0000000000000000000000000000000000000000..e2bb313f55211a305e201f529d7da810898252ac --- /dev/null +++ b/fs/erofs/initrd.c @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include + +#include "internal.h" + +static size_t __init detect_erofs(void *block_data) +{ + struct erofs_super_block *erofsb = block_data; + + BUILD_BUG_ON(sizeof(*erofsb) > BLOCK_SIZE); + + if (le32_to_cpu(erofsb->magic) != EROFS_SUPER_MAGIC_V1) + return 0; + + return le32_to_cpu(erofsb->blocks) << erofsb->blkszbits; +} + +initrd_fs_detect(detect_erofs, EROFS_SUPER_OFFSET);