Commit 2f15cfd187f1cf7a0606a1ec3e637954311a735a

Authored by Stefan Roese
1 parent b1a14f8a1c

UBI/UBIFS: Automatically unmount UBIFS volume upon UBI partition change

Automatically unmount UBIFS partition when user changes the UBI device.
Otherwise the following UBIFS commands will crash.

Signed-off-by: Stefan Roese <sr@denx.de>

Showing 2 changed files with 35 additions and 6 deletions Side-by-side Diff

... ... @@ -42,6 +42,11 @@
42 42  
43 43 static struct selected_dev ubi_dev;
44 44  
  45 +#ifdef CONFIG_CMD_UBIFS
  46 +int ubifs_is_mounted(void);
  47 +void cmd_ubifs_umount(void);
  48 +#endif
  49 +
45 50 static void ubi_dump_vol_info(const struct ubi_volume *vol)
46 51 {
47 52 ubi_msg("volume information dump:");
... ... @@ -471,6 +476,16 @@
471 476  
472 477 if (argc < 3)
473 478 return cmd_usage(cmdtp);
  479 +
  480 +#ifdef CONFIG_CMD_UBIFS
  481 + /*
  482 + * Automatically unmount UBIFS partition when user
  483 + * changes the UBI device. Otherwise the following
  484 + * UBIFS commands will crash.
  485 + */
  486 + if (ubifs_is_mounted())
  487 + cmd_ubifs_umount();
  488 +#endif
474 489  
475 490 /* todo: get dev number for NAND... */
476 491 ubi_dev.nr = 0;
... ... @@ -72,6 +72,25 @@
72 72 return 0;
73 73 }
74 74  
  75 +int ubifs_is_mounted(void)
  76 +{
  77 + return ubifs_mounted;
  78 +}
  79 +
  80 +void cmd_ubifs_umount(void)
  81 +{
  82 +
  83 + if (ubifs_sb) {
  84 + printf("Unmounting UBIFS volume %s!\n",
  85 + ((struct ubifs_info *)(ubifs_sb->s_fs_info))->vi.name);
  86 + ubifs_umount(ubifs_sb->s_fs_info);
  87 + }
  88 +
  89 + ubifs_sb = NULL;
  90 + ubifs_mounted = 0;
  91 + ubifs_initialized = 0;
  92 +}
  93 +
75 94 int do_ubifs_umount(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
76 95 {
77 96 if (argc != 1)
... ... @@ -82,12 +101,7 @@
82 101 return -1;
83 102 }
84 103  
85   - if (ubifs_sb)
86   - ubifs_umount(ubifs_sb->s_fs_info);
87   -
88   - ubifs_sb = NULL;
89   - ubifs_mounted = 0;
90   - ubifs_initialized = 0;
  104 + cmd_ubifs_umount();
91 105  
92 106 return 0;
93 107 }