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