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