From patchwork Sat Dec 27 20:43:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1088 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=1766868278; bh=QvEaVXnlXNcJFkuHsROglpYl4LWDSJb4ErR6QQ2rT+o=; 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=f7Au1YDKDSzdK6onj9vTVAVDn50OBxIYdWsBMY+clIY226P5+0nk+34MgYUlQ6TkO PtRyw0d4Mtx2tpf6SQKv4k3io+y/mtGZGN9xADoB27cIneiFWSO0JpxFURYjvWmar0 Jm9czLXvaOFcxVtnMbGGsS9wObfPUNIpYIJ7XHe34umGwTxBk4Ib8G51wKTiQBkGjG a2gTJvyDQtAZ/Bb/0X6A9+YU9gEiSo3LaRxPORojzy+u2iDJy1pmjA0/mQSpil9NUb 3d86Zf0yNXl2NsomvC3djHOvXOOtCR7UXh/Y0RfUSP4a5QlHLsqieWLbrQLXv6doOe po4tQIrzpY+xw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9A8CC64E4D for ; Sat, 27 Dec 2025 13:44:38 -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 WEpSeSoHqLxi for ; Sat, 27 Dec 2025 13:44:38 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1766868278; bh=QvEaVXnlXNcJFkuHsROglpYl4LWDSJb4ErR6QQ2rT+o=; 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=f7Au1YDKDSzdK6onj9vTVAVDn50OBxIYdWsBMY+clIY226P5+0nk+34MgYUlQ6TkO PtRyw0d4Mtx2tpf6SQKv4k3io+y/mtGZGN9xADoB27cIneiFWSO0JpxFURYjvWmar0 Jm9czLXvaOFcxVtnMbGGsS9wObfPUNIpYIJ7XHe34umGwTxBk4Ib8G51wKTiQBkGjG a2gTJvyDQtAZ/Bb/0X6A9+YU9gEiSo3LaRxPORojzy+u2iDJy1pmjA0/mQSpil9NUb 3d86Zf0yNXl2NsomvC3djHOvXOOtCR7UXh/Y0RfUSP4a5QlHLsqieWLbrQLXv6doOe po4tQIrzpY+xw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8A1D068BF3 for ; Sat, 27 Dec 2025 13:44:38 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1766868276; bh=pFE2tFbMHfXA48D9P7YYatTNlfZMtbyrVMQBvnisVKg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d0tf9ADomZEDYxfSL/vZjNSPEsAk+Qgxkj9vdj0wLy+N9SXU0sDzrENLv0Q+zZhz+ PV9SxHWmzYDfZhNFwDMFouJlW/ZevWK5PqcwsWoTAJvtb+Uq6MlVzktpK1yUzU376V hXcD1gZYc2QjmX3XfYHe0wdMinM42isO12ESPD27XSGd+Xn/btvUcuEBk5OhTcIVkM KW+HdbH0jucSHF6RCIgMVHh8/XwL0gnecnDDex7PSe8zDelbxHiPGtYloXB6wmZU5r 4l0KWxJs9sAhcaj2utH2QrOb8vhs9fX/GgJh7pPm/6VDEDbUB4Z3bz/1MEVdV4o+Iw rVcFOwB3luD5Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D663464E4D; Sat, 27 Dec 2025 13:44:36 -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 G2GqNPTPf99I; Sat, 27 Dec 2025 13:44:36 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1766868271; bh=3LvVHyUUNWi0guv0wQgFubqJidkmfxlIyjqon3GobsI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m6TY+e5qf5j0MrWc1fLjt5oqy0Y/dWI0dcrUEMLib381ez8pt2iKw/eDxIGs4FaD9 zT3ya0CGBNiFesFpWZmkGih/h7n4jjlbbbflR8Zm88eOeRA2PONa2YsypNMa3kDLBz jHMBlYCV/fMLink/FXE7umePqwK0EeggQeVUnUutnXsde7DvV4LATjGc4AhShHGCUS GTHzD12LidvPxU7AgKP4d/NtgT8GYAXaRkmCD3PQ048Yhl7oJY4fufnOxkPL7cqICW u5+0JfWCHqy0M8Z4tkp9j05/mW28ASobpYaksQxigjq7kay3NQINqPHIddxZCuOxDv BfjBmmFk7+jqA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 9066364E1F; Sat, 27 Dec 2025 13:44:30 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 27 Dec 2025 13:43:06 -0700 Message-ID: <20251227204318.886983-12-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: MHNW2OGZB6OSQWTSZD2LLS5NXYGCWDWW X-Message-ID-Hash: MHNW2OGZB6OSQWTSZD2LLS5NXYGCWDWW 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 , Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 11/16] ext4l: Add size() 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 ext4l_size() function to retrieve the size of a file or directory. Wire it into the filesystem operations table in fs_legacy.c. Signed-off-by: Simon Glass Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/interface.c | 14 ++++++++++++ fs/fs_legacy.c | 2 +- include/ext4l.h | 9 ++++++++ test/fs/ext4l.c | 34 +++++++++++++++++++++++++++++ test/py/tests/test_fs/test_ext4l.py | 7 ++++++ 5 files changed, 65 insertions(+), 1 deletion(-) diff --git a/fs/ext4l/interface.c b/fs/ext4l/interface.c index 409a3ff7edc..17648a59077 100644 --- a/fs/ext4l/interface.c +++ b/fs/ext4l/interface.c @@ -649,6 +649,20 @@ int ext4l_exists(const char *filename) return 1; } +int ext4l_size(const char *filename, loff_t *sizep) +{ + struct inode *inode; + int ret; + + ret = ext4l_resolve_path(filename, &inode); + if (ret) + return ret; + + *sizep = inode->i_size; + + return 0; +} + void ext4l_close(void) { if (ext4l_open_dirs > 0) diff --git a/fs/fs_legacy.c b/fs/fs_legacy.c index 849c0304668..5edc35c4cdb 100644 --- a/fs/fs_legacy.c +++ b/fs/fs_legacy.c @@ -267,7 +267,7 @@ static struct fstype_info fstypes[] = { .close = ext4l_close, .ls = ext4l_ls, .exists = ext4l_exists, - .size = fs_size_unsupported, + .size = ext4l_size, .read = fs_read_unsupported, .write = fs_write_unsupported, .uuid = fs_uuid_unsupported, diff --git a/include/ext4l.h b/include/ext4l.h index 23d53b30d9e..6fee701f335 100644 --- a/include/ext4l.h +++ b/include/ext4l.h @@ -46,6 +46,15 @@ int ext4l_ls(const char *dirname); */ int ext4l_exists(const char *filename); +/** + * ext4l_size() - Get the size of a file + * + * @filename: Path to file + * @sizep: Returns the file size + * Return: 0 on success, negative on error + */ +int ext4l_size(const char *filename, loff_t *sizep); + /** * ext4l_get_uuid() - Get the filesystem UUID * diff --git a/test/fs/ext4l.c b/test/fs/ext4l.c index 79813375ff1..f58a91893cc 100644 --- a/test/fs/ext4l.c +++ b/test/fs/ext4l.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -223,3 +224,36 @@ static int fs_test_ext4l_exists_norun(struct unit_test_state *uts) } FS_TEST_ARGS(fs_test_ext4l_exists_norun, UTF_SCAN_FDT | UTF_CONSOLE | UTF_MANUAL, { "fs_image", UT_ARG_STR }); + +/** + * fs_test_ext4l_size_norun() - Test ext4l_size function + * + * Verifies that ext4l_size correctly reports file size. + * + * Arguments: + * fs_image: Path to the ext4 filesystem image + */ +static int fs_test_ext4l_size_norun(struct unit_test_state *uts) +{ + const char *fs_image = ut_str(EXT4L_ARG_IMAGE); + loff_t size; + + 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 root directory size - one block on a 4K block filesystem */ + ut_assertok(ext4l_size("/", &size)); + ut_asserteq(SZ_4K, size); + + /* Test file size - testfile.txt contains "hello world\n" */ + ut_assertok(ext4l_size("/testfile.txt", &size)); + ut_asserteq(12, size); + + /* Test non-existent path returns -ENOENT */ + ut_asserteq(-ENOENT, ext4l_size("/no/such/path", &size)); + + return 0; +} +FS_TEST_ARGS(fs_test_ext4l_size_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 890b6aeaef1..922fa37a7d8 100644 --- a/test/py/tests/test_fs/test_ext4l.py +++ b/test/py/tests/test_fs/test_ext4l.py @@ -103,3 +103,10 @@ class TestExt4l: output = ubman.run_command( f'ut -f fs fs_test_ext4l_exists_norun fs_image={ext4_image}') assert 'failures: 0' in output + + def test_size(self, ubman, ext4_image): + """Test that ext4l_size reports file size correctly.""" + with ubman.log.section('Test ext4l size'): + output = ubman.run_command( + f'ut -f fs fs_test_ext4l_size_norun fs_image={ext4_image}') + assert 'failures: 0' in output