]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
fs/squashfs: implement exists() function
authorRichard Genoud <richard.genoud@posteo.net>
Tue, 3 Nov 2020 11:11:26 +0000 (12:11 +0100)
committerTom Rini <trini@konsulko.com>
Thu, 19 Nov 2020 14:45:49 +0000 (09:45 -0500)
This permits to find a file and use the distro_bootcmd

Reviewed-by: Joao Marcos Costa <jmcosta944@gmail.com>
Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
fs/fs.c
fs/squashfs/sqfs.c
include/squashfs.h

diff --git a/fs/fs.c b/fs/fs.c
index fb27c910d4f66ba1f1ff85a7e4033030bdfca7bc..7a4020607a3950e76ca46f53dbc4aa6296f2b55d 100644 (file)
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -296,7 +296,7 @@ static struct fstype_info fstypes[] = {
                .size = sqfs_size,
                .close = sqfs_close,
                .closedir = sqfs_closedir,
-               .exists = fs_exists_unsupported,
+               .exists = sqfs_exists,
                .uuid = fs_uuid_unsupported,
                .write = fs_write_unsupported,
                .ln = fs_ln_unsupported,
index 80a85e76e8a1b7e078c53099909d3d786ff65697..608a2bb454c1cf561dc608a80ff46845944df9bf 100644 (file)
@@ -1649,6 +1649,44 @@ free_strings:
        return ret;
 }
 
+int sqfs_exists(const char *filename)
+{
+       struct fs_dir_stream *dirsp = NULL;
+       struct squashfs_dir_stream *dirs;
+       char *dir, *file;
+       struct fs_dirent *dent;
+       int ret;
+
+       sqfs_split_path(&file, &dir, filename);
+       /*
+        * sqfs_opendir will uncompress inode and directory tables, and will
+        * return a pointer to the directory that contains the requested file.
+        */
+       ret = sqfs_opendir(dir, &dirsp);
+       if (ret) {
+               ret = -EINVAL;
+               goto free_strings;
+       }
+
+       dirs = (struct squashfs_dir_stream *)dirsp;
+
+       while (!sqfs_readdir(dirsp, &dent)) {
+               ret = strcmp(dent->name, file);
+               if (!ret)
+                       break;
+               free(dirs->entry);
+               dirs->entry = NULL;
+       }
+
+       sqfs_closedir(dirsp);
+
+free_strings:
+       free(dir);
+       free(file);
+
+       return ret == 0;
+}
+
 void sqfs_close(void)
 {
        free(ctxt.sblk);
index 819cf8c2da8db0e44d8b36f4861626686fc8d171..7489eefa1f2fe2d4b7056fd6403685190cc1a101 100644 (file)
@@ -19,6 +19,7 @@ int sqfs_probe(struct blk_desc *fs_dev_desc,
 int sqfs_read(const char *filename, void *buf, loff_t offset,
              loff_t len, loff_t *actread);
 int sqfs_size(const char *filename, loff_t *size);
+int sqfs_exists(const char *filename);
 void sqfs_close(void);
 void sqfs_closedir(struct fs_dir_stream *dirs);