mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Markus Pargmann <mpa@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v2 8/8] ubiformat: Cleanly umount and detach the ubi before formating
Date: Mon, 14 Mar 2016 08:41:56 +0100	[thread overview]
Message-ID: <20160314074156.GQ30994@pengutronix.de> (raw)
In-Reply-To: <1457598600-10669-8-git-send-email-mpa@pengutronix.de>

On Thu, Mar 10, 2016 at 09:30:00AM +0100, Markus Pargmann wrote:
> 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>
> ---
>  commands/ubiformat.c | 29 +++++++++++++++++++++++++++--
>  1 file changed, 27 insertions(+), 2 deletions(-)
> 
> diff --git a/commands/ubiformat.c b/commands/ubiformat.c
> index f9c50b7936eb..4a80952dca61 100644
> --- a/commands/ubiformat.c
> +++ b/commands/ubiformat.c
> @@ -42,6 +42,7 @@
>  #include <libbb.h>
>  #include <libfile.h>
>  #include <linux/mtd/mtd.h>
> +#include <linux/mtd/ubi.h>
>  #include <linux/kernel.h>
>  #include <linux/stat.h>
>  #include <linux/log2.h>
> @@ -555,6 +556,8 @@ int do_ubiformat(int argc, char *argv[])
>  	struct mtd_dev_info mtd;
>  	struct ubigen_info ui;
>  	struct ubi_scan_info *si;
> +	int ubi_detached = -1;
> +	struct mtd_info_user mtd_info;
>  
>  	err = parse_opt(argc, argv);
>  	if (err)
> @@ -614,8 +617,19 @@ int do_ubiformat(int argc, char *argv[])
>  		goto out_close;
>  	}
>  
> -	/* Make sure this MTD device is not attached to UBI */
> -	/* FIXME! Find a proper way to do this in barebox! */
> +	err = ioctl(args.node_fd, MEMGETINFO, &mtd_info);
> +	if (err) {
> +		sys_errmsg("Failed to get user info %d\n", err);
> +		goto out_close;
> +	}
> +
> +	ubi_detached = ubi_num_get_by_mtd(mtd_info.mtd);
> +	err = ubi_detach_by_mtd(mtd_info.mtd, args.yes);
> +	if (err) {
> +		sys_errmsg("Cannot detach %d\n", err);
> +		goto out_close;
> +	}

ubi_detach_by_mtd() returns an error if the mtd device hasn't been
attached to ubi. I think there's a if (ubi_detached >= 0) missing here.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      reply	other threads:[~2016-03-14  7:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-10  8:29 [PATCH v2 1/8] fs: Add for_each_fs_device_safe() Markus Pargmann
2016-03-10  8:29 ` [PATCH v2 2/8] fs: umount based on device path and mount path Markus Pargmann
2016-03-10  8:29 ` [PATCH v2 3/8] ubi: Add getter ubi_volume_get_cdev() Markus Pargmann
2016-03-10  8:29 ` [PATCH v2 4/8] ubi: Add helper to map a mtd device to a ubi number Markus Pargmann
2016-03-10  8:29 ` [PATCH v2 5/8] ubi: Helper to iterate over all ubi volumes Markus Pargmann
2016-03-10  8:29 ` [PATCH v2 6/8] ubi: Add function to detach a UBI by using mtd_info Markus Pargmann
2016-03-10  8:29 ` [PATCH v2 7/8] ubi: Let ubidetach umount all filesystems before detaching Markus Pargmann
2016-03-14  7:32   ` Sascha Hauer
2016-03-10  8:30 ` [PATCH v2 8/8] ubiformat: Cleanly umount and detach the ubi before formating Markus Pargmann
2016-03-14  7:41   ` Sascha Hauer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160314074156.GQ30994@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=mpa@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox