Commit e86a3786 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] (25/25) more cleanups of struct gendisk.

	* we remove the paritition 0 from ->part[] and put the old
contents of ->part[0] into gendisk itself; indexes are shifted, obviously.
	* ->part is allocated at add_gendisk() time and freed at del_gendisk()
according to value of ->minor_shift; static arrays of hd_struct are gone
from drivers, ditto for manual allocations a-la ide.  As the matter of fact,
none of the drivers know about struct hd_struct now.
parent 3708de94
......@@ -193,8 +193,6 @@ struct mfm_info {
#define MFM_DRV_INFO mfm_info[raw_cmd.dev]
static struct hd_struct mfm[MFM_MAXDRIVES << 6];
/* Stuff from the assembly routines */
extern unsigned int hdc63463_baseaddress; /* Controller base address */
extern unsigned int hdc63463_irqpolladdress; /* Address to read to test for int */
......@@ -888,14 +886,12 @@ static struct gendisk mfm_gendisk[2] = {
.first_minor = 0,
.major_name = "mfma",
.minor_shift = 6,
.part = mfm,
},
{
.major = MAJOR_NR,
.first_minor = 64,
.major_name = "mfmb",
.minor_shift = 6,
.part = mfm + 64,
};
static void mfm_request(void)
......
......@@ -1968,7 +1968,6 @@ static boolean DAC960_RegisterBlockDevice(DAC960_Controller_T *Controller)
struct gendisk *disk = &Controller->disks[n];
memset(disk, 0, sizeof(struct gendisk));
sprintf(names + 9 * n, "rd/c%dd%d", Controller->ControllerNumber, n);
disk->part = Controller->DiskPartitions + (n<<DAC960_MaxPartitionsBits);
disk->major = MajorNumber;
disk->first_minor = n << DAC960_MaxPartitionsBits;
disk->major_name = names + 9 * n;
......
......@@ -2196,7 +2196,6 @@ typedef struct file File_T;
typedef struct block_device_operations BlockDeviceOperations_T;
typedef struct completion Completion_T;
typedef struct hd_geometry DiskGeometry_T;
typedef struct hd_struct DiskPartition_T;
typedef struct inode Inode_T;
typedef struct inode_operations InodeOperations_T;
typedef kdev_t KernelDevice_T;
......@@ -2472,7 +2471,6 @@ typedef struct DAC960_Controller
boolean LogicalDriveFoundDuringScan[DAC960_MaxLogicalDrives];
} V2;
} FW;
DiskPartition_T DiskPartitions[DAC960_MinorCount];
unsigned char ProgressBuffer[DAC960_ProgressBufferSize];
unsigned char UserStatusBuffer[DAC960_UserMessageSize];
}
......
......@@ -245,7 +245,6 @@ char *acsi_buffer;
unsigned long phys_acsi_buffer;
static int NDevices;
static struct hd_struct acsi_part[MAX_DEV<<4];
static char acsi_names[MAX_DEV*4];
static int access_count[MAX_DEV];
......@@ -1698,7 +1697,6 @@ static void acsi_geninit(void)
disk->first_minor = i << 4;
disk->major_name = acsi_names + 4*i;
disk->minor_shift = (acsi_info[i].type==HARDDISK)?4:0;
disk->part = acsi_part + (i<<4);
disk->fops = &acsi_fops;
add_gendisk(disk);
register_disk(disk, mk_kdev(disk->major, disk->first_minor),
......
......@@ -95,18 +95,18 @@ int add_partition(struct block_device *bdev, struct blkpg_partition *p)
return -EINVAL;
/* partition number in use? */
if (g->part[p->pno].nr_sects != 0)
if (g->part[p->pno - 1].nr_sects != 0)
return -EBUSY;
/* overlap? */
for (i = 1; i < (1<<g->minor_shift); i++)
for (i = 0; i < (1<<g->minor_shift) - 1; i++)
if (!(pstart+plength <= g->part[i].start_sect ||
pstart >= g->part[i].start_sect + g->part[i].nr_sects))
return -EBUSY;
/* all seems OK */
g->part[p->pno].start_sect = pstart;
g->part[p->pno].nr_sects = plength;
g->part[p->pno - 1].start_sect = pstart;
g->part[p->pno - 1].nr_sects = plength;
update_partition(g, p->pno);
return 0;
}
......@@ -138,7 +138,7 @@ int del_partition(struct block_device *bdev, struct blkpg_partition *p)
return -EINVAL;
/* existing drive and partition? */
if (g->part[p->pno].nr_sects == 0)
if (g->part[p->pno - 1].nr_sects == 0)
return -ENXIO;
/* partition in use? Incomplete check for now. */
......@@ -154,8 +154,8 @@ int del_partition(struct block_device *bdev, struct blkpg_partition *p)
fsync_bdev(bdevp);
invalidate_bdev(bdevp, 0);
g->part[p->pno].start_sect = 0;
g->part[p->pno].nr_sects = 0;
g->part[p->pno - 1].start_sect = 0;
g->part[p->pno - 1].nr_sects = 0;
update_partition(g, p->pno);
bd_release(bdevp);
bdput(bdevp);
......
......@@ -750,7 +750,6 @@ static int revalidate_allvol(kdev_t dev)
* Set the partition and block size structures for all volumes
* on this controller to zero. We will reread all of this data
*/
memset(hba[ctlr]->hd, 0, sizeof(struct hd_struct) * 256);
memset(hba[ctlr]->drv, 0, sizeof(drive_info_struct)
* CISS_MAX_LUN);
/*
......@@ -2445,7 +2444,6 @@ static int __init cciss_init_one(struct pci_dev *pdev,
disk->first_minor = j << NWD_SHIFT;
disk->major_name = NULL;
disk->minor_shift = NWD_SHIFT;
disk->part = hba[i]->hd + (j << NWD_SHIFT);
if( !(drv->nr_blocks))
continue;
(BLK_DEFAULT_QUEUE(MAJOR_NR + i))->hardsect_size = drv->block_size;
......
......@@ -83,9 +83,6 @@ struct ctlr_info
// Disk structures we need to pass back
struct gendisk gendisk[NWD];
char names[12 * NWD];
// indexed by minor numbers
struct hd_struct hd[256];
int sizes[256];
#ifdef CONFIG_CISS_SCSI_TAPE
void *scsi_ctlr; /* ptr to structure containing scsi related stuff */
#endif
......
......@@ -102,7 +102,6 @@ static struct board_type products[] = {
{ 0x40580E11, "Smart Array 431", &smart4_access },
};
static struct hd_struct * ida;
static char *ida_names;
static struct gendisk ida_gendisk[MAX_CTLR * NWD];
......@@ -320,7 +319,6 @@ void cleanup_module(void)
}
devfs_find_and_unregister(NULL, "ida", 0, 0, 0, 0);
remove_proc_entry("cpqarray", proc_root_driver);
kfree(ida);
kfree(ida_names);
}
#endif /* MODULE */
......@@ -346,15 +344,12 @@ int __init cpqarray_init(void)
printk("Found %d controller(s)\n", nr_ctlr);
/* allocate space for disk structs */
ida = kmalloc(sizeof(struct hd_struct)*nr_ctlr*NWD*16, GFP_KERNEL);
ida_names = kmalloc(nr_ctlr*NWD*10, GFP_KERNEL);
if (!ida || !ida_names) {
if (!ida_names) {
printk( KERN_ERR "cpqarray: out of memory");
kfree(ida);
kfree(ida_names);
return(num_cntlrs_reg);
}
memset(ida, 0, sizeof(struct hd_struct)*nr_ctlr*NWD*16);
/*
* register block devices
* Find disks and fill in structs
......@@ -407,7 +402,6 @@ int __init cpqarray_init(void)
if (num_cntlrs_reg == 0)
{
kfree(ida);
kfree(ida_names);
}
return(num_cntlrs_reg);
......@@ -449,7 +443,6 @@ int __init cpqarray_init(void)
disk->major = MAJOR_NR + i;
disk->first_minor = j<<NWD_SHIFT;
disk->minor_shift = NWD_SHIFT;
disk->part = ida + i*256 + (j<<NWD_SHIFT);
disk->flags = GENHD_FL_DEVFS;
disk->fops = &ida_fops;
if (!drv->nr_blks)
......@@ -1462,7 +1455,6 @@ static int revalidate_allvol(kdev_t dev)
del_gendisk(disk);
disk->major_name = NULL;
}
memset(ida+(ctlr*256), 0, sizeof(struct hd_struct)*NWD*16);
memset(hba[ctlr]->drv, 0, sizeof(drv_info_t)*NWD);
/*
......
......@@ -23,6 +23,7 @@
#include <linux/init.h>
#include <linux/spinlock.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
static rwlock_t gendisk_lock;
......@@ -43,6 +44,19 @@ void
add_gendisk(struct gendisk *gp)
{
struct gendisk *sgp;
struct hd_struct *p = NULL;
if (gp->minor_shift) {
size_t size = sizeof(struct hd_struct)*((1<<gp->minor_shift)-1);
p = kmalloc(size, GFP_KERNEL);
if (!p) {
printk(KERN_ERR "out of memory; no partitions for %s\n",
gp->major_name);
gp->minor_shift = 0;
} else
memset(p, 0, size);
}
gp->part = p;
write_lock(&gendisk_lock);
......@@ -148,13 +162,17 @@ static int show_partition(struct seq_file *part, void *v)
seq_puts(part, "major minor #blocks name\n\n");
/* show the full disk and all non-0 size partitions of it */
for (n = 0; n < 1<<sgp->minor_shift; n++) {
if (n && sgp->part[n].nr_sects == 0)
seq_printf(part, "%4d %4d %10ld %s\n",
sgp->major, sgp->first_minor,
get_capacity(sgp) >> 1,
disk_name(sgp, 0, buf));
for (n = 0; n < (1<<sgp->minor_shift) - 1; n++) {
if (sgp->part[n].nr_sects == 0)
continue;
seq_printf(part, "%4d %4d %10ld %s\n",
sgp->major, n + sgp->first_minor,
sgp->major, n + 1 + sgp->first_minor,
sgp->part[n].nr_sects >> 1 ,
disk_name(sgp, n, buf));
disk_name(sgp, n + 1, buf));
}
return 0;
......
......@@ -271,8 +271,6 @@ static void pd_doorlock(int unit, int func);
static int pd_check_media(kdev_t dev);
static void pd_eject( int unit);
static struct hd_struct pd_hd[PD_DEVS];
#define PD_NAMELEN 8
struct pd_unit {
......@@ -689,7 +687,6 @@ static int pd_detect( void )
PD.gd.fops = &pd_fops;
PD.gd.major = major;
PD.gd.first_minor = unit << PD_BITS;
PD.gd.part = pd_hd + (unit << PD_BITS);
add_gendisk(&PD.gd);
register_disk(&PD.gd,mk_kdev(MAJOR_NR,unit<<PD_BITS),
PD_PARTNS,&pd_fops,
......
......@@ -109,7 +109,6 @@ static DECLARE_WAIT_QUEUE_HEAD(ps2esdi_int);
static int no_int_yet;
static int ps2esdi_drives;
static struct hd_struct ps2esdi[MAX_HD << 6];
static u_short io_base;
static struct timer_list esdi_timer = { function: ps2esdi_reset_timer };
static int reset_status;
......@@ -152,14 +151,12 @@ static struct gendisk ps2esdi_gendisk[2] = {
major_name: "eda",
first_minor: 0,
minor_shift: 6,
part: ps2esdi,
fops: &ps2esdi_fops,
},{
major: MAJOR_NR,
first_minor: 64,
major_name: "edb",
minor_shift: 6,
part: ps2esdi+64,
fops: &ps2esdi_fops,
}
};
......
......@@ -159,9 +159,6 @@ static struct cardinfo cards[MM_MAXCARDS];
static struct block_device_operations mm_fops;
static struct timer_list battery_timer;
static struct hd_struct mm_partitions[MM_MAXCARDS << MM_SHIFT];
static int num_cards = 0;
static struct gendisk mm_gendisk[MM_MAXCARDS];
......@@ -1192,7 +1189,6 @@ int __init mm_init(void)
struct gendisk *disk = mm_gendisk + i;
sprintf(mm_names + i*6, "umem%c", 'a'+i);
spin_lock_init(&cards[i].lock);
disk->part = mm_partitions + (i << MM_SHIFT);
disk->major = major_nr;
disk->first_minor = i << MM_SHIFT;
disk->major_name = mm_names + i*6;
......
......@@ -121,8 +121,6 @@ static unsigned int xd_bases[] __initdata =
0xE0000
};
static struct hd_struct xd_struct[XD_MAXDRIVES << 6];
static spinlock_t xd_lock = SPIN_LOCK_UNLOCKED;
extern struct block_device_operations xd_fops;
......@@ -133,14 +131,12 @@ static struct gendisk xd_gendisk[2] = {
.first_minor = 0,
.major_name = "xda",
.minor_shift = 6,
.part = xd_struct,
.fops = &xd_fops,
},{
.major = MAJOR_NR,
.first_minor = 64,
.major_name = "xdb",
.minor_shift = 6,
.part = xd_struct + 64,
.fops = &xd_fops,
}
};
......
......@@ -145,8 +145,6 @@ static struct hd_i_struct hd_info[MAX_HD];
static int NR_HD;
#endif
static struct hd_struct hd[MAX_HD<<6];
static struct timer_list device_timer;
#define TIMEOUT_VALUE (6*HZ)
......@@ -706,14 +704,12 @@ static struct gendisk hd_gendisk[2] = {
.first_minor = 0,
.major_name = "hda",
.minor_shift = 6,
.part = hd,
.fops = &hd_fops,
},{
.major = MAJOR_NR,
.first_minor = 64,
.major_name = "hdb",
.minor_shift = 6,
.part = hd + 64,
.fops = &hd_fops,
}
};
......
......@@ -807,7 +807,6 @@ static int init_irq (ide_hwif_t *hwif)
static void init_gendisk (ide_hwif_t *hwif)
{
struct gendisk *gd;
struct hd_struct *part;
unsigned int unit, units, minors;
extern devfs_handle_t ide_devfs_handle;
char *names;
......@@ -828,20 +827,12 @@ static void init_gendisk (ide_hwif_t *hwif)
goto err_kmalloc_gd;
memset(gd, 0, MAX_DRIVES * sizeof(struct gendisk));
part = kmalloc(minors * sizeof(struct hd_struct), GFP_KERNEL);
if (!part)
goto err_kmalloc_gd_part;
memset(part, 0, minors * sizeof(struct hd_struct));
names = kmalloc (4 * MAX_DRIVES, GFP_KERNEL);
if (!names)
goto err_kmalloc_gd_names;
memset(names, 0, 4 * MAX_DRIVES);
for (unit = 0; unit < units; ++unit) {
gd[unit].part = part + (unit << PARTN_BITS);
hwif->drives[unit].part = gd[unit].part;
gd[unit].major = hwif->major;
gd[unit].first_minor = unit << PARTN_BITS;
sprintf(names + 4*unit, "hd%c",'a'+hwif->index*MAX_DRIVES+unit);
......@@ -877,8 +868,6 @@ static void init_gendisk (ide_hwif_t *hwif)
return;
err_kmalloc_gd_names:
kfree(part);
err_kmalloc_gd_part:
kfree(gd);
err_kmalloc_gd:
printk(KERN_WARNING "(ide::init_gendisk) Out of memory\n");
......
......@@ -2058,10 +2058,9 @@ void ide_unregister (unsigned int index)
gd = hwif->drives[0].disk;
if (gd) {
int i;
kfree(gd->part);
kfree(gd);
for (i = 0; i < MAX_DRIVES; i++)
hwif->drives[i].disk = NULL;
kfree(gd);
}
old_hwif = *hwif;
init_hwif_data (index); /* restore hwif data to pristine status */
......
......@@ -103,11 +103,6 @@ static ctl_table raid_root_table[] = {
{0}
};
/*
* these have to be allocated separately because external
* subsystems want to have a pre-defined structure
*/
struct hd_struct md_hd_struct[MAX_MD_DEVS];
static void md_recover_arrays(void);
static mdk_thread_t *md_recovery_thread;
......@@ -1458,7 +1453,6 @@ static int do_md_run(mddev_t * mddev)
disk->minor_shift = 0;
sprintf(major_name, "md%d", mdidx(mddev));
disk->major_name = major_name;
disk->part = md_hd_struct + mdidx(mddev);
disk->fops = &md_fops;
mddev->pers = pers[pnum];
......@@ -3178,11 +3172,10 @@ int __init md_init(void)
return (-1);
}
devfs_handle = devfs_mk_dir (NULL, "md", NULL);
/* we don't use devfs_register_series because we want to fill md_hd_struct */
for (minor=0; minor < MAX_MD_DEVS; ++minor) {
char devname[128];
sprintf (devname, "%u", minor);
md_hd_struct[minor].de = devfs_register (devfs_handle,
devfs_register (devfs_handle,
devname, DEVFS_FL_DEFAULT, MAJOR_NR, minor,
S_IFBLK | S_IRUSR | S_IWUSR, &md_fops, NULL);
}
......
......@@ -186,7 +186,6 @@ static struct i2ob_request *i2ob_backlog_tail[MAX_I2O_CONTROLLERS];
static struct i2ob_device i2ob_dev[MAX_I2OB<<4];
static int i2ob_dev_count = 0;
static struct hd_struct i2ob[MAX_I2OB<<4];
static struct gendisk i2o_disk[MAX_I2OB];
static char i2o_names[MAX_I2OB * 8];
......@@ -1771,7 +1770,6 @@ int i2o_block_init(void)
disk->major = MAJOR_NR;
disk->first_minor = i<<4;
disk->minor_shift = 4;
disk->part = i2ob + (i<<4);
disk->fops = &i2ob_fops;
disk->major_name = i2o_names + i*8;
sprintf(disk->major_name, "i2o/hd%c", 'a' + i);
......
......@@ -175,8 +175,6 @@ static struct mtd_notifier ftl_notifier = {
#define XFER_PREPARED 0x03
#define XFER_FAILED 0x04
static struct hd_struct ftl_hd[MINOR_NR(MAX_DEV, 0, 0)];
/*====================================================================*/
static int ftl_ioctl(struct inode *inode, struct file *file,
......@@ -1252,7 +1250,6 @@ static void ftl_notify_add(struct mtd_info *mtd)
disk->first_minor = device << 4;
disk->major_name = name;
disk->minor_shift = PART_BITS;
disk->part = ftl_hd + (device << 4);
disk->fops = &ftl_blk_fops;
partition->mtd = mtd;
partition->disk = disk;
......
......@@ -49,16 +49,6 @@
/* Linux-specific block device functions */
/* I _HATE_ the Linux block device setup more than anything else I've ever
* encountered, except ...
*/
/* .. for the Linux partition table handling. */
/* So why didn't you fucking go and clean it up? -- AV */
struct hd_struct part_table[256];
static struct block_device_operations nftl_fops;
struct NFTLrecord *NFTLs[MAX_NFTLS];
static void NFTL_setup(struct mtd_info *mtd)
......@@ -150,7 +140,6 @@ static void NFTL_setup(struct mtd_info *mtd)
gd->major = MAJOR_NR;
gd->first_minor = firstfree << NFTL_PARTN_BITS;
gd->minor_shift = NFTL_PARTN_BITS;
gd->part = part_table + (firstfree << NFTL_PARTN_BITS);
gd->major_name = name;
nftl->disk = gd;
add_gendisk(gd);
......
......@@ -35,7 +35,6 @@ struct major_info {
int major;
struct gendisk disks[DASD_PER_MAJOR];
char names[DASD_PER_MAJOR * 8];
struct hd_struct part[1<<MINORBITS];
};
/*
......@@ -106,7 +105,6 @@ dasd_register_major(int major)
disk->minor_shift = DASD_PARTN_BITS;
disk->fops = &dasd_device_operations;
disk->flags = GENHD_FL_DEVFS;
disk->part = mi->part + (i << DASD_PARTN_BITS);
}
/* Setup block device pointers for the new major. */
......
......@@ -84,9 +84,6 @@
#define SD_DSK_ARR_LUMP 6 /* amount to over allocate sd_dsk_arr by */
struct hd_struct *sd;
static Scsi_Disk ** sd_dsk_arr;
static rwlock_t sd_dsk_arr_lock = RW_LOCK_UNLOCKED;
......@@ -1195,12 +1192,10 @@ static int sd_init()
init_mem_lth(sd_disks, sd_template.dev_max);
if (sd_disks)
zero_mem_lth(sd_disks, sd_template.dev_max);
init_mem_lth(sd, maxparts);
if (!sd_dsk_arr || !sd || !sd_disks)
if (!sd_dsk_arr || !sd_disks)
goto cleanup_mem;
zero_mem_lth(sd, maxparts);
return 0;
#undef init_mem_lth
......@@ -1209,8 +1204,6 @@ static int sd_init()
cleanup_mem:
vfree(sd_disks);
sd_disks = NULL;
vfree(sd);
sd = NULL;
if (sd_dsk_arr) {
for (k = 0; k < sd_template.dev_max; ++k)
vfree(sd_dsk_arr[k]);
......@@ -1347,7 +1340,6 @@ static int sd_attach(Scsi_Device * sdp)
gd->major = SD_MAJOR(dsk_nr>>4);
gd->first_minor = (dsk_nr & 15)<<4;
gd->minor_shift = 4;
gd->part = sd + (dsk_nr << 4);
gd->fops = &sd_fops;
if (dsk_nr > 26)
sprintf(p->name, "sd%c%c", 'a'+dsk_nr/26-1, 'a'+dsk_nr%26);
......@@ -1465,7 +1457,6 @@ static void __exit exit_sd(void)
vfree(sd_dsk_arr[k]);
vfree(sd_dsk_arr);
}
vfree((char *) sd);
for (k = 0; k < N_USED_SD_MAJORS; k++) {
blk_dev[SD_MAJOR(k)].queue = NULL;
blk_clear(SD_MAJOR(k));
......
......@@ -20,8 +20,6 @@
#include <linux/genhd.h>
#endif
extern struct hd_struct *sd;
typedef struct scsi_disk {
unsigned capacity; /* size in 512-byte sectors */
Scsi_Device *device;
......
......@@ -744,31 +744,25 @@ void sr_finish()
for (i = 0; i < sr_template.nr_dev; ++i) {
struct gendisk *disk;
/* KLUDGE - will go away */
struct {
struct gendisk disk;
struct hd_struct part;
} *p;
Scsi_CD *cd = &scsi_CDs[i];
/* If we have already seen this, then skip it. Comes up
* with loadable modules. */
if (cd->disk)
continue;
p = kmalloc(sizeof(*p), GFP_KERNEL);
if (!p)
disk = kmalloc(sizeof(struct gendisk), GFP_KERNEL);
if (!disk)
continue;
if (cd->disk) {
kfree(p);
kfree(disk);
continue;
}
memset(p, 0, sizeof(*p));
p->disk.part = &p->part;
p->disk.major = MAJOR_NR;
p->disk.first_minor = i;
p->disk.major_name = cd->cdi.name;
p->disk.minor_shift = 0;
p->disk.fops = &sr_bdops;
cd->disk = disk = &p->disk;
memset(disk, 0, sizeof(struct gendisk));
disk->major = MAJOR_NR;
disk->first_minor = i;
disk->minor_shift = 0;
disk->major_name = cd->cdi.name;
disk->fops = &sr_bdops;
cd->disk = disk;
cd->capacity = 0x1fffff;
cd->device->sector_size = 2048;/* A guess, just in case */
cd->needs_sector_size = 1;
......
......@@ -503,7 +503,6 @@ int check_disk_change(struct block_device *bdev)
struct block_device_operations * bdops = bdev->bd_op;
kdev_t dev = to_kdev_t(bdev->bd_dev);
struct gendisk *disk;
struct hd_struct *part;
if (bdops->check_media_change == NULL)
return 0;
......@@ -517,7 +516,6 @@ int check_disk_change(struct block_device *bdev)
printk("VFS: busy inodes on changed media.\n");
disk = get_gendisk(dev);
part = disk->part + minor(dev) - disk->first_minor;
if (bdops->revalidate)
bdops->revalidate(dev);
if (disk && disk->minor_shift)
......@@ -632,11 +630,9 @@ static int do_open(struct block_device *bdev, struct inode *inode, struct file *
sector_t sect = 0;
bdev->bd_offset = 0;
if (g) {
struct hd_struct *p;
p = g->part + minor(dev) - g->first_minor;
sect = p->nr_sects;
} else if (blk_size[major(dev)])
if (g)
sect = get_capacity(g);
else if (blk_size[major(dev)])
sect = blk_size[major(dev)][minor(dev)] << 1;
bd_set_size(bdev, (loff_t)sect << 9);
bdi = blk_get_backing_dev_info(bdev);
......@@ -653,7 +649,7 @@ static int do_open(struct block_device *bdev, struct inode *inode, struct file *
if (!bdev->bd_openers) {
struct gendisk *g = get_gendisk(dev);
struct hd_struct *p;
p = g->part + minor(dev) - g->first_minor;
p = g->part + minor(dev) - g->first_minor - 1;
inode->i_data.backing_dev_info =
bdev->bd_inode->i_data.backing_dev_info =
bdev->bd_contains->bd_inode->i_data.backing_dev_info;
......
......@@ -89,19 +89,25 @@ static int (*check_part[])(struct parsed_partitions *, struct block_device *) =
char *disk_name(struct gendisk *hd, int part, char *buf)
{
if (part < 1<<hd->minor_shift && hd->part[part].de) {
int pos;
pos = devfs_generate_path(hd->part[part].de, buf, 64);
if (!part) {
if (hd->disk_de) {
pos = devfs_generate_path(hd->disk_de, buf, 64);
if (pos >= 0)
return buf + pos;
}
if (!part)
sprintf(buf, "%s", hd->major_name);
else if (isdigit(hd->major_name[strlen(hd->major_name)-1]))
} else {
if (hd->part[part-1].de) {
pos = devfs_generate_path(hd->part[part-1].de, buf, 64);
if (pos >= 0)
return buf + pos;
}
if (isdigit(hd->major_name[strlen(hd->major_name)-1]))
sprintf(buf, "%sp%d", hd->major_name, part);
else
sprintf(buf, "%s%d", hd->major_name, part);
}
return buf;
}
......@@ -144,21 +150,29 @@ static void driverfs_create_partitions(struct gendisk *hd)
*name = *bus_id = '\0';
}
dev = &p[0].hd_driverfs_dev;
dev = &hd->disk_dev;
dev->driver_data = (void *)(long)__mkdev(hd->major, hd->first_minor);
sprintf(dev->name, "%sdisc", name);
sprintf(dev->bus_id, "%sdisc", bus_id);
for (part=1; part < max_p; part++) {
dev = &p[part].hd_driverfs_dev;
dev = &p[part-1].hd_driverfs_dev;
sprintf(dev->name, "%spart%d", name, part);
sprintf(dev->bus_id, "%s:p%d", bus_id, part);
if (!p[part].nr_sects)
if (!p[part-1].nr_sects)
continue;
dev->driver_data =
(void *)(long)__mkdev(hd->major, hd->first_minor+part);
}
for (part=0; part < max_p; part++) {
dev = &hd->disk_dev;
dev->parent = parent;
if (parent)
dev->bus = parent->bus;
device_register(dev);
device_create_file(dev, &dev_attr_type);
device_create_file(dev, &dev_attr_kdev);
for (part=0; part < max_p-1; part++) {
dev = &p[part].hd_driverfs_dev;
dev->parent = parent;
if (parent)
......@@ -174,11 +188,12 @@ static void driverfs_create_partitions(struct gendisk *hd)
static void driverfs_remove_partitions(struct gendisk *hd)
{
int max_p = 1<<hd->minor_shift;
struct device *dev;
struct hd_struct *p;
int part;
for (part=0, p = hd->part; part < max_p; part++, p++) {
struct device *dev = &p->hd_driverfs_dev;
for (part=1, p = hd->part; part < max_p; part++, p++) {
dev = &p->hd_driverfs_dev;
if (dev->driver_data) {
device_remove_file(dev, &dev_attr_type);
device_remove_file(dev, &dev_attr_kdev);
......@@ -186,6 +201,13 @@ static void driverfs_remove_partitions(struct gendisk *hd)
dev->driver_data = NULL;
}
}
dev = &hd->disk_dev;
if (dev->driver_data) {
device_remove_file(dev, &dev_attr_type);
device_remove_file(dev, &dev_attr_kdev);
put_device(dev);
dev->driver_data = NULL;
}
}
static void check_partition(struct gendisk *hd, struct block_device *bdev)
......@@ -227,10 +249,10 @@ static void check_partition(struct gendisk *hd, struct block_device *bdev)
}
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;
p[j-1].start_sect = state->parts[j].from;
p[j-1].nr_sects = state->parts[j].size;
#if CONFIG_BLK_DEV_MD
if (!state->parts[j].flags)
if (!state->parts[j-1].flags)
continue;
md_autodetect_dev(dev+j);
#endif
......@@ -248,15 +270,15 @@ static void devfs_register_partition(struct gendisk *dev, int part)
struct hd_struct *p = dev->part;
char devname[16];
if (p[part].de)
if (p[part-1].de)
return;
dir = devfs_get_parent(p[0].de);
dir = devfs_get_parent(dev->disk_de);
if (!dir)
return;
if (dev->flags & GENHD_FL_REMOVABLE)
devfs_flags |= DEVFS_FL_REMOVABLE;
sprintf(devname, "part%d", part);
p[part].de = devfs_register (dir, devname, devfs_flags,
p[part-1].de = devfs_register (dir, devname, devfs_flags,
dev->major, dev->first_minor + part,
S_IFBLK | S_IRUSR | S_IWUSR,
dev->fops, NULL);
......@@ -300,10 +322,10 @@ static void devfs_create_partitions(struct gendisk *dev)
sprintf(symlink, "disc%d", dev->number);
devfs_mk_symlink (devfs_handle, symlink, DEVFS_FL_DEFAULT,
dirname + pos, &slave, NULL);
p->de = devfs_register(dir, "disc", devfs_flags,
dev->disk_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->de, slave);
devfs_auto_unregister(dev->disk_de, slave);
if (!(dev->flags & GENHD_FL_DEVFS))
devfs_auto_unregister (slave, dir);
for (part = 1, p++; part < max_p; part++, p++)
......@@ -316,10 +338,12 @@ static void devfs_remove_partitions(struct gendisk *dev)
{
#ifdef CONFIG_DEVFS_FS
int part;
for (part = 1<<dev->minor_shift; part--; ) {
for (part = (1<<dev->minor_shift)-1; part--; ) {
devfs_unregister(dev->part[part].de);
dev->part[part].de = NULL;
}
devfs_unregister(dev->disk_de);
dev->disk_de = NULL;
devfs_dealloc_unique_number(&disc_numspace, dev->number);
#endif
}
......@@ -363,7 +387,7 @@ void register_disk(struct gendisk *disk, kdev_t dev, unsigned minors,
void update_partition(struct gendisk *disk, int part)
{
struct hd_struct *p = disk->part + part;
struct hd_struct *p = disk->part + part - 1;
struct device *dev = &p->hd_driverfs_dev;
if (!p->nr_sects) {
......@@ -402,7 +426,7 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
if (res)
return res;
bdev->bd_invalidated = 0;
for (p = 1; p < (1<<disk->minor_shift); p++) {
for (p = 0; p < (1<<disk->minor_shift) - 1; p++) {
disk->part[p].start_sect = 0;
disk->part[p].nr_sects = 0;
}
......@@ -441,22 +465,32 @@ unsigned char *read_dev_sector(struct block_device *bdev, unsigned long n, Secto
static int wipe_partitions(struct gendisk *disk)
{
int max_p = 1 << disk->minor_shift;
kdev_t devp;
int res;
int p;
/* invalidate stuff */
for (p = max_p - 1; p >= 0; p--) {
kdev_t devp = mk_kdev(disk->major,disk->first_minor + p);
int res;
for (p = max_p - 1; p > 0; p--) {
devp = mk_kdev(disk->major,disk->first_minor + p);
#if 0 /* %%% superfluous? */
if (disk->part[p].nr_sects == 0)
if (disk->part[p-1].nr_sects == 0)
continue;
#endif
res = invalidate_device(devp, 1);
if (res)
return res;
disk->part[p].start_sect = 0;
disk->part[p].nr_sects = 0;
disk->part[p-1].start_sect = 0;
disk->part[p-1].nr_sects = 0;
}
devp = mk_kdev(disk->major,disk->first_minor);
#if 0 /* %%% superfluous? */
if (disk->part[p].nr_sects == 0)
continue;
#endif
res = invalidate_device(devp, 1);
if (res)
return res;
disk->capacity = 0;
return 0;
}
......@@ -466,4 +500,8 @@ void del_gendisk(struct gendisk *disk)
wipe_partitions(disk);
unlink_gendisk(disk);
devfs_remove_partitions(disk);
if (disk->part) {
kfree(disk->part);
disk->part = NULL;
}
}
......@@ -79,11 +79,14 @@ struct gendisk {
struct hd_struct *part; /* [indexed by minor] */
struct gendisk *next;
struct block_device_operations *fops;
sector_t capacity;
devfs_handle_t de;
struct device *driverfs_dev;
int flags;
int number; /* devfs crap */
devfs_handle_t de; /* more of the same */
devfs_handle_t disk_de; /* piled higher and deeper */
struct device *driverfs_dev;
struct device disk_dev;
};
/* drivers/block/genhd.c */
......@@ -97,11 +100,11 @@ static inline unsigned long get_start_sect(struct block_device *bdev)
}
static inline sector_t get_capacity(struct gendisk *disk)
{
return disk->part[0].nr_sects;
return disk->capacity;
}
static inline void set_capacity(struct gendisk *disk, sector_t size)
{
disk->part[0].nr_sects = size;
disk->capacity = size;
}
#endif /* __KERNEL__ */
......
......@@ -508,7 +508,6 @@ typedef struct ide_drive_s {
struct hwif_s *hwif; /* actually (ide_hwif_t *) */
wait_queue_head_t wqueue; /* used to wait for drive in open() */
struct hd_driveid *id; /* drive model identification info */
struct hd_struct *part; /* drive partition table */
char name[4]; /* drive name, such as "hda" */
struct ide_driver_s *driver; /* (ide_driver_t *) */
void *driver_data; /* extra driver data */
......
......@@ -61,7 +61,6 @@
#define MD_PATCHLEVEL_VERSION 0
extern int md_size[MAX_MD_DEVS];
extern struct hd_struct md_hd_struct[MAX_MD_DEVS];
extern char * partition_name (kdev_t dev);
extern inline char * bdev_partition_name (struct block_device *bdev)
......
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