Commit 5a22d00c authored by Dave Jones's avatar Dave Jones Committed by Linus Torvalds

[PATCH] MTD update.

Numerous bugfixes brought forward from 2.4. I added some quick bio fixes
to mtdblock.c, which seemed to work for me whilst testing JFFS2 changes.
parent 34a7eea9
This diff is collapsed.
......@@ -16,11 +16,8 @@
#define MAJOR_NR MTD_BLOCK_MAJOR
#define DEVICE_NAME "mtdblock"
#define DEVICE_REQUEST mtdblock_request
#define DEVICE_NR(device) (device)
#define DEVICE_ON(device)
#define DEVICE_OFF(device)
#define DEVICE_NO_RANDOM
#define LOCAL_END_REQUEST
#include <linux/blk.h>
/* for old kernels... */
#ifndef QUEUE_EMPTY
......@@ -283,7 +280,7 @@ static int mtdblock_open(struct inode *inode, struct file *file)
if (!inode)
return -EINVAL;
dev = MINOR(inode->i_rdev);
dev = minor(inode->i_rdev);
if (dev >= MAX_MTD_DEVICES)
return -EINVAL;
......@@ -373,7 +370,7 @@ static release_t mtdblock_release(struct inode *inode, struct file *file)
invalidate_device(inode->i_rdev, 1);
dev = MINOR(inode->i_rdev);
dev = minor(inode->i_rdev);
mtdblk = mtdblks[dev];
down(&mtdblk->cache_sem);
......@@ -417,18 +414,20 @@ static void handle_mtdblock_request(void)
INIT_REQUEST;
req = CURRENT;
spin_unlock_irq(&QUEUE->queue_lock);
mtdblk = mtdblks[MINOR(req->rq_dev)];
mtdblk = mtdblks[minor(req->rq_dev)];
res = 0;
if (MINOR(req->rq_dev) >= MAX_MTD_DEVICES)
if (minor(req->rq_dev) >= MAX_MTD_DEVICES)
panic(__FUNCTION__": minor out of bound");
if (req->flags & REQ_CMD)
goto end_req;
if ((req->sector + req->current_nr_sectors) > (mtdblk->mtd->size >> 9))
goto end_req;
// Handle the request
switch (req->cmd)
{
switch (rq_data_dir(CURRENT)) {
int err;
case READ:
......@@ -459,7 +458,11 @@ static void handle_mtdblock_request(void)
end_req:
spin_lock_irq(&QUEUE->queue_lock);
end_request(res);
if (!end_that_request_first(req, res, req->hard_cur_sectors)) {
blkdev_dequeue_request(req);
end_that_request_last(req);
}
}
}
......@@ -519,7 +522,7 @@ static int mtdblock_ioctl(struct inode * inode, struct file * file,
{
struct mtdblk_dev *mtdblk;
mtdblk = mtdblks[MINOR(inode->i_rdev)];
mtdblk = mtdblks[minor(inode->i_rdev)];
#ifdef PARANOIA
if (!mtdblk)
......@@ -597,6 +600,8 @@ static void mtd_notify_remove(struct mtd_info* mtd)
}
#endif
static spinlock_t mtddev_lock = SPIN_LOCK_UNLOCKED;
int __init init_mtdblock(void)
{
int i;
......@@ -630,7 +635,7 @@ int __init init_mtdblock(void)
blksize_size[MAJOR_NR] = mtd_blksizes;
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, &mtddev_lock);
kernel_thread (mtdblock_thread, NULL, CLONE_FS|CLONE_FILES|CLONE_SIGHAND);
return 0;
}
......
......@@ -16,13 +16,10 @@
#include <linux/mtd/mtd.h>
#include <linux/mtd/compatmac.h>
#define LOCAL_END_REQUEST
#define MAJOR_NR MTD_BLOCK_MAJOR
#define DEVICE_NAME "mtdblock"
#define DEVICE_REQUEST mtdblock_request
#define DEVICE_NR(device) (device)
#define DEVICE_ON(device)
#define DEVICE_OFF(device)
#define DEVICE_NO_RANDOM
#include <linux/blk.h>
#if LINUX_VERSION_CODE < 0x20300
......@@ -52,7 +49,7 @@ static int mtdblock_open(struct inode *inode, struct file *file)
if (inode == 0)
return -EINVAL;
dev = MINOR(inode->i_rdev);
dev = minor(inode->i_rdev);
mtd = get_mtd_device(NULL, dev);
if (!mtd)
......@@ -81,7 +78,7 @@ static release_t mtdblock_release(struct inode *inode, struct file *file)
invalidate_device(inode->i_rdev, 1);
dev = MINOR(inode->i_rdev);
dev = minor(inode->i_rdev);
mtd = __get_mtd_device(NULL, dev);
if (!mtd) {
......@@ -97,8 +94,15 @@ static release_t mtdblock_release(struct inode *inode, struct file *file)
DEBUG(1, "ok\n");
release_return(0);
}
}
static inline void mtdblock_end_request(struct request *req, int uptodate)
{
if (end_that_request_first(req, uptodate, req->hard_cur_sectors))
return;
blkdev_dequeue_request(req);
end_that_request_last(req);
}
static void mtdblock_request(RQFUNC_ARG)
{
......@@ -113,19 +117,19 @@ static void mtdblock_request(RQFUNC_ARG)
INIT_REQUEST;
current_request = CURRENT;
if (MINOR(current_request->rq_dev) >= MAX_MTD_DEVICES)
if (minor(current_request->rq_dev) >= MAX_MTD_DEVICES)
{
printk("mtd: Unsupported device!\n");
end_request(0);
mtdblock_end_request(current_request, 0);
continue;
}
// Grab our MTD structure
mtd = __get_mtd_device(NULL, MINOR(current_request->rq_dev));
mtd = __get_mtd_device(NULL, minor(current_request->rq_dev));
if (!mtd) {
printk("MTD device %d doesn't appear to exist any more\n", CURRENT_DEV);
end_request(0);
mtdblock_end_request(current_request, 0);
}
if (current_request->sector << 9 > mtd->size ||
......@@ -133,7 +137,7 @@ static void mtdblock_request(RQFUNC_ARG)
{
printk("mtd: Attempt to read past end of device!\n");
printk("size: %x, sector: %lx, nr_sectors %lx\n", mtd->size, current_request->sector, current_request->nr_sectors);
end_request(0);
mtdblock_end_request(current_request, 0);
continue;
}
......@@ -192,7 +196,7 @@ static void mtdblock_request(RQFUNC_ARG)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
spin_lock_irq(&io_request_lock);
#endif
end_request(res);
mtdblock_end_request(current_request, res);
}
}
......@@ -203,7 +207,7 @@ static int mtdblock_ioctl(struct inode * inode, struct file * file,
{
struct mtd_info *mtd;
mtd = __get_mtd_device(NULL, MINOR(inode->i_rdev));
mtd = __get_mtd_device(NULL, minor(inode->i_rdev));
if (!mtd) return -EINVAL;
......
......@@ -64,7 +64,7 @@ static loff_t mtd_lseek (struct file *file, loff_t offset, int orig)
static int mtd_open(struct inode *inode, struct file *file)
{
int minor = MINOR(inode->i_rdev);
int minor = minor(inode->i_rdev);
int devnum = minor >> 1;
struct mtd_info *mtd;
......
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