Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 195411
b: refs/heads/master
c: 31436a1
h: refs/heads/master
i:
  195409: 6f53e61
  195407: afcd3c4
v: v3
  • Loading branch information
Fabien Chouteau authored and Greg Kroah-Hartman committed May 20, 2010
1 parent b19effc commit 2c883f0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: f48cf80f93ba974eb3201ab2d0f2c4cef950f3fc
refs/heads/master: 31436a1a64b8eed834fba5d570038dd676e04842
48 changes: 45 additions & 3 deletions trunk/drivers/usb/gadget/f_mass_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@
* ro setting are not allowed when the medium is loaded or if CD-ROM
* emulation is being used.
*
* When a LUN receive an "eject" SCSI request (Start/Stop Unit),
* if the LUN is removable, the backing file is released to simulate
* ejection.
*
*
* This function is heavily based on "File-backed Storage Gadget" by
* Alan Stern which in turn is heavily based on "Gadget Zero" by David
Expand Down Expand Up @@ -1384,12 +1388,50 @@ static int do_mode_sense(struct fsg_common *common, struct fsg_buffhd *bh)

static int do_start_stop(struct fsg_common *common)
{
if (!common->curlun) {
struct fsg_lun *curlun = common->curlun;
int loej, start;

if (!curlun) {
return -EINVAL;
} else if (!common->curlun->removable) {
common->curlun->sense_data = SS_INVALID_COMMAND;
} else if (!curlun->removable) {
curlun->sense_data = SS_INVALID_COMMAND;
return -EINVAL;
}

loej = common->cmnd[4] & 0x02;
start = common->cmnd[4] & 0x01;

/* eject code from file_storage.c:do_start_stop() */

if ((common->cmnd[1] & ~0x01) != 0 || /* Mask away Immed */
(common->cmnd[4] & ~0x03) != 0) { /* Mask LoEj, Start */
curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
return -EINVAL;
}

if (!start) {
/* Are we allowed to unload the media? */
if (curlun->prevent_medium_removal) {
LDBG(curlun, "unload attempt prevented\n");
curlun->sense_data = SS_MEDIUM_REMOVAL_PREVENTED;
return -EINVAL;
}
if (loej) { /* Simulate an unload/eject */
up_read(&common->filesem);
down_write(&common->filesem);
fsg_lun_close(curlun);
up_write(&common->filesem);
down_read(&common->filesem);
}
} else {

/* Our emulation doesn't support mounting; the medium is
* available for use as soon as it is loaded. */
if (!fsg_lun_is_open(curlun)) {
curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
return -EINVAL;
}
}
return 0;
}

Expand Down

0 comments on commit 2c883f0

Please sign in to comment.