Commit 5a13388d authored by Finn Thain's avatar Finn Thain Committed by Jens Axboe

block/swim: Fix IO error at end of medium

Reading to the end of a 720K disk results in an IO error instead of EOF
because the block layer thinks the disk has 2880 sectors. (Partly this
is a result of inverted logic of the ONEMEG_MEDIA bit that's now fixed.)

Initialize the density and head count in swim_add_floppy() to agree
with the device size passed to set_capacity() during drive probe.

Call set_capacity() again upon device open, after refreshing the density
and head count values.

Cc: Laurent Vivier <lvivier@redhat.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: stable@vger.kernel.org # v4.14+
Tested-by: default avatarStan Johnson <userm57@yahoo.com>
Signed-off-by: default avatarFinn Thain <fthain@telegraphics.com.au>
Acked-by: default avatarLaurent Vivier <lvivier@redhat.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 8a500df6
...@@ -612,7 +612,6 @@ static void setup_medium(struct floppy_state *fs) ...@@ -612,7 +612,6 @@ static void setup_medium(struct floppy_state *fs)
struct floppy_struct *g; struct floppy_struct *g;
fs->disk_in = 1; fs->disk_in = 1;
fs->write_protected = swim_readbit(base, WRITE_PROT); fs->write_protected = swim_readbit(base, WRITE_PROT);
fs->type = swim_readbit(base, TWOMEG_MEDIA);
if (swim_track00(base)) if (swim_track00(base))
printk(KERN_ERR printk(KERN_ERR
...@@ -620,6 +619,9 @@ static void setup_medium(struct floppy_state *fs) ...@@ -620,6 +619,9 @@ static void setup_medium(struct floppy_state *fs)
swim_track00(base); swim_track00(base);
fs->type = swim_readbit(base, TWOMEG_MEDIA) ?
HD_MEDIA : DD_MEDIA;
fs->head_number = swim_readbit(base, SINGLE_SIDED) ? 1 : 2;
get_floppy_geometry(fs, 0, &g); get_floppy_geometry(fs, 0, &g);
fs->total_secs = g->size; fs->total_secs = g->size;
fs->secpercyl = g->head * g->sect; fs->secpercyl = g->head * g->sect;
...@@ -656,6 +658,8 @@ static int floppy_open(struct block_device *bdev, fmode_t mode) ...@@ -656,6 +658,8 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
goto out; goto out;
} }
set_capacity(fs->disk, fs->total_secs);
if (mode & FMODE_NDELAY) if (mode & FMODE_NDELAY)
return 0; return 0;
...@@ -808,10 +812,9 @@ static int swim_add_floppy(struct swim_priv *swd, enum drive_location location) ...@@ -808,10 +812,9 @@ static int swim_add_floppy(struct swim_priv *swd, enum drive_location location)
swim_motor(base, OFF); swim_motor(base, OFF);
if (swim_readbit(base, SINGLE_SIDED)) fs->type = HD_MEDIA;
fs->head_number = 1;
else
fs->head_number = 2; fs->head_number = 2;
fs->ref_count = 0; fs->ref_count = 0;
fs->ejected = 1; fs->ejected = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment