Commit 19187672 authored by Richard Purdie's avatar Richard Purdie Committed by David Woodhouse

[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: default avatarRichard Purdie <rpurdie@openedhand.com>
Signed-off-by: default avatarDavid Woodhouse <dwmw2@infradead.org>
parent 90afffc8
...@@ -1054,7 +1054,7 @@ static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) ...@@ -1054,7 +1054,7 @@ static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
le32_to_cpu(partition->header.FormattedSize) >> 10); le32_to_cpu(partition->header.FormattedSize) >> 10);
#endif #endif
partition->mbd.size = le32_to_cpu(partition->header.FormattedSize) >> 9; partition->mbd.size = le32_to_cpu(partition->header.FormattedSize) >> 9;
partition->mbd.blksize = SECTOR_SIZE;
partition->mbd.tr = tr; partition->mbd.tr = tr;
partition->mbd.devnum = -1; partition->mbd.devnum = -1;
if (!add_mtd_blktrans_dev((void *)partition)) if (!add_mtd_blktrans_dev((void *)partition))
...@@ -1076,6 +1076,7 @@ struct mtd_blktrans_ops ftl_tr = { ...@@ -1076,6 +1076,7 @@ struct mtd_blktrans_ops ftl_tr = {
.name = "ftl", .name = "ftl",
.major = FTL_MAJOR, .major = FTL_MAJOR,
.part_bits = PART_BITS, .part_bits = PART_BITS,
.blksize = SECTOR_SIZE,
.readsect = ftl_readsect, .readsect = ftl_readsect,
.writesect = ftl_writesect, .writesect = ftl_writesect,
.getgeo = ftl_getgeo, .getgeo = ftl_getgeo,
......
...@@ -77,7 +77,7 @@ static void inftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) ...@@ -77,7 +77,7 @@ static void inftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
inftl->mbd.mtd = mtd; inftl->mbd.mtd = mtd;
inftl->mbd.devnum = -1; inftl->mbd.devnum = -1;
inftl->mbd.blksize = 512;
inftl->mbd.tr = tr; inftl->mbd.tr = tr;
if (INFTL_mount(inftl) < 0) { if (INFTL_mount(inftl) < 0) {
...@@ -945,6 +945,7 @@ static struct mtd_blktrans_ops inftl_tr = { ...@@ -945,6 +945,7 @@ static struct mtd_blktrans_ops inftl_tr = {
.name = "inftl", .name = "inftl",
.major = INFTL_MAJOR, .major = INFTL_MAJOR,
.part_bits = INFTL_PARTN_BITS, .part_bits = INFTL_PARTN_BITS,
.blksize = 512,
.getgeo = inftl_getgeo, .getgeo = inftl_getgeo,
.readsect = inftl_readblock, .readsect = inftl_readblock,
.writesect = inftl_writeblock, .writesect = inftl_writeblock,
......
...@@ -42,19 +42,20 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr, ...@@ -42,19 +42,20 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
unsigned long block, nsect; unsigned long block, nsect;
char *buf; char *buf;
block = req->sector; block = req->sector << 9 >> tr->blkshift;
nsect = req->current_nr_sectors; nsect = req->current_nr_sectors << 9 >> tr->blkshift;
buf = req->buffer; buf = req->buffer;
if (!blk_fs_request(req)) if (!blk_fs_request(req))
return 0; return 0;
if (block + nsect > get_capacity(req->rq_disk)) if (req->sector + req->current_nr_sectors > get_capacity(req->rq_disk))
return 0; return 0;
switch(rq_data_dir(req)) { switch(rq_data_dir(req)) {
case READ: case READ:
for (; nsect > 0; nsect--, block++, buf += 512) for (; nsect > 0; nsect--, block++, buf += tr->blksize)
if (tr->readsect(dev, block, buf)) if (tr->readsect(dev, block, buf))
return 0; return 0;
return 1; return 1;
...@@ -63,7 +64,7 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr, ...@@ -63,7 +64,7 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
if (!tr->writesect) if (!tr->writesect)
return 0; return 0;
for (; nsect > 0; nsect--, block++, buf += 512) for (; nsect > 0; nsect--, block++, buf += tr->blksize)
if (tr->writesect(dev, block, buf)) if (tr->writesect(dev, block, buf))
return 0; return 0;
return 1; return 1;
...@@ -297,7 +298,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new) ...@@ -297,7 +298,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
/* 2.5 has capacity in units of 512 bytes while still /* 2.5 has capacity in units of 512 bytes while still
having BLOCK_SIZE_BITS set to 10. Just to keep us amused. */ having BLOCK_SIZE_BITS set to 10. Just to keep us amused. */
set_capacity(gd, (new->size * new->blksize) >> 9); set_capacity(gd, (new->size * tr->blksize) >> 9);
gd->private_data = new; gd->private_data = new;
new->blkcore_priv = gd; new->blkcore_priv = gd;
...@@ -401,6 +402,8 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr) ...@@ -401,6 +402,8 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
} }
tr->blkcore_priv->rq->queuedata = tr; tr->blkcore_priv->rq->queuedata = tr;
blk_queue_hardsect_size(tr->blkcore_priv->rq, tr->blksize);
tr->blkshift = ffs(tr->blksize) - 1;
ret = kernel_thread(mtd_blktrans_thread, tr, CLONE_KERNEL); ret = kernel_thread(mtd_blktrans_thread, tr, CLONE_KERNEL);
if (ret < 0) { if (ret < 0) {
......
...@@ -348,7 +348,7 @@ static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) ...@@ -348,7 +348,7 @@ static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
dev->mtd = mtd; dev->mtd = mtd;
dev->devnum = mtd->index; dev->devnum = mtd->index;
dev->blksize = 512;
dev->size = mtd->size >> 9; dev->size = mtd->size >> 9;
dev->tr = tr; dev->tr = tr;
...@@ -368,6 +368,7 @@ static struct mtd_blktrans_ops mtdblock_tr = { ...@@ -368,6 +368,7 @@ static struct mtd_blktrans_ops mtdblock_tr = {
.name = "mtdblock", .name = "mtdblock",
.major = 31, .major = 31,
.part_bits = 0, .part_bits = 0,
.blksize = 512,
.open = mtdblock_open, .open = mtdblock_open,
.flush = mtdblock_flush, .flush = mtdblock_flush,
.release = mtdblock_release, .release = mtdblock_release,
......
...@@ -42,7 +42,7 @@ static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) ...@@ -42,7 +42,7 @@ static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
dev->mtd = mtd; dev->mtd = mtd;
dev->devnum = mtd->index; dev->devnum = mtd->index;
dev->blksize = 512;
dev->size = mtd->size >> 9; dev->size = mtd->size >> 9;
dev->tr = tr; dev->tr = tr;
dev->readonly = 1; dev->readonly = 1;
...@@ -60,6 +60,7 @@ static struct mtd_blktrans_ops mtdblock_tr = { ...@@ -60,6 +60,7 @@ static struct mtd_blktrans_ops mtdblock_tr = {
.name = "mtdblock", .name = "mtdblock",
.major = 31, .major = 31,
.part_bits = 0, .part_bits = 0,
.blksize = 512,
.readsect = mtdblock_readsect, .readsect = mtdblock_readsect,
.writesect = mtdblock_writesect, .writesect = mtdblock_writesect,
.add_mtd = mtdblock_add_mtd, .add_mtd = mtdblock_add_mtd,
......
...@@ -67,7 +67,7 @@ static void nftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) ...@@ -67,7 +67,7 @@ static void nftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
nftl->mbd.mtd = mtd; nftl->mbd.mtd = mtd;
nftl->mbd.devnum = -1; nftl->mbd.devnum = -1;
nftl->mbd.blksize = 512;
nftl->mbd.tr = tr; nftl->mbd.tr = tr;
if (NFTL_mount(nftl) < 0) { if (NFTL_mount(nftl) < 0) {
...@@ -797,6 +797,7 @@ static struct mtd_blktrans_ops nftl_tr = { ...@@ -797,6 +797,7 @@ static struct mtd_blktrans_ops nftl_tr = {
.name = "nftl", .name = "nftl",
.major = NFTL_MAJOR, .major = NFTL_MAJOR,
.part_bits = NFTL_PARTN_BITS, .part_bits = NFTL_PARTN_BITS,
.blksize = 512,
.getgeo = nftl_getgeo, .getgeo = nftl_getgeo,
.readsect = nftl_readblock, .readsect = nftl_readblock,
#ifdef CONFIG_NFTL_RW #ifdef CONFIG_NFTL_RW
......
...@@ -787,7 +787,6 @@ static void rfd_ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) ...@@ -787,7 +787,6 @@ static void rfd_ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
if (scan_header(part) == 0) { if (scan_header(part) == 0) {
part->mbd.size = part->sector_count; part->mbd.size = part->sector_count;
part->mbd.blksize = SECTOR_SIZE;
part->mbd.tr = tr; part->mbd.tr = tr;
part->mbd.devnum = -1; part->mbd.devnum = -1;
if (!(mtd->flags & MTD_WRITEABLE)) if (!(mtd->flags & MTD_WRITEABLE))
...@@ -829,6 +828,8 @@ struct mtd_blktrans_ops rfd_ftl_tr = { ...@@ -829,6 +828,8 @@ struct mtd_blktrans_ops rfd_ftl_tr = {
.name = "rfd", .name = "rfd",
.major = RFD_FTL_MAJOR, .major = RFD_FTL_MAJOR,
.part_bits = PART_BITS, .part_bits = PART_BITS,
.blksize = SECTOR_SIZE,
.readsect = rfd_ftl_readsect, .readsect = rfd_ftl_readsect,
.writesect = rfd_ftl_writesect, .writesect = rfd_ftl_writesect,
.getgeo = rfd_ftl_getgeo, .getgeo = rfd_ftl_getgeo,
......
...@@ -24,7 +24,6 @@ struct mtd_blktrans_dev { ...@@ -24,7 +24,6 @@ struct mtd_blktrans_dev {
struct mtd_info *mtd; struct mtd_info *mtd;
struct mutex lock; struct mutex lock;
int devnum; int devnum;
int blksize;
unsigned long size; unsigned long size;
int readonly; int readonly;
void *blkcore_priv; /* gendisk in 2.5, devfs_handle in 2.4 */ void *blkcore_priv; /* gendisk in 2.5, devfs_handle in 2.4 */
...@@ -36,6 +35,8 @@ struct mtd_blktrans_ops { ...@@ -36,6 +35,8 @@ struct mtd_blktrans_ops {
char *name; char *name;
int major; int major;
int part_bits; int part_bits;
int blksize;
int blkshift;
/* Access functions */ /* Access functions */
int (*readsect)(struct mtd_blktrans_dev *dev, int (*readsect)(struct mtd_blktrans_dev *dev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment