
From: Simon Glass <sjg@chromium.org> At present a new directory device is created for every access to a directory. This means that a new device is always created when 'ls' is used. Where the directory being accessed matches an existing device, this is not necessary. Check that path against existing directories and reuse the device if possible. Signed-off-by: Simon Glass <sjg@chromium.org> --- fs/fs-uclass.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/fs/fs-uclass.c b/fs/fs-uclass.c index 96fb04a106c..a335391bd74 100644 --- a/fs/fs-uclass.c +++ b/fs/fs-uclass.c @@ -9,6 +9,7 @@ #include <bootdev.h> #include <bootmeth.h> +#include <dir.h> #include <dm.h> #include <fs.h> #include <dm/device-internal.h> @@ -41,8 +42,35 @@ int fs_split_path(const char *fname, char **subdirp, const char **leafp) int fs_lookup_dir(struct udevice *dev, const char *path, struct udevice **dirp) { struct fs_ops *ops = fs_get_ops(dev); + struct udevice *dir; + int ret; + + if (!path || !strcmp("/", path)) + path = ""; + + /* see if we already have this directory */ + device_foreach_child(dir, dev) { + struct dir_uc_priv *priv; + + if (!device_active(dir)) + continue; + + priv = dev_get_uclass_priv(dir); + log_debug("dir %s '%s' '%s'\n", dir->name, path, priv->path); + if (!strcmp(path, priv->path)) { + *dirp = dir; + log_debug("found: dev '%s'\n", dir->name); + return 0; + } + } + + ret = ops->lookup_dir(dev, path, &dir); + if (ret) + return log_msg_ret("fld", ret); - return ops->lookup_dir(dev, path, dirp); + *dirp = dir; + + return 0; } int fs_mount(struct udevice *dev) -- 2.43.0 base-commit: 41d10e0f8b88ed7fabd6c95cc129bf52fed080a7 branch: virt