From 83b116e96f7cfe6a6ef5cd1df119910482e2ff39 Mon Sep 17 00:00:00 2001 From: Richard Genoud Date: Tue, 3 Nov 2020 12:11:26 +0100 Subject: [PATCH] fs/squashfs: implement exists() function This permits to find a file and use the distro_bootcmd Reviewed-by: Joao Marcos Costa Signed-off-by: Richard Genoud [jh80.chung: cherry picked from mainline commit dd4866b43754b18f0c06672e341d93e16b8bf674] Signed-off-by: Jaehoon Chung Change-Id: Idafbcb37c30445e3731d40924f1c43499f149b1a --- fs/fs.c | 6 ++++++ fs/squashfs/sqfs.c | 38 ++++++++++++++++++++++++++++++++++++++ include/squashfs.h | 1 + 3 files changed, 45 insertions(+) diff --git a/fs/fs.c b/fs/fs.c index 29ad4d1a69..bac17664ee 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -295,6 +295,12 @@ static struct fstype_info fstypes[] = { .size = sqfs_size, .close = sqfs_close, .closedir = sqfs_closedir, + .exists = sqfs_exists, + .uuid = fs_uuid_unsupported, + .write = fs_write_unsupported, + .ln = fs_ln_unsupported, + .unlink = fs_unlink_unsupported, + .mkdir = fs_mkdir_unsupported, }, #endif { diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c index fc4c2bbb60..8064756939 100644 --- a/fs/squashfs/sqfs.c +++ b/fs/squashfs/sqfs.c @@ -1652,6 +1652,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); diff --git a/include/squashfs.h b/include/squashfs.h index 819cf8c2da..7489eefa1f 100644 --- a/include/squashfs.h +++ b/include/squashfs.h @@ -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); -- 2.34.1