From patchwork Fri Apr 3 14:04:49 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2110 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=1775225204; bh=sZjOQAorUueDvWOr53c34XYGtJIVSmxM5T3rGB7710g=; 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=GI5UvTHoajxlCH7CJyYKIxpsJw+FXPZiHgENBMT4l06EJdkFDRzgC3W1mksh2FOA2 7D2kbhtxvHHBLiIrxuubO0L6yJxrJhTdxG0+lzcf5kXBnZK8Vk4HU+5oZp1wtuLcWd shPlMk39eIOH64U6o//u0Fk74MP15itzAZfjLXJ1HqaVD16V75dqSg6b2sa8+vaW1A lelTK6v/yUf3frocLrRASKIEDu9V6BdZncpiTKw90KtjIudVafv4KUe2e7vKZxZs7R FcGlnCbGj7iSdaZTKG9S24f7IP/ooKSVhWn7b0XKRkhxyiu43jdzxTrw2mFwXYBeID bu6osZY04vACw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C4B546A376 for ; Fri, 3 Apr 2026 08:06:44 -0600 (MDT) 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 RGftsP1MM7bg for ; Fri, 3 Apr 2026 08:06:44 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775225202; bh=sZjOQAorUueDvWOr53c34XYGtJIVSmxM5T3rGB7710g=; 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=V6N/8oiHfJRcVKyb1Yy3Wp74kZjUWi49CVwJxFoEmob3Z887yDnAVODrX4X8h4jhx FXxT6NPxyfUw/QhVtw/gtjRZl+VlhZquEhsQOAlE1ncdX0qP1U9VF273+E0cbTuGR6 ozQ44MJjaO0xqK8RjgQC/s+nj5eqCSB8BDPPI1fHpGmJLofUcXvcx98/9Ecs1ge4oO thFi3poSs90MKVbz3KhpiqTEoVBFI/Ys0AvCFKr3HjfxJUeP0XjbUUAh+v+84V+PCW WmVWIso/xz+07rKAR3jMx/vw4mBe67aToCknTSF0XUWkgY00ql7NEIHeJLD0NFdaAo ziskymtIQnqFw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BE65E6A362 for ; Fri, 3 Apr 2026 08:06:42 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775225200; bh=aYpMmAgIr0xMwOD/cJerMUfR+lFWcOY2/uEm0JB4fHs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ELQyCGQvZRVYHJRJsuhE/if9s3F07wNLJkTngbHJfz5lW6l3wGjbofQbV4fZ8q3b1 x4lVW8HMBg2Rgc9WqulNXXXgfqSgaEO8Zeux4fkLHEFuP2BbPcvcwSJsmxpnkvPoPi wOQQiZJ5YOKXHcOTc+TzNlFanqK7Xxmrs13UCMjmNscgKvpq42XdDp4hLyR1F5Ng4q A20TP1o5sLXbDe4VY38IBFfaijTpaTiAv+xzbu9d3u+sVwKqYq2Ev97+5qBU5+DEYW 0yC0Y44yOiD5eBd5a+u3A+CKwxBy9seGVQY/s9/KDzzi5g/LuwPZKwesgckq2DPgG7 RmPqHTPviZsEQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 89A476A34C; Fri, 3 Apr 2026 08:06:40 -0600 (MDT) 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 gIIC6SEGSvkI; Fri, 3 Apr 2026 08:06:40 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775225197; bh=luhfssFOhjd2d9Gs4kotcDoeygkrzBSLeca9jrTdDvA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HRHO3jZd+boGA8f0/6ohQIvDzqm/eMDIftD1ixIMho2z/weeu2bjTOpTBlO47069+ 5c3uHf1Gk2lpHXnlt3U0093gyLutDtaTC+XLiUgkfhp2GBF52IRzNcnuWBNGVm9GNY WiQ3JC/MDe3tP+MvIW6AU0RXCTw3Er6PkrYMMFx6IYe9sVWf0UIDNx/wK04XviYlnT sn8VDusxPyVY4GHurlhMpXriz79OkvUprjq/QZ60BLG0thJA87dm8WBNZNXc02f2cO H84gURQn4Y0g0F1PJ/dBPXb8J6YmY963+8Up3fsnKdUSpszyU/QA2CVJtxacogq0ck PRKzxNe7J1rqg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 2908467EE6; Fri, 3 Apr 2026 08:06:37 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Fri, 3 Apr 2026 08:04:49 -0600 Message-ID: <20260403140523.1998228-28-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260403140523.1998228-1-sjg@u-boot.org> References: <20260403140523.1998228-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 77G6G3GF336S2YU2MGCLDCEZM4NBNWAG X-Message-ID-Hash: 77G6G3GF336S2YU2MGCLDCEZM4NBNWAG 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 27/34] cmd: Add VFS file and directory tests to the test command 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 -f and -d operators to the test command when VFS is enabled. These use vfs_stat() to check whether a path is a regular file (-f) or a directory (-d), complementing the existing -e operator which uses the legacy filesystem interface. Signed-off-by: Simon Glass --- cmd/test.c | 24 ++++++++++++++++++++++++ test/dm/fs.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/cmd/test.c b/cmd/test.c index 6ff7adf2074..93e654a8597 100644 --- a/cmd/test.c +++ b/cmd/test.c @@ -6,6 +6,8 @@ #include #include +#include +#include #include #include #include @@ -29,6 +31,8 @@ #define OP_INT_GE 15 #define OP_FILE_EXISTS 16 #define OP_REGEX 17 +#define OP_VFS_FILE 18 +#define OP_VFS_DIR 19 const struct { int arg; @@ -52,6 +56,10 @@ const struct { {0, "-z", OP_STR_EMPTY, 2}, {0, "-n", OP_STR_NEMPTY, 2}, {0, "-e", OP_FILE_EXISTS, 4}, +#if IS_ENABLED(CONFIG_VFS) + {0, "-f", OP_VFS_FILE, 2}, + {0, "-d", OP_VFS_DIR, 2}, +#endif #ifdef CONFIG_REGEX {1, "=~", OP_REGEX, 3}, #endif @@ -147,6 +155,22 @@ static int do_test(struct cmd_tbl *cmdtp, int flag, int argc, case OP_FILE_EXISTS: expr = file_exists(ap[1], ap[2], ap[3], FS_TYPE_ANY); break; +#if IS_ENABLED(CONFIG_VFS) + case OP_VFS_FILE: { + struct fs_dirent dent; + + expr = !vfs_stat(ap[1], &dent) && + dent.type == FS_DT_REG; + break; + } + case OP_VFS_DIR: { + struct fs_dirent dent; + + expr = !vfs_stat(ap[1], &dent) && + dent.type == FS_DT_DIR; + break; + } +#endif #ifdef CONFIG_REGEX case OP_REGEX: { struct slre slre; diff --git a/test/dm/fs.c b/test/dm/fs.c index 60a0408dd99..e0c7f37e155 100644 --- a/test/dm/fs.c +++ b/test/dm/fs.c @@ -1020,6 +1020,37 @@ static int dm_test_vfs_stat(struct unit_test_state *uts) } DM_TEST(dm_test_vfs_stat, UTF_SCAN_FDT); +/* Test the -f and -d operators in the test command */ +static int dm_test_vfs_test_fd(struct unit_test_state *uts) +{ + ut_assertok(vfs_init()); + + ut_assertok(run_command("mount hostfs /host", 0)); + ut_assert_console_end(); + + /* -f should succeed for a regular file */ + ut_assertok(run_command("test -f /host/README", 0)); + + /* -f should fail for a directory */ + ut_asserteq(1, run_command("test -f /host/cmd", 0)); + + /* -d should succeed for a directory */ + ut_assertok(run_command("test -d /host/cmd", 0)); + + /* -d should fail for a regular file */ + ut_asserteq(1, run_command("test -d /host/README", 0)); + + /* Both should fail for non-existent paths */ + ut_asserteq(1, run_command("test -f /host/no-such-file", 0)); + ut_asserteq(1, run_command("test -d /host/no-such-dir", 0)); + + ut_assertok(run_command("umount /host", 0)); + ut_assert_console_end(); + + return 0; +} +DM_TEST(dm_test_vfs_test_fd, UTF_SCAN_FDT); + /* Test the cat command via VFS */ static int dm_test_vfs_cat(struct unit_test_state *uts) {