Skip to content
Permalink
Browse files

Working USB/CDROM patch.

  • Loading branch information...
lavanoid committed Apr 18, 2019
1 parent 729fc6f commit 218dbe49bbdb6cd6473b277feb7e47df34ba8ead
Showing with 41 additions and 0 deletions.
  1. +5 −0 drivers/usb/gadget/f_mass_storage.c
  2. +36 −0 drivers/usb/gadget/storage_common.c
@@ -2559,6 +2559,7 @@ static int fsg_main_thread(void *common_)
static DEVICE_ATTR(ro, 0644, fsg_show_ro, fsg_store_ro);
static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, fsg_store_nofua);
static DEVICE_ATTR(file, 0644, fsg_show_file, fsg_store_file);
static DEVICE_ATTR(cdrom, 0644, fsg_show_cdrom, fsg_store_cdrom);
#ifdef CONFIG_USB_MSC_PROFILING
static DEVICE_ATTR(perf, 0644, fsg_show_perf, fsg_store_perf);
#endif
@@ -2695,6 +2696,9 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
rc = device_create_file(&curlun->dev, &dev_attr_nofua);
if (rc)
goto error_luns;
rc = device_create_file(&curlun->dev, &dev_attr_cdrom);
if (rc)
goto error_luns;
#ifdef CONFIG_USB_MSC_PROFILING
rc = device_create_file(&curlun->dev, &dev_attr_perf);
if (rc)
@@ -2834,6 +2838,7 @@ static void fsg_common_release(struct kref *ref)
#ifdef CONFIG_USB_MSC_PROFILING
device_remove_file(&lun->dev, &dev_attr_perf);
#endif
device_remove_file(&lun->dev, &dev_attr_cdrom);
device_remove_file(&lun->dev, &dev_attr_nofua);
device_remove_file(&lun->dev, &dev_attr_ro);
device_remove_file(&lun->dev, &dev_attr_file);
@@ -800,6 +800,13 @@ static ssize_t fsg_show_nofua(struct device *dev, struct device_attribute *attr,

return sprintf(buf, "%u\n", curlun->nofua);
}
static ssize_t fsg_show_cdrom (struct device *dev, struct device_attribute *attr,
char *buf)
{
struct fsg_lun *curlun = fsg_lun_from_dev(dev);

return sprintf(buf, "%d\n", curlun->cdrom);
}

#ifdef CONFIG_USB_MSC_PROFILING
static ssize_t fsg_show_perf(struct device *dev, struct device_attribute *attr,
@@ -956,3 +963,32 @@ static ssize_t fsg_store_file(struct device *dev, struct device_attribute *attr,
up_write(filesem);
return (rc < 0 ? rc : count);
}

static ssize_t fsg_store_cdrom(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
ssize_t rc;
struct fsg_lun *curlun = fsg_lun_from_dev(dev);
struct rw_semaphore *filesem = dev_get_drvdata(dev);
unsigned cdrom;

rc = kstrtouint(buf, 2, &cdrom);
if (rc)
return rc;

/*
* Allow the cdrom status to change only while the
* backing file is closed.
*/
down_read(filesem);
if (fsg_lun_is_open(curlun)) {
LDBG(curlun, "cdrom status change prevented\n");
rc = -EBUSY;
} else {
curlun->cdrom = cdrom;
LDBG(curlun, "cdrom status set to %d\n", curlun->cdrom);
rc = count;
}
up_read(filesem);
return rc;
}

0 comments on commit 218dbe4

Please sign in to comment.
You can’t perform that action at this time.