From patchwork Sat Dec 27 20:43: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: 1087 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=1766868274; bh=GB++VOqv8kbzOUU+UeBEkdUf9TdjXzw4TqrBetVbW5w=; 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=IWvlB+hnhIEWY9eHjsmCt3muCapwZCK0LgzbL69yQuBWQs4U5peuOQ5phdLPg9DwZ 0432BUNERcC912JWKOZzmujcvr/1rY10fuApSb1Dvq4WVWRTBBtKWtRhMr1rifx5yK SgI1c+EwblfFpgVL2Ag9ef7sdkgiJ33VdcmMhn3xmb1/Oam9cZJjC1qnyutlpFrmWi L9p3YNYlV1ySXbjCduoBPlF4ihyYLr/ytMqacTkj6wrALCvS5cuf/36ycdNKAU5OnZ qnvee4Ior3FeoKPv8NsWiZoSDSYO4MwjAlISb54F4HB6m1/OjycYVuTEO2UzBUrY+k fykT97nlIzsJw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 98A3764E4D for ; Sat, 27 Dec 2025 13:44:34 -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 0tN_LmKzxkwu for ; Sat, 27 Dec 2025 13:44:34 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1766868273; bh=GB++VOqv8kbzOUU+UeBEkdUf9TdjXzw4TqrBetVbW5w=; 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=j4LvaACI7sRGQr7Efecw+9WgNMs6XAOuFX1ki+AGLjeXWVHaafK65FmCGAdxeGpIb A7AC/gD1bE7tgxXs75cdc2D8zdjQpVb65NnUPyUfLwOZFOEMJ/pnde65ISRdZ850DF irGUEEvowGZMKAVc5jFhn52zevUCpwjrxPAUiyKhD0GSd1qv8C1NINgBlAsnKiKYif P1p/58r3/KvFqcEcn6v8eiLeNs+A2mmoC+Aiut+D97/87wJ7aloNeMNWX15yFbH54E TG4BUYBcElqSyNYsU5YSpZi1OYPJx/Xx44f0LtP1qUSlo79mDUab8mBhQKX9BmOcCL 6LgSD2++eMdsQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1FB2468BF3 for ; Sat, 27 Dec 2025 13:44:33 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1766868270; bh=kCDXp7+5WhiNBM8AiHTMaC/iBItq3+6NrEc15H9kL5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mwfTEVhWSyYIlwQ5lzWTm9aU3zvKJnuKq7L0l7TtPdekWf8OnvGM55yuRKLyH0v9l s8FweI5aKQRDnP8ipGVD2TBx4r05iY8kZINm2W0CHVVj0uDqa/qyKRHfWKKgbO/QUS xQEwiRViF7XZBzET90X4aIrXFhdKpGlB5yzlCncsFAPPc9JLvhtrbiqTbzACeva7yC GrcDE71d0RqstWV6+WVCpLf0LjgQ8yJGyEIdqPU7tTJSMFSa2XCy6zQIoYfMvagIb+ /3fCBljc1g6vdHwfxYvCW8/CPRjBOrQGvISzMRcQX+5Mm/JU/GTZnRTcdzrjgY0UtN 4UXMho+YYAdnw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 49AC764E49; Sat, 27 Dec 2025 13:44:30 -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 9WYjzFj-qVOc; Sat, 27 Dec 2025 13:44:30 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1766868270; bh=U4mzSx0vZs+c9vMMDrMUHVgahRQa7NvpTYl4XikxuL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iGl3Xsb8XadvXSRFvNov3KDdn3yEnC+85oJ8QV1a41ch0mqyx/dXAJT7TIK+97nwS ERkSRPBtFBKNpsANgbZjfP4AI2zY4FkMvIxlpPxzP+gUMGF3fw3jy5K93HydcEwG2P lj+pmE2E7jZyc0ts4habmLOyVjXJqDgdqR9z66rJ/0dhoMQrw/akEByXD20/FYzPCl s/6YbRTfRiQqXMSlzVLRs96Pu2/t8baZa6u/AZW10OWc3oWbG8aVglY3uRKmURCB1k Sosxn+HV+aGs+xdAwx6Bm1DPBVQLY4c32W28hrRvElSTvqpjDy2m8TJk3nUvUJjjSl wVrRtw9Mvzydw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 9B99264E1F; Sat, 27 Dec 2025 13:44:29 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 27 Dec 2025 13:43:05 -0700 Message-ID: <20251227204318.886983-11-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251227204318.886983-1-sjg@u-boot.org> References: <20251227204318.886983-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 2NEUICWQFMY677MZBNCCQGVXU2UMC7W4 X-Message-ID-Hash: 2NEUICWQFMY677MZBNCCQGVXU2UMC7W4 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: Heinrich Schuchardt , Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 10/16] ext4l: Add exists() 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 Implement ext4l_exists() to check if a file or directory exists on the filesystem. This uses ext4l_resolve_path() to look up the path and returns 1 if found, 0 otherwise. Wire the function into fs_legacy.c and add a basic test. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/interface.c | 13 +++++++++++++ fs/fs_legacy.c | 2 +- include/ext4l.h | 8 ++++++++ test/fs/ext4l.c | 27 +++++++++++++++++++++++++++ test/py/tests/test_fs/test_ext4l.py | 7 +++++++ 5 files changed, 56 insertions(+), 1 deletion(-) diff --git a/fs/ext4l/interface.c b/fs/ext4l/interface.c index e7f09fd45dc..409a3ff7edc 100644 --- a/fs/ext4l/interface.c +++ b/fs/ext4l/interface.c @@ -636,6 +636,19 @@ int ext4l_ls(const char *dirname) return ret; } +int ext4l_exists(const char *filename) +{ + struct inode *inode; + + if (!filename) + return 0; + + if (ext4l_resolve_path(filename, &inode)) + return 0; + + return 1; +} + void ext4l_close(void) { if (ext4l_open_dirs > 0) diff --git a/fs/fs_legacy.c b/fs/fs_legacy.c index 7d293468ea8..849c0304668 100644 --- a/fs/fs_legacy.c +++ b/fs/fs_legacy.c @@ -266,7 +266,7 @@ static struct fstype_info fstypes[] = { .probe = ext4l_probe, .close = ext4l_close, .ls = ext4l_ls, - .exists = fs_exists_unsupported, + .exists = ext4l_exists, .size = fs_size_unsupported, .read = fs_read_unsupported, .write = fs_write_unsupported, diff --git a/include/ext4l.h b/include/ext4l.h index 6d8eba84f4e..23d53b30d9e 100644 --- a/include/ext4l.h +++ b/include/ext4l.h @@ -38,6 +38,14 @@ void ext4l_close(void); */ int ext4l_ls(const char *dirname); +/** + * ext4l_exists() - Check if a file or directory exists + * + * @filename: Path to check + * Return: 1 if exists, 0 if not + */ +int ext4l_exists(const char *filename); + /** * ext4l_get_uuid() - Get the filesystem UUID * diff --git a/test/fs/ext4l.c b/test/fs/ext4l.c index d9ed21407e7..79813375ff1 100644 --- a/test/fs/ext4l.c +++ b/test/fs/ext4l.c @@ -196,3 +196,30 @@ static int fs_test_ext4l_opendir_norun(struct unit_test_state *uts) } FS_TEST_ARGS(fs_test_ext4l_opendir_norun, UTF_SCAN_FDT | UTF_CONSOLE | UTF_MANUAL, { "fs_image", UT_ARG_STR }); + +/** + * fs_test_ext4l_exists_norun() - Test ext4l_exists function + * + * Verifies that ext4l_exists correctly reports file existence. + * + * Arguments: + * fs_image: Path to the ext4 filesystem image + */ +static int fs_test_ext4l_exists_norun(struct unit_test_state *uts) +{ + const char *fs_image = ut_str(EXT4L_ARG_IMAGE); + + ut_assertnonnull(fs_image); + ut_assertok(run_commandf("host bind 0 %s", fs_image)); + ut_assertok(fs_set_blk_dev("host", "0", FS_TYPE_ANY)); + + /* Test existing directory */ + ut_asserteq(1, ext4l_exists("/")); + + /* Test non-existent paths */ + ut_asserteq(0, ext4l_exists("/no/such/path")); + + return 0; +} +FS_TEST_ARGS(fs_test_ext4l_exists_norun, UTF_SCAN_FDT | UTF_CONSOLE | + UTF_MANUAL, { "fs_image", UT_ARG_STR }); diff --git a/test/py/tests/test_fs/test_ext4l.py b/test/py/tests/test_fs/test_ext4l.py index 073b02a80ce..890b6aeaef1 100644 --- a/test/py/tests/test_fs/test_ext4l.py +++ b/test/py/tests/test_fs/test_ext4l.py @@ -96,3 +96,10 @@ class TestExt4l: output = ubman.run_command( f'ut -f fs fs_test_ext4l_opendir_norun fs_image={ext4_image}') assert 'failures: 0' in output + + def test_exists(self, ubman, ext4_image): + """Test that ext4l_exists reports file existence correctly.""" + with ubman.log.section('Test ext4l exists'): + output = ubman.run_command( + f'ut -f fs fs_test_ext4l_exists_norun fs_image={ext4_image}') + assert 'failures: 0' in output