[U-Boot] [PATCH 2/3] ubifs: Add a ubifsexists command

Hans de Goede hdegoede at redhat.com
Thu Aug 20 18:04:14 CEST 2015


Add a ubifsexists command to check whether a file exists on an ubifs volume.

This is useful for use in standardized bootscripts, such as the scripts
from include/config_distro_bootcmd.h.

Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 common/cmd_ubifs.c | 23 +++++++++++++++++++++++
 fs/ubifs/ubifs.c   | 12 ++++++++++++
 fs/ubifs/ubifs.h   |  1 +
 3 files changed, 36 insertions(+)

diff --git a/common/cmd_ubifs.c b/common/cmd_ubifs.c
index 8e9a4e5..1a54ba0 100644
--- a/common/cmd_ubifs.c
+++ b/common/cmd_ubifs.c
@@ -145,6 +145,22 @@ static int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc,
 	return ret;
 }
 
+int do_ubifs_exists(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	if (!ubifs_mounted) {
+		printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
+		return -1;
+	}
+
+	if (argc != 2)
+		return CMD_RET_USAGE;
+
+	if (!ubifs_exists(argv[1]))
+		return CMD_RET_FAILURE;
+
+	return 0;
+}
+
 U_BOOT_CMD(
 	ubifsmount, 2, 0, do_ubifs_mount,
 	"mount UBIFS volume",
@@ -171,3 +187,10 @@ U_BOOT_CMD(
 	"<addr> <filename> [bytes]\n"
 	"    - load file 'filename' to address 'addr'"
 );
+
+U_BOOT_CMD(
+	ubifsexists, 2, 0, do_ubifs_exists,
+	"check file exists on an UBIFS filesystem",
+	"<filename>\n"
+	"    - check 'filename' exists"
+);
diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c
index 6dd6174..2ef6ab8 100644
--- a/fs/ubifs/ubifs.c
+++ b/fs/ubifs/ubifs.c
@@ -857,3 +857,15 @@ out:
 	ubi_close_volume(c->ubi);
 	return err;
 }
+
+int ubifs_exists(char *filename)
+{
+	struct ubifs_info *c = ubifs_sb->s_fs_info;
+	unsigned long inum;
+
+	c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READONLY);
+	inum = ubifs_findfile(ubifs_sb, filename);
+	ubi_close_volume(c->ubi);
+
+	return inum != 0;
+}
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h
index a51b237..070fcde 100644
--- a/fs/ubifs/ubifs.h
+++ b/fs/ubifs/ubifs.h
@@ -2385,5 +2385,6 @@ int uboot_ubifs_mount(char *vol_name);
 void ubifs_umount(struct ubifs_info *c);
 int ubifs_ls(char *dir_name);
 int ubifs_load(char *filename, u32 addr, u32 size);
+int ubifs_exists(char *filename);
 #endif
 #endif /* !__UBIFS_H__ */
-- 
2.4.3



More information about the U-Boot mailing list