mtd/drivers/mtd/devices blkmtd.c,1.14,1.15
spse at infradead.org
spse at infradead.org
Wed Sep 11 10:10:17 EDT 2002
Update of /home/cvs/mtd/drivers/mtd/devices
In directory phoenix.infradead.org:/tmp/cvs-serv31375
Modified Files:
blkmtd.c
Log Message:
- dont include compatmac.h, its in mtd.h.
- add devices in order that they are given as args.
- set blocksize to PAGE_SIZE, loses devicesize % PAGE_SIZE
bytes but these are ignored by jffs2 anyway.
Index: blkmtd.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/devices/blkmtd.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- blkmtd.c 4 Sep 2002 22:59:31 -0000 1.14
+++ blkmtd.c 11 Sep 2002 14:10:14 -0000 1.15
@@ -51,7 +51,6 @@
#include <linux/slab.h>
#include <linux/pagemap.h>
#include <linux/list.h>
-#include <linux/mtd/compatmac.h>
#include <linux/mtd/mtd.h>
#ifdef CONFIG_MTD_DEBUG
@@ -77,11 +76,6 @@
struct blkmtd_dev {
struct list_head list;
struct block_device *binding;
- int sector_size, sector_bits;
- int partial_last_page; /* 0 if device ends on page boundary, */
- /* else page no of last page */
- int last_page_sectors; /* Number of sectors in last page */
- /* if partial_last_page != 0 */
int readonly;
struct mtd_info mtd_info;
};
@@ -148,7 +142,6 @@
static int blkmtd_readpage(struct blkmtd_dev *dev, struct page *page)
{
int err;
- int sectornr, sectors, i;
struct kiobuf *iobuf;
kdev_t kdev;
unsigned long *blocks;
@@ -230,32 +223,10 @@
iobuf->length = PAGE_SIZE;
iobuf->locked = 1;
iobuf->maplist[0] = page;
- sectornr = page->index << (PAGE_SHIFT - dev->sector_bits);
- sectors = 1 << (PAGE_SHIFT - dev->sector_bits);
- if(dev->partial_last_page
- && page->index == dev->partial_last_page) {
- DEBUG(3, "blkmtd: handling partial last page\n");
- sectors = dev->last_page_sectors;
- }
- DEBUG(3, "blkmtd: readpage: sectornr = %d sectors = %d\n",
- sectornr, sectors);
- for(i = 0; i < sectors; i++) {
- blocks[i] = sectornr++;
- }
- /* If only a partial page read in, clear the rest of the page */
- if(dev->partial_last_page
- && page->index == dev->partial_last_page) {
- int offset = dev->last_page_sectors << dev->sector_bits;
- int count = PAGE_SIZE-offset;
- DEBUG(3, "blkmtd: clear last partial page: offset = %d count = %d\n",
- offset, count);
- memset(page_address(page)+offset, 0, count);
- sectors = dev->last_page_sectors;
- }
-
+ blocks[0] = page->index;
DEBUG(3, "bklmtd: readpage: starting brw_kiovec\n");
- err = brw_kiovec(READ, 1, &iobuf, kdev, blocks, dev->sector_size);
+ err = brw_kiovec(READ, 1, &iobuf, kdev, blocks, PAGE_SIZE);
DEBUG(3, "blkmtd: readpage: finished, err = %d\n", err);
iobuf->locked = 0;
free_kiovec(1, &iobuf);
@@ -341,28 +312,18 @@
struct page **pages = item->pages;
int i;
- int sectornr = item->pagenr << (PAGE_SHIFT - item->dev->sector_bits);
- int sectorcnt = item->pagecnt << (PAGE_SHIFT - item->dev->sector_bits);
- int max_sectors = KIO_MAX_SECTORS >> (item->dev->sector_bits - 9);
+ int sectornr = item->pagenr;
+ int sectorcnt = item->pagecnt;
+ int max_sectors = KIO_STATIC_PAGES;
kdev_t kdev = to_kdev_t(item->dev->binding->bd_dev);
- /* If we are writing to the last page on the device
- * and it doesn't end on a page boundary, subtract
- * the number of sectors that dont exist.
- */
- if(item->dev->partial_last_page
- && (item->pagenr + item->pagecnt -1) == item->dev->partial_last_page) {
- sectorcnt -= (1 << (PAGE_SHIFT - item->dev->sector_bits));
- sectorcnt += item->dev->last_page_sectors;
- }
-
DEBUG(3, "blkmtd: writetask: got %d queue items\n",
write_queue_cnt);
set_current_state(TASK_RUNNING);
spin_unlock(&mbd_writeq_lock);
- DEBUG(2, "blkmtd: writetask: writing pagenr = %d pagecnt = %d sectornr = %d sectorcnt = %d\n",
- item->pagenr, item->pagecnt, sectornr, sectorcnt);
+ DEBUG(2, "blkmtd: writetask: writing pagenr = %d pagecnt = %d\n",
+ item->pagenr, item->pagecnt);
iobuf->offset = 0;
iobuf->locked = 1;
@@ -373,7 +334,7 @@
*/
while(sectorcnt) {
int cursectors = (sectorcnt < max_sectors) ? sectorcnt : max_sectors;
- int cpagecnt = (cursectors << item->dev->sector_bits) + PAGE_SIZE-1;
+ int cpagecnt = (cursectors << PAGE_SHIFT) + PAGE_SIZE-1;
cpagecnt >>= PAGE_SHIFT;
for(i = 0; i < cpagecnt; i++) {
@@ -389,12 +350,11 @@
}
iobuf->nr_pages = cpagecnt;
- iobuf->length = cursectors << item->dev->sector_bits;
+ iobuf->length = iobuf->nr_pages << PAGE_SHIFT;
DEBUG(3, "blkmtd: write_task: about to kiovec\n");
- err = brw_kiovec(WRITE, 1, &iobuf, kdev, blocks,
- item->dev->sector_size);
+ err = brw_kiovec(WRITE, 1, &iobuf, kdev, blocks, PAGE_SIZE);
DEBUG(3, "bklmtd: write_task: done, err = %d\n", err);
- if(err != (cursectors << item->dev->sector_bits)) {
+ if(err != (cursectors << PAGE_SHIFT)) {
/* if an error occured - set this to
* exit the loop
*/
@@ -741,7 +701,6 @@
len = (mtd->size - to);
}
-
pagenr = to >> PAGE_SHIFT;
offset = to - (pagenr << PAGE_SHIFT);
@@ -991,11 +950,13 @@
kfree(dev->mtd_info.eraseregions);
if(dev->mtd_info.name)
kfree(dev->mtd_info.name);
-
- invalidate_inode_pages(dev->binding->bd_inode);
-
- if(dev->binding)
+
+ if(dev->binding) {
+ kdev_t kdev = to_kdev_t(dev->binding->bd_dev);
+ invalidate_inode_pages(dev->binding->bd_inode);
+ set_blocksize(kdev, 1 << 10);
blkdev_put(dev->binding, BDEV_RAW);
+ }
kfree(dev);
}
}
@@ -1074,9 +1035,6 @@
static struct blkmtd_dev *add_device(char *devname, int readonly, int erase_size)
{
int maj, min;
- int blocksize, blocksize_bits;
- loff_t size = 0;
- int err;
kdev_t kdev;
int mode;
struct blkmtd_dev *dev;
@@ -1133,9 +1091,6 @@
DEBUG(1, "blkmtd: devname = %s\n", bdevname(kdev));
- blocksize = block_size(kdev);
- blocksize_bits = blksize_bits(blocksize);
-
dev = kmalloc(sizeof(struct blkmtd_dev), GFP_KERNEL);
if(dev == NULL)
return NULL;
@@ -1143,25 +1098,17 @@
memset(dev, 0, sizeof(struct blkmtd_dev));
/* get the block device */
dev->binding = bdget(kdev_t_to_nr(MKDEV(maj, min)));
- err = blkdev_get(dev->binding, mode, 0, BDEV_RAW);
- if (err) {
+ if(blkdev_get(dev->binding, mode, 0, BDEV_RAW))
goto devinit_err;
- }
- size = dev->binding->bd_inode->i_size;
- DEBUG(1, "blkmtd: size = %ld\n", (long int)size);
- dev->sector_size = blocksize;
- dev->sector_bits = blocksize_bits;
- dev->readonly = readonly;
- /* See if device ends on page boundary */
- if(size % PAGE_SIZE) {
- dev->partial_last_page = size >> PAGE_SHIFT;
- dev->last_page_sectors = (size & (PAGE_SIZE-1)) >> blocksize_bits;
+ if(set_blocksize(kdev, PAGE_SIZE)) {
+ err("cant set block size to PAGE_SIZE on %s", bdevname(kdev));
+ goto devinit_err;
}
- DEBUG(2, "sector_size = %d, sector_bits = %d, partial_last_page = %d last_page_sectors = %d\n",
- dev->sector_size, dev->sector_bits,
- dev->partial_last_page, dev->last_page_sectors);
+ dev->mtd_info.size = dev->binding->bd_inode->i_size & PAGE_MASK;
+ DEBUG(1, "blkmtd: size = %ld\n", (long int)dev->mtd_info.size);
+ dev->readonly = readonly;
/* Setup the MTD structure */
/* make the name contain the block device in */
@@ -1170,13 +1117,11 @@
goto devinit_err;
sprintf(dev->mtd_info.name, "blkmtd: %s", devname);
-
- dev->mtd_info.eraseregions = calc_erase_regions(erase_size, size,
+ dev->mtd_info.eraseregions = calc_erase_regions(erase_size, dev->mtd_info.size,
&dev->mtd_info.numeraseregions);
- if(dev->mtd_info.eraseregions == NULL) {
- err = -ENOMEM;
+ if(dev->mtd_info.eraseregions == NULL)
goto devinit_err;
- }
+
dev->mtd_info.erasesize = dev->mtd_info.eraseregions->erasesize;
DEBUG(1, "blkmtd: init: found %d erase regions\n",
dev->mtd_info.numeraseregions);
@@ -1188,7 +1133,6 @@
dev->mtd_info.type = MTD_RAM;
dev->mtd_info.flags = MTD_CAP_RAM;
}
- dev->mtd_info.size = size;
dev->mtd_info.erase = blkmtd_erase;
dev->mtd_info.read = blkmtd_read;
dev->mtd_info.write = blkmtd_write;
@@ -1196,8 +1140,8 @@
dev->mtd_info.point = 0;
dev->mtd_info.unpoint = 0;
dev->mtd_info.priv = dev;
+ dev->mtd_info.module = THIS_MODULE;
- dev->mtd_info.module = THIS_MODULE;
list_add(&dev->list, &blkmtd_device_list);
if (add_mtd_device(&dev->mtd_info)) {
/* Device didnt get added, so free the entry */
@@ -1310,7 +1254,7 @@
{
int err = 0;
struct blkmtd_dev *dev;
- int i = MAX_DEVICES-1;
+ int i;
int global_ro = 1;
/* Check args - device[0] is the bare minimum*/
@@ -1327,13 +1271,13 @@
write_queue_sz = wqs;
}
- do {
+ for(i = 0; i < MAX_DEVICES; i++) {
dev = add_device(device[i], ro[i], erasesz[i] << 10);
if(dev) {
if(global_ro && !ro[i])
global_ro = 0;
}
- } while(i--);
+ }
if(list_empty(&blkmtd_device_list))
goto init_err;
More information about the linux-mtd-cvs
mailing list