mtd/drivers/mtd/devices blkmtd-25.c,1.4,1.5

spse at infradead.org spse at infradead.org
Wed Jul 16 02:48:29 EDT 2003


Update of /home/cvs/mtd/drivers/mtd/devices
In directory phoenix.infradead.org:/tmp/cvs-serv1963

Modified Files:
	blkmtd-25.c 
Log Message:
blkmtd-25.c

Index: blkmtd-25.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/devices/blkmtd-25.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- blkmtd-25.c	20 May 2003 21:03:07 -0000	1.4
+++ blkmtd-25.c	16 Jul 2003 06:48:27 -0000	1.5
@@ -27,7 +27,7 @@
 #include <linux/bio.h>
 #include <linux/pagemap.h>
 #include <linux/list.h>
-#include <linux/slab.h>
+#include <linux/init.h>
 #include <linux/mtd/mtd.h>
 
 
@@ -39,7 +39,7 @@
 
 /* Default erase size in K, always make it a multiple of PAGE_SIZE */
 #define CONFIG_MTD_BLKDEV_ERASESIZE (128 << 10)	/* 128KiB */
-#define VERSION "1.12"
+#define VERSION "$Revision$"
 
 /* Info for the block device */
 struct blkmtd_dev {
@@ -119,7 +119,6 @@
 	} while (bvec >= bio->bi_io_vec);
 	
 	complete((struct completion*)bio->bi_private);
-	bio_put(bio);
 	return 0;
 }
 
@@ -170,6 +169,7 @@
 static int blkmtd_write_out(struct bio *bio)
 {
 	struct completion event;
+	int err;
 
 	if(!bio->bi_vcnt) {
 		bio_put(bio);
@@ -182,7 +182,10 @@
 	submit_bio(WRITE, bio);
 	blk_run_queues();
 	wait_for_completion(&event);
-	return test_bit(BIO_UPTODATE, &bio->bi_flags) ? 0 : -EIO;
+	DEBUG(3, "submit_bio completed, bi_vcnt = %d\n", bio->bi_vcnt);
+	err = test_bit(BIO_UPTODATE, &bio->bi_flags) ? 0 : -EIO;
+	bio_put(bio);
+	return err; 
 }
 
 
@@ -193,7 +196,7 @@
  * @page: page to add
  * @pagecnt: pages left to add
  *
- * Adds a page to the current bio, allocating it if necessary. If it cant be
+ * Adds a page to the current bio, allocating it if necessary. If it cannot be
  * added, the current bio is written out and a new one is allocated. Returns
  * the new bio to add or NULL on error
  */
@@ -229,9 +232,8 @@
  *
  * Grab pages from the page cache and fill them with the source data.
  * Non page aligned start and end result in a readin of the page and
- * part of the page being modified. Pages are added to the wr_buf kiobuf
- * until this becomes full or the next page written to has a lower pagenr
- * then the current max pagenr in the kiobuf.
+ * part of the page being modified. Pages are added to the bio and then written
+ * out.
  */
 static int write_pages(struct blkmtd_dev *dev, const u_char *buf, loff_t to,
 		    size_t len, size_t *retlen)
@@ -318,7 +320,7 @@
 				BUG();
 			}
 			if(!page) {
-				warn("write: cant grab cache page %d", pagenr);
+				warn("write: cannot grab cache page %d", pagenr);
 				err = -ENOMEM;
 				goto write_err;
 			}
@@ -401,7 +403,7 @@
 
 	/* check erase region has valid start and length */
 	DEBUG(2, "blkmtd: erase: dev = `%s' from = 0x%x len = 0x%lx\n",
-	      bdevname(dev->blkdev), from, len);
+	      mtd->name+9, from, len);
 	while(numregions) {
 		DEBUG(3, "blkmtd: checking erase region = 0x%08X size = 0x%X num = 0x%x\n",
 		      einfo->offset, einfo->erasesize, einfo->numblocks);
@@ -454,7 +456,7 @@
 	size_t thislen = 0;
 
 	DEBUG(2, "blkmtd: read: dev = `%s' from = %ld len = %d buf = %p\n",
-	      bdevname(dev->blkdev), (long int)from, len, buf);
+	      mtd->name+9, (long int)from, len, buf);
 
 	if(from > mtd->size)
 		return -EINVAL;
@@ -512,7 +514,7 @@
 		return 0;
 
 	DEBUG(2, "blkmtd: write: dev = `%s' to = %ld len = %d buf = %p\n",
-	      bdevname(dev->blkdev), (long int)to, len, buf);
+	      mtd->name+9, (long int)to, len, buf);
 
 	if(to >= mtd->size) {
 		return -ENOSPC;
@@ -548,8 +550,7 @@
 
 		if(dev->blkdev) {
 			invalidate_inode_pages(dev->blkdev->bd_inode->i_mapping);
-			bd_release(dev->blkdev);
-			blkdev_put(dev->blkdev, BDEV_RAW);
+			close_bdev_excl(dev->blkdev, BDEV_RAW);
 		}
 		kfree(dev);
 	}
@@ -620,87 +621,54 @@
 }
 
 
+extern dev_t __init name_to_dev_t(const char *line);
+
 static struct blkmtd_dev *add_device(char *devname, int readonly, int erase_size)
 {
-	dev_t bdev;
+	struct block_device *bdev;
 	int mode;
 	struct blkmtd_dev *dev;
 
-#ifdef MODULE
-	struct file *file = NULL;
-	struct inode *inode;
-#endif
-
 	if(!devname)
 		return NULL;
 
 	/* Get a handle on the device */
-	mode = (readonly) ? O_RDONLY : O_RDWR;
 
-#ifdef MODULE
 
-	file = filp_open(devname, mode, 0);
-	if(IS_ERR(file)) {
-		err("error: cant open device %s", devname);
-		DEBUG(2, "blkmtd: filp_open returned %ld\n", PTR_ERR(file));
-		return NULL;
-	}
-
-	/* determine is this is a block device and
-	 * if so get its major and minor numbers
-	 */
-	inode = file->f_dentry->d_inode;
-	if(!S_ISBLK(inode->i_mode)) {
-		err("%s not a block device", devname);
-		filp_close(file, NULL);
-		return NULL;
-	}
-	bdev = inode->i_bdev->bd_dev;
-	filp_close(file, NULL);
+#ifdef MODULE
+	mode = (readonly) ? O_RDONLY : O_RDWR;
+	bdev = open_bdev_excl(devname, mode, BDEV_RAW, NULL);
 #else
-	bdev = name_to_dev_t(devname);
-#endif	/* MODULE */
-
-	if(!bdev) {
-		err("bad block device: `%s'", devname);
+	mode = (readonly) ? FMODE_READ : FMODE_WRITE;
+	bdev = open_by_devnum(name_to_dev_t(devname), mode, BDEV_RAW);
+#endif
+	if(IS_ERR(bdev)) {
+		err("error: cannot open device %s", devname);
+		DEBUG(2, "blkmtd: opening bdev returned %ld\n", PTR_ERR(bdev));
 		return NULL;
 	}
 
 	DEBUG(1, "blkmtd: found a block device major = %d, minor = %d\n",
-	      MAJOR(bdev), MINOR(bdev));
+	      MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev));
 
-	if(MAJOR(bdev) == MTD_BLOCK_MAJOR) {
+	if(MAJOR(bdev->bd_dev) == MTD_BLOCK_MAJOR) {
 		err("attempting to use an MTD device as a block device");
+		blkdev_put(bdev, BDEV_RAW);
 		return NULL;
 	}
 
 	dev = kmalloc(sizeof(struct blkmtd_dev), GFP_KERNEL);
-	if(dev == NULL)
+	if(dev == NULL) {
+		blkdev_put(bdev, BDEV_RAW);
 		return NULL;
+	}
 
 	memset(dev, 0, sizeof(struct blkmtd_dev));
 	if(!readonly) {
 		init_MUTEX(&dev->wrbuf_mutex);
 	}
 
-	/* get the block device */
-	dev->blkdev = bdget(bdev);
-	if(!dev->blkdev)
-		goto devinit_err;
-
-	if(bd_claim(dev->blkdev, add_device)) {
-		err("Device %s in use", devname);
-		bdput(dev->blkdev);
-		dev->blkdev = NULL;
-		goto devinit_err;
-	}
-
-	if(blkdev_get(dev->blkdev, mode, 0, BDEV_RAW)) {
-		bd_release(dev->blkdev);
-		dev->blkdev = NULL;
-		goto devinit_err;
-	}
-
+	dev->blkdev = bdev;
 	dev->mtd_info.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
 
 	/* Setup the MTD structure */
@@ -727,11 +695,13 @@
 		dev->mtd_info.flags = MTD_CAP_RAM;
 		dev->mtd_info.erase = blkmtd_erase;
 		dev->mtd_info.write = blkmtd_write;
+		dev->mtd_info.writev = default_mtd_writev;
 		dev->mtd_info.sync = blkmtd_sync;
 	}
 	dev->mtd_info.read = blkmtd_read;
+	dev->mtd_info.readv = default_mtd_readv;
 	dev->mtd_info.priv = dev;
-	&dev->mtd_info->owner = THIS_MODULE;
+	dev->mtd_info.owner = THIS_MODULE;
 
 	list_add(&dev->list, &blkmtd_device_list);
 	if (add_mtd_device(&dev->mtd_info)) {




More information about the linux-mtd-cvs mailing list