From patchwork Sat Dec 27 20:43:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1091 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=1766868291; bh=qNSQJw0JNK7lEWGlRDJ3jQgTQUMZKw0hrPnD0o/cZXI=; 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=rPsYG3TiiMQeNXI6H6dnDFWJ5e5jsWEezwEAo55OtQIZggJ5qrrHb6ZMd71SxF5Ye YoI7RKoPNRHkpXmZ1tirwwjthve40kc9CZ7eV66bsloj28RBL1t92zevhhtei4gWAB 6iV1SNB1LUv9lizk/SVXjKa3OxwTgLIvUKpZI0My3iBJyiDSdcZ15hC9kAxRH6bR5J iBprwA8kt5cqUDUM6mXOxRKXFlFPQqOGrpJ2rNRH3iCV8rjXhD83NCewExzka+ONTF As8j8gshKBA5C+Lz1ocFx5ciJNzJshgs42C6kxW4nqnlDOF1Gj/zrJXCcRJi0h5myB imLNQauwq0qEg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1F20E68C3F for ; Sat, 27 Dec 2025 13:44:51 -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 V_wTObKBppJa for ; Sat, 27 Dec 2025 13:44:51 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1766868291; bh=qNSQJw0JNK7lEWGlRDJ3jQgTQUMZKw0hrPnD0o/cZXI=; 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=rPsYG3TiiMQeNXI6H6dnDFWJ5e5jsWEezwEAo55OtQIZggJ5qrrHb6ZMd71SxF5Ye YoI7RKoPNRHkpXmZ1tirwwjthve40kc9CZ7eV66bsloj28RBL1t92zevhhtei4gWAB 6iV1SNB1LUv9lizk/SVXjKa3OxwTgLIvUKpZI0My3iBJyiDSdcZ15hC9kAxRH6bR5J iBprwA8kt5cqUDUM6mXOxRKXFlFPQqOGrpJ2rNRH3iCV8rjXhD83NCewExzka+ONTF As8j8gshKBA5C+Lz1ocFx5ciJNzJshgs42C6kxW4nqnlDOF1Gj/zrJXCcRJi0h5myB imLNQauwq0qEg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0E72164E4D for ; Sat, 27 Dec 2025 13:44:51 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1766868289; bh=fNQOeu1i7uPtDJPh7QioG6tteHaVihVrKOFrVjOH0Bg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q/byhpBXZ8KieHR+PXq2BKspTIO+6DNuIiCoI0YKm2UOd+tO9VGyz2qTsl97WP96b jP+yGa8dDE238Gwby61yM8RZnx0XodDnj2k+/CqsVSzB4gHSXofTXBNnnU4wMk9Q7K DwQLGFUZZJ29uFDMrTGPu3E1nEgDNBVMsjBulW0/J2WsxGBPlpVp/k5kBuG18lelPk v9YrtAiIw57l4MNiVXKpeL1GToSxBFjhG4JVEIeCh4kt+tb4UDrx5lEEEMC6wdwJ/l 6PG9hBLy1X5OYOC33JfErDuelcf9LQsQvw8PV+IsIqK6ILCsx5JGHJxDF55BMJZmxP DCwAiq3KSN/vQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id ACE5064E1F; Sat, 27 Dec 2025 13:44:49 -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 Gb4oK-tKdSBQ; Sat, 27 Dec 2025 13:44:49 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1766868285; bh=5+UDK4uT2g0xoX4etoPaHgAClGbuzWzb7eUSKIsKP+A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=blBtcuSOnO7bql3bQXeyydVLT+woU5f/AkaSnH2lu//IxkPWl/3oqczv7fOBWhfVM ammchPvoF7sFcZkNtfF3yB/fhxS5fl1wl33dQBYoOsSrDNuiFEhK8EHAxZs8dEqnla 3RPdduIHCMa2zciCRGNyDbeIc8BtObddpYTVhc4/4hzRmosQ6nRDfg49Wub1Pj0AA9 2TCzPMEQ3G1SUvTwmItjw+3JUa+Ktm3IcAUWRlRFy6WFC0+iJtIVzyWPsqlfNDaoPf rgTS7N/rNc28HUjy6hEDyOBTY/Dike3g2ikDW5AGKwrTeiXroLwWMeZ5RTxa3ExulR Hfl22/zG+F5FQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 3B2AB64C0C; Sat, 27 Dec 2025 13:44:45 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 27 Dec 2025 13:43:09 -0700 Message-ID: <20251227204318.886983-15-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: SV7DVW3GE2NUDKHWZFZ4DQB5B62I4Q34 X-Message-ID-Hash: SV7DVW3GE2NUDKHWZFZ4DQB5B62I4Q34 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 14/16] fs: Add statfs method to the filesystem interface 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 infrastructure for obtaining filesystem statistics. This includes: - struct fs_statfs to hold block size, total blocks, and free blocks - statfs method in struct fstype_info - fs_statfs() wrapper function - fs_statfs_unsupported() stub for filesystems without support Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/fs_legacy.c | 37 +++++++++++++++++++++++++++++++++++++ include/fs_legacy.h | 21 +++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/fs/fs_legacy.c b/fs/fs_legacy.c index 71f8e56715f..e8a5f8d9672 100644 --- a/fs/fs_legacy.c +++ b/fs/fs_legacy.c @@ -154,6 +154,11 @@ static inline int fs_rename_unsupported(const char *old_path, return -1; } +static inline int fs_statfs_unsupported(struct fs_statfs *stats) +{ + return -1; +} + struct fstype_info { int fstype; char *name; @@ -195,6 +200,13 @@ struct fstype_info { int (*mkdir)(const char *dirname); int (*ln)(const char *filename, const char *target); int (*rename)(const char *old_path, const char *new_path); + + /* + * Get filesystem statistics. On success return 0 and fill stats + * with block size, total blocks, and free blocks. On error + * return -errno. See fs_statfs(). + */ + int (*statfs)(struct fs_statfs *stats); }; static struct fstype_info fstypes[] = { @@ -228,6 +240,7 @@ static struct fstype_info fstypes[] = { #else .rename = fs_rename_unsupported, #endif + .statfs = fs_statfs_unsupported, }, #endif @@ -256,6 +269,7 @@ static struct fstype_info fstypes[] = { .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, .rename = fs_rename_unsupported, + .statfs = fs_statfs_unsupported, }, #endif #if CONFIG_IS_ENABLED(FS_EXT4L) @@ -278,6 +292,7 @@ static struct fstype_info fstypes[] = { .mkdir = fs_mkdir_unsupported, .ln = fs_ln_unsupported, .rename = fs_rename_unsupported, + .statfs = fs_statfs_unsupported, }, #endif #if IS_ENABLED(CONFIG_SANDBOX) && !IS_ENABLED(CONFIG_XPL_BUILD) @@ -298,6 +313,7 @@ static struct fstype_info fstypes[] = { .mkdir = fs_mkdir_unsupported, .ln = fs_ln_unsupported, .rename = fs_rename_unsupported, + .statfs = fs_statfs_unsupported, }, #endif #if CONFIG_IS_ENABLED(SEMIHOSTING) @@ -318,6 +334,7 @@ static struct fstype_info fstypes[] = { .mkdir = fs_mkdir_unsupported, .ln = fs_ln_unsupported, .rename = fs_rename_unsupported, + .statfs = fs_statfs_unsupported, }, #endif #ifndef CONFIG_XPL_BUILD @@ -339,6 +356,7 @@ static struct fstype_info fstypes[] = { .mkdir = fs_mkdir_unsupported, .ln = fs_ln_unsupported, .rename = fs_rename_unsupported, + .statfs = fs_statfs_unsupported, }, #endif #endif @@ -361,6 +379,7 @@ static struct fstype_info fstypes[] = { .mkdir = fs_mkdir_unsupported, .ln = fs_ln_unsupported, .rename = fs_rename_unsupported, + .statfs = fs_statfs_unsupported, }, #endif #endif @@ -384,6 +403,7 @@ static struct fstype_info fstypes[] = { .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, .rename = fs_rename_unsupported, + .statfs = fs_statfs_unsupported, }, #endif #if IS_ENABLED(CONFIG_FS_EROFS) @@ -406,6 +426,7 @@ static struct fstype_info fstypes[] = { .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, .rename = fs_rename_unsupported, + .statfs = fs_statfs_unsupported, }, #endif #if IS_ENABLED(CONFIG_FS_EXFAT) @@ -428,6 +449,7 @@ static struct fstype_info fstypes[] = { .unlink = exfat_fs_unlink, .mkdir = exfat_fs_mkdir, .rename = exfat_fs_rename, + .statfs = fs_statfs_unsupported, }, #endif #if CONFIG_IS_ENABLED(VIRTIO_FS) @@ -450,6 +472,7 @@ static struct fstype_info fstypes[] = { .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, .rename = fs_rename_unsupported, + .statfs = fs_statfs_unsupported, }, #endif { @@ -469,6 +492,7 @@ static struct fstype_info fstypes[] = { .mkdir = fs_mkdir_unsupported, .ln = fs_ln_unsupported, .rename = fs_rename_unsupported, + .statfs = fs_statfs_unsupported, }, }; @@ -624,6 +648,19 @@ int fs_size(const char *filename, loff_t *size) return ret; } +int fs_statfs(struct fs_statfs *stats) +{ + int ret; + + struct fstype_info *info = fs_get_info(fs_type); + + ret = info->statfs(stats); + + fs_close(); + + return ret; +} + #if CONFIG_IS_ENABLED(LMB) /* Check if a file may be read to the given address */ static int fs_read_lmb_check(const char *filename, ulong addr, loff_t offset, diff --git a/include/fs_legacy.h b/include/fs_legacy.h index f1be6fbdc13..331a15cf7bd 100644 --- a/include/fs_legacy.h +++ b/include/fs_legacy.h @@ -172,6 +172,27 @@ struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs); */ void fs_closedir(struct fs_dir_stream *dirs); +/** + * struct fs_statfs - filesystem statistics + * + * @bsize: block size + * @blocks: total blocks + * @bfree: free blocks + */ +struct fs_statfs { + ulong bsize; + u64 blocks; + u64 bfree; +}; + +/** + * fs_statfs - Get filesystem statistics + * + * @stats: pointer to struct fs_statfs to fill + * Return: 0 on success, -1 on error + */ +int fs_statfs(struct fs_statfs *stats); + /** * fs_unlink - delete a file or directory *