From patchwork Mon Dec 22 11:56:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1031 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1766404621; bh=8FSmBAzbbPRiC9bPd1m92bE0GgIIUruExVE2joAfUNY=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=Gxb2Xk+/vIdXUOfAiZJpcDNIaX0hsUB6V5IrmqMmr7hms8XTjLyKnunfqLSc7yiQ+ o1fqGH2ifd69e4oskpzXcD5O6JMkjraE/NvtzW1BcqgrtpTejOds8zbXIV/OsfnuRH y05xJGkLnMEzGkyp4SEQZUdKZq4N46Rg3J2laUpg4MHwlKUwxcjM3U/rjbQ79zJmaw TTu/XHHlGdAPHdX2SJzVp10Pjm34nT+DUycX5oQuPzBs/JUC23P47iOX/xZ+k48WKx LGh/lzhTlIE0RXswAGn6g9PTnyiIjxEoh8+/N5kQa4aLHXzuiiuTybKEgLLGiSRSck HuQRxcdIiwngg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DEF1664D60 for ; Mon, 22 Dec 2025 04:57:01 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id tQ0UwUrHeGkm for ; Mon, 22 Dec 2025 04:57:01 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1766404621; bh=8FSmBAzbbPRiC9bPd1m92bE0GgIIUruExVE2joAfUNY=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=Gxb2Xk+/vIdXUOfAiZJpcDNIaX0hsUB6V5IrmqMmr7hms8XTjLyKnunfqLSc7yiQ+ o1fqGH2ifd69e4oskpzXcD5O6JMkjraE/NvtzW1BcqgrtpTejOds8zbXIV/OsfnuRH y05xJGkLnMEzGkyp4SEQZUdKZq4N46Rg3J2laUpg4MHwlKUwxcjM3U/rjbQ79zJmaw TTu/XHHlGdAPHdX2SJzVp10Pjm34nT+DUycX5oQuPzBs/JUC23P47iOX/xZ+k48WKx LGh/lzhTlIE0RXswAGn6g9PTnyiIjxEoh8+/N5kQa4aLHXzuiiuTybKEgLLGiSRSck HuQRxcdIiwngg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id CDFE364D59 for ; Mon, 22 Dec 2025 04:57:01 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1766404620; bh=/xuYJZpqGHaKIU3whqkkOBjuECsQwkNqzdhtnjsB9Ng=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T7XoOYHOPUY8+nyA4k3bh76GSjtQn7fvoDXRGVOQqe8YdvGYW2OA1WkGnCTzZaUIS 6wmJyQDuMm3KJt1bgcgekUwlEzrNv5DX7YKEEdvhuWNjmr65WwM92sRH1FxHRMOH/L 62+hDdgE3RRfwW5Oq2WZaGOnrl2XegOsnNReS0xXDTX/mRPIFxZfRRV3U8rGuTfe9f vhxkdkCrZouDA2vWODYvBJS5Pyq9OOi+IuTFFKU6HGT5o3YmTP+L5Ss6eqBiNAfL8V zInVrvlnXFOv0ag75R9057GqKWD6uxdRA73gpdv4TY+YLyGijFjL+wqQbWfGXbHpGX mKszSWYbbsFGQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D513164D5E; Mon, 22 Dec 2025 04:57:00 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id f4HLBUk8KNUv; Mon, 22 Dec 2025 04:57:00 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1766404620; bh=RSNStL2Id/1nz+kSnJpssgT7b7MECqBZEtm/zx46JTk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JiQYmBJWWKlLe1Q2CGbyQW24Rd2NAfS2rH5VNj2Wbh78eTOU+vKCuIe8nC6oDfhAT ak4taNdxzP4f4g4cIRhP6UG+g1E3TmwVoCHBuFTPdP0b2vpeBXSq2sh2gIVFXmJqTw ha4y1mnwjdfbnyTBuDHxaEmkd2YmPauYlg1eU6Jf25lVrrXGUn7fOlyCwtknm5JFeo chuUn+xg4uZKonUfjycf+BGDJLFegj4Hnv3pi+4KCvS6YBxWbrDylIPl4XlmaDQyai dar3CPoCWhlV5Uro3Kv5SpEAzlEyTajspNCjW9uBqXPb6L6k8E1KYQ47d6ILt3QyG4 f/LYl96fF5tkg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 0013264D59; Mon, 22 Dec 2025 04:56:59 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Mon, 22 Dec 2025 04:56:05 -0700 Message-ID: <20251222115639.700578-2-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251222115639.700578-1-sjg@u-boot.org> References: <20251222115639.700578-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: S3N5FSZJV6VIQ36CUSWHTSND6HFXNNA7 X-Message-ID-Hash: S3N5FSZJV6VIQ36CUSWHTSND6HFXNNA7 X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 01/26] fs: ext4l: Add minimal probe support List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add a minimal ext4l probe function that: - Reads the superblock from the block device - Validates the ext4 magic number - Returns proper error codes (-EINVAL, -ENOMEM, -EIO) Create include/ext4l.h header with function declarations and documentation. Update fs_legacy.c to use the header. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/interface.c | 57 ++++++++++++++++++++++++++++++++++++++++++-- fs/fs_legacy.c | 5 ++-- include/ext4l.h | 31 ++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 include/ext4l.h diff --git a/fs/ext4l/interface.c b/fs/ext4l/interface.c index 455e101b65f..eb625e0b1a5 100644 --- a/fs/ext4l/interface.c +++ b/fs/ext4l/interface.c @@ -2,19 +2,72 @@ /* * U-Boot interface for ext4l filesystem (Linux port) * + * Copyright 2025 Canonical Ltd + * Written by Simon Glass + * * This provides the minimal interface between U-Boot and the ext4l driver. - * Currently just stubs - the filesystem doesn't work yet. */ #include #include +#include +#include +#include +#include + +#include "ext4_uboot.h" +#include "ext4.h" + +/* Global state */ +static struct blk_desc *ext4l_dev_desc; +static struct disk_partition ext4l_part; int ext4l_probe(struct blk_desc *fs_dev_desc, struct disk_partition *fs_partition) { - return -1; + loff_t part_offset; + __le16 *magic; + u8 *buf; + int ret; + + if (!fs_dev_desc) + return -EINVAL; + + buf = malloc(BLOCK_SIZE + 512); + if (!buf) + return -ENOMEM; + + /* Calculate partition offset in bytes */ + part_offset = fs_partition ? (loff_t)fs_partition->start * fs_dev_desc->blksz : 0; + + /* Read sectors containing the superblock */ + if (blk_dread(fs_dev_desc, + (part_offset + BLOCK_SIZE) / fs_dev_desc->blksz, + 2, buf) != 2) { + ret = -EIO; + goto out; + } + + /* Check magic number within superblock */ + magic = (__le16 *)(buf + (BLOCK_SIZE % fs_dev_desc->blksz) + + offsetof(struct ext4_super_block, s_magic)); + if (le16_to_cpu(*magic) != EXT4_SUPER_MAGIC) { + ret = -EINVAL; + goto out; + } + + /* Save device info for later operations */ + ext4l_dev_desc = fs_dev_desc; + if (fs_partition) + memcpy(&ext4l_part, fs_partition, sizeof(ext4l_part)); + + ret = 0; +out: + free(buf); + return ret; } void ext4l_close(void) { + ext4l_dev_desc = NULL; } diff --git a/fs/fs_legacy.c b/fs/fs_legacy.c index 405aa8aba54..5b96e1465d8 100644 --- a/fs/fs_legacy.c +++ b/fs/fs_legacy.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -262,8 +263,8 @@ static struct fstype_info fstypes[] = { .fstype = FS_TYPE_EXT, .name = "ext4", .null_dev_desc_ok = false, - .probe = fs_probe_unsupported, - .close = fs_close_unsupported, + .probe = ext4l_probe, + .close = ext4l_close, .ls = fs_ls_unsupported, .exists = fs_exists_unsupported, .size = fs_size_unsupported, diff --git a/include/ext4l.h b/include/ext4l.h new file mode 100644 index 00000000000..5a300fd6559 --- /dev/null +++ b/include/ext4l.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * ext4l filesystem interface + * + * Copyright 2025 Canonical Ltd + * Written by Simon Glass + */ + +#ifndef __EXT4L_H__ +#define __EXT4L_H__ + +struct blk_desc; +struct disk_partition; + +/** + * ext4l_probe() - Probe a block device for an ext4 filesystem + * + * @fs_dev_desc: Block device descriptor + * @fs_partition: Partition information + * Return: 0 on success, -EINVAL if no device or invalid magic, + * -ENOMEM on allocation failure, -EIO on read error + */ +int ext4l_probe(struct blk_desc *fs_dev_desc, + struct disk_partition *fs_partition); + +/** + * ext4l_close() - Close the ext4 filesystem + */ +void ext4l_close(void); + +#endif /* __EXT4L_H__ */