[U-Boot] [PATCH 4/4] UBI/UBIFS: Prevent UBI partition change while UBIFS is mounted

Stefan Roese sr at denx.de
Thu Oct 28 14:09:36 CEST 2010


Only allow (re-)assignment to an UBI partition/device when UBIFS is
currently not mounted. Otherwise the following UBIFS commands will
crash.

Signed-off-by: Stefan Roese <sr at denx.de>
---
 common/cmd_ubi.c   |   13 +++++++++++++
 common/cmd_ubifs.c |    5 +++++
 2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/common/cmd_ubi.c b/common/cmd_ubi.c
index 7692ac7..1e73f48 100644
--- a/common/cmd_ubi.c
+++ b/common/cmd_ubi.c
@@ -42,6 +42,8 @@ struct selected_dev {
 
 static struct selected_dev ubi_dev;
 
+int ubifs_is_mounted(void);
+
 static void ubi_dump_vol_info(const struct ubi_volume *vol)
 {
 	ubi_msg("volume information dump:");
@@ -472,6 +474,17 @@ static int do_ubi(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
 		if (argc < 3)
 			return cmd_usage(cmdtp);
 
+		/*
+		 * Only allow (re-)assignment to an UBI partition/device
+		 * when UBIFS is currently not mounted. Otherwise
+		 * the following UBIFS commands will crash.
+		 */
+		if (ubifs_is_mounted()) {
+			printf("UBIFS is currently mounted!"
+			       " Unmount using ubifsumount first!\n");
+			return -EPERM;
+		}
+
 		/* todo: get dev number for NAND... */
 		ubi_dev.nr = 0;
 
diff --git a/common/cmd_ubifs.c b/common/cmd_ubifs.c
index 9526780..76fe057 100644
--- a/common/cmd_ubifs.c
+++ b/common/cmd_ubifs.c
@@ -92,6 +92,11 @@ int do_ubifs_umount(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	return 0;
 }
 
+int ubifs_is_mounted(void)
+{
+	return ubifs_mounted;
+}
+
 int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	char *filename = "/";
-- 
1.7.3.2



More information about the U-Boot mailing list