return 0;
}
-#if LINUX_VERSION_CODE < 0x20300
-#define RQFUNC_ARG void
-#else
-#define RQFUNC_ARG request_queue_t *q
-#endif
-
-static void mtdblock_request(RQFUNC_ARG)
+static void mtdblock_request(request_queue *q)
{
/* Don't do anything, except wake the thread if necessary */
wake_up(&thr_wq);
return put_user((u64)mtdblk->mtd->size, (u64 *)arg);
case BLKFLSBUF:
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
if(!capable(CAP_SYS_ADMIN))
return -EACCES;
-#endif
fsync_bdev(inode->i_bdev);
invalidate_bdev(inode->i_bdev, 0);
down(&mtdblk->cache_sem);
}
}
-#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 =
{
owner: THIS_MODULE,
release: mtdblock_release,
ioctl: mtdblock_ioctl
};
-#endif
#ifdef CONFIG_DEVFS_FS
/* Notification that a new device has been added. Create the devfs entry for
#define DEVICE_NR(device) (device)
#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
-#endif
#ifdef MTDBLOCK_DEBUG
static int debug = MTDBLOCK_DEBUG;
MODULE_PARM(debug, "i");
#endif
-
-static int mtd_sizes[MAX_MTD_DEVICES];
-
+static struct gendisk mtd_disks[MAX_MTD_DEVICES];
+static char names names[MAX_MTD_DEVICES][11];
static int mtdblock_open(struct inode *inode, struct file *file)
{
struct mtd_info *mtd = NULL;
-
- int dev;
+ int dev = minor(inode->i_rdev);
+ struct gendisk *disk = mtd_disks + dev;
DEBUG(1,"mtdblock_open\n");
-
- if (inode == 0)
- return -EINVAL;
-
- dev = minor(inode->i_rdev);
-
+
mtd = get_mtd_device(NULL, dev);
if (!mtd)
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");
printk(KERN_WARNING "MTD device is absent on mtd_release!\n");
release_return(-ENODEV);
}
+
+ del_gendisk(mtd_disks + dev);
if (mtd->sync)
mtd->sync(mtd);
/* Remove the request we are handling from the request list so nobody messes
with it */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
/* 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
we spend processing it. */
spin_unlock_irq(&io_request_lock);
-#endif
// Handle the request
switch (current_request->cmd)
}
// 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);
-#endif
mtdblock_end_request(current_request, res);
}
}
mtd = __get_mtd_device(NULL, minor(inode->i_rdev));
- if (!mtd) return -EINVAL;
-
- switch (cmd) {
- case BLKGETSIZE: /* Return device size */
- return put_user((mtd->size >> 9), (unsigned long *) arg);
- case BLKGETSIZE64:
- return put_user((u64)mtd->size, (u64 *)arg);
-
- case BLKFLSBUF:
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,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 (!mtd || cmd != BLKFLSBUF)
+ return -EINVAL;
+
+ if(!capable(CAP_SYS_ADMIN))
+ return -EACCES;
+ fsync_bdev(inode->i_bdev);
+ invalidate_bdev(inode->i_bdev, 0);
+ if (mtd->sync)
+ mtd->sync(mtd);
+ return 0;
}
-#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 =
{
- owner: THIS_MODULE,
- open: mtdblock_open,
- release: mtdblock_release,
- ioctl: mtdblock_ioctl
+ .owner = THIS_MODULE,
+ .open = mtdblock_open,
+ .release = mtdblock_release,
+ .ioctl = mtdblock_ioctl
};
-#endif
int __init init_mtdblock(void)
{
MTD_BLOCK_MAJOR);
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);
+
+ 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;
}