Commit 22dda8bf authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] gendisk fixes

 - fixes an idiocy with floppy_find() et.al. - they forgot to set
   *part to 0.  As the result, open() on anything other than fd0 had
   lead to interesting effects...

 - fixes off-by-1 in set_disk_ro().
parent b3caff53
...@@ -1528,6 +1528,7 @@ static struct gendisk *floppy_find(dev_t dev, int *part, void *data) ...@@ -1528,6 +1528,7 @@ static struct gendisk *floppy_find(dev_t dev, int *part, void *data)
int drive = *part & 3; int drive = *part & 3;
if ((*part >> 2) > NUM_DISK_TYPES || drive >= FD_MAX_UNITS) if ((*part >> 2) > NUM_DISK_TYPES || drive >= FD_MAX_UNITS)
return NULL; return NULL;
*part = 0;
return get_disk(disks[drive]); return get_disk(disks[drive]);
} }
......
...@@ -1765,6 +1765,7 @@ static struct gendisk *floppy_find(dev_t dev, int *part, void *data) ...@@ -1765,6 +1765,7 @@ static struct gendisk *floppy_find(dev_t dev, int *part, void *data)
int drive = *part & 3; int drive = *part & 3;
if (unit[drive].type->code == FD_NODRIVE) if (unit[drive].type->code == FD_NODRIVE)
return NULL; return NULL;
*part = 0;
return get_disk(unit[drive].gendisk); return get_disk(unit[drive].gendisk);
} }
......
...@@ -1919,6 +1919,7 @@ static struct gendisk *floppy_find(dev_t dev, int *part, void *data) ...@@ -1919,6 +1919,7 @@ static struct gendisk *floppy_find(dev_t dev, int *part, void *data)
int type = *part >> 2; int type = *part >> 2;
if (drive >= FD_MAX_UNITS || type > NUM_DISK_MINORS) if (drive >= FD_MAX_UNITS || type > NUM_DISK_MINORS)
return NULL; return NULL;
*part = 0;
return get_disk(unit[drive].disk); return get_disk(unit[drive].disk);
} }
......
...@@ -4210,6 +4210,7 @@ static struct gendisk *floppy_find(dev_t dev, int *part, void *data) ...@@ -4210,6 +4210,7 @@ static struct gendisk *floppy_find(dev_t dev, int *part, void *data)
!(allowed_drive_mask & (1 << drive)) || !(allowed_drive_mask & (1 << drive)) ||
fdc_state[FDC(drive)].version == FDC_NONE) fdc_state[FDC(drive)].version == FDC_NONE)
return NULL; return NULL;
*part = 0;
return get_disk(disks[drive]); return get_disk(disks[drive]);
} }
......
...@@ -92,9 +92,7 @@ EXPORT_SYMBOL(blk_unregister_region); ...@@ -92,9 +92,7 @@ EXPORT_SYMBOL(blk_unregister_region);
static struct gendisk *exact_match(dev_t dev, int *part, void *data) static struct gendisk *exact_match(dev_t dev, int *part, void *data)
{ {
struct gendisk *p = data; return data;
*part = MINOR(dev) - p->first_minor;
return p;
} }
static int exact_lock(dev_t dev, void *data) static int exact_lock(dev_t dev, void *data)
...@@ -363,7 +361,7 @@ void set_disk_ro(struct gendisk *disk, int flag) ...@@ -363,7 +361,7 @@ void set_disk_ro(struct gendisk *disk, int flag)
{ {
int i; int i;
disk->policy = flag; disk->policy = flag;
for (i = 0; i < disk->minors; i++) for (i = 0; i < disk->minors - 1; i++)
disk->part[i].policy = flag; disk->part[i].policy = flag;
} }
......
...@@ -982,7 +982,7 @@ static int ata_lock(dev_t dev, void *data) ...@@ -982,7 +982,7 @@ static int ata_lock(dev_t dev, void *data)
struct gendisk *ata_probe(dev_t dev, int *part, void *data) struct gendisk *ata_probe(dev_t dev, int *part, void *data)
{ {
ide_hwif_t *hwif = data; ide_hwif_t *hwif = data;
int unit = MINOR(dev) >> PARTN_BITS; int unit = *part >> PARTN_BITS;
ide_drive_t *drive = &hwif->drives[unit]; ide_drive_t *drive = &hwif->drives[unit];
if (!drive->present) if (!drive->present)
return NULL; return NULL;
...@@ -1000,6 +1000,7 @@ struct gendisk *ata_probe(dev_t dev, int *part, void *data) ...@@ -1000,6 +1000,7 @@ struct gendisk *ata_probe(dev_t dev, int *part, void *data)
} }
if (!drive->driver) if (!drive->driver)
return NULL; return NULL;
*part &= (1 << PARTN_BITS) - 1;
return get_disk(drive->disk); return get_disk(drive->disk);
} }
......
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