Commit 847c633a authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] disk->minor_shift cleanup

	new field - disk->minors (1 << disk->minor_shift).  Almost all uses
of ->minor_shift had that form and thus had been replaced.
parent b8ed1788
...@@ -1739,7 +1739,10 @@ int acsi_init( void ) ...@@ -1739,7 +1739,10 @@ int acsi_init( void )
sprintf(disk->disk_name, "ad%c", 'a'+i); sprintf(disk->disk_name, "ad%c", 'a'+i);
disk->major = MAJOR_NR; disk->major = MAJOR_NR;
disk->first_minor = i << 4; disk->first_minor = i << 4;
disk->minor_shift = (acsi_info[i].type==HARDDISK)?4:0; if (acsi_info[i].type != HARDDISK) {
disk->minor_shift = 0;
disk->minors = 1;
}
disk->fops = &acsi_fops; disk->fops = &acsi_fops;
set_capacity(disk, acsi_info[i].size); set_capacity(disk, acsi_info[i].size);
add_disk(disk); add_disk(disk);
......
...@@ -97,7 +97,7 @@ int add_partition(struct block_device *bdev, struct blkpg_partition *p) ...@@ -97,7 +97,7 @@ int add_partition(struct block_device *bdev, struct blkpg_partition *p)
return -EINVAL; return -EINVAL;
if (part) if (part)
BUG(); BUG();
if (p->pno <= 0 || p->pno >= (1 << g->minor_shift)) if (p->pno <= 0 || p->pno >= g->minors)
return -EINVAL; return -EINVAL;
/* partition number in use? */ /* partition number in use? */
...@@ -105,7 +105,7 @@ int add_partition(struct block_device *bdev, struct blkpg_partition *p) ...@@ -105,7 +105,7 @@ int add_partition(struct block_device *bdev, struct blkpg_partition *p)
return -EBUSY; return -EBUSY;
/* overlap? */ /* overlap? */
for (i = 0; i < (1<<g->minor_shift) - 1; i++) for (i = 0; i < g->minors - 1; i++)
if (!(ppstart+pplength <= g->part[i].start_sect || if (!(ppstart+pplength <= g->part[i].start_sect ||
ppstart >= g->part[i].start_sect + g->part[i].nr_sects)) ppstart >= g->part[i].start_sect + g->part[i].nr_sects))
return -EBUSY; return -EBUSY;
...@@ -142,7 +142,7 @@ int del_partition(struct block_device *bdev, struct blkpg_partition *p) ...@@ -142,7 +142,7 @@ int del_partition(struct block_device *bdev, struct blkpg_partition *p)
return -EINVAL; return -EINVAL;
if (part) if (part)
BUG(); BUG();
if (p->pno <= 0 || p->pno >= (1 << g->minor_shift)) if (p->pno <= 0 || p->pno >= g->minors)
return -EINVAL; return -EINVAL;
/* existing drive and partition? */ /* existing drive and partition? */
......
...@@ -61,7 +61,7 @@ void add_disk(struct gendisk *disk) ...@@ -61,7 +61,7 @@ void add_disk(struct gendisk *disk)
{ {
write_lock(&gendisk_lock); write_lock(&gendisk_lock);
list_add(&disk->list, &gendisks[disk->major].list); list_add(&disk->list, &gendisks[disk->major].list);
if (disk->minor_shift) if (disk->minors > 1)
list_add_tail(&disk->full_list, &gendisk_list); list_add_tail(&disk->full_list, &gendisk_list);
else else
INIT_LIST_HEAD(&disk->full_list); INIT_LIST_HEAD(&disk->full_list);
...@@ -107,7 +107,7 @@ get_gendisk(dev_t dev, int *part) ...@@ -107,7 +107,7 @@ get_gendisk(dev_t dev, int *part)
disk = list_entry(p, struct gendisk, list); disk = list_entry(p, struct gendisk, list);
if (disk->first_minor > minor) if (disk->first_minor > minor)
continue; continue;
if (disk->first_minor + (1<<disk->minor_shift) <= minor) if (disk->first_minor + disk->minors <= minor)
continue; continue;
read_unlock(&gendisk_lock); read_unlock(&gendisk_lock);
*part = minor - disk->first_minor; *part = minor - disk->first_minor;
...@@ -163,7 +163,7 @@ static int show_partition(struct seq_file *part, void *v) ...@@ -163,7 +163,7 @@ static int show_partition(struct seq_file *part, void *v)
sgp->major, sgp->first_minor, sgp->major, sgp->first_minor,
(unsigned long long)get_capacity(sgp) >> 1, (unsigned long long)get_capacity(sgp) >> 1,
disk_name(sgp, 0, buf)); disk_name(sgp, 0, buf));
for (n = 0; n < (1<<sgp->minor_shift) - 1; n++) { for (n = 0; n < sgp->minors - 1; n++) {
if (sgp->part[n].nr_sects == 0) if (sgp->part[n].nr_sects == 0)
continue; continue;
seq_printf(part, "%4d %4d %10llu %s\n", seq_printf(part, "%4d %4d %10llu %s\n",
......
...@@ -3193,6 +3193,7 @@ static int ide_cdrom_attach (ide_drive_t *drive) ...@@ -3193,6 +3193,7 @@ static int ide_cdrom_attach (ide_drive_t *drive)
memset(info, 0, sizeof (struct cdrom_info)); memset(info, 0, sizeof (struct cdrom_info));
drive->driver_data = info; drive->driver_data = info;
DRIVER(drive)->busy++; DRIVER(drive)->busy++;
g->minors = 1;
g->minor_shift = 0; g->minor_shift = 0;
g->de = drive->de; g->de = drive->de;
g->flags = GENHD_FL_CD; g->flags = GENHD_FL_CD;
......
...@@ -1871,6 +1871,7 @@ static int idedisk_attach(ide_drive_t *drive) ...@@ -1871,6 +1871,7 @@ static int idedisk_attach(ide_drive_t *drive)
goto failed; goto failed;
} }
DRIVER(drive)->busy--; DRIVER(drive)->busy--;
g->minors = 1 << PARTN_BITS;
g->minor_shift = PARTN_BITS; g->minor_shift = PARTN_BITS;
g->de = drive->de; g->de = drive->de;
g->flags = drive->removable ? GENHD_FL_REMOVABLE : 0; g->flags = drive->removable ? GENHD_FL_REMOVABLE : 0;
......
...@@ -2108,6 +2108,7 @@ static int idefloppy_attach (ide_drive_t *drive) ...@@ -2108,6 +2108,7 @@ static int idefloppy_attach (ide_drive_t *drive)
DRIVER(drive)->busy++; DRIVER(drive)->busy++;
idefloppy_setup (drive, floppy); idefloppy_setup (drive, floppy);
DRIVER(drive)->busy--; DRIVER(drive)->busy--;
g->minors = 1 << PARTN_BITS;
g->minor_shift = PARTN_BITS; g->minor_shift = PARTN_BITS;
g->de = drive->de; g->de = drive->de;
g->flags = drive->removable ? GENHD_FL_REMOVABLE : 0; g->flags = drive->removable ? GENHD_FL_REMOVABLE : 0;
......
...@@ -540,7 +540,7 @@ int check_disk_change(struct block_device *bdev) ...@@ -540,7 +540,7 @@ int check_disk_change(struct block_device *bdev)
disk = get_gendisk(bdev->bd_dev, &part); disk = get_gendisk(bdev->bd_dev, &part);
if (bdops->revalidate) if (bdops->revalidate)
bdops->revalidate(dev); bdops->revalidate(dev);
if (disk && disk->minor_shift) if (disk && disk->minors > 1)
bdev->bd_invalidated = 1; bdev->bd_invalidated = 1;
return 1; return 1;
} }
...@@ -799,7 +799,7 @@ static int blkdev_reread_part(struct block_device *bdev) ...@@ -799,7 +799,7 @@ static int blkdev_reread_part(struct block_device *bdev)
struct gendisk *disk = get_gendisk(bdev->bd_dev, &part); struct gendisk *disk = get_gendisk(bdev->bd_dev, &part);
int res = 0; int res = 0;
if (!disk || !disk->minor_shift || bdev != bdev->bd_contains) if (!disk || disk->minors == 1 || bdev != bdev->bd_contains)
return -EINVAL; return -EINVAL;
if (part) if (part)
BUG(); BUG();
......
...@@ -130,7 +130,7 @@ static DEVICE_ATTR(type,S_IRUGO,partition_device_type_read,NULL); ...@@ -130,7 +130,7 @@ static DEVICE_ATTR(type,S_IRUGO,partition_device_type_read,NULL);
static void driverfs_create_partitions(struct gendisk *hd) static void driverfs_create_partitions(struct gendisk *hd)
{ {
int max_p = 1<<hd->minor_shift; int max_p = hd->minors;
struct hd_struct *p = hd->part; struct hd_struct *p = hd->part;
char name[DEVICE_NAME_SIZE]; char name[DEVICE_NAME_SIZE];
char bus_id[BUS_ID_SIZE]; char bus_id[BUS_ID_SIZE];
...@@ -187,7 +187,7 @@ static void driverfs_create_partitions(struct gendisk *hd) ...@@ -187,7 +187,7 @@ static void driverfs_create_partitions(struct gendisk *hd)
static void driverfs_remove_partitions(struct gendisk *hd) static void driverfs_remove_partitions(struct gendisk *hd)
{ {
int max_p = 1<<hd->minor_shift; int max_p = hd->minors;
struct device *dev; struct device *dev;
struct hd_struct *p; struct hd_struct *p;
int part; int part;
...@@ -233,7 +233,7 @@ static void check_partition(struct gendisk *hd, struct block_device *bdev) ...@@ -233,7 +233,7 @@ static void check_partition(struct gendisk *hd, struct block_device *bdev)
if (isdigit(state->name[strlen(state->name)-1])) if (isdigit(state->name[strlen(state->name)-1]))
sprintf(state->name, "p"); sprintf(state->name, "p");
} }
state->limit = 1<<hd->minor_shift; state->limit = hd->minors;
for (i = 0; check_part[i]; i++) { for (i = 0; check_part[i]; i++) {
int res, j; int res, j;
struct hd_struct *p; struct hd_struct *p;
...@@ -298,7 +298,7 @@ static void devfs_create_partitions(struct gendisk *dev) ...@@ -298,7 +298,7 @@ static void devfs_create_partitions(struct gendisk *dev)
unsigned int devfs_flags = DEVFS_FL_DEFAULT; unsigned int devfs_flags = DEVFS_FL_DEFAULT;
char dirname[64], symlink[16]; char dirname[64], symlink[16];
static devfs_handle_t devfs_handle; static devfs_handle_t devfs_handle;
int part, max_p = 1<<dev->minor_shift; int part, max_p = dev->minors;
struct hd_struct *p = dev->part; struct hd_struct *p = dev->part;
if (dev->flags & GENHD_FL_REMOVABLE) if (dev->flags & GENHD_FL_REMOVABLE)
...@@ -380,7 +380,7 @@ static void devfs_remove_partitions(struct gendisk *dev) ...@@ -380,7 +380,7 @@ static void devfs_remove_partitions(struct gendisk *dev)
{ {
#ifdef CONFIG_DEVFS_FS #ifdef CONFIG_DEVFS_FS
int part; int part;
for (part = (1<<dev->minor_shift)-1; part--; ) { for (part = dev->minors-1; part--; ) {
devfs_unregister(dev->part[part].de); devfs_unregister(dev->part[part].de);
dev->part[part].de = NULL; dev->part[part].de = NULL;
} }
...@@ -401,7 +401,7 @@ void register_disk(struct gendisk *disk) ...@@ -401,7 +401,7 @@ void register_disk(struct gendisk *disk)
devfs_create_cdrom(disk); devfs_create_cdrom(disk);
/* No minors to use for partitions */ /* No minors to use for partitions */
if (!disk->minor_shift) if (disk->minors == 1)
return; return;
/* No such device (e.g., media were just removed) */ /* No such device (e.g., media were just removed) */
...@@ -458,7 +458,7 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev) ...@@ -458,7 +458,7 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
if (res) if (res)
return res; return res;
bdev->bd_invalidated = 0; bdev->bd_invalidated = 0;
for (p = 0; p < (1<<disk->minor_shift) - 1; p++) { for (p = 0; p < disk->minors - 1; p++) {
disk->part[p].start_sect = 0; disk->part[p].start_sect = 0;
disk->part[p].nr_sects = 0; disk->part[p].nr_sects = 0;
} }
...@@ -466,7 +466,7 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev) ...@@ -466,7 +466,7 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
bdev->bd_op->revalidate(dev); bdev->bd_op->revalidate(dev);
if (get_capacity(disk)) if (get_capacity(disk))
check_partition(disk, bdev); check_partition(disk, bdev);
for (p = 1; p < (1<<disk->minor_shift); p++) for (p = 1; p < disk->minors; p++)
update_partition(disk, p); update_partition(disk, p);
return res; return res;
} }
...@@ -495,7 +495,7 @@ unsigned char *read_dev_sector(struct block_device *bdev, sector_t n, Sector *p) ...@@ -495,7 +495,7 @@ unsigned char *read_dev_sector(struct block_device *bdev, sector_t n, Sector *p)
static int wipe_partitions(struct gendisk *disk) static int wipe_partitions(struct gendisk *disk)
{ {
int max_p = 1 << disk->minor_shift; int max_p = disk->minors;
kdev_t devp; kdev_t devp;
int res; int res;
int p; int p;
......
...@@ -74,6 +74,7 @@ struct hd_struct { ...@@ -74,6 +74,7 @@ struct hd_struct {
struct gendisk { struct gendisk {
int major; /* major number of driver */ int major; /* major number of driver */
int first_minor; int first_minor;
int minors;
int minor_shift; /* number of times minor is shifted to int minor_shift; /* number of times minor is shifted to
get real minor */ get real minor */
char disk_name[16]; /* name of major driver */ char disk_name[16]; /* name of major driver */
......
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