[PATCH 06/24] [Storage] RO flag handling changed

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

 



Previously the read-only flag for LUN was initialised
at the beginning and then used.  However, if a read-only file
was specified as backing file the flag was set (which is good)
and remained set even after the file has been closed (which may
be considered not-good).  Currently, the initial read-only flag
is preserved so if it was unset each time file is opened code
will try to open it read-write even if previous file was opened
read-only.

Signed-off-by: Michal Nazarewicz <m.nazarewicz@xxxxxxxxxxx>
---
 drivers/usb/gadget/file_storage.c   |    1 +
 drivers/usb/gadget/storage_common.c |    8 ++++++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index 66201af..4105393 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -3359,6 +3359,7 @@ static int __init fsg_bind(struct usb_gadget *gadget)
 		curlun = &fsg->luns[i];
 		curlun->cdrom = !!mod_data.cdrom;
 		curlun->ro = mod_data.cdrom || mod_data.ro[i];
+		curlun->initially_ro = curlun->ro;
 		curlun->removable = mod_data.removable;
 		curlun->dev.release = lun_release;
 		curlun->dev.parent = &gadget->dev;
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c
index e3c37e0..681268e 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -209,6 +209,7 @@ struct fsg_lun {
 	loff_t		file_length;
 	loff_t		num_sectors;
 
+	unsigned int	initially_ro : 1;
 	unsigned int	ro : 1;
 	unsigned int	removable : 1;
 	unsigned int	cdrom : 1;
@@ -464,7 +465,7 @@ static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
 	loff_t				min_sectors;
 
 	/* R/W if we can, R/O if we must */
-	ro = curlun->ro;
+	ro = curlun->initially_ro;
 	if (!ro) {
 		filp = filp_open(filename, O_RDWR | O_LARGEFILE, 0);
 		if (-EROFS == PTR_ERR(filp))
@@ -586,7 +587,9 @@ static ssize_t fsg_show_ro(struct device *dev,
 {
 	struct fsg_lun	*curlun = fsg_lun_from_dev(dev);
 
-	return sprintf(buf, "%d\n", curlun->ro);
+	return sprintf(buf, "%d\n", fsg_lun_is_open(curlun)
+				  ? curlun->ro
+				  : curlun->initially_ro);
 }
 
 static ssize_t fsg_show_file(struct device *dev,
@@ -640,6 +643,7 @@ static ssize_t fsg_store_ro(struct device *dev,
 		rc = -EBUSY;
 	} else {
 		curlun->ro = !!i;
+		curlun->initially_ro = !!i;
 		LDBG(curlun, "read-only status set to %d\n", curlun->ro);
 	}
 	up_read(filesem);
-- 
1.6.3.3


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux