diff options
author | Richard Purdie <rpurdie@openedhand.com> | 2006-10-27 04:09:33 -0400 |
---|---|---|
committer | David Woodhouse <dwmw2@infradead.org> | 2006-11-28 17:27:47 -0500 |
commit | 191876729901d0c8dab8a331f9a1e4b73a56457b (patch) | |
tree | 1e25eb24ac84c09b0300e32eea55b33adc567015 | |
parent | 90afffc8bd79d130b58acd18f972ce4e00b8e20f (diff) |
[MTD] Allow variable block sizes in mtd_blkdevs
Currently, mtd_blkdevs enforces a block size of 512, even if the drivers
can seemingly request a different size. This patch fixes mtd_blkdevs so
block sizes other than 512 work correctly.
Signed-off-by: Richard Purdie <rpurdie@openedhand.com>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
-rw-r--r-- | drivers/mtd/ftl.c | 3 | ||||
-rw-r--r-- | drivers/mtd/inftlcore.c | 3 | ||||
-rw-r--r-- | drivers/mtd/mtd_blkdevs.c | 15 | ||||
-rw-r--r-- | drivers/mtd/mtdblock.c | 3 | ||||
-rw-r--r-- | drivers/mtd/mtdblock_ro.c | 3 | ||||
-rw-r--r-- | drivers/mtd/nftlcore.c | 3 | ||||
-rw-r--r-- | drivers/mtd/rfd_ftl.c | 3 | ||||
-rw-r--r-- | include/linux/mtd/blktrans.h | 3 |
8 files changed, 23 insertions, 13 deletions
diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c index 8a878b34eca0..da39355132d8 100644 --- a/drivers/mtd/ftl.c +++ b/drivers/mtd/ftl.c | |||
@@ -1054,7 +1054,7 @@ static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) | |||
1054 | le32_to_cpu(partition->header.FormattedSize) >> 10); | 1054 | le32_to_cpu(partition->header.FormattedSize) >> 10); |
1055 | #endif | 1055 | #endif |
1056 | partition->mbd.size = le32_to_cpu(partition->header.FormattedSize) >> 9; | 1056 | partition->mbd.size = le32_to_cpu(partition->header.FormattedSize) >> 9; |
1057 | partition->mbd.blksize = SECTOR_SIZE; | 1057 | |
1058 | partition->mbd.tr = tr; | 1058 | partition->mbd.tr = tr; |
1059 | partition->mbd.devnum = -1; | 1059 | partition->mbd.devnum = -1; |
1060 | if (!add_mtd_blktrans_dev((void *)partition)) | 1060 | if (!add_mtd_blktrans_dev((void *)partition)) |
@@ -1076,6 +1076,7 @@ struct mtd_blktrans_ops ftl_tr = { | |||
1076 | .name = "ftl", | 1076 | .name = "ftl", |
1077 | .major = FTL_MAJOR, | 1077 | .major = FTL_MAJOR, |
1078 | .part_bits = PART_BITS, | 1078 | .part_bits = PART_BITS, |
1079 | .blksize = SECTOR_SIZE, | ||
1079 | .readsect = ftl_readsect, | 1080 | .readsect = ftl_readsect, |
1080 | .writesect = ftl_writesect, | 1081 | .writesect = ftl_writesect, |
1081 | .getgeo = ftl_getgeo, | 1082 | .getgeo = ftl_getgeo, |
diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c index 4116535805f1..a1b2de605000 100644 --- a/drivers/mtd/inftlcore.c +++ b/drivers/mtd/inftlcore.c | |||
@@ -77,7 +77,7 @@ static void inftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) | |||
77 | 77 | ||
78 | inftl->mbd.mtd = mtd; | 78 | inftl->mbd.mtd = mtd; |
79 | inftl->mbd.devnum = -1; | 79 | inftl->mbd.devnum = -1; |
80 | inftl->mbd.blksize = 512; | 80 | |
81 | inftl->mbd.tr = tr; | 81 | inftl->mbd.tr = tr; |
82 | 82 | ||
83 | if (INFTL_mount(inftl) < 0) { | 83 | if (INFTL_mount(inftl) < 0) { |
@@ -945,6 +945,7 @@ static struct mtd_blktrans_ops inftl_tr = { | |||
945 | .name = "inftl", | 945 | .name = "inftl", |
946 | .major = INFTL_MAJOR, | 946 | .major = INFTL_MAJOR, |
947 | .part_bits = INFTL_PARTN_BITS, | 947 | .part_bits = INFTL_PARTN_BITS, |
948 | .blksize = 512, | ||
948 | .getgeo = inftl_getgeo, | 949 | .getgeo = inftl_getgeo, |
949 | .readsect = inftl_readblock, | 950 | .readsect = inftl_readblock, |
950 | .writesect = inftl_writeblock, | 951 | .writesect = inftl_writeblock, |
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index 178b53b56be9..b5d62cb357da 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c | |||
@@ -42,19 +42,20 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr, | |||
42 | unsigned long block, nsect; | 42 | unsigned long block, nsect; |
43 | char *buf; | 43 | char *buf; |
44 | 44 | ||
45 | block = req->sector; | 45 | block = req->sector << 9 >> tr->blkshift; |
46 | nsect = req->current_nr_sectors; | 46 | nsect = req->current_nr_sectors << 9 >> tr->blkshift; |
47 | |||
47 | buf = req->buffer; | 48 | buf = req->buffer; |
48 | 49 | ||
49 | if (!blk_fs_request(req)) | 50 | if (!blk_fs_request(req)) |
50 | return 0; | 51 | return 0; |
51 | 52 | ||
52 | if (block + nsect > get_capacity(req->rq_disk)) | 53 | if (req->sector + req->current_nr_sectors > get_capacity(req->rq_disk)) |
53 | return 0; | 54 | return 0; |
54 | 55 | ||
55 | switch(rq_data_dir(req)) { | 56 | switch(rq_data_dir(req)) { |
56 | case READ: | 57 | case READ: |
57 | for (; nsect > 0; nsect--, block++, buf += 512) | 58 | for (; nsect > 0; nsect--, block++, buf += tr->blksize) |
58 | if (tr->readsect(dev, block, buf)) | 59 | if (tr->readsect(dev, block, buf)) |
59 | return 0; | 60 | return 0; |
60 | return 1; | 61 | return 1; |
@@ -63,7 +64,7 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr, | |||
63 | if (!tr->writesect) | 64 | if (!tr->writesect) |
64 | return 0; | 65 | return 0; |
65 | 66 | ||
66 | for (; nsect > 0; nsect--, block++, buf += 512) | 67 | for (; nsect > 0; nsect--, block++, buf += tr->blksize) |
67 | if (tr->writesect(dev, block, buf)) | 68 | if (tr->writesect(dev, block, buf)) |
68 | return 0; | 69 | return 0; |
69 | return 1; | 70 | return 1; |
@@ -297,7 +298,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new) | |||
297 | 298 | ||
298 | /* 2.5 has capacity in units of 512 bytes while still | 299 | /* 2.5 has capacity in units of 512 bytes while still |
299 | having BLOCK_SIZE_BITS set to 10. Just to keep us amused. */ | 300 | having BLOCK_SIZE_BITS set to 10. Just to keep us amused. */ |
300 | set_capacity(gd, (new->size * new->blksize) >> 9); | 301 | set_capacity(gd, (new->size * tr->blksize) >> 9); |
301 | 302 | ||
302 | gd->private_data = new; | 303 | gd->private_data = new; |
303 | new->blkcore_priv = gd; | 304 | new->blkcore_priv = gd; |
@@ -401,6 +402,8 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr) | |||
401 | } | 402 | } |
402 | 403 | ||
403 | tr->blkcore_priv->rq->queuedata = tr; | 404 | tr->blkcore_priv->rq->queuedata = tr; |
405 | blk_queue_hardsect_size(tr->blkcore_priv->rq, tr->blksize); | ||
406 | tr->blkshift = ffs(tr->blksize) - 1; | ||
404 | 407 | ||
405 | ret = kernel_thread(mtd_blktrans_thread, tr, CLONE_KERNEL); | 408 | ret = kernel_thread(mtd_blktrans_thread, tr, CLONE_KERNEL); |
406 | if (ret < 0) { | 409 | if (ret < 0) { |
diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c index 04ed34694b14..a052648f6e31 100644 --- a/drivers/mtd/mtdblock.c +++ b/drivers/mtd/mtdblock.c | |||
@@ -348,7 +348,7 @@ static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) | |||
348 | 348 | ||
349 | dev->mtd = mtd; | 349 | dev->mtd = mtd; |
350 | dev->devnum = mtd->index; | 350 | dev->devnum = mtd->index; |
351 | dev->blksize = 512; | 351 | |
352 | dev->size = mtd->size >> 9; | 352 | dev->size = mtd->size >> 9; |
353 | dev->tr = tr; | 353 | dev->tr = tr; |
354 | 354 | ||
@@ -368,6 +368,7 @@ static struct mtd_blktrans_ops mtdblock_tr = { | |||
368 | .name = "mtdblock", | 368 | .name = "mtdblock", |
369 | .major = 31, | 369 | .major = 31, |
370 | .part_bits = 0, | 370 | .part_bits = 0, |
371 | .blksize = 512, | ||
371 | .open = mtdblock_open, | 372 | .open = mtdblock_open, |
372 | .flush = mtdblock_flush, | 373 | .flush = mtdblock_flush, |
373 | .release = mtdblock_release, | 374 | .release = mtdblock_release, |
diff --git a/drivers/mtd/mtdblock_ro.c b/drivers/mtd/mtdblock_ro.c index 29563ed258a4..642ccc66f283 100644 --- a/drivers/mtd/mtdblock_ro.c +++ b/drivers/mtd/mtdblock_ro.c | |||
@@ -42,7 +42,7 @@ static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) | |||
42 | 42 | ||
43 | dev->mtd = mtd; | 43 | dev->mtd = mtd; |
44 | dev->devnum = mtd->index; | 44 | dev->devnum = mtd->index; |
45 | dev->blksize = 512; | 45 | |
46 | dev->size = mtd->size >> 9; | 46 | dev->size = mtd->size >> 9; |
47 | dev->tr = tr; | 47 | dev->tr = tr; |
48 | dev->readonly = 1; | 48 | dev->readonly = 1; |
@@ -60,6 +60,7 @@ static struct mtd_blktrans_ops mtdblock_tr = { | |||
60 | .name = "mtdblock", | 60 | .name = "mtdblock", |
61 | .major = 31, | 61 | .major = 31, |
62 | .part_bits = 0, | 62 | .part_bits = 0, |
63 | .blksize = 512, | ||
63 | .readsect = mtdblock_readsect, | 64 | .readsect = mtdblock_readsect, |
64 | .writesect = mtdblock_writesect, | 65 | .writesect = mtdblock_writesect, |
65 | .add_mtd = mtdblock_add_mtd, | 66 | .add_mtd = mtdblock_add_mtd, |
diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c index b5a5f8da4722..d974adab3492 100644 --- a/drivers/mtd/nftlcore.c +++ b/drivers/mtd/nftlcore.c | |||
@@ -67,7 +67,7 @@ static void nftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) | |||
67 | 67 | ||
68 | nftl->mbd.mtd = mtd; | 68 | nftl->mbd.mtd = mtd; |
69 | nftl->mbd.devnum = -1; | 69 | nftl->mbd.devnum = -1; |
70 | nftl->mbd.blksize = 512; | 70 | |
71 | nftl->mbd.tr = tr; | 71 | nftl->mbd.tr = tr; |
72 | 72 | ||
73 | if (NFTL_mount(nftl) < 0) { | 73 | if (NFTL_mount(nftl) < 0) { |
@@ -797,6 +797,7 @@ static struct mtd_blktrans_ops nftl_tr = { | |||
797 | .name = "nftl", | 797 | .name = "nftl", |
798 | .major = NFTL_MAJOR, | 798 | .major = NFTL_MAJOR, |
799 | .part_bits = NFTL_PARTN_BITS, | 799 | .part_bits = NFTL_PARTN_BITS, |
800 | .blksize = 512, | ||
800 | .getgeo = nftl_getgeo, | 801 | .getgeo = nftl_getgeo, |
801 | .readsect = nftl_readblock, | 802 | .readsect = nftl_readblock, |
802 | #ifdef CONFIG_NFTL_RW | 803 | #ifdef CONFIG_NFTL_RW |
diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c index fa4362fb4dd8..d60cc6696cbd 100644 --- a/drivers/mtd/rfd_ftl.c +++ b/drivers/mtd/rfd_ftl.c | |||
@@ -787,7 +787,6 @@ static void rfd_ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) | |||
787 | 787 | ||
788 | if (scan_header(part) == 0) { | 788 | if (scan_header(part) == 0) { |
789 | part->mbd.size = part->sector_count; | 789 | part->mbd.size = part->sector_count; |
790 | part->mbd.blksize = SECTOR_SIZE; | ||
791 | part->mbd.tr = tr; | 790 | part->mbd.tr = tr; |
792 | part->mbd.devnum = -1; | 791 | part->mbd.devnum = -1; |
793 | if (!(mtd->flags & MTD_WRITEABLE)) | 792 | if (!(mtd->flags & MTD_WRITEABLE)) |
@@ -829,6 +828,8 @@ struct mtd_blktrans_ops rfd_ftl_tr = { | |||
829 | .name = "rfd", | 828 | .name = "rfd", |
830 | .major = RFD_FTL_MAJOR, | 829 | .major = RFD_FTL_MAJOR, |
831 | .part_bits = PART_BITS, | 830 | .part_bits = PART_BITS, |
831 | .blksize = SECTOR_SIZE, | ||
832 | |||
832 | .readsect = rfd_ftl_readsect, | 833 | .readsect = rfd_ftl_readsect, |
833 | .writesect = rfd_ftl_writesect, | 834 | .writesect = rfd_ftl_writesect, |
834 | .getgeo = rfd_ftl_getgeo, | 835 | .getgeo = rfd_ftl_getgeo, |
diff --git a/include/linux/mtd/blktrans.h b/include/linux/mtd/blktrans.h index 72fc68c5ee96..9a6e2f953cba 100644 --- a/include/linux/mtd/blktrans.h +++ b/include/linux/mtd/blktrans.h | |||
@@ -24,7 +24,6 @@ struct mtd_blktrans_dev { | |||
24 | struct mtd_info *mtd; | 24 | struct mtd_info *mtd; |
25 | struct mutex lock; | 25 | struct mutex lock; |
26 | int devnum; | 26 | int devnum; |
27 | int blksize; | ||
28 | unsigned long size; | 27 | unsigned long size; |
29 | int readonly; | 28 | int readonly; |
30 | void *blkcore_priv; /* gendisk in 2.5, devfs_handle in 2.4 */ | 29 | void *blkcore_priv; /* gendisk in 2.5, devfs_handle in 2.4 */ |
@@ -36,6 +35,8 @@ struct mtd_blktrans_ops { | |||
36 | char *name; | 35 | char *name; |
37 | int major; | 36 | int major; |
38 | int part_bits; | 37 | int part_bits; |
38 | int blksize; | ||
39 | int blkshift; | ||
39 | 40 | ||
40 | /* Access functions */ | 41 | /* Access functions */ |
41 | int (*readsect)(struct mtd_blktrans_dev *dev, | 42 | int (*readsect)(struct mtd_blktrans_dev *dev, |