Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 316918
b: refs/heads/master
c: d6e16a8
h: refs/heads/master
v: v3
  • Loading branch information
Michal Nazarewicz authored and Felipe Balbi committed Jun 22, 2012
1 parent 9e028ff commit 57793cc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 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: f87cabf4d56e1fc5d08434df9d54ef3450a756f0
refs/heads/master: d6e16a89578fcc8834be634c85c5c5ddc2d13229
52 changes: 29 additions & 23 deletions trunk/drivers/usb/gadget/storage_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,16 @@ static struct usb_gadget_strings fsg_stringtab = {
* the caller must own fsg->filesem for writing.
*/

static void fsg_lun_close(struct fsg_lun *curlun)
{
if (curlun->filp) {
LDBG(curlun, "close backing file\n");
fput(curlun->filp);
curlun->filp = NULL;
}
}


static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
{
int ro;
Expand All @@ -626,6 +636,8 @@ static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
loff_t size;
loff_t num_sectors;
loff_t min_sectors;
unsigned int blkbits;
unsigned int blksize;

/* R/W if we can, R/O if we must */
ro = curlun->initially_ro;
Expand Down Expand Up @@ -670,17 +682,17 @@ static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
}

if (curlun->cdrom) {
curlun->blksize = 2048;
curlun->blkbits = 11;
blksize = 2048;
blkbits = 11;
} else if (inode->i_bdev) {
curlun->blksize = bdev_logical_block_size(inode->i_bdev);
curlun->blkbits = blksize_bits(curlun->blksize);
blksize = bdev_logical_block_size(inode->i_bdev);
blkbits = blksize_bits(blksize);
} else {
curlun->blksize = 512;
curlun->blkbits = 9;
blksize = 512;
blkbits = 9;
}

num_sectors = size >> curlun->blkbits; /* File size in logic-block-size blocks */
num_sectors = size >> blkbits; /* File size in logic-block-size blocks */
min_sectors = 1;
if (curlun->cdrom) {
min_sectors = 300; /* Smallest track is 300 frames */
Expand All @@ -697,7 +709,12 @@ static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
goto out;
}

if (fsg_lun_is_open(curlun))
fsg_lun_close(curlun);

get_file(filp);
curlun->blksize = blksize;
curlun->blkbits = blkbits;
curlun->ro = ro;
curlun->filp = filp;
curlun->file_length = size;
Expand All @@ -711,16 +728,6 @@ static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
}


static void fsg_lun_close(struct fsg_lun *curlun)
{
if (curlun->filp) {
LDBG(curlun, "close backing file\n");
fput(curlun->filp);
curlun->filp = NULL;
}
}


/*-------------------------------------------------------------------------*/

/*
Expand Down Expand Up @@ -871,19 +878,18 @@ static ssize_t fsg_store_file(struct device *dev, struct device_attribute *attr,
if (count > 0 && buf[count-1] == '\n')
((char *) buf)[count-1] = 0; /* Ugh! */

/* Eject current medium */
down_write(filesem);
if (fsg_lun_is_open(curlun)) {
fsg_lun_close(curlun);
curlun->unit_attention_data = SS_MEDIUM_NOT_PRESENT;
}

/* Load new medium */
down_write(filesem);
if (count > 0 && buf[0]) {
/* fsg_lun_open() will close existing file if any. */
rc = fsg_lun_open(curlun, buf);
if (rc == 0)
curlun->unit_attention_data =
SS_NOT_READY_TO_READY_TRANSITION;
} else if (fsg_lun_is_open(curlun)) {
fsg_lun_close(curlun);
curlun->unit_attention_data = SS_MEDIUM_NOT_PRESENT;
}
up_write(filesem);
return (rc < 0 ? rc : count);
Expand Down

0 comments on commit 57793cc

Please sign in to comment.