Commit 56aa021c authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] gendisk for mtdblock_ro

mtdblock_ro switched to use of gendisk, both mtdblock.c and mtdblock_ro.c
slightly cleaned up.
parent 95bf6a39
...@@ -490,13 +490,7 @@ int mtdblock_thread(void *dummy) ...@@ -490,13 +490,7 @@ int mtdblock_thread(void *dummy)
return 0; return 0;
} }
#if LINUX_VERSION_CODE < 0x20300 static void mtdblock_request(request_queue *q)
#define RQFUNC_ARG void
#else
#define RQFUNC_ARG request_queue_t *q
#endif
static void mtdblock_request(RQFUNC_ARG)
{ {
/* Don't do anything, except wake the thread if necessary */ /* Don't do anything, except wake the thread if necessary */
wake_up(&thr_wq); wake_up(&thr_wq);
...@@ -522,10 +516,8 @@ static int mtdblock_ioctl(struct inode * inode, struct file * file, ...@@ -522,10 +516,8 @@ static int mtdblock_ioctl(struct inode * inode, struct file * file,
return put_user((u64)mtdblk->mtd->size, (u64 *)arg); return put_user((u64)mtdblk->mtd->size, (u64 *)arg);
case BLKFLSBUF: case BLKFLSBUF:
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
if(!capable(CAP_SYS_ADMIN)) if(!capable(CAP_SYS_ADMIN))
return -EACCES; return -EACCES;
#endif
fsync_bdev(inode->i_bdev); fsync_bdev(inode->i_bdev);
invalidate_bdev(inode->i_bdev, 0); invalidate_bdev(inode->i_bdev, 0);
down(&mtdblk->cache_sem); down(&mtdblk->cache_sem);
...@@ -540,16 +532,6 @@ static int mtdblock_ioctl(struct inode * inode, struct file * file, ...@@ -540,16 +532,6 @@ static int mtdblock_ioctl(struct inode * inode, struct file * file,
} }
} }
#if LINUX_VERSION_CODE < 0x20326
static struct file_operations mtd_fops =
{
open: mtdblock_open,
ioctl: mtdblock_ioctl,
release: mtdblock_release,
read: block_read,
write: block_write
};
#else
static struct block_device_operations mtd_fops = static struct block_device_operations mtd_fops =
{ {
owner: THIS_MODULE, owner: THIS_MODULE,
...@@ -557,7 +539,6 @@ static struct block_device_operations mtd_fops = ...@@ -557,7 +539,6 @@ static struct block_device_operations mtd_fops =
release: mtdblock_release, release: mtdblock_release,
ioctl: mtdblock_ioctl ioctl: mtdblock_ioctl
}; };
#endif
#ifdef CONFIG_DEVFS_FS #ifdef CONFIG_DEVFS_FS
/* Notification that a new device has been added. Create the devfs entry for /* Notification that a new device has been added. Create the devfs entry for
......
...@@ -22,35 +22,24 @@ ...@@ -22,35 +22,24 @@
#define DEVICE_NR(device) (device) #define DEVICE_NR(device) (device)
#include <linux/blk.h> #include <linux/blk.h>
#if LINUX_VERSION_CODE < 0x20300
#define RQFUNC_ARG void
#define blkdev_dequeue_request(req) do {CURRENT = req->next;} while (0)
#else
#define RQFUNC_ARG request_queue_t *q #define RQFUNC_ARG request_queue_t *q
#endif
#ifdef MTDBLOCK_DEBUG #ifdef MTDBLOCK_DEBUG
static int debug = MTDBLOCK_DEBUG; static int debug = MTDBLOCK_DEBUG;
MODULE_PARM(debug, "i"); MODULE_PARM(debug, "i");
#endif #endif
static struct gendisk mtd_disks[MAX_MTD_DEVICES];
static int mtd_sizes[MAX_MTD_DEVICES]; static char names names[MAX_MTD_DEVICES][11];
static int mtdblock_open(struct inode *inode, struct file *file) static int mtdblock_open(struct inode *inode, struct file *file)
{ {
struct mtd_info *mtd = NULL; struct mtd_info *mtd = NULL;
int dev = minor(inode->i_rdev);
int dev; struct gendisk *disk = mtd_disks + dev;
DEBUG(1,"mtdblock_open\n"); DEBUG(1,"mtdblock_open\n");
if (inode == 0)
return -EINVAL;
dev = minor(inode->i_rdev);
mtd = get_mtd_device(NULL, dev); mtd = get_mtd_device(NULL, dev);
if (!mtd) if (!mtd)
return -EINVAL; return -EINVAL;
...@@ -59,7 +48,10 @@ static int mtdblock_open(struct inode *inode, struct file *file) ...@@ -59,7 +48,10 @@ static int mtdblock_open(struct inode *inode, struct file *file)
return -EINVAL; return -EINVAL;
} }
mtd_sizes[dev] = mtd->size>>9; set_capacit(disk, mtd->size>>9);
add_gendisk(disk);
register_disk(disk, mk_kdev(disk->major, disk->first_minor),
1<<disk->minor_shift, disk->fops, get_capacity(disk));
DEBUG(1, "ok\n"); DEBUG(1, "ok\n");
...@@ -83,6 +75,8 @@ static release_t mtdblock_release(struct inode *inode, struct file *file) ...@@ -83,6 +75,8 @@ static release_t mtdblock_release(struct inode *inode, struct file *file)
printk(KERN_WARNING "MTD device is absent on mtd_release!\n"); printk(KERN_WARNING "MTD device is absent on mtd_release!\n");
release_return(-ENODEV); release_return(-ENODEV);
} }
del_gendisk(mtd_disks + dev);
if (mtd->sync) if (mtd->sync)
mtd->sync(mtd); mtd->sync(mtd);
...@@ -143,12 +137,10 @@ static void mtdblock_request(RQFUNC_ARG) ...@@ -143,12 +137,10 @@ static void mtdblock_request(RQFUNC_ARG)
/* Remove the request we are handling from the request list so nobody messes /* Remove the request we are handling from the request list so nobody messes
with it */ with it */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
/* Now drop the lock that the ll_rw_blk functions grabbed for us /* Now drop the lock that the ll_rw_blk functions grabbed for us
and process the request. This is necessary due to the extreme time and process the request. This is necessary due to the extreme time
we spend processing it. */ we spend processing it. */
spin_unlock_irq(&io_request_lock); spin_unlock_irq(&io_request_lock);
#endif
// Handle the request // Handle the request
switch (current_request->cmd) switch (current_request->cmd)
...@@ -193,9 +185,7 @@ static void mtdblock_request(RQFUNC_ARG) ...@@ -193,9 +185,7 @@ static void mtdblock_request(RQFUNC_ARG)
} }
// Grab the lock and re-thread the item onto the linked list // Grab the lock and re-thread the item onto the linked list
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
spin_lock_irq(&io_request_lock); spin_lock_irq(&io_request_lock);
#endif
mtdblock_end_request(current_request, res); mtdblock_end_request(current_request, res);
} }
} }
...@@ -209,47 +199,25 @@ static int mtdblock_ioctl(struct inode * inode, struct file * file, ...@@ -209,47 +199,25 @@ static int mtdblock_ioctl(struct inode * inode, struct file * file,
mtd = __get_mtd_device(NULL, minor(inode->i_rdev)); mtd = __get_mtd_device(NULL, minor(inode->i_rdev));
if (!mtd) return -EINVAL; if (!mtd || cmd != BLKFLSBUF)
return -EINVAL;
switch (cmd) {
case BLKGETSIZE: /* Return device size */ if(!capable(CAP_SYS_ADMIN))
return put_user((mtd->size >> 9), (unsigned long *) arg); return -EACCES;
case BLKGETSIZE64: fsync_bdev(inode->i_bdev);
return put_user((u64)mtd->size, (u64 *)arg); invalidate_bdev(inode->i_bdev, 0);
if (mtd->sync)
case BLKFLSBUF: mtd->sync(mtd);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0) return 0;
if(!capable(CAP_SYS_ADMIN)) return -EACCES;
#endif
fsync_bdev(inode->i_bdev);
invalidate_bdev(inode->i_bdev, 0);
if (mtd->sync)
mtd->sync(mtd);
return 0;
default:
return -ENOTTY;
}
} }
#if LINUX_VERSION_CODE < 0x20326
static struct file_operations mtd_fops =
{
open: mtdblock_open,
ioctl: mtdblock_ioctl,
release: mtdblock_release,
read: block_read,
write: block_write
};
#else
static struct block_device_operations mtd_fops = static struct block_device_operations mtd_fops =
{ {
owner: THIS_MODULE, .owner = THIS_MODULE,
open: mtdblock_open, .open = mtdblock_open,
release: mtdblock_release, .release = mtdblock_release,
ioctl: mtdblock_ioctl .ioctl = mtdblock_ioctl
}; };
#endif
int __init init_mtdblock(void) int __init init_mtdblock(void)
{ {
...@@ -260,16 +228,17 @@ int __init init_mtdblock(void) ...@@ -260,16 +228,17 @@ int __init init_mtdblock(void)
MTD_BLOCK_MAJOR); MTD_BLOCK_MAJOR);
return -EAGAIN; return -EAGAIN;
} }
/* We fill it in at open() time. */
for (i=0; i< MAX_MTD_DEVICES; i++) {
mtd_sizes[i] = 0;
}
/* Allow the block size to default to BLOCK_SIZE. */
blk_size[MAJOR_NR] = mtd_sizes;
blk_init_queue(BLK_DEFAULT_QUEUE(MAJOR_NR), &mtdblock_request); blk_init_queue(BLK_DEFAULT_QUEUE(MAJOR_NR), &mtdblock_request);
for (i = 0; i < MAX_MTD_DEVICES; i++) {
struct gendisk *disk = mtd_disks + i;
disk->major = MAJOR_NR;
disk->first_minor = i;
sprintf(names[i], "mtdblock%d", i);
disk->major_name = names[i];
disk->fops = &mtd_fops;
}
return 0; return 0;
} }
......
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