mtd/drivers/mtd ftl.c,1.50,1.51 inftlcore.c,1.10,1.11
mtd_blkdevs-24.c,1.10,1.11 mtd_blkdevs.c,1.14,1.15
mtdblock.c,1.62,1.63 mtdblock_ro.c,1.17,1.18 nftlcore.c,1.93,1.94
David Woodhouse
dwmw2 at infradead.org
Mon Jun 23 08:00:11 EDT 2003
Update of /home/cvs/mtd/drivers/mtd
In directory phoenix.infradead.org:/tmp/cvs-serv18104/drivers/mtd
Modified Files:
ftl.c inftlcore.c mtd_blkdevs-24.c mtd_blkdevs.c mtdblock.c
mtdblock_ro.c nftlcore.c
Log Message:
From:Â Christoph Hellwig <hch at lst.de>
->open and ->release lose the totally pointless inode and file
arguments, ->ioctl gets replaced by ->getgeo and ->flush, removing
duplicated code from the individual drivers and avoiding to sneak
more ioctl mess.. :)
Index: ftl.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/ftl.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -r1.50 -r1.51
--- ftl.c 21 May 2003 10:49:47 -0000 1.50
+++ ftl.c 23 Jun 2003 12:00:08 -0000 1.51
@@ -984,37 +984,20 @@
return 0;
} /* ftl_write */
-/*======================================================================
-
- IOCTL calls for getting device parameters.
-
-======================================================================*/
-
-static int ftl_ioctl(struct mtd_blktrans_dev *dev, struct inode *inode,
- struct file *file, u_int cmd, u_long arg)
+static int ftl_getgeo(struct mtd_blktrans_dev *dev, struct hd_geometry *geo)
{
- struct hd_geometry *geo = (struct hd_geometry *)arg;
- partition_t *part = (void *)dev;
- u_long sect;
+ partition_t *part = (void *)dev;
+ u_long sect;
- switch (cmd) {
- case HDIO_GETGEO:
- /* Sort of arbitrary: round size down to 4K boundary */
+ /* Sort of arbitrary: round size down to 4KiB boundary */
sect = le32_to_cpu(part->header.FormattedSize)/SECTOR_SIZE;
- if (put_user(1, (char *)&geo->heads) ||
- put_user(8, (char *)&geo->sectors) ||
- put_user((sect>>3), (short *)&geo->cylinders) ||
- put_user(0, (u_long *)&geo->start))
- return -EFAULT;
-
- case BLKFLSBUF:
- return 0;
- }
- return -ENOTTY;
-} /* ftl_ioctl */
+ geo->heads = 1;
+ geo->sectors = 8;
+ geo->cylinders = sect >> 3;
-/*======================================================================*/
+ return 0;
+}
static int ftl_readsect(struct mtd_blktrans_dev *dev,
unsigned long block, char *buf)
@@ -1102,7 +1085,7 @@
.part_bits = PART_BITS,
.readsect = ftl_readsect,
.writesect = ftl_writesect,
- .ioctl = ftl_ioctl,
+ .getgeo = ftl_getgeo,
.add_mtd = ftl_add_mtd,
.remove_dev = ftl_remove_dev,
.owner = THIS_MODULE,
Index: inftlcore.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/inftlcore.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- inftlcore.c 11 Jun 2003 13:27:51 -0000 1.10
+++ inftlcore.c 23 Jun 2003 12:00:08 -0000 1.11
@@ -835,35 +835,22 @@
return 0;
}
-
-static int inftl_ioctl(struct mtd_blktrans_dev *dev,
- struct inode *inode, struct file *file,
- unsigned int cmd, unsigned long arg)
+static int inftl_getgeo(struct mtd_blktrans_dev *dev, struct hd_geometry *geo)
{
struct NFTLrecord *nftl = (void *)dev;
- switch (cmd) {
- case HDIO_GETGEO: {
- struct hd_geometry g;
-
- g.heads = nftl->heads;
- g.sectors = nftl->sectors;
- g.cylinders = nftl->cylinders;
- g.start = 0;
- return copy_to_user((void *)arg, &g, sizeof g) ? -EFAULT : 0;
- }
+ geo->heads = nftl->heads;
+ geo->sectors = nftl->sectors;
+ geo->cylinders = nftl->cylinders;
- default:
- return -ENOTTY;
- }
+ return 0;
}
-
struct mtd_blktrans_ops inftl_tr = {
.name = "inftl",
.major = INFTL_MAJOR,
.part_bits = INFTL_PARTN_BITS,
- .ioctl = inftl_ioctl,
+ .getgeo = inftl_getgeo,
.readsect = inftl_readblock,
.writesect = inftl_writeblock,
.add_mtd = inftl_add_mtd,
Index: mtd_blkdevs-24.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/mtd_blkdevs-24.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- mtd_blkdevs-24.c 26 May 2003 11:16:44 -0000 1.10
+++ mtd_blkdevs-24.c 23 Jun 2003 12:00:08 -0000 1.11
@@ -18,8 +18,10 @@
#include <linux/blk.h>
#include <linux/blkpg.h>
#include <linux/spinlock.h>
+#include <linux/hdreg.h>
#include <linux/init.h>
#include <asm/semaphore.h>
+#include <asm/uaccess.h>
static LIST_HEAD(blktrans_majors);
@@ -239,7 +241,7 @@
dev->mtd->usecount++;
ret = 0;
- if (tr->open && (ret = tr->open(dev, i, f))) {
+ if (tr->open && (ret = tr->open(dev))) {
dev->mtd->usecount--;
if (dev->mtd->owner)
__MOD_DEC_USE_COUNT(dev->mtd->owner);
@@ -277,7 +279,7 @@
}
if (tr->release)
- ret = tr->release(dev, i, f);
+ ret = tr->release(dev);
if (!ret) {
dev->mtd->usecount--;
@@ -369,13 +371,28 @@
case BLKFLSBUF:
blk_ioctl(inode->i_rdev, cmd, arg);
- if (!tr->ioctl)
- return 0;
+ if (tr->flush)
+ return tr->flush(dev);
+ /* The core code did the work, we had nothing to do. */
+ return 0;
+ case HDIO_GETGEO:
+ if (tr->getgeo) {
+ struct hd_geometry g;
+ struct gendisk *gd = &(tr->blkcore_priv->gd);
+
+ memset(&g, 0, sizeof(g));
+ int ret = tr->getgeo(dev, &g);
+ if (ret)
+ return ret;
+
+ g.start = gd->part[MINOR(inode->i_rdev)].start_sect;
+ if (copy_to_user((void *)arg, &g, sizeof(g)))
+ return -EFAULT;
+ return 0;
+ } /* else */
default:
- if (!tr->ioctl)
- return -ENOTTY;
- return tr->ioctl(dev, inode, file, cmd, arg);
+ return -ENOTTY;
}
}
Index: mtd_blkdevs.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/mtd_blkdevs.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- mtd_blkdevs.c 23 Jun 2003 09:07:25 -0000 1.14
+++ mtd_blkdevs.c 23 Jun 2003 12:00:08 -0000 1.15
@@ -18,8 +18,10 @@
#include <linux/blk.h>
#include <linux/blkpg.h>
#include <linux/spinlock.h>
+#include <linux/hdreg.h>
#include <linux/init.h>
#include <asm/semaphore.h>
+#include <asm/uaccess.h>
#include <linux/devfs_fs_kernel.h>
static LIST_HEAD(blktrans_majors);
@@ -161,7 +163,7 @@
dev->mtd->usecount++;
ret = 0;
- if (tr->open && (ret = tr->open(dev, i, f))) {
+ if (tr->open && (ret = tr->open(dev))) {
dev->mtd->usecount--;
module_put(dev->mtd->owner);
out_tr:
@@ -181,7 +183,7 @@
tr = dev->tr;
if (tr->release)
- ret = tr->release(dev, i, f);
+ ret = tr->release(dev);
if (!ret) {
dev->mtd->usecount--;
@@ -196,21 +198,33 @@
static int blktrans_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
{
- struct mtd_blktrans_dev *dev;
- struct mtd_blktrans_ops *tr;
- int ret = -ENOTTY;
-
- dev = inode->i_bdev->bd_disk->private_data;
- tr = dev->tr;
-
- if (tr->ioctl)
- ret = tr->ioctl(dev, inode, file, cmd, arg);
+ struct mtd_blktrans_dev *dev = inode->i_bdev->bd_disk->private_data;
+ struct mtd_blktrans_ops *tr = dev->tr;
- if (ret == -ENOTTY && (cmd == BLKROSET || cmd == BLKFLSBUF)) {
+ switch (cmd) {
+ case BLKFLSBUF:
+ if (tr->flush)
+ return tr->flush(dev);
/* The core code did the work, we had nothing to do. */
- ret = 0;
+ return 0;
+
+ case HDIO_GETGEO:
+ if (tr->getgeo) {
+ struct hd_geometry g;
+
+ memset(&g, 0, sizeof(g));
+ int ret = tr->getgeo(dev, &g);
+ if (ret)
+ return ret;
+
+ g.start = get_start_sect(inode->i_bdev);
+ if (copy_to_user((void *)arg, &g, sizeof(g)))
+ return -EFAULT;
+ return 0;
+ } /* else */
+ default:
+ return -ENOTTY;
}
- return ret;
}
struct block_device_operations mtd_blktrans_ops = {
Index: mtdblock.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/mtdblock.c,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -r1.62 -r1.63
--- mtdblock.c 2 Jun 2003 16:29:47 -0000 1.62
+++ mtdblock.c 23 Jun 2003 12:00:08 -0000 1.63
@@ -260,8 +260,7 @@
return do_cached_write(mtdblk, block<<9, 512, buf);
}
-static int mtdblock_open(struct mtd_blktrans_dev *mbd,
- struct inode *inode, struct file *file)
+static int mtdblock_open(struct mtd_blktrans_dev *mbd)
{
struct mtdblk_dev *mtdblk;
struct mtd_info *mtd = mbd->mtd;
@@ -298,17 +297,13 @@
return 0;
}
-static int mtdblock_release(struct mtd_blktrans_dev *mbd,
- struct inode *inode, struct file *file)
+static int mtdblock_release(struct mtd_blktrans_dev *mbd)
{
- int dev;
- struct mtdblk_dev *mtdblk;
+ int dev = mbd->devnum;
+ struct mtdblk_dev *mtdblk = mtdblks[dev];
DEBUG(MTD_DEBUG_LEVEL1, "mtdblock_release\n");
- dev = minor(inode->i_rdev);
- mtdblk = mtdblks[dev];
-
down(&mtdblk->cache_sem);
write_cached_data(mtdblk);
up(&mtdblk->cache_sem);
@@ -326,27 +321,17 @@
return 0;
}
-
-static int mtdblock_ioctl(struct mtd_blktrans_dev *dev,
- struct inode * inode, struct file * file,
- unsigned int cmd, unsigned long arg)
+static int mtdblock_flush(struct mtd_blktrans_dev *dev)
{
- struct mtdblk_dev *mtdblk;
-
- mtdblk = mtdblks[minor(inode->i_rdev)];
+ struct mtdblk_dev *mtdblk = mtdblks[dev->devnum];
- switch (cmd) {
- case BLKFLSBUF:
- down(&mtdblk->cache_sem);
- write_cached_data(mtdblk);
- up(&mtdblk->cache_sem);
- if (mtdblk->mtd->sync)
- mtdblk->mtd->sync(mtdblk->mtd);
- return 0;
+ down(&mtdblk->cache_sem);
+ write_cached_data(mtdblk);
+ up(&mtdblk->cache_sem);
- default:
- return -ENOTTY;
- }
+ if (mtdblk->mtd->sync)
+ mtdblk->mtd->sync(mtdblk->mtd);
+ return 0;
}
static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
@@ -381,7 +366,7 @@
.major = 31,
.part_bits = 0,
.open = mtdblock_open,
- .ioctl = mtdblock_ioctl,
+ .flush = mtdblock_flush,
.release = mtdblock_release,
.readsect = mtdblock_readsect,
.writesect = mtdblock_writesect,
Index: mtdblock_ro.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/mtdblock_ro.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- mtdblock_ro.c 18 May 2003 19:27:27 -0000 1.17
+++ mtdblock_ro.c 23 Jun 2003 12:00:08 -0000 1.18
@@ -6,6 +6,7 @@
* Simple read-only (writable only for RAM) mtdblock driver
*/
+#include <linux/init.h>
#include <linux/slab.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/blktrans.h>
Index: nftlcore.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/nftlcore.c,v
retrieving revision 1.93
retrieving revision 1.94
diff -u -r1.93 -r1.94
--- nftlcore.c 11 Jun 2003 13:27:51 -0000 1.93
+++ nftlcore.c 23 Jun 2003 12:00:08 -0000 1.94
@@ -699,29 +699,17 @@
return 0;
}
-static int nftl_ioctl(struct mtd_blktrans_dev *dev,
- struct inode * inode, struct file * file,
- unsigned int cmd, unsigned long arg)
+static int nftl_getgeo(struct mtd_blktrans_dev *dev, struct hd_geometry *geo)
{
struct NFTLrecord *nftl = (void *)dev;
- switch (cmd) {
- case HDIO_GETGEO: {
- struct hd_geometry g;
+ geo->heads = nftl->heads;
+ geo->sectors = nftl->sectors;
+ geo->cylinders = nftl->cylinders;
- g.heads = nftl->heads;
- g.sectors = nftl->sectors;
- g.cylinders = nftl->cylinders;
- g.start = 0;
- return copy_to_user((void *)arg, &g, sizeof g) ? -EFAULT : 0;
- }
-
- default:
- return -ENOTTY;
- }
+ return 0;
}
-
/****************************************************************************
*
* Module stuff
@@ -733,7 +721,7 @@
.name = "nftl",
.major = NFTL_MAJOR,
.part_bits = NFTL_PARTN_BITS,
- .ioctl = nftl_ioctl,
+ .getgeo = nftl_getgeo,
.readsect = nftl_readblock,
#ifdef CONFIG_NFTL_RW
.writesect = nftl_writeblock,
More information about the linux-mtd-cvs
mailing list