diff -Naur tmp/drivers/usb/gadget/f_mass_storage.c tmp2/drivers/usb/gadget/f_mass_storage.c
--- tmp/drivers/usb/gadget/f_mass_storage.c	2017-06-10 05:44:12.938960948 -0700
+++ tmp2/drivers/usb/gadget/f_mass_storage.c	2017-06-09 18:08:43.465852381 -0700
@@ -3160,6 +3160,7 @@
 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);
 
 static struct device_attribute dev_attr_ro_cdrom =
 	__ATTR(ro, 0444, fsg_show_ro, NULL);
@@ -3252,6 +3253,10 @@
 		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)
@@ -3461,6 +3466,7 @@
 #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,
 					   lun->cdrom
diff -Naur tmp/drivers/usb/gadget/storage_common.c tmp2/drivers/usb/gadget/storage_common.c
--- tmp/drivers/usb/gadget/storage_common.c	2017-06-10 05:44:12.950961021 -0700
+++ tmp2/drivers/usb/gadget/storage_common.c	2017-06-10 04:53:52.811036488 -0700
@@ -587,6 +587,14 @@
 	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,
 			      char *buf)
@@ -608,6 +616,7 @@
 					"%lu bytes in %lld microseconds\n",
 					wbytes, wtime, rbytes, rtime);
 }
+
 static ssize_t fsg_store_perf(struct device *dev, struct device_attribute *attr,
 			const char *buf, size_t count)
 {
@@ -624,6 +633,36 @@
 	return count;
 }
 #endif
+
+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;
+}
+
 static ssize_t fsg_show_file(struct device *dev, struct device_attribute *attr,
 			     char *buf)
 {
