From patchwork Fri Apr 3 14:04:35 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2098 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=1775225174; bh=yho+J91aUwL4r/nT38eSi4bMHsL7knbiU9n7BeF/9Mg=; 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=E5mtbhEdzqrVbe8sYR9z8qVvoplFaAYZk7OekaNUmwbbd8NrAKw0E8e47q2XwL9g+ Mix6ZSK1WtbxrC7d6P2FCe/cVahrn9IzP2K5fzvoCrft9itsYPnhTkqoN5WpaEpqxN G8ify0oTvS4Vrd+6pZIaNRbpm64xGHTdugICHJDG//3k3WlZg+fsOVwpkj5TS25lSD s0ruNpOKxtadCpaDwviDFGuPxqscCc120pgZu827jksMGOxd7OBwnK/xSRrGyfw1mF r7BsP0lgYjB1XW5tkDrVta6ESDNFEawOi7satPGq84voUG2HqdlVSdaJ2pzRfK92bY 25y2AACcP2Hcg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id F29276A36B for ; Fri, 3 Apr 2026 08:06:14 -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 1XfK_EB1wM5Z for ; Fri, 3 Apr 2026 08:06:14 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775225171; bh=yho+J91aUwL4r/nT38eSi4bMHsL7knbiU9n7BeF/9Mg=; 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=uNQzXPCd6Ae5HwqHTaNb6gS92Mo9r8v455SQLO2ugiyjpmdZCbiz7o5mZtW6e2ZOx JglVAhLuU5MSkSFO0y6lV/HXiJcqM0GWuxoXDMFIL2SO9A8/Jl2AhdDs2Z2Z0hiq0Y qCaaUw2ISTMmolY1ccONq0S8a2yzUvspSG1MGyxyDfumN95IY/xqRhLrxLMj/PAYz6 tlBaZpCF29+cjhgDpiFDo9IgzYhg7m97dPV+5GkyYjObJ1MYYpIIq+kjkte/iOcZDY OPjmsB0jhFp26I2y/RgnvuWJnmXgGHF9sda2sIB2L5KzoaEwFJfRlo2I6LJOSdWTkk rb4pIQRGUQzSQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0E78A6A36E for ; Fri, 3 Apr 2026 08:06:11 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775225167; bh=XSJiIcEROdk9J+oLtuwnmd+ovcbU7+rPZ27fN+zpSoQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ddbZWB1e+hl9CKab/eYOWpKM5l93m+r8XZOSFFBGYz7/7inGmYeEYckcPUtFyrZH0 feJKWsQMD2HS6Zfcb3KRR5dtb6O5K1dsOXmHpyFzA5ieBtJmOUsIodVqx882XASTKL whB+n3dvoCG+LKhi56D/q9ewjU0EYyjR8MePKB1sMa30zDYFE9mGcgeePN9HSrzOkG 3v/GhgPOwLvv/7t02Bm2/PNnntE1MqL4nh6gQG05+Ng8MrcbM+xN5X+hzzH4+8y8lz bQGphKd8B37OmZND1+gA7zx9ldJ9ScUEeK7elx4KXjAutDoI+lVbxOLCvmKZ9DH05b vmGdSrbgWBYCg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 250D46A34C; Fri, 3 Apr 2026 08:06:07 -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 C5d0-fDmS5EG; Fri, 3 Apr 2026 08:06:07 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775225164; bh=CM8vn6uHa6ez9ecKbNbxypFhF3j3pvHqWN1P0LBjKv8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gTxcIe9gXBgxJ9R0SbioqhvNu2C1HV6QV4STgjd6PO1CrbShyYv2R/LNy+Jk+O0R4 7V3hjPaTZK6EVZbY6QLxinqpT2vhcCQJgiSVZ2dP6WV3P1f/4pHAc42ZvLefymmwSl BirEeK/pFKIhBYQvRT9HzaoxCG1Bw2xI55GyXynCVSTmRnpEsk/D9WPjMfzBkD21Hw sDlF8qvbDZgiVmP8tbeb2yY541OpoloEkJ2K6gXpL32QAe+8YhlfbfFBBfOAR7+nLr w1P3vRQrLqFr2HQTk/Y+WOytM5XE4TfPJjnrDvZaT2N4PSwgTIgJq7yBugte6XVt66 jp4wYO7fP3UBA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id A7CBB6A35D; Fri, 3 Apr 2026 08:06:04 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Fri, 3 Apr 2026 08:04:35 -0600 Message-ID: <20260403140523.1998228-14-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: C57R5C2Z2PCAX72SEZRUZTKLADUETIQH X-Message-ID-Hash: C57R5C2Z2PCAX72SEZRUZTKLADUETIQH 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 13/34] vfs: Add vfs_open_file() to open a file by path 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 vfs_open_file() which resolves an absolute VFS path to a UCLASS_FILE device in one call, replacing the repeated sequence of vfs_find_mount / fs_split_path / fs_lookup_dir / dir_open_file. Signed-off-by: Simon Glass --- fs/vfs.c | 35 +++++++++++++++++++++++++++++++++++ include/vfs.h | 16 ++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/fs/vfs.c b/fs/vfs.c index e05a02ad5b0..f06844f2a33 100644 --- a/fs/vfs.c +++ b/fs/vfs.c @@ -331,6 +331,41 @@ void vfs_print_mounts(void) } } +int vfs_open_file(const char *path, enum dir_open_flags_t oflags, + struct udevice **filp) +{ + struct udevice *vfs, *mnt, *dir; + const char *subpath, *leaf; + struct vfsmount *mnt_priv; + char *dirpath; + int ret; + + vfs = vfs_root(); + if (!vfs) + return log_msg_ret("voi", -ENXIO); + + ret = vfs_find_mount(vfs, path, &mnt, &subpath); + if (ret) + return log_msg_ret("vom", ret); + + mnt_priv = dev_get_uclass_priv(mnt); + + ret = fs_split_path(subpath, &dirpath, &leaf); + if (ret) + return log_msg_ret("vos", ret); + + ret = fs_lookup_dir(mnt_priv->target, dirpath, &dir); + free(dirpath); + if (ret) + return log_msg_ret("vod", ret); + + ret = dir_open_file(dir, leaf, oflags, filp); + if (ret) + return log_msg_ret("vof", ret); + + return 0; +} + int vfs_ls(const char *path) { struct udevice *vfs, *mnt, *dir = NULL; diff --git a/include/vfs.h b/include/vfs.h index f85f45da4dd..53d1932e861 100644 --- a/include/vfs.h +++ b/include/vfs.h @@ -11,6 +11,8 @@ #ifndef __VFS_H #define __VFS_H +#include + struct udevice; /** @@ -136,4 +138,18 @@ void vfs_print_mounts(void); */ int vfs_ls(const char *path); +/** + * vfs_open_file() - Open a file by absolute VFS path + * + * Resolves the path through the mount tree, splits into directory and leaf, + * then opens the file. + * + * @path: Absolute VFS path to the file + * @oflags: Open flags (DIR_O_RDONLY, DIR_O_WRONLY, DIR_O_RDWR) + * @filp: Returns the UCLASS_FILE device + * Return: 0 if OK, -ve on error + */ +int vfs_open_file(const char *path, enum dir_open_flags_t oflags, + struct udevice **filp); + #endif