From a885c8c4316e1c1d2d2c8755da3f3d14f852528d Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Sun, 8 Jan 2006 01:02:50 -0800 Subject: [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 Cc: Jens Axboe Cc: Cc: Jeff Dike Cc: Paolo Giarrusso Cc: Bartlomiej Zolnierkiewicz Cc: Neil Brown Cc: Markus Lidel Cc: Russell King Cc: David Woodhouse Cc: Martin Schwidefsky Cc: James Bottomley Signed-off-by: Adrian Bunk Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/block/floppy.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'drivers/block/floppy.c') diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index a5b857c5c4b8..b86613b21cf1 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -3445,6 +3445,23 @@ static int get_floppy_geometry(int drive, int type, struct floppy_struct **g) return 0; } +static int fd_getgeo(struct block_device *bdev, struct hd_geometry *geo) +{ + int drive = (long)bdev->bd_disk->private_data; + int type = ITYPE(drive_state[drive].fd_device); + struct floppy_struct *g; + int ret; + + ret = get_floppy_geometry(drive, type, &g); + if (ret) + return ret; + + geo->heads = g->head; + geo->sectors = g->sect; + geo->cylinders = g->track; + return 0; +} + static int fd_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long param) { @@ -3474,23 +3491,6 @@ static int fd_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, cmd = FDEJECT; } - /* generic block device ioctls */ - switch (cmd) { - /* the following have been inspired by the corresponding - * code for other block devices. */ - struct floppy_struct *g; - case HDIO_GETGEO: - { - struct hd_geometry loc; - ECALL(get_floppy_geometry(drive, type, &g)); - loc.heads = g->head; - loc.sectors = g->sect; - loc.cylinders = g->track; - loc.start = 0; - return _COPYOUT(loc); - } - } - /* convert the old style command into a new style command */ if ((cmd & 0xff00) == 0x0200) { ECALL(normalize_ioctl(&cmd, &size)); @@ -3938,6 +3938,7 @@ static struct block_device_operations floppy_fops = { .open = floppy_open, .release = floppy_release, .ioctl = fd_ioctl, + .getgeo = fd_getgeo, .media_changed = check_floppy_change, .revalidate_disk = floppy_revalidate, }; -- cgit v1.2.3 From 945f390f02ce44a13aefc6d9449c99f33c9286a5 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 8 Jan 2006 01:05:11 -0800 Subject: [PATCH] drivers/block: Use ARRAY_SIZE macro Use ARRAY_SIZE macro instead of sizeof(x)/sizeof(x[0]) and remove a duplicate of ARRAY_SIZE. Some trailing whitespaces are also removed. drivers/block/acsi* has been left out as it's marked BROKEN. Signed-off-by: Tobias Klauser Cc: Jens Axboe Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/block/floppy.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'drivers/block/floppy.c') diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index b86613b21cf1..374621a512e0 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -479,7 +479,6 @@ static struct floppy_struct floppy_type[32] = { { 3200,20,2,80,0,0x1C,0x00,0xCF,0x2C,"H1600" }, /* 31 1.6MB 3.5" */ }; -#define NUMBER(x) (sizeof(x) / sizeof(*(x))) #define SECTSIZE (_FD_SECTSIZE(*floppy)) /* Auto-detection: Disk type used until the next media change occurs. */ @@ -3645,7 +3644,7 @@ static void __init config_types(void) const char *name = NULL; static char temparea[32]; - if (type < NUMBER(default_drive_params)) { + if (type < ARRAY_SIZE(default_drive_params)) { params = &default_drive_params[type].params; if (type) { name = default_drive_params[type].name; @@ -3961,7 +3960,7 @@ static void __init register_devfs_entries(int drive) { int base_minor = (drive < 4) ? drive : (124 + drive); - if (UDP->cmos < NUMBER(default_drive_params)) { + if (UDP->cmos < ARRAY_SIZE(default_drive_params)) { int i = 0; do { int minor = base_minor + (table_sup[UDP->cmos][i] << 2); @@ -4219,7 +4218,7 @@ static struct kobject *floppy_find(dev_t dev, int *part, void *data) !(allowed_drive_mask & (1 << drive)) || fdc_state[FDC(drive)].version == FDC_NONE) return NULL; - if (((*part >> 2) & 0x1f) >= NUMBER(floppy_type)) + if (((*part >> 2) & 0x1f) >= ARRAY_SIZE(floppy_type)) return NULL; *part = 0; return get_disk(disks[drive]); @@ -4571,7 +4570,7 @@ static void unregister_devfs_entries(int drive) { int i; - if (UDP->cmos < NUMBER(default_drive_params)) { + if (UDP->cmos < ARRAY_SIZE(default_drive_params)) { i = 0; do { devfs_remove("floppy/%d%s", drive, -- cgit v1.2.3 From 46a9f65f8bb39778646b83220d9619aff1490bcd Mon Sep 17 00:00:00 2001 From: Domen Puncer Date: Sun, 15 Jan 2006 02:20:28 +0100 Subject: remove unused LOCAL_END_REQUEST Remove the last occurence of LOCAL_END_REQUEST. Signed-off-by: Domen Puncer Signed-off-by: Adrian Bunk --- drivers/block/floppy.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/block/floppy.c') diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index 374621a512e0..d23b54332d7e 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -242,7 +242,6 @@ static int allowed_drive_mask = 0x33; static int irqdma_allocated; -#define LOCAL_END_REQUEST #define DEVICE_NAME "floppy" #include -- cgit v1.2.3