[PATCH] fastboot: Umount filesystems of target devices before flashing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
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@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux