Commit 36bd834b authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] (3/25) Removing useless minor arguments

	driverfs_remove_partitions(), devfs_register_partitions(),
driverfs_create_partitions(), devfs_register_partition(), devfs_register_disc(),
had lost 'minor' argument - it's always disk->first_minor these days.
disk_name() takes partition number instead of minor now.  Callers of
wipe_partitions() in fs/block_dev.c expanded.  Remaining caller passes
gendisk instead of kdev_t now.
parent 4e493886
......@@ -71,7 +71,6 @@ int add_partition(struct block_device *bdev, struct blkpg_partition *p)
long pstart, plength;
int i;
kdev_t dev = to_kdev_t(bdev->bd_dev);
struct hd_struct *part;
/* convert bytes to sectors, check for fit in a hd_struct */
ppstart = (p->start >> 9);
......@@ -86,7 +85,6 @@ int add_partition(struct block_device *bdev, struct blkpg_partition *p)
g = get_gendisk(dev);
if (!g)
return -ENXIO;
part = g->part + minor(dev) - g->first_minor;
/* existing drive? */
......@@ -97,19 +95,19 @@ int add_partition(struct block_device *bdev, struct blkpg_partition *p)
return -EINVAL;
/* partition number in use? */
if (part[p->pno].nr_sects != 0)
if (g->part[p->pno].nr_sects != 0)
return -EBUSY;
/* overlap? */
for (i = 1; i < (1<<g->minor_shift); i++)
if (!(pstart+plength <= part[i].start_sect ||
pstart >= part[i].start_sect + part[i].nr_sects))
if (!(pstart+plength <= g->part[i].start_sect ||
pstart >= g->part[i].start_sect + g->part[i].nr_sects))
return -EBUSY;
/* all seems OK */
part[p->pno].start_sect = pstart;
part[p->pno].nr_sects = plength;
devfs_register_partitions (g, minor(dev), 0);
g->part[p->pno].start_sect = pstart;
g->part[p->pno].nr_sects = plength;
devfs_register_partitions (g, 0);
return 0;
}
......@@ -128,22 +126,19 @@ int del_partition(struct block_device *bdev, struct blkpg_partition *p)
kdev_t dev = to_kdev_t(bdev->bd_dev);
struct gendisk *g;
struct block_device *bdevp;
struct hd_struct *part;
int holder;
/* find the drive major */
g = get_gendisk(dev);
if (!g)
return -ENXIO;
part = g->part + minor(dev) - g->first_minor;
if (bdev != bdev->bd_contains)
return -EINVAL;
if (p->pno <= 0 || p->pno >= (1 << g->minor_shift))
return -EINVAL;
/* existing drive and partition? */
if (part[p->pno].nr_sects == 0)
if (g->part[p->pno].nr_sects == 0)
return -ENXIO;
/* partition in use? Incomplete check for now. */
......@@ -159,9 +154,9 @@ int del_partition(struct block_device *bdev, struct blkpg_partition *p)
fsync_bdev(bdevp);
invalidate_bdev(bdevp, 0);
part[p->pno].start_sect = 0;
part[p->pno].nr_sects = 0;
devfs_register_partitions (g, minor(dev), 0);
g->part[p->pno].start_sect = 0;
g->part[p->pno].nr_sects = 0;
devfs_register_partitions (g, 0);
bd_release(bdevp);
bdput(bdevp);
......
......@@ -81,7 +81,7 @@ del_gendisk(struct gendisk *disk)
{
struct gendisk **p;
wipe_partitions(mk_kdev(disk->major, disk->first_minor));
wipe_partitions(disk);
write_lock(&gendisk_lock);
for (p = &gendisk_head; *p; p = &((*p)->next))
if (*p == disk)
......@@ -89,7 +89,7 @@ del_gendisk(struct gendisk *disk)
if (*p)
*p = (*p)->next;
write_unlock(&gendisk_lock);
devfs_register_partitions(disk, disk->first_minor, 1);
devfs_register_partitions(disk, 1);
}
EXPORT_SYMBOL(del_gendisk);
......@@ -168,7 +168,7 @@ static int show_partition(struct seq_file *part, void *v)
seq_printf(part, "%4d %4d %10ld %s\n",
sgp->major, n + sgp->first_minor,
sgp->part[n].nr_sects >> 1 ,
disk_name(sgp, n + sgp->first_minor, buf));
disk_name(sgp, n, buf));
}
return 0;
......
......@@ -276,7 +276,7 @@ char * partition_name(kdev_t dev)
hd = get_gendisk (dev);
dname->name = NULL;
if (hd)
dname->name = disk_name (hd, minor(dev), dname->namebuf);
dname->name = disk_name(hd, minor(dev)-hd->first_minor, dname->namebuf);
if (!dname->name) {
sprintf (dname->namebuf, "[dev %s]", kdevname(dev));
dname->name = dname->namebuf;
......
......@@ -126,8 +126,6 @@ static void sd_rw_intr(Scsi_Cmnd * SCpnt);
static Scsi_Disk * sd_get_sdisk(int index);
extern void driverfs_remove_partitions(struct gendisk *hd, int minor);
#if defined(CONFIG_PPC32)
/**
* sd_find_target - find kdev_t of first scsi disk that matches
......@@ -1424,7 +1422,7 @@ static void sd_detach(Scsi_Device * sdp)
if (sdkp->has_been_registered) {
sdkp->has_been_registered = 0;
dev = MKDEV_SD(dsk_nr);
driverfs_remove_partitions(sd_disks[dsk_nr], minor(dev));
driverfs_remove_partitions(sd_disks[dsk_nr]);
del_gendisk(sd_disks[dsk_nr]);
}
sdp->attached--;
......
......@@ -528,16 +528,21 @@ int check_disk_change(struct block_device *bdev)
int full_check_disk_change(struct block_device *bdev)
{
int res;
if (bdev->bd_contains != bdev)
BUG();
down(&bdev->bd_sem);
res = check_disk_change(bdev);
if (bdev->bd_invalidated && !bdev->bd_part_count) {
struct gendisk *g = get_gendisk(to_kdev_t(bdev->bd_dev));
struct hd_struct *part;
part = g->part + MINOR(bdev->bd_dev) - g->first_minor;
struct gendisk *disk = get_gendisk(to_kdev_t(bdev->bd_dev));
int p;
bdev->bd_invalidated = 0;
wipe_partitions(to_kdev_t(bdev->bd_dev));
if (part[0].nr_sects)
check_partition(g, bdev);
for (p = 1; p < 1<<disk->minor_shift; p++) {
disk->part[p].start_sect = 0;
disk->part[p].nr_sects = 0;
}
res = invalidate_device(to_kdev_t(bdev->bd_dev), 1);
if (disk->part[0].nr_sects)
check_partition(disk, bdev);
}
up(&bdev->bd_sem);
return res;
......@@ -650,11 +655,14 @@ static int do_open(struct block_device *bdev, struct inode *inode, struct file *
bdev->bd_inode->i_data.backing_dev_info = bdi;
}
if (bdev->bd_invalidated && !bdev->bd_part_count) {
struct hd_struct *part;
part = g->part + minor(dev) - g->first_minor;
int p;
bdev->bd_invalidated = 0;
wipe_partitions(dev);
if (part[0].nr_sects)
for (p = 1; p < 1<<g->minor_shift; p++) {
g->part[p].start_sect = 0;
g->part[p].nr_sects = 0;
}
invalidate_device(dev, 1);
if (g->part[0].nr_sects)
check_partition(g, bdev);
}
} else {
......@@ -791,12 +799,10 @@ static int blkdev_reread_part(struct block_device *bdev)
{
kdev_t dev = to_kdev_t(bdev->bd_dev);
struct gendisk *disk = get_gendisk(dev);
struct hd_struct *part;
int res;
int p, res;
if (!disk || !disk->minor_shift)
if (!disk || !disk->minor_shift || bdev != bdev->bd_contains)
return -EINVAL;
part = disk->part + minor(dev) - disk->first_minor;
if (!capable(CAP_SYS_ADMIN))
return -EACCES;
if (down_trylock(&bdev->bd_sem))
......@@ -805,11 +811,15 @@ static int blkdev_reread_part(struct block_device *bdev)
up(&bdev->bd_sem);
return -EBUSY;
}
res = wipe_partitions(dev);
for (p = 1; p < 1 << disk->minor_shift; p++) {
disk->part[p].start_sect = 0;
disk->part[p].nr_sects = 0;
}
res = invalidate_device(dev, 1);
if (!res) {
if (bdev->bd_op->revalidate)
bdev->bd_op->revalidate(dev);
if (part[0].nr_sects)
if (disk->part[0].nr_sects)
check_partition(disk, bdev);
}
up(&bdev->bd_sem);
......
......@@ -87,28 +87,21 @@ static int (*check_part[])(struct parsed_partitions *, struct block_device *) =
* a pointer to that same buffer (for convenience).
*/
char *disk_name (struct gendisk *hd, int minor, char *buf)
char *disk_name (struct gendisk *hd, int part, char *buf)
{
unsigned int part = minor - hd->first_minor;
struct hd_struct *p = hd->part + part;
char s[40];
const char *maj;
if (part < 1<<hd->minor_shift && p->de) {
if (part < 1<<hd->minor_shift && hd->part[part].de) {
int pos;
pos = devfs_generate_path(p->de, buf, 64);
pos = devfs_generate_path(hd->part[part].de, buf, 64);
if (pos >= 0)
return buf + pos;
}
maj = hd->major_name;
if (!part)
sprintf(buf, "%s", maj);
else if (isdigit(maj[strlen(maj)-1]))
sprintf(buf, "%sp%d", maj, part);
sprintf(buf, "%s", hd->major_name);
else if (isdigit(hd->major_name[strlen(hd->major_name)-1]))
sprintf(buf, "%sp%d", hd->major_name, part);
else
sprintf(buf, "%s%d", maj, part);
sprintf(buf, "%s%d", hd->major_name, part);
return buf;
}
......@@ -129,7 +122,7 @@ static ssize_t partition_device_type_read(struct device *driverfs_dev,
}
static DEVICE_ATTR(type,S_IRUGO,partition_device_type_read,NULL);
void driverfs_create_partitions(struct gendisk *hd, int minor)
static void driverfs_create_partitions(struct gendisk *hd)
{
int pos = -1;
char dirname[256];
......@@ -137,7 +130,7 @@ void driverfs_create_partitions(struct gendisk *hd, int minor)
int max_p;
int part;
devfs_handle_t dir = 0;
struct hd_struct *p = hd->part + minor - hd->first_minor;
struct hd_struct *p = hd->part;
/* get parent driverfs device structure */
if (hd->driverfs_dev_arr)
......@@ -154,7 +147,7 @@ void driverfs_create_partitions(struct gendisk *hd, int minor)
}
if (pos < 0) {
disk_name(hd, minor, dirname);
disk_name(hd, 0, dirname);
pos = 0;
}
......@@ -168,7 +161,7 @@ void driverfs_create_partitions(struct gendisk *hd, int minor)
current_driverfs_dev->parent = parent;
/* handle disc case */
current_driverfs_dev->driver_data =
(void *)(long)__mkdev(hd->major, minor+part);
(void *)(long)__mkdev(hd->major, hd->first_minor+part);
if (part == 0) {
if (parent) {
sprintf(current_driverfs_dev->name,
......@@ -204,12 +197,12 @@ void driverfs_create_partitions(struct gendisk *hd, int minor)
}
}
void driverfs_remove_partitions(struct gendisk *hd, int minor)
void driverfs_remove_partitions(struct gendisk *hd)
{
int max_p;
int part;
struct device * current_driverfs_dev;
struct hd_struct *p = hd->part + minor - hd->first_minor;
struct hd_struct *p = hd->part;
max_p=(1 << hd->minor_shift);
......@@ -225,10 +218,8 @@ void driverfs_remove_partitions(struct gendisk *hd, int minor)
}
}
current_driverfs_dev = &p->hd_driverfs_dev;
device_remove_file(current_driverfs_dev,
&dev_attr_type);
device_remove_file(current_driverfs_dev,
&dev_attr_kdev);
device_remove_file(current_driverfs_dev, &dev_attr_type);
device_remove_file(current_driverfs_dev, &dev_attr_kdev);
put_device(current_driverfs_dev);
return;
}
......@@ -256,7 +247,7 @@ void check_partition(struct gendisk *hd, struct block_device *bdev)
sprintf(state->name, "p");
} else {
unsigned n = hd->major;
disk_name(hd, minor(dev), state->name);
disk_name(hd, 0, state->name);
printk(KERN_INFO " %s:", state->name);
if (n - COMPAQ_SMART2_MAJOR <= 7 || n - COMPAQ_CISS_MAJOR <= 7)
sprintf(state->name, "p");
......@@ -274,7 +265,7 @@ void check_partition(struct gendisk *hd, struct block_device *bdev)
printk(" unable to read partition table\n");
goto out;
}
p = hd->part + minor(dev) - hd->first_minor;
p = hd->part;
for (j = 1; j < state->limit; j++) {
p[j].start_sect = state->parts[j].from;
p[j].nr_sects = state->parts[j].size;
......@@ -289,16 +280,16 @@ void check_partition(struct gendisk *hd, struct block_device *bdev)
printk(" unknown partition table\n");
out:
driverfs_create_partitions(hd, minor(dev));
devfs_register_partitions (hd, minor(dev), 0);
driverfs_create_partitions(hd);
devfs_register_partitions(hd, 0);
}
#ifdef CONFIG_DEVFS_FS
static void devfs_register_partition (struct gendisk *dev, int minor, int part)
static void devfs_register_partition(struct gendisk *dev, int part)
{
devfs_handle_t dir;
unsigned int devfs_flags = DEVFS_FL_DEFAULT;
struct hd_struct *p = dev->part + minor - dev->first_minor;
struct hd_struct *p = dev->part;
char devname[16];
if (p[part].de)
......@@ -310,21 +301,21 @@ static void devfs_register_partition (struct gendisk *dev, int minor, int part)
devfs_flags |= DEVFS_FL_REMOVABLE;
sprintf (devname, "part%d", part);
p[part].de = devfs_register (dir, devname, devfs_flags,
dev->major, minor + part,
dev->major, dev->first_minor + part,
S_IFBLK | S_IRUSR | S_IWUSR,
dev->fops, NULL);
}
static struct unique_numspace disc_numspace = UNIQUE_NUMBERSPACE_INITIALISER;
static void devfs_register_disc (struct gendisk *dev, int minor)
static void devfs_register_disc(struct gendisk *dev)
{
int pos = 0;
devfs_handle_t dir, slave;
unsigned int devfs_flags = DEVFS_FL_DEFAULT;
char dirname[64], symlink[16];
static devfs_handle_t devfs_handle;
struct hd_struct *p = dev->part + minor - dev->first_minor;
struct hd_struct *p = dev->part;
if (p[0].de)
return;
......@@ -350,7 +341,8 @@ static void devfs_register_disc (struct gendisk *dev, int minor)
sprintf(symlink, "disc%d", p[0].number);
devfs_mk_symlink (devfs_handle, symlink, DEVFS_FL_DEFAULT,
dirname + pos, &slave, NULL);
p[0].de = devfs_register (dir, "disc", devfs_flags, dev->major, minor,
p[0].de = devfs_register (dir, "disc", devfs_flags,
dev->major, dev->first_minor,
S_IFBLK | S_IRUSR | S_IWUSR, dev->fops, NULL);
devfs_auto_unregister(p[0].de, slave);
if (!dev->de_arr)
......@@ -358,14 +350,14 @@ static void devfs_register_disc (struct gendisk *dev, int minor)
}
#endif /* CONFIG_DEVFS_FS */
void devfs_register_partitions (struct gendisk *dev, int minor, int unregister)
void devfs_register_partitions (struct gendisk *dev, int unregister)
{
#ifdef CONFIG_DEVFS_FS
int part, max_p;
struct hd_struct *p = dev->part + minor - dev->first_minor;
struct hd_struct *p = dev->part;
if (!unregister)
devfs_register_disc (dev, minor);
devfs_register_disc(dev);
max_p = (1 << dev->minor_shift);
for (part = 1; part < max_p; part++) {
if ( unregister || (p[part].nr_sects < 1) ) {
......@@ -373,7 +365,7 @@ void devfs_register_partitions (struct gendisk *dev, int minor, int unregister)
p[part].de = NULL;
continue;
}
devfs_register_partition (dev, minor, part);
devfs_register_partition(dev, part);
}
if (unregister) {
devfs_unregister(p[0].de);
......@@ -402,7 +394,7 @@ void register_disk(struct gendisk *g, kdev_t dev, unsigned minors,
if (!g)
return;
p = g->part + minor(dev) - g->first_minor;
p = g->part;
p[0].nr_sects = size;
/* No minors to use for partitions */
......@@ -443,38 +435,24 @@ unsigned char *read_dev_sector(struct block_device *bdev, unsigned long n, Secto
return NULL;
}
int wipe_partitions(kdev_t dev)
int wipe_partitions(struct gendisk *disk)
{
struct gendisk *g;
kdev_t devp;
int p, major, minor, minor0, max_p, res;
struct hd_struct *part;
g = get_gendisk(dev);
if (g == NULL)
return -EINVAL;
max_p = 1 << g->minor_shift;
major = major(dev);
minor = minor(dev);
minor0 = minor & ~(max_p - 1);
if (minor0 != minor) /* for now only whole-disk reread */
return -EINVAL; /* %%% later.. */
part = g->part + minor - g->first_minor;
int max_p = 1 << disk->minor_shift;
int p;
/* invalidate stuff */
for (p = max_p - 1; p >= 0; p--) {
minor = minor0 + p;
devp = mk_kdev(major,minor);
kdev_t devp = mk_kdev(disk->major,disk->first_minor + p);
int res;
#if 0 /* %%% superfluous? */
if (part[p].nr_sects == 0)
if (disk->part[p].nr_sects == 0)
continue;
#endif
res = invalidate_device(devp, 1);
if (res)
return res;
part[p].start_sect = 0;
part[p].nr_sects = 0;
disk->part[p].start_sect = 0;
disk->part[p].nr_sects = 0;
}
return 0;
}
......@@ -281,7 +281,7 @@ struct sec_size {
extern struct sec_size * blk_sec[MAX_BLKDEV];
extern struct blk_dev_struct blk_dev[MAX_BLKDEV];
extern int wipe_partitions(kdev_t dev);
extern int wipe_partitions(struct gendisk *disk);
extern void register_disk(struct gendisk *dev, kdev_t first, unsigned minors, struct block_device_operations *ops, long size);
extern void check_partition(struct gendisk *disk, struct block_device *bdev);
extern void generic_make_request(struct bio *bio);
......
......@@ -240,11 +240,10 @@ struct unixware_disklabel {
#ifdef __KERNEL__
char *disk_name (struct gendisk *hd, int minor, char *buf);
char *disk_name (struct gendisk *hd, int part, char *buf);
extern void devfs_register_partitions (struct gendisk *dev, int minor,
int unregister);
extern void driverfs_remove_partitions (struct gendisk *hd, int minor);
extern void devfs_register_partitions (struct gendisk *dev, int unregister);
extern void driverfs_remove_partitions (struct gendisk *hd);
static inline unsigned int disk_index (kdev_t dev)
{
......
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