mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 03:01:39 -04:00
[PATCH] Add block_device_operations.getgeo block device method
HDIO_GETGEO is implemented in most block drivers, and all of them have to
duplicate the code to copy the structure to userspace, as well as getting
the start sector. This patch moves that to common code [1] and adds a
->getgeo method to fill out the raw kernel hd_geometry structure. For many
drivers this means ->ioctl can go away now.
[1] the s390 block drivers are odd in this respect. xpram sets ->start
to 4 always which seems more than odd, and the dasd driver shifts
the start offset around, probably because of it's non-standard
sector size.
Signed-off-by: Christoph Hellwig <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: <[email protected]>
Cc: Jeff Dike <[email protected]>
Cc: Paolo Giarrusso <[email protected]>
Cc: Bartlomiej Zolnierkiewicz <[email protected]>
Cc: Neil Brown <[email protected]>
Cc: Markus Lidel <[email protected]>
Cc: Russell King <[email protected]>
Cc: David Woodhouse <[email protected]>
Cc: Martin Schwidefsky <[email protected]>
Cc: James Bottomley <[email protected]>
Signed-off-by: Adrian Bunk <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
parent
5b0ed2c64d
commit
a885c8c431
30 changed files with 340 additions and 456 deletions
|
|
@ -18,6 +18,7 @@
|
|||
#include <linux/major.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/buffer_head.h>
|
||||
#include <linux/hdreg.h>
|
||||
|
||||
#include <asm/ccwdev.h>
|
||||
#include <asm/ebcdic.h>
|
||||
|
|
@ -1723,12 +1724,34 @@ dasd_release(struct inode *inp, struct file *filp)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return disk geometry.
|
||||
*/
|
||||
static int
|
||||
dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
|
||||
{
|
||||
struct dasd_device *device;
|
||||
|
||||
device = bdev->bd_disk->private_data;
|
||||
if (!device)
|
||||
return -ENODEV;
|
||||
|
||||
if (!device->discipline ||
|
||||
!device->discipline->fill_geometry)
|
||||
return -EINVAL;
|
||||
|
||||
device->discipline->fill_geometry(device, geo);
|
||||
geo->start = get_start_sect(bdev) >> device->s2b_shift;
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct block_device_operations
|
||||
dasd_device_operations = {
|
||||
.owner = THIS_MODULE,
|
||||
.open = dasd_open,
|
||||
.release = dasd_release,
|
||||
.ioctl = dasd_ioctl,
|
||||
.getgeo = dasd_getgeo,
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -485,33 +485,6 @@ dasd_ioctl_set_ro(struct block_device *bdev, int no, long args)
|
|||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return disk geometry.
|
||||
*/
|
||||
static int
|
||||
dasd_ioctl_getgeo(struct block_device *bdev, int no, long args)
|
||||
{
|
||||
struct hd_geometry geo = { 0, };
|
||||
struct dasd_device *device;
|
||||
|
||||
device = bdev->bd_disk->private_data;
|
||||
if (device == NULL)
|
||||
return -ENODEV;
|
||||
|
||||
if (device == NULL || device->discipline == NULL ||
|
||||
device->discipline->fill_geometry == NULL)
|
||||
return -EINVAL;
|
||||
|
||||
geo = (struct hd_geometry) {};
|
||||
device->discipline->fill_geometry(device, &geo);
|
||||
geo.start = get_start_sect(bdev) >> device->s2b_shift;
|
||||
if (copy_to_user((struct hd_geometry __user *) args, &geo,
|
||||
sizeof (struct hd_geometry)))
|
||||
return -EFAULT;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* List of static ioctls.
|
||||
*/
|
||||
|
|
@ -528,7 +501,6 @@ static struct { int no; dasd_ioctl_fn_t fn; } dasd_ioctls[] =
|
|||
{ BIODASDPRRST, dasd_ioctl_reset_profile },
|
||||
{ BLKROSET, dasd_ioctl_set_ro },
|
||||
{ DASDAPIVER, dasd_ioctl_api_version },
|
||||
{ HDIO_GETGEO, dasd_ioctl_getgeo },
|
||||
{ -1, NULL }
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -328,31 +328,27 @@ fail:
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int xpram_ioctl (struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
static int xpram_getgeo(struct block_device *bdev, struct hd_geometry *geo)
|
||||
{
|
||||
struct hd_geometry __user *geo;
|
||||
unsigned long size;
|
||||
if (cmd != HDIO_GETGEO)
|
||||
return -EINVAL;
|
||||
|
||||
/*
|
||||
* get geometry: we have to fake one... trim the size to a
|
||||
* multiple of 64 (32k): tell we have 16 sectors, 4 heads,
|
||||
* whatever cylinders. Tell also that data starts at sector. 4.
|
||||
*/
|
||||
geo = (struct hd_geometry __user *) arg;
|
||||
size = (xpram_pages * 8) & ~0x3f;
|
||||
put_user(size >> 6, &geo->cylinders);
|
||||
put_user(4, &geo->heads);
|
||||
put_user(16, &geo->sectors);
|
||||
put_user(4, &geo->start);
|
||||
geo->cylinders = size >> 6;
|
||||
geo->heads = 4;
|
||||
geo->sectors = 16;
|
||||
geo->start = 4;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct block_device_operations xpram_devops =
|
||||
{
|
||||
.owner = THIS_MODULE,
|
||||
.ioctl = xpram_ioctl,
|
||||
.getgeo = xpram_getgeo,
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Reference in a new issue