mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] fastboot: Umount filesystems of target devices before flashing
@ 2016-03-09  9:10 Markus Pargmann
  0 siblings, 0 replies; only message in thread
From: Markus Pargmann @ 2016-03-09  9:10 UTC (permalink / raw)
  To: barebox

Before flashing data to some device, we should check whether this device
is in use. If it is mounted it is umounted and flashed afterwards.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
Hi,

This patch requires the for_each_fs_device_safe() macro which was sent as a
patch yesterday.

Best Regards,

Markus


 drivers/usb/gadget/f_fastboot.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 9a1058a9670b..e81392f38ae9 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -664,6 +664,37 @@ static void __maybe_unused cb_boot(struct usb_ep *ep, struct usb_request *req,
 	fastboot_tx_print(f_fb, "OKAY");
 }
 
+/**
+ * fastboot_flash_umount_target checks whether the target file is a device and
+ * umounts mounted filesystems
+ * @param filename Target file name
+ * @return 0 on success, < 0 otherwise
+ */
+static int fastboot_flash_umount_target(const char *filename)
+{
+	struct cdev *tgt_cdev;
+	struct fs_device_d *fs;
+	struct fs_device_d *fs_tmp;
+
+	tgt_cdev = cdev_by_path(filename);
+	if (!tgt_cdev)
+		return 0;
+
+	for_each_fs_device_safe(fs_tmp, fs) {
+		int ret;
+
+		if (fs->cdev == tgt_cdev) {
+			ret = umount(fs->path);
+			if (ret) {
+				pr_err("Failed umounting %s, %d, continuing anyway\n",
+				       fs->path, ret);
+			}
+		}
+	}
+
+	return 0;
+}
+
 static void cb_flash(struct usb_ep *ep, struct usb_request *req, const char *cmd)
 {
 	struct f_fastboot *f_fb = req->context;
@@ -745,6 +776,8 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req, const char *cmd
 		goto out;
 	}
 
+	fastboot_flash_umount_target(filename);
+
 copy:
 	ret = copy_file(FASTBOOT_TMPFILE, filename, 1);
 	if (ret) {
-- 
2.7.0


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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-03-09  9:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-09  9:10 [PATCH] fastboot: Umount filesystems of target devices before flashing Markus Pargmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox