Commit 3708de94 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] (24/25) disk capacity helpers

	new helpers - get_capacity(gendisk)/set_capacity(gendisk, sectors).
Drivers switched to these; that eliminates most of the accesses to
disk->part[]... in the drivers (and makes code more readable, while
we are at it).  That had caught several bugs when minor had been
used in place of minor>>minor_shift (acsi.c is especially nasty in
that respect; I don't know if it had ever been used with multiple
devices...)
parent 07586b33
...@@ -882,6 +882,22 @@ static void mfm_rerequest(void) ...@@ -882,6 +882,22 @@ static void mfm_rerequest(void)
mfm_request(); mfm_request();
} }
static struct gendisk mfm_gendisk[2] = {
{
.major = MAJOR_NR,
.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) static void mfm_request(void)
{ {
DBG("mfm_request CURRENT=%p Busy=%d\n", CURRENT, Busy); DBG("mfm_request CURRENT=%p Busy=%d\n", CURRENT, Busy);
...@@ -895,7 +911,7 @@ static void mfm_request(void) ...@@ -895,7 +911,7 @@ static void mfm_request(void)
Busy = 1; Busy = 1;
while (1) { while (1) {
unsigned int dev, block, nsect; unsigned int dev, block, nsect, unit;
DBG("mfm_request: loop start\n"); DBG("mfm_request: loop start\n");
sti(); sti();
...@@ -912,26 +928,26 @@ static void mfm_request(void) ...@@ -912,26 +928,26 @@ static void mfm_request(void)
DBG("mfm_request: before arg extraction\n"); DBG("mfm_request: before arg extraction\n");
dev = minor(CURRENT->rq_dev); dev = minor(CURRENT->rq_dev);
unit = dev>>6;
block = CURRENT->sector; block = CURRENT->sector;
nsect = CURRENT->nr_sectors; nsect = CURRENT->nr_sectors;
#ifdef DEBUG #ifdef DEBUG
/*if ((dev>>6)==1) */ console_printf("mfm_request: raw vals: dev=%d (block=512 bytes) block=%d nblocks=%d\n", dev, block, nsect); /*if (unit==1) */ console_printf("mfm_request: raw vals: dev=%d (block=512 bytes) block=%d nblocks=%d\n", dev, block, nsect);
#endif #endif
if (dev >= (mfm_drives << 6) || if (unit >= mfm_drives ||
block >= mfm[dev].nr_sects || ((block+nsect) > mfm[dev].nr_sects)) { block >= get_capacity(mfm_gendisk + unit) ||
if (dev >= (mfm_drives << 6)) ((block+nsect) > get_capacity(mfm_gendisk + unit))) {
if (unit >= mfm_drives)
printk("mfm: bad minor number: device=%s\n", kdevname(CURRENT->rq_dev)); printk("mfm: bad minor number: device=%s\n", kdevname(CURRENT->rq_dev));
else else
printk("mfm%c: bad access: block=%d, count=%d, nr_sects=%ld\n", (dev >> 6)+'a', printk("mfm%c: bad access: block=%d, count=%d, nr_sects=%ld\n", unit+'a',
block, nsect, mfm[dev].nr_sects); block, nsect, get_capacity(mfm_gendisk+unit));
printk("mfm: continue 1\n"); printk("mfm: continue 1\n");
end_request(CURRENT, 0); end_request(CURRENT, 0);
Busy = 0; Busy = 0;
continue; continue;
} }
block += mfm[dev].start_sect;
/* DAG: Linux doesn't cope with this - even though it has an array telling /* DAG: Linux doesn't cope with this - even though it has an array telling
it the hardware block size - silly */ it the hardware block size - silly */
block <<= 1; /* Now in 256 byte sectors */ block <<= 1; /* Now in 256 byte sectors */
...@@ -1163,18 +1179,9 @@ static int mfm_initdrives(void) ...@@ -1163,18 +1179,9 @@ static int mfm_initdrives(void)
static int mfm_ioctl(struct inode *inode, struct file *file, u_int cmd, u_long arg) static int mfm_ioctl(struct inode *inode, struct file *file, u_int cmd, u_long arg)
{ {
struct hd_geometry *geo = (struct hd_geometry *) arg; struct hd_geometry *geo = (struct hd_geometry *) arg;
kdev_t dev; int device = DEVICE_NR(minor(inode->i_rdev));
int device, minor, err;
if (!inode || !(dev = inode->i_rdev))
return -EINVAL;
minor = minor(dev);
device = DEVICE_NR(minor(inode->i_rdev)), err;
if (device >= mfm_drives) if (device >= mfm_drives)
return -EINVAL; return -EINVAL;
if (cmd != HDIO_GETGEO) if (cmd != HDIO_GETGEO)
return -EINVAL; return -EINVAL;
if (!arg) if (!arg)
...@@ -1185,7 +1192,8 @@ static int mfm_ioctl(struct inode *inode, struct file *file, u_int cmd, u_long a ...@@ -1185,7 +1192,8 @@ static int mfm_ioctl(struct inode *inode, struct file *file, u_int cmd, u_long a
return -EFAULT; return -EFAULT;
if (put_user (mfm_info[device].cylinders, &geo->cylinders)) if (put_user (mfm_info[device].cylinders, &geo->cylinders))
return -EFAULT; return -EFAULT;
if (put_user (mfm[minor].start_sect, &geo->start)) start = get_start_sect(inode->i_bdev);
if (put_user (get_start_sect(inode->i_bdev), &geo->start))
return -EFAULT; return -EFAULT;
return 0; return 0;
} }
...@@ -1237,27 +1245,10 @@ void xd_set_geometry(struct block_device *bdev, unsigned char secsptrack, ...@@ -1237,27 +1245,10 @@ void xd_set_geometry(struct block_device *bdev, unsigned char secsptrack,
if (raw_cmd.dev == drive) if (raw_cmd.dev == drive)
mfm_specify (); mfm_specify ();
mfm_geometry (drive); mfm_geometry (drive);
mfm[drive << 6].start_sect = 0; set_capacity(&mfm_gendisk[drive], mfm_info[drive].cylinders * mfm_info[drive].heads * mfm_info[drive].sectors / 2);
mfm[drive << 6].nr_sects = mfm_info[drive].cylinders * mfm_info[drive].heads * mfm_info[drive].sectors / 2;
} }
} }
static struct gendisk mfm_gendisk[2] = {
{
.major = MAJOR_NR,
.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 struct block_device_operations mfm_fops = static struct block_device_operations mfm_fops =
{ {
.owner = THIS_MODULE, .owner = THIS_MODULE,
......
...@@ -2033,10 +2033,9 @@ static long disk_size(DAC960_Controller_T *Controller, int disk) ...@@ -2033,10 +2033,9 @@ static long disk_size(DAC960_Controller_T *Controller, int disk)
static void DAC960_ComputeGenericDiskInfo(DAC960_Controller_T *Controller) static void DAC960_ComputeGenericDiskInfo(DAC960_Controller_T *Controller)
{ {
struct gendisk *disks = Controller->disks;
int disk; int disk;
for (disk = 0; disk < DAC960_MaxLogicalDrives; disk++) for (disk = 0; disk < DAC960_MaxLogicalDrives; disk++)
disks->part[0].nr_sects = disk_size(Controller, disk); set_capacity(Controller->disks + disk, disk_size(Controller, disk));
} }
static int DAC960_revalidate(kdev_t dev) static int DAC960_revalidate(kdev_t dev)
...@@ -2044,7 +2043,7 @@ static int DAC960_revalidate(kdev_t dev) ...@@ -2044,7 +2043,7 @@ static int DAC960_revalidate(kdev_t dev)
int ctlr = DAC960_ControllerNumber(dev); int ctlr = DAC960_ControllerNumber(dev);
int disk = DAC960_LogicalDriveNumber(dev); int disk = DAC960_LogicalDriveNumber(dev);
DAC960_Controller_T *p = DAC960_Controllers[ctlr]; DAC960_Controller_T *p = DAC960_Controllers[ctlr];
p->disks[disk].part[0].nr_sects = disk_size(p, disk); set_capacity(&p->disks[disk], disk_size(p, disk));
return 0; return 0;
} }
...@@ -5276,7 +5275,7 @@ static int DAC960_Open(Inode_T *Inode, File_T *File) ...@@ -5276,7 +5275,7 @@ static int DAC960_Open(Inode_T *Inode, File_T *File)
DAC960_KernelDevice(Controller->ControllerNumber, LogicalDriveNumber, 0), DAC960_KernelDevice(Controller->ControllerNumber, LogicalDriveNumber, 0),
DAC960_MaxPartitions, &DAC960_BlockDeviceOperations, size); DAC960_MaxPartitions, &DAC960_BlockDeviceOperations, size);
} }
if (Controller->disks[LogicalDriveNumber].part[0].nr_sects == 0) if (!get_capacity(&Controller->disks[LogicalDriveNumber]))
return -ENXIO; return -ENXIO;
/* /*
Increment Controller and Logical Drive Usage Counts. Increment Controller and Logical Drive Usage Counts.
......
...@@ -783,7 +783,7 @@ static void read_intr( void ) ...@@ -783,7 +783,7 @@ static void read_intr( void )
status = acsi_getstatus(); status = acsi_getstatus();
if (status != 0) { if (status != 0) {
int dev = minor(CURRENT->rq_dev); int dev = DEVICE_NR(CURRENT->rq_dev);
printk( KERN_ERR "ad%c: ", dev+'a' ); printk( KERN_ERR "ad%c: ", dev+'a' );
if (!acsi_reqsense( acsi_buffer, acsi_info[dev].target, if (!acsi_reqsense( acsi_buffer, acsi_info[dev].target,
acsi_info[dev].lun)) acsi_info[dev].lun))
...@@ -814,7 +814,7 @@ static void write_intr(void) ...@@ -814,7 +814,7 @@ static void write_intr(void)
status = acsi_getstatus(); status = acsi_getstatus();
if (status != 0) { if (status != 0) {
int dev = minor(CURRENT->rq_dev); int dev = DEVICE_NR(CURRENT->rq_dev);
printk( KERN_ERR "ad%c: ", dev+'a' ); printk( KERN_ERR "ad%c: ", dev+'a' );
if (!acsi_reqsense( acsi_buffer, acsi_info[dev].target, if (!acsi_reqsense( acsi_buffer, acsi_info[dev].target,
acsi_info[dev].lun)) acsi_info[dev].lun))
...@@ -973,15 +973,15 @@ static void redo_acsi_request( void ) ...@@ -973,15 +973,15 @@ static void redo_acsi_request( void )
panic(DEVICE_NAME ": block not locked"); panic(DEVICE_NAME ": block not locked");
} }
dev = minor(CURRENT->rq_dev); dev = DEVICE_NR(CURRENT->rq_dev);
block = CURRENT->sector; block = CURRENT->sector;
if (dev >= NDevices || if (dev >= NDevices ||
block+CURRENT->nr_sectors >= acsi_part[dev].nr_sects) { block+CURRENT->nr_sectors >= get_capacity(acsi_gendisk + dev)) {
#ifdef DEBUG #ifdef DEBUG
printk( "ad%c: attempted access for blocks %d...%ld past end of device at block %ld.\n", printk( "ad%c: attempted access for blocks %d...%ld past end of device at block %ld.\n",
dev+'a', dev+'a',
block, block + CURRENT->nr_sectors - 1, block, block + CURRENT->nr_sectors - 1,
acsi_part[dev].nr_sects); get_capacity(acsi_gendisk + dev));
#endif #endif
end_request(CURRENT, 0); end_request(CURRENT, 0);
goto repeat; goto repeat;
...@@ -1088,11 +1088,7 @@ static void redo_acsi_request( void ) ...@@ -1088,11 +1088,7 @@ static void redo_acsi_request( void )
static int acsi_ioctl( struct inode *inode, struct file *file, static int acsi_ioctl( struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg ) unsigned int cmd, unsigned long arg )
{ {
dev_t dev; int dev = DEVICE_NR(inode->i_rdev);
if (!inode)
return -EINVAL;
dev = minor(inode->i_rdev);
if (dev >= NDevices) if (dev >= NDevices)
return -EINVAL; return -EINVAL;
switch (cmd) { switch (cmd) {
...@@ -1140,7 +1136,7 @@ static int acsi_open( struct inode * inode, struct file * filp ) ...@@ -1140,7 +1136,7 @@ static int acsi_open( struct inode * inode, struct file * filp )
int device; int device;
struct acsi_info_struct *aip; struct acsi_info_struct *aip;
device = minor(inode->i_rdev); device = DEVICE_NR(inode->i_rdev);
if (device >= NDevices) if (device >= NDevices)
return -ENXIO; return -ENXIO;
aip = &acsi_info[device]; aip = &acsi_info[device];
...@@ -1176,7 +1172,7 @@ static int acsi_open( struct inode * inode, struct file * filp ) ...@@ -1176,7 +1172,7 @@ static int acsi_open( struct inode * inode, struct file * filp )
static int acsi_release( struct inode * inode, struct file * file ) static int acsi_release( struct inode * inode, struct file * file )
{ {
int device = minor(inode->i_rdev); int device = DEVICE_NR(inode->i_rdev);
if (--access_count[device] == 0 && acsi_info[device].removable) if (--access_count[device] == 0 && acsi_info[device].removable)
acsi_prevent_removal(device, 0); acsi_prevent_removal(device, 0);
return( 0 ); return( 0 );
...@@ -1204,7 +1200,7 @@ static void acsi_prevent_removal(int device, int flag) ...@@ -1204,7 +1200,7 @@ static void acsi_prevent_removal(int device, int flag)
static int acsi_media_change (kdev_t dev) static int acsi_media_change (kdev_t dev)
{ {
int device = minor(dev); int device = DEVICE_NR(dev);
struct acsi_info_struct *aip; struct acsi_info_struct *aip;
aip = &acsi_info[device]; aip = &acsi_info[device];
...@@ -1807,7 +1803,7 @@ void cleanup_module(void) ...@@ -1807,7 +1803,7 @@ void cleanup_module(void)
static int acsi_revalidate(kdev_t dev) static int acsi_revalidate(kdev_t dev)
{ {
int unit = DEVICE_NR(minor(dev)); int unit = DEVICE_NR(dev);
struct acsi_info_struct *aip = &acsi_info[unit]; struct acsi_info_struct *aip = &acsi_info[unit];
stdma_lock( NULL, NULL ); stdma_lock( NULL, NULL );
if (acsi_devinit(aip) != DEV_SUPPORTED) { if (acsi_devinit(aip) != DEV_SUPPORTED) {
...@@ -1821,6 +1817,6 @@ static int acsi_revalidate(kdev_t dev) ...@@ -1821,6 +1817,6 @@ static int acsi_revalidate(kdev_t dev)
ENABLE_IRQ(); ENABLE_IRQ();
stdma_release(); stdma_release();
acsi_part[minor(dev)].nr_sects = aip->size; set_capacity(acsi_gendisk + unit, aip->size);
return 0; return 0;
} }
...@@ -407,8 +407,7 @@ static int cciss_ioctl(struct inode *inode, struct file *filep, ...@@ -407,8 +407,7 @@ static int cciss_ioctl(struct inode *inode, struct file *filep,
driver_geo.sectors = 0x3f; driver_geo.sectors = 0x3f;
driver_geo.cylinders = hba[ctlr]->drv[dsk].nr_blocks / (0xff*0x3f); driver_geo.cylinders = hba[ctlr]->drv[dsk].nr_blocks / (0xff*0x3f);
} }
driver_geo.start= driver_geo.start= get_start_sect(inode->i_bdev);
hba[ctlr]->hd[minor(inode->i_rdev)].start_sect;
if (copy_to_user((void *) arg, &driver_geo, if (copy_to_user((void *) arg, &driver_geo,
sizeof( struct hd_geometry))) sizeof( struct hd_geometry)))
return -EFAULT; return -EFAULT;
...@@ -705,7 +704,7 @@ static int cciss_revalidate(kdev_t dev) ...@@ -705,7 +704,7 @@ static int cciss_revalidate(kdev_t dev)
int ctlr = major(dev) - MAJOR_NR; int ctlr = major(dev) - MAJOR_NR;
int target = minor(dev) >> NWD_SHIFT; int target = minor(dev) >> NWD_SHIFT;
struct gendisk *disk = &hba[ctlr]->gendisk[target]; struct gendisk *disk = &hba[ctlr]->gendisk[target];
disk->part[0].nr_sects = hba[ctlr]->drv[target].nr_blocks; set_capacity(disk, hba[ctlr]->drv[target].nr_blocks);
return 0; return 0;
} }
......
...@@ -1497,7 +1497,7 @@ static int ida_revalidate(kdev_t dev) ...@@ -1497,7 +1497,7 @@ static int ida_revalidate(kdev_t dev)
int ctlr = major(dev) - MAJOR_NR; int ctlr = major(dev) - MAJOR_NR;
int target = DEVICE_NR(dev); int target = DEVICE_NR(dev);
struct gendisk *gdev = &ida_gendisk[ctlr*NWD+target]; struct gendisk *gdev = &ida_gendisk[ctlr*NWD+target];
gdev->part[minor(dev)].nr_sects = hba[ctlr]->drv[target].nr_blks; set_capacity(gdev, hba[ctlr]->drv[target].nr_blks);
return 0; return 0;
} }
......
...@@ -438,9 +438,9 @@ static int pd_revalidate(kdev_t dev) ...@@ -438,9 +438,9 @@ static int pd_revalidate(kdev_t dev)
if ((unit >= PD_UNITS) || !PD.present) if ((unit >= PD_UNITS) || !PD.present)
return -ENODEV; return -ENODEV;
if (pd_identify(unit)) if (pd_identify(unit))
pd_hd[minor(dev)].nr_sects = PD.capacity; set_capacity(&PD.gd, PD.capacity);
else else
pd_hd[minor(dev)].nr_sects = 0; set_capacity(&PD.gd, 0);
return 0; return 0;
} }
...@@ -727,7 +727,7 @@ static void do_pd_request (request_queue_t * q) ...@@ -727,7 +727,7 @@ static void do_pd_request (request_queue_t * q)
pd_count = CURRENT->current_nr_sectors; pd_count = CURRENT->current_nr_sectors;
if ((pd_dev >= PD_DEVS) || if ((pd_dev >= PD_DEVS) ||
((pd_block+pd_count) > pd_hd[pd_dev].nr_sects)) { ((pd_block+pd_count) > get_capacity(&pd[unit].gd))) {
end_request(CURRENT, 0); end_request(CURRENT, 0);
goto repeat; goto repeat;
} }
......
...@@ -487,6 +487,7 @@ static void __init ps2esdi_get_device_cfg(void) ...@@ -487,6 +487,7 @@ static void __init ps2esdi_get_device_cfg(void)
static void do_ps2esdi_request(request_queue_t * q) static void do_ps2esdi_request(request_queue_t * q)
{ {
u_int block, count; u_int block, count;
int unit;
/* since, this routine is called with interrupts cleared - they /* since, this routine is called with interrupts cleared - they
must be before it finishes */ must be before it finishes */
...@@ -503,18 +504,19 @@ static void do_ps2esdi_request(request_queue_t * q) ...@@ -503,18 +504,19 @@ static void do_ps2esdi_request(request_queue_t * q)
if (blk_queue_empty(QUEUE)) if (blk_queue_empty(QUEUE))
return; return;
unit = DEVICE_NR(CURRENT->rq_dev);
if (isa_virt_to_bus(CURRENT->buffer + CURRENT->current_nr_sectors * 512) > 16 * MB) { if (isa_virt_to_bus(CURRENT->buffer + CURRENT->current_nr_sectors * 512) > 16 * MB) {
printk("%s: DMA above 16MB not supported\n", DEVICE_NAME); printk("%s: DMA above 16MB not supported\n", DEVICE_NAME);
end_request(CURRENT, FAIL); end_request(CURRENT, FAIL);
} /* check for above 16Mb dmas */ } /* check for above 16Mb dmas */
else if ((DEVICE_NR(CURRENT->rq_dev) < ps2esdi_drives) && else if ((unit < ps2esdi_drives) &&
(CURRENT->sector + CURRENT->current_nr_sectors <= (CURRENT->sector + CURRENT->current_nr_sectors <=
ps2esdi[minor(CURRENT->rq_dev)].nr_sects) && get_capacity(&ps2esdi_gendisk[unit])) &&
CURRENT->flags & REQ_CMD) { CURRENT->flags & REQ_CMD) {
#if 0 #if 0
printk("%s:got request. device : %d minor : %d command : %d sector : %ld count : %ld\n", printk("%s:got request. device : %d minor : %d command : %d sector : %ld count : %ld\n",
DEVICE_NAME, DEVICE_NAME,
DEVICE_NR(CURRENT->rq_dev), minor(CURRENT->rq_dev), unit, minor(CURRENT->rq_dev),
CURRENT->cmd, CURRENT->sector, CURRENT->cmd, CURRENT->sector,
CURRENT->current_nr_sectors); CURRENT->current_nr_sectors);
#endif #endif
...@@ -524,10 +526,10 @@ static void do_ps2esdi_request(request_queue_t * q) ...@@ -524,10 +526,10 @@ static void do_ps2esdi_request(request_queue_t * q)
switch (rq_data_dir(CURRENT)) { switch (rq_data_dir(CURRENT)) {
case READ: case READ:
ps2esdi_readwrite(READ, DEVICE_NR(CURRENT->rq_dev), block, count); ps2esdi_readwrite(READ, unit, block, count);
break; break;
case WRITE: case WRITE:
ps2esdi_readwrite(WRITE, DEVICE_NR(CURRENT->rq_dev), block, count); ps2esdi_readwrite(WRITE, unit, block, count);
break; break;
default: default:
printk("%s: Unknown command\n", DEVICE_NAME); printk("%s: Unknown command\n", DEVICE_NAME);
...@@ -538,7 +540,7 @@ static void do_ps2esdi_request(request_queue_t * q) ...@@ -538,7 +540,7 @@ static void do_ps2esdi_request(request_queue_t * q)
/* is request is valid */ /* is request is valid */
else { else {
printk("Grrr. error. ps2esdi_drives: %d, %lu %lu\n", ps2esdi_drives, printk("Grrr. error. ps2esdi_drives: %d, %lu %lu\n", ps2esdi_drives,
CURRENT->sector, ps2esdi[minor(CURRENT->rq_dev)].nr_sects); CURRENT->sector, get_capacity(&ps2esdi_gendisk[unit]));
end_request(CURRENT, FAIL); end_request(CURRENT, FAIL);
} }
......
...@@ -812,7 +812,7 @@ static void del_battery_timer(void) ...@@ -812,7 +812,7 @@ static void del_battery_timer(void)
static int mm_revalidate(kdev_t i_rdev) static int mm_revalidate(kdev_t i_rdev)
{ {
int card_number = DEVICE_NR(i_rdev); int card_number = DEVICE_NR(i_rdev);
mm_partitions[minor(i_rdev)].nr_sects = cards[card_number].mm_size << 1; set_capacity(mm_gendisk + card_number, cards[card_number].mm_size << 1);
return 0; return 0;
} }
/* /*
......
...@@ -279,15 +279,17 @@ static void do_xd_request (request_queue_t * q) ...@@ -279,15 +279,17 @@ static void do_xd_request (request_queue_t * q)
return; return;
while (1) { while (1) {
int unit;
code = 0; code = 0;
/* do some checking on the request structure */ /* do some checking on the request structure */
if (blk_queue_empty(QUEUE)) if (blk_queue_empty(QUEUE))
return; return;
if (DEVICE_NR(CURRENT->rq_dev) < xd_drives unit = DEVICE_NR(CURRENT->rq_dev);
if (unit < xd_drives
&& (CURRENT->flags & REQ_CMD) && (CURRENT->flags & REQ_CMD)
&& CURRENT->sector + CURRENT->nr_sectors && CURRENT->sector + CURRENT->nr_sectors
<= xd_struct[minor(CURRENT->rq_dev)].nr_sects) { <= get_capacity(xd_gendisk + unit)) {
block = CURRENT->sector; block = CURRENT->sector;
count = CURRENT->nr_sectors; count = CURRENT->nr_sectors;
...@@ -295,7 +297,7 @@ static void do_xd_request (request_queue_t * q) ...@@ -295,7 +297,7 @@ static void do_xd_request (request_queue_t * q)
case READ: case READ:
case WRITE: case WRITE:
for (retry = 0; (retry < XD_RETRIES) && !code; retry++) for (retry = 0; (retry < XD_RETRIES) && !code; retry++)
code = xd_readwrite(rq_data_dir(CURRENT),DEVICE_NR(CURRENT->rq_dev), code = xd_readwrite(rq_data_dir(CURRENT),unit,
CURRENT->buffer,block,count); CURRENT->buffer,block,count);
break; break;
default: default:
......
...@@ -596,22 +596,21 @@ static void hd_request(void) ...@@ -596,22 +596,21 @@ static void hd_request(void)
reset_hd(); reset_hd();
return; return;
} }
dev = minor(CURRENT->rq_dev); dev = DEVICE_NR(CURRENT->rq_dev);
block = CURRENT->sector; block = CURRENT->sector;
nsect = CURRENT->nr_sectors; nsect = CURRENT->nr_sectors;
if (dev >= (NR_HD<<6) || (dev & 0x3f) || if (dev >= NR_HD || block >= get_capacity(hd_gendisk+dev) ||
block >= hd[dev].nr_sects || ((block+nsect) > hd[dev].nr_sects)) { ((block+nsect) > get_capacity(hd_gendisk+unit))) {
if (dev >= (NR_HD<<6) || (dev & 0x3f)) if (dev >= NR_HD)
printk("hd: bad minor number: device=%s\n", printk("hd: bad minor number: device=%s\n",
kdevname(CURRENT->rq_dev)); kdevname(CURRENT->rq_dev));
else else
printk("hd%c: bad access: block=%d, count=%d\n", printk("hd%c: bad access: block=%d, count=%d\n",
(minor(CURRENT->rq_dev)>>6)+'a', block, nsect); dev+'a', block, nsect);
end_request(CURRENT, 0); end_request(CURRENT, 0);
goto repeat; goto repeat;
} }
dev >>= 6;
if (special_op[dev]) { if (special_op[dev]) {
if (do_special_op(dev)) if (do_special_op(dev))
goto repeat; goto repeat;
...@@ -819,10 +818,11 @@ static void __init hd_geninit(void) ...@@ -819,10 +818,11 @@ static void __init hd_geninit(void)
#endif #endif
for (drive=0 ; drive < NR_HD ; drive++) { for (drive=0 ; drive < NR_HD ; drive++) {
hd[drive<<6].nr_sects = hd_info[drive].head * sector_t size = hd_info[drive].head *
hd_info[drive].sect * hd_info[drive].cyl; hd_info[drive].sect * hd_info[drive].cyl;
printk ("hd%c: %ldMB, CHS=%d/%d/%d\n", drive+'a', set_capacity(hd_gendisk + drive, size);
hd[drive<<6].nr_sects / 2048, hd_info[drive].cyl, printk ("%s: %ldMB, CHS=%d/%d/%d\n", hd_gendisk[drive].major_name,
size / 2048, hd_info[drive].cyl,
hd_info[drive].head, hd_info[drive].sect); hd_info[drive].head, hd_info[drive].sect);
} }
if (!NR_HD) if (!NR_HD)
......
...@@ -2138,7 +2138,7 @@ static int cdrom_read_toc(ide_drive_t *drive, struct request_sense *sense) ...@@ -2138,7 +2138,7 @@ static int cdrom_read_toc(ide_drive_t *drive, struct request_sense *sense)
if (stat) if (stat)
toc->capacity = 0x1fffff; toc->capacity = 0x1fffff;
drive->part[0].nr_sects = toc->capacity * SECTORS_PER_FRAME; set_capacity(drive->disk, toc->capacity * SECTORS_PER_FRAME);
/* Remember that we've read this stuff. */ /* Remember that we've read this stuff. */
CDROM_STATE_FLAGS (drive)->toc_valid = 1; CDROM_STATE_FLAGS (drive)->toc_valid = 1;
...@@ -3148,7 +3148,7 @@ static int ide_cdrom_reinit (ide_drive_t *drive) ...@@ -3148,7 +3148,7 @@ static int ide_cdrom_reinit (ide_drive_t *drive)
add_gendisk(g); add_gendisk(g);
register_disk(g, mk_kdev(g->major,g->first_minor), register_disk(g, mk_kdev(g->major,g->first_minor),
1<<g->minor_shift, ide_fops, 1<<g->minor_shift, ide_fops,
g->part[0].nr_sects); get_capacity(g));
return 0; return 0;
failed: failed:
return 1; return 1;
......
...@@ -1500,7 +1500,7 @@ static int idefloppy_get_capacity (ide_drive_t *drive) ...@@ -1500,7 +1500,7 @@ static int idefloppy_get_capacity (ide_drive_t *drive)
drive->bios_cyl = 0; drive->bios_cyl = 0;
drive->bios_head = drive->bios_sect = 0; drive->bios_head = drive->bios_sect = 0;
floppy->blocks = floppy->bs_factor = 0; floppy->blocks = floppy->bs_factor = 0;
drive->part[0].nr_sects = 0; set_capacity(drive->disk, 0);
idefloppy_create_read_capacity_cmd (&pc); idefloppy_create_read_capacity_cmd (&pc);
if (idefloppy_queue_pc_tail (drive, &pc)) { if (idefloppy_queue_pc_tail (drive, &pc)) {
...@@ -1555,7 +1555,7 @@ static int idefloppy_get_capacity (ide_drive_t *drive) ...@@ -1555,7 +1555,7 @@ static int idefloppy_get_capacity (ide_drive_t *drive)
(void) idefloppy_get_flexible_disk_page (drive); (void) idefloppy_get_flexible_disk_page (drive);
} }
drive->part[0].nr_sects = floppy->blocks * floppy->bs_factor; set_capacity(drive->disk, floppy->blocks * floppy->bs_factor);
return rc; return rc;
} }
...@@ -2213,7 +2213,7 @@ static int idefloppy_reinit (ide_drive_t *drive) ...@@ -2213,7 +2213,7 @@ static int idefloppy_reinit (ide_drive_t *drive)
add_gendisk(g); add_gendisk(g);
register_disk(g, mk_kdev(g->major,g->first_minor), register_disk(g, mk_kdev(g->major,g->first_minor),
1<<g->minor_shift, ide_fops, 1<<g->minor_shift, ide_fops,
g->part[0].nr_sects); get_capacity(g));
return 0; return 0;
failed: failed:
return 1; return 1;
......
...@@ -214,7 +214,7 @@ int ide_xlate_1024 (kdev_t i_rdev, int xparm, int ptheads, const char *msg) ...@@ -214,7 +214,7 @@ int ide_xlate_1024 (kdev_t i_rdev, int xparm, int ptheads, const char *msg)
ret = 1; ret = 1;
} }
drive->part[0].nr_sects = current_capacity(drive); set_capacity(drive->disk, current_capacity(drive));
if (ret) if (ret)
printk("%s%s [%d/%d/%d]", msg, msg1, printk("%s%s [%d/%d/%d]", msg, msg1,
......
...@@ -1661,7 +1661,7 @@ ide_drive_t *get_info_ptr (kdev_t i_rdev) ...@@ -1661,7 +1661,7 @@ ide_drive_t *get_info_ptr (kdev_t i_rdev)
if (unit < MAX_DRIVES) { if (unit < MAX_DRIVES) {
ide_drive_t *drive = &hwif->drives[unit]; ide_drive_t *drive = &hwif->drives[unit];
#if 0 #if 0
if ((drive->present) && (drive->part[minor].nr_sects)) if (drive->present && get_capacity(drive->disk))
#else #else
if (drive->present) if (drive->present)
#endif #endif
...@@ -1748,7 +1748,7 @@ int ide_do_drive_cmd (ide_drive_t *drive, struct request *rq, ide_action_t actio ...@@ -1748,7 +1748,7 @@ int ide_do_drive_cmd (ide_drive_t *drive, struct request *rq, ide_action_t actio
void ide_revalidate_drive (ide_drive_t *drive) void ide_revalidate_drive (ide_drive_t *drive)
{ {
drive->disk->part[0].nr_sects = current_capacity(drive); set_capacity(drive->disk, current_capacity(drive));
} }
/* /*
...@@ -1975,7 +1975,7 @@ void ide_unregister (unsigned int index) ...@@ -1975,7 +1975,7 @@ void ide_unregister (unsigned int index)
continue; continue;
minor = drive->select.b.unit << PARTN_BITS; minor = drive->select.b.unit << PARTN_BITS;
for (p = 0; p < (1<<PARTN_BITS); ++p) { for (p = 0; p < (1<<PARTN_BITS); ++p) {
if (drive->part[p].nr_sects > 0) { if (get_capacity(drive->disk)) {
kdev_t devp = mk_kdev(hwif->major, minor+p); kdev_t devp = mk_kdev(hwif->major, minor+p);
invalidate_device(devp, 0); invalidate_device(devp, 0);
} }
...@@ -2523,7 +2523,7 @@ static int ide_ioctl (struct inode *inode, struct file *file, ...@@ -2523,7 +2523,7 @@ static int ide_ioctl (struct inode *inode, struct file *file,
if (put_user(drive->bios_head, (byte *) &loc->heads)) return -EFAULT; if (put_user(drive->bios_head, (byte *) &loc->heads)) return -EFAULT;
if (put_user(drive->bios_sect, (byte *) &loc->sectors)) return -EFAULT; if (put_user(drive->bios_sect, (byte *) &loc->sectors)) return -EFAULT;
if (put_user(bios_cyl, (unsigned short *) &loc->cylinders)) return -EFAULT; if (put_user(bios_cyl, (unsigned short *) &loc->cylinders)) return -EFAULT;
if (put_user((unsigned)drive->part[minor(inode->i_rdev)&PARTN_MASK].start_sect, if (put_user((unsigned)get_start_sect(inode->i_bdev),
(unsigned long *) &loc->start)) return -EFAULT; (unsigned long *) &loc->start)) return -EFAULT;
return 0; return 0;
} }
...@@ -2535,7 +2535,7 @@ static int ide_ioctl (struct inode *inode, struct file *file, ...@@ -2535,7 +2535,7 @@ static int ide_ioctl (struct inode *inode, struct file *file,
if (put_user(drive->head, (byte *) &loc->heads)) return -EFAULT; if (put_user(drive->head, (byte *) &loc->heads)) return -EFAULT;
if (put_user(drive->sect, (byte *) &loc->sectors)) return -EFAULT; if (put_user(drive->sect, (byte *) &loc->sectors)) return -EFAULT;
if (put_user(drive->cyl, (unsigned int *) &loc->cylinders)) return -EFAULT; if (put_user(drive->cyl, (unsigned int *) &loc->cylinders)) return -EFAULT;
if (put_user((unsigned)drive->part[minor(inode->i_rdev)&PARTN_MASK].start_sect, if (put_user((unsigned)get_start_sect(inode->i_bdev),
(unsigned long *) &loc->start)) return -EFAULT; (unsigned long *) &loc->start)) return -EFAULT;
return 0; return 0;
} }
......
...@@ -618,7 +618,7 @@ static void free_mddev(mddev_t *mddev) ...@@ -618,7 +618,7 @@ static void free_mddev(mddev_t *mddev)
export_array(mddev); export_array(mddev);
md_size[mdidx(mddev)] = 0; md_size[mdidx(mddev)] = 0;
md_hd_struct[mdidx(mddev)].nr_sects = 0; set_capacity(disks[mdidx(mddev)], 0);
} }
#undef BAD_CSUM #undef BAD_CSUM
...@@ -2343,7 +2343,7 @@ static int md_ioctl(struct inode *inode, struct file *file, ...@@ -2343,7 +2343,7 @@ static int md_ioctl(struct inode *inode, struct file *file,
err = put_user (4, (char *) &loc->sectors); err = put_user (4, (char *) &loc->sectors);
if (err) if (err)
goto abort_unlock; goto abort_unlock;
err = put_user (md_hd_struct[mdidx(mddev)].nr_sects/8, err = put_user(get_capacity(disks[mdidx(mddev)])/8,
(short *) &loc->cylinders); (short *) &loc->cylinders);
if (err) if (err)
goto abort_unlock; goto abort_unlock;
......
...@@ -248,7 +248,7 @@ static u32 i2ob_get(struct i2ob_device *dev) ...@@ -248,7 +248,7 @@ static u32 i2ob_get(struct i2ob_device *dev)
* Turn a Linux block request into an I2O block read/write. * Turn a Linux block request into an I2O block read/write.
*/ */
static int i2ob_send(u32 m, struct i2ob_device *dev, struct i2ob_request *ireq, u32 base, int unit) static int i2ob_send(u32 m, struct i2ob_device *dev, struct i2ob_request *ireq, int unit)
{ {
struct i2o_controller *c = dev->controller; struct i2o_controller *c = dev->controller;
int tid = dev->tid; int tid = dev->tid;
...@@ -279,7 +279,7 @@ static int i2ob_send(u32 m, struct i2ob_device *dev, struct i2ob_request *ireq, ...@@ -279,7 +279,7 @@ static int i2ob_send(u32 m, struct i2ob_device *dev, struct i2ob_request *ireq,
/* This can be optimised later - just want to be sure its right for /* This can be optimised later - just want to be sure its right for
starters */ starters */
offset = ((u64)(req->sector+base)) << 9; offset = ((u64)req->sector) << 9;
__raw_writel( offset & 0xFFFFFFFF, msg+24); __raw_writel( offset & 0xFFFFFFFF, msg+24);
__raw_writel(offset>>32, msg+28); __raw_writel(offset>>32, msg+28);
mptr=msg+32; mptr=msg+32;
...@@ -724,7 +724,7 @@ static int i2ob_evt(void *dummy) ...@@ -724,7 +724,7 @@ static int i2ob_evt(void *dummy)
register_disk(p, register_disk(p,
mk_kdev(p->major, p->first_minor), mk_kdev(p->major, p->first_minor),
1<<p->minor_shift, p->fops, 1<<p->minor_shift, p->fops,
i2ob[unit].nr_sects); get_capacity(p));
break; break;
} }
...@@ -768,7 +768,7 @@ static int i2ob_evt(void *dummy) ...@@ -768,7 +768,7 @@ static int i2ob_evt(void *dummy)
i2ob_query_device(&i2ob_dev[unit], 0x0000, 4, &size, 8); i2ob_query_device(&i2ob_dev[unit], 0x0000, 4, &size, 8);
spin_lock_irqsave(I2O_LOCK(unit), flags); spin_lock_irqsave(I2O_LOCK(unit), flags);
i2ob[unit].nr_sects = size>>9; set_capacity(&i2o_disk[unit>>4], size>>9);
spin_unlock_irqrestore(I2O_LOCK(unit), flags); spin_unlock_irqrestore(I2O_LOCK(unit), flags);
break; break;
} }
...@@ -869,7 +869,7 @@ static int i2ob_backlog_request(struct i2o_controller *c, struct i2ob_device *de ...@@ -869,7 +869,7 @@ static int i2ob_backlog_request(struct i2o_controller *c, struct i2ob_device *de
i2ob_backlog_tail[c->unit] = NULL; i2ob_backlog_tail[c->unit] = NULL;
unit = minor(ireq->req->rq_dev); unit = minor(ireq->req->rq_dev);
i2ob_send(m, dev, ireq, i2ob[unit].start_sect, unit); i2ob_send(m, dev, ireq, unit);
} }
if(i2ob_backlog[c->unit]) if(i2ob_backlog[c->unit])
return 1; return 1;
...@@ -969,7 +969,7 @@ static void i2ob_request(request_queue_t *q) ...@@ -969,7 +969,7 @@ static void i2ob_request(request_queue_t *q)
i2ob_queues[dev->unit]->i2ob_qhead = ireq->next; i2ob_queues[dev->unit]->i2ob_qhead = ireq->next;
ireq->req = req; ireq->req = req;
i2ob_send(m, dev, ireq, i2ob[unit].start_sect, (unit&0xF0)); i2ob_send(m, dev, ireq, (unit&0xF0));
} }
} }
...@@ -1038,7 +1038,7 @@ static int i2ob_ioctl(struct inode *inode, struct file *file, ...@@ -1038,7 +1038,7 @@ static int i2ob_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)
{ {
struct hd_geometry g; struct hd_geometry g;
int u = minor(inode->i_rdev) & 0xF0; int u = minor(inode->i_rdev) >> 4;
/* Anyone capable of this syscall can do *real bad* things */ /* Anyone capable of this syscall can do *real bad* things */
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
...@@ -1046,7 +1046,7 @@ static int i2ob_ioctl(struct inode *inode, struct file *file, ...@@ -1046,7 +1046,7 @@ static int i2ob_ioctl(struct inode *inode, struct file *file,
if (cmd != HDIO_GETGEO) if (cmd != HDIO_GETGEO)
return -EINVAL; return -EINVAL;
i2o_block_biosparam(i2ob[u].nr_sects, i2o_block_biosparam(get_capacity(&i2o_disk[u]),
&g.cylinders, &g.heads, &g.sectors); &g.cylinders, &g.heads, &g.sectors);
g.start = get_start_sect(inode->i_bdev); g.start = get_start_sect(inode->i_bdev);
return copy_to_user((void *)arg, &g, sizeof(g)) ? -EFAULT : 0; return copy_to_user((void *)arg, &g, sizeof(g)) ? -EFAULT : 0;
...@@ -1222,7 +1222,7 @@ static int i2ob_install_device(struct i2o_controller *c, struct i2o_device *d, i ...@@ -1222,7 +1222,7 @@ static int i2ob_install_device(struct i2o_controller *c, struct i2o_device *d, i
i2ob_query_device(dev, 0x0000, 5, &flags, 4); i2ob_query_device(dev, 0x0000, 5, &flags, 4);
i2ob_query_device(dev, 0x0000, 6, &status, 4); i2ob_query_device(dev, 0x0000, 6, &status, 4);
i2ob[unit].nr_sects = size>>9; set_capacity(&i2o_disk[unit>>4], size>>9);
/* Set limit based on inbound frame size */ /* Set limit based on inbound frame size */
limit = (d->controller->status_block->inbound_frame_size - 8)/2; limit = (d->controller->status_block->inbound_frame_size - 8)/2;
...@@ -1326,7 +1326,7 @@ static int i2ob_install_device(struct i2o_controller *c, struct i2o_device *d, i ...@@ -1326,7 +1326,7 @@ static int i2ob_install_device(struct i2o_controller *c, struct i2o_device *d, i
i2o_event_register(c, d->lct_data.tid, i2ob_context, unit, i2o_event_register(c, d->lct_data.tid, i2ob_context, unit,
(I2OB_EVENT_MASK & d->lct_data.event_capabilities)); (I2OB_EVENT_MASK & d->lct_data.event_capabilities));
i2ob[unit].nr_sects = size>>9; set_capacity(i2o_disk[unit>>4], size>>9);
return 0; return 0;
} }
...@@ -1471,7 +1471,7 @@ static void i2ob_scan(int bios) ...@@ -1471,7 +1471,7 @@ static void i2ob_scan(int bios)
register_disk(p, register_disk(p,
mk_kdev(p->major, p->first_minor), mk_kdev(p->major, p->first_minor),
1<<p->minor_shift, p->fops, 1<<p->minor_shift, p->fops,
i2ob[scan_unit].nr_sects); get_capacity(p));
scan_unit+=16; scan_unit+=16;
i2ob_dev_count++; i2ob_dev_count++;
...@@ -1564,7 +1564,7 @@ void i2ob_new_device(struct i2o_controller *c, struct i2o_device *d) ...@@ -1564,7 +1564,7 @@ void i2ob_new_device(struct i2o_controller *c, struct i2o_device *d)
register_disk(p, register_disk(p,
mk_kdev(p->major, p->first_minor), mk_kdev(p->major, p->first_minor),
1<<p->minor_shift, p->fops, 1<<p->minor_shift, p->fops,
i2ob[unit].nr_sects); get_capacity(p));
i2ob_dev_count++; i2ob_dev_count++;
i2o_device_notify_on(d, &i2o_block_handler); i2o_device_notify_on(d, &i2o_block_handler);
} }
......
...@@ -846,7 +846,7 @@ static int ftl_open(struct inode *inode, struct file *file) ...@@ -846,7 +846,7 @@ static int ftl_open(struct inode *inode, struct file *file)
if (partition->state != FTL_FORMATTED) if (partition->state != FTL_FORMATTED)
return -ENXIO; return -ENXIO;
if (partition->disk->part[0].nr_sects == 0) if (get_capacity(partition->disk) == 0)
return -ENXIO; return -ENXIO;
if (!get_mtd_device(partition->mtd, -1)) if (!get_mtd_device(partition->mtd, -1))
...@@ -1132,8 +1132,8 @@ static int ftl_revalidate(kdev_t dev) ...@@ -1132,8 +1132,8 @@ static int ftl_revalidate(kdev_t dev)
int unit = minor(dev) >> 4; int unit = minor(dev) >> 4;
partition_t *part = myparts[unit]; partition_t *part = myparts[unit];
scan_header(part); scan_header(part);
part->disk->part[0].nr_sects = set_capacity(part->disk,
le32_to_cpu(part->header.FormattedSize)/SECTOR_SIZE); le32_to_cpu(part->header.FormattedSize)/SECTOR_SIZE));
return 0; return 0;
} }
......
...@@ -846,10 +846,10 @@ void nftl_request(RQFUNC_ARG) ...@@ -846,10 +846,10 @@ void nftl_request(RQFUNC_ARG)
down(&nftl->mutex); down(&nftl->mutex);
DEBUG(MTD_DEBUG_LEVEL3, "Got mutex\n"); DEBUG(MTD_DEBUG_LEVEL3, "Got mutex\n");
if (block + nsect > part_table[dev].nr_sects) { if (block + nsect > get_capacity(nftl->disk)) {
/* access past the end of device */ /* access past the end of device */
printk("nftl%c%d: bad access: block = %d, count = %d\n", printk("nftl%c%d: bad access: block = %d, count = %d\n",
(minor(req->rq_dev)>>6)+'a', dev & 0xf, block, nsect); unit+'a', dev & 0xf, block, nsect);
up(&nftl->mutex); up(&nftl->mutex);
res = 0; /* fail */ res = 0; /* fail */
goto repeat; goto repeat;
......
...@@ -286,6 +286,8 @@ static request_queue_t *sd_find_queue(kdev_t dev) ...@@ -286,6 +286,8 @@ static request_queue_t *sd_find_queue(kdev_t dev)
return NULL; /* No such device */ return NULL; /* No such device */
} }
static struct gendisk **sd_disks;
/** /**
* sd_init_command - build a scsi (read or write) command from * sd_init_command - build a scsi (read or write) command from
* information in the request structure. * information in the request structure.
...@@ -321,7 +323,7 @@ static int sd_init_command(Scsi_Cmnd * SCpnt) ...@@ -321,7 +323,7 @@ static int sd_init_command(Scsi_Cmnd * SCpnt)
/* >>>>> this change is not in the lk 2.5 series */ /* >>>>> this change is not in the lk 2.5 series */
if (part_nr >= (sd_template.dev_max << 4) || (part_nr & 0xf) || if (part_nr >= (sd_template.dev_max << 4) || (part_nr & 0xf) ||
!sdp || !sdp->online || !sdp || !sdp->online ||
block + SCpnt->request->nr_sectors > sd[part_nr].nr_sects) { block + SCpnt->request->nr_sectors > get_capacity(sd_disks[dsk_nr])) {
SCSI_LOG_HLQUEUE(2, printk("Finishing %ld sectors\n", SCSI_LOG_HLQUEUE(2, printk("Finishing %ld sectors\n",
SCpnt->request->nr_sectors)); SCpnt->request->nr_sectors));
SCSI_LOG_HLQUEUE(2, printk("Retry with 0x%p\n", SCpnt)); SCSI_LOG_HLQUEUE(2, printk("Retry with 0x%p\n", SCpnt));
...@@ -588,8 +590,6 @@ static struct block_device_operations sd_fops = ...@@ -588,8 +590,6 @@ static struct block_device_operations sd_fops =
revalidate: sd_revalidate revalidate: sd_revalidate
}; };
static struct gendisk **sd_disks;
/** /**
* sd_rw_intr - bottom half handler: called when the lower level * sd_rw_intr - bottom half handler: called when the lower level
* driver has completed (successfully or otherwise) a scsi command. * driver has completed (successfully or otherwise) a scsi command.
...@@ -1374,7 +1374,7 @@ static int sd_revalidate(kdev_t dev) ...@@ -1374,7 +1374,7 @@ static int sd_revalidate(kdev_t dev)
return -ENODEV; return -ENODEV;
sd_init_onedisk(sdkp, dsk_nr); sd_init_onedisk(sdkp, dsk_nr);
sd_disks[dsk_nr]->part[0].nr_sects = sdkp->capacity; set_capacity(sd_disks[dsk_nr], sdkp->capacity);
return 0; return 0;
} }
......
...@@ -234,9 +234,9 @@ static void rw_intr(Scsi_Cmnd * SCpnt) ...@@ -234,9 +234,9 @@ static void rw_intr(Scsi_Cmnd * SCpnt)
* block. Therefore, if we hit a medium error within the last * block. Therefore, if we hit a medium error within the last
* 75 2K sectors, we decrease the saved size value. * 75 2K sectors, we decrease the saved size value.
*/ */
if (error_sector < cd->disk->part[0].nr_sects && if (error_sector < get_capacity(cd->disk) &&
cd->capacity - error_sector < 4 * 75) cd->capacity - error_sector < 4 * 75)
cd->disk->part[0].nr_sects = error_sector; set_capacity(cd->disk, error_sector);
} }
/* /*
...@@ -555,7 +555,7 @@ static void get_sectorsize(Scsi_CD *cd) ...@@ -555,7 +555,7 @@ static void get_sectorsize(Scsi_CD *cd)
* what the device is capable of. * what the device is capable of.
*/ */
cd->needs_sector_size = 0; cd->needs_sector_size = 0;
cd->disk->part[0].nr_sects = cd->capacity; set_capacity(cd->disk, cd->capacity);
} }
queue = &cd->device->request_queue; queue = &cd->device->request_queue;
......
...@@ -338,13 +338,11 @@ void register_disk(struct gendisk *disk, kdev_t dev, unsigned minors, ...@@ -338,13 +338,11 @@ void register_disk(struct gendisk *disk, kdev_t dev, unsigned minors,
struct block_device_operations *ops, long size) struct block_device_operations *ops, long size)
{ {
struct block_device *bdev; struct block_device *bdev;
struct hd_struct *p;
if (!disk) if (!disk)
return; return;
p = disk->part; set_capacity(disk, size);
p[0].nr_sects = size;
/* No minors to use for partitions */ /* No minors to use for partitions */
if (!disk->minor_shift) if (!disk->minor_shift)
...@@ -410,7 +408,7 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev) ...@@ -410,7 +408,7 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
} }
if (bdev->bd_op->revalidate) if (bdev->bd_op->revalidate)
bdev->bd_op->revalidate(dev); bdev->bd_op->revalidate(dev);
if (disk->part[0].nr_sects) if (get_capacity(disk))
check_partition(disk, bdev); check_partition(disk, bdev);
for (p = 1; p < (1<<disk->minor_shift); p++) for (p = 1; p < (1<<disk->minor_shift); p++)
update_partition(disk, p); update_partition(disk, p);
......
...@@ -95,6 +95,14 @@ static inline unsigned long get_start_sect(struct block_device *bdev) ...@@ -95,6 +95,14 @@ static inline unsigned long get_start_sect(struct block_device *bdev)
{ {
return bdev->bd_offset; return bdev->bd_offset;
} }
static inline sector_t get_capacity(struct gendisk *disk)
{
return disk->part[0].nr_sects;
}
static inline void set_capacity(struct gendisk *disk, sector_t size)
{
disk->part[0].nr_sects = size;
}
#endif /* __KERNEL__ */ #endif /* __KERNEL__ */
......
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