diff options
| -rw-r--r-- | drivers/usb/gadget/file_storage.c | 12 | ||||
| -rw-r--r-- | drivers/usb/gadget/storage_common.c | 7 |
2 files changed, 13 insertions, 6 deletions
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c index 90233f4f3601..ee712a5715e7 100644 --- a/drivers/usb/gadget/file_storage.c +++ b/drivers/usb/gadget/file_storage.c | |||
| @@ -3138,7 +3138,9 @@ static ssize_t show_ro(struct device *dev, struct device_attribute *attr, char * | |||
| 3138 | { | 3138 | { |
| 3139 | struct fsg_lun *curlun = fsg_lun_from_dev(dev); | 3139 | struct fsg_lun *curlun = fsg_lun_from_dev(dev); |
| 3140 | 3140 | ||
| 3141 | return sprintf(buf, "%d\n", curlun->ro); | 3141 | return sprintf(buf, "%d\n", fsg_lun_is_open(curlun) |
| 3142 | ? curlun->ro | ||
| 3143 | : curlun->initially_ro); | ||
| 3142 | } | 3144 | } |
| 3143 | 3145 | ||
| 3144 | static ssize_t show_file(struct device *dev, struct device_attribute *attr, | 3146 | static ssize_t show_file(struct device *dev, struct device_attribute *attr, |
| @@ -3188,6 +3190,7 @@ static ssize_t store_ro(struct device *dev, struct device_attribute *attr, | |||
| 3188 | rc = -EBUSY; | 3190 | rc = -EBUSY; |
| 3189 | } else { | 3191 | } else { |
| 3190 | curlun->ro = !!i; | 3192 | curlun->ro = !!i; |
| 3193 | curlun->initially_ro = !!i; | ||
| 3191 | LDBG(curlun, "read-only status set to %d\n", curlun->ro); | 3194 | LDBG(curlun, "read-only status set to %d\n", curlun->ro); |
| 3192 | } | 3195 | } |
| 3193 | up_read(&fsg->filesem); | 3196 | up_read(&fsg->filesem); |
| @@ -3433,9 +3436,10 @@ static int __init fsg_bind(struct usb_gadget *gadget) | |||
| 3433 | 3436 | ||
| 3434 | for (i = 0; i < fsg->nluns; ++i) { | 3437 | for (i = 0; i < fsg->nluns; ++i) { |
| 3435 | curlun = &fsg->luns[i]; | 3438 | curlun = &fsg->luns[i]; |
| 3436 | curlun->ro = mod_data.ro[i]; | 3439 | curlun->cdrom = !!mod_data.cdrom; |
| 3437 | if (mod_data.cdrom) | 3440 | curlun->ro = mod_data.cdrom || mod_data.ro[i]; |
| 3438 | curlun->ro = 1; | 3441 | curlun->initially_ro = curlun->ro; |
| 3442 | curlun->removable = mod_data.removable; | ||
| 3439 | curlun->dev.release = lun_release; | 3443 | curlun->dev.release = lun_release; |
| 3440 | curlun->dev.parent = &gadget->dev; | 3444 | curlun->dev.parent = &gadget->dev; |
| 3441 | curlun->dev.driver = &fsg_driver.driver; | 3445 | curlun->dev.driver = &fsg_driver.driver; |
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c index 19bf1e330dd0..affd23b5436f 100644 --- a/drivers/usb/gadget/storage_common.c +++ b/drivers/usb/gadget/storage_common.c | |||
| @@ -225,7 +225,10 @@ struct fsg_lun { | |||
| 225 | loff_t file_length; | 225 | loff_t file_length; |
| 226 | loff_t num_sectors; | 226 | loff_t num_sectors; |
| 227 | 227 | ||
| 228 | unsigned int initially_ro : 1; | ||
| 228 | unsigned int ro : 1; | 229 | unsigned int ro : 1; |
| 230 | unsigned int removable : 1; | ||
| 231 | unsigned int cdrom : 1; | ||
| 229 | unsigned int prevent_medium_removal : 1; | 232 | unsigned int prevent_medium_removal : 1; |
| 230 | unsigned int registered : 1; | 233 | unsigned int registered : 1; |
| 231 | unsigned int info_valid : 1; | 234 | unsigned int info_valid : 1; |
| @@ -478,7 +481,7 @@ static int fsg_lun_open(struct fsg_lun *curlun, const char *filename) | |||
| 478 | loff_t min_sectors; | 481 | loff_t min_sectors; |
| 479 | 482 | ||
| 480 | /* R/W if we can, R/O if we must */ | 483 | /* R/W if we can, R/O if we must */ |
| 481 | ro = curlun->ro; | 484 | ro = curlun->initially_ro; |
| 482 | if (!ro) { | 485 | if (!ro) { |
| 483 | filp = filp_open(filename, O_RDWR | O_LARGEFILE, 0); | 486 | filp = filp_open(filename, O_RDWR | O_LARGEFILE, 0); |
| 484 | if (-EROFS == PTR_ERR(filp)) | 487 | if (-EROFS == PTR_ERR(filp)) |
| @@ -521,7 +524,7 @@ static int fsg_lun_open(struct fsg_lun *curlun, const char *filename) | |||
| 521 | } | 524 | } |
| 522 | num_sectors = size >> 9; // File size in 512-byte blocks | 525 | num_sectors = size >> 9; // File size in 512-byte blocks |
| 523 | min_sectors = 1; | 526 | min_sectors = 1; |
| 524 | if (mod_data.cdrom) { | 527 | if (curlun->cdrom) { |
| 525 | num_sectors &= ~3; // Reduce to a multiple of 2048 | 528 | num_sectors &= ~3; // Reduce to a multiple of 2048 |
| 526 | min_sectors = 300*4; // Smallest track is 300 frames | 529 | min_sectors = 300*4; // Smallest track is 300 frames |
| 527 | if (num_sectors >= 256*60*75*4) { | 530 | if (num_sectors >= 256*60*75*4) { |
