ubiformat: Cleanly umount and detach the ubi before formating
This was an open fixme for some time. ubiformat does not care about used ubi volumes or attached ubis. This patch adds functionality that umounts all filesystems that are mounted from this nand device. After that the ubi is detached. Then the normal ubiformat code reformats the ubi. If a ubi was detached previously, the code tries to reattach the ubi. Filesystems are not remounted. Signed-off-by: Markus Pargmann <mpa@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
abb8c2703a
commit
d43c5b45ab
|
@ -42,6 +42,7 @@
|
||||||
#include <libbb.h>
|
#include <libbb.h>
|
||||||
#include <libfile.h>
|
#include <libfile.h>
|
||||||
#include <linux/mtd/mtd.h>
|
#include <linux/mtd/mtd.h>
|
||||||
|
#include <linux/mtd/ubi.h>
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
#include <linux/stat.h>
|
#include <linux/stat.h>
|
||||||
#include <linux/log2.h>
|
#include <linux/log2.h>
|
||||||
|
@ -562,6 +563,7 @@ int do_ubiformat(int argc, char *argv[])
|
||||||
struct ubigen_info ui;
|
struct ubigen_info ui;
|
||||||
struct ubi_scan_info *si;
|
struct ubi_scan_info *si;
|
||||||
struct mtd_info_user mtd_user;
|
struct mtd_info_user mtd_user;
|
||||||
|
int ubi_num;
|
||||||
|
|
||||||
err = parse_opt(argc, argv);
|
err = parse_opt(argc, argv);
|
||||||
if (err)
|
if (err)
|
||||||
|
@ -622,8 +624,15 @@ int do_ubiformat(int argc, char *argv[])
|
||||||
goto out_close;
|
goto out_close;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure this MTD device is not attached to UBI */
|
ubi_num = ubi_num_get_by_mtd(mtd_user.mtd);
|
||||||
/* FIXME! Find a proper way to do this in barebox! */
|
if (ubi_num >= 0) {
|
||||||
|
err = ubi_detach(ubi_num);
|
||||||
|
if (err) {
|
||||||
|
sys_errmsg("Cannot detach %d\n", err);
|
||||||
|
goto out_close;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
eb_cnt = mtd_div_by_eb(mtd->size, mtd);
|
eb_cnt = mtd_div_by_eb(mtd->size, mtd);
|
||||||
|
|
||||||
|
@ -759,6 +768,17 @@ int do_ubiformat(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
libscan_ubi_scan_free(si);
|
libscan_ubi_scan_free(si);
|
||||||
|
|
||||||
|
/* Reattach the ubi device in case it was attached in the beginning */
|
||||||
|
if (ubi_num >= 0) {
|
||||||
|
err = ubi_attach_mtd_dev(mtd_user.mtd, ubi_num, 0, 20);
|
||||||
|
if (err) {
|
||||||
|
pr_err("Failed to reattach ubi device to ubi number %d, %d\n",
|
||||||
|
ubi_num, err);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out_free:
|
out_free:
|
||||||
|
|
Loading…
Reference in New Issue