diff options
author | Richard Genoud <richard.genoud@posteo.net> | 2020-11-03 14:11:26 +0300 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2020-11-19 17:45:49 +0300 |
commit | dd4866b43754b18f0c06672e341d93e16b8bf674 (patch) | |
tree | c551b408e9b714348c1f4f34b14a23d4641021b8 /fs/squashfs/sqfs.c | |
parent | 21b1b3bad58b50e5464b1bf016e7c96bf18ddb8d (diff) | |
download | u-boot-dd4866b43754b18f0c06672e341d93e16b8bf674.tar.xz |
fs/squashfs: implement exists() function
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>
Diffstat (limited to 'fs/squashfs/sqfs.c')
-rw-r--r-- | fs/squashfs/sqfs.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c index 80a85e76e8..608a2bb454 100644 --- a/fs/squashfs/sqfs.c +++ b/fs/squashfs/sqfs.c @@ -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); |