Skip to content

Commit 1918767

Browse files
Richard Purdiedwmw2
authored andcommitted
[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>
1 parent 90afffc commit 1918767

8 files changed

Lines changed: 23 additions & 13 deletions

File tree

‎drivers/mtd/ftl.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
10541054
le32_to_cpu(partition->header.FormattedSize) >> 10);
10551055
#endif
10561056
partition->mbd.size = le32_to_cpu(partition->header.FormattedSize) >> 9;
1057-
partition->mbd.blksize = SECTOR_SIZE;
1057+
10581058
partition->mbd.tr = tr;
10591059
partition->mbd.devnum = -1;
10601060
if (!add_mtd_blktrans_dev((void *)partition))
@@ -1076,6 +1076,7 @@ struct mtd_blktrans_ops ftl_tr = {
10761076
.name = "ftl",
10771077
.major = FTL_MAJOR,
10781078
.part_bits = PART_BITS,
1079+
.blksize = SECTOR_SIZE,
10791080
.readsect = ftl_readsect,
10801081
.writesect = ftl_writesect,
10811082
.getgeo = ftl_getgeo,

‎drivers/mtd/inftlcore.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static void inftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
7777

7878
inftl->mbd.mtd = mtd;
7979
inftl->mbd.devnum = -1;
80-
inftl->mbd.blksize = 512;
80+
8181
inftl->mbd.tr = tr;
8282

8383
if (INFTL_mount(inftl) < 0) {
@@ -945,6 +945,7 @@ static struct mtd_blktrans_ops inftl_tr = {
945945
.name = "inftl",
946946
.major = INFTL_MAJOR,
947947
.part_bits = INFTL_PARTN_BITS,
948+
.blksize = 512,
948949
.getgeo = inftl_getgeo,
949950
.readsect = inftl_readblock,
950951
.writesect = inftl_writeblock,

‎drivers/mtd/mtd_blkdevs.c‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,20 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
4242
unsigned long block, nsect;
4343
char *buf;
4444

45-
block = req->sector;
46-
nsect = req->current_nr_sectors;
45+
block = req->sector << 9 >> tr->blkshift;
46+
nsect = req->current_nr_sectors << 9 >> tr->blkshift;
47+
4748
buf = req->buffer;
4849

4950
if (!blk_fs_request(req))
5051
return 0;
5152

52-
if (block + nsect > get_capacity(req->rq_disk))
53+
if (req->sector + req->current_nr_sectors > get_capacity(req->rq_disk))
5354
return 0;
5455

5556
switch(rq_data_dir(req)) {
5657
case READ:
57-
for (; nsect > 0; nsect--, block++, buf += 512)
58+
for (; nsect > 0; nsect--, block++, buf += tr->blksize)
5859
if (tr->readsect(dev, block, buf))
5960
return 0;
6061
return 1;
@@ -63,7 +64,7 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
6364
if (!tr->writesect)
6465
return 0;
6566

66-
for (; nsect > 0; nsect--, block++, buf += 512)
67+
for (; nsect > 0; nsect--, block++, buf += tr->blksize)
6768
if (tr->writesect(dev, block, buf))
6869
return 0;
6970
return 1;
@@ -297,7 +298,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
297298

298299
/* 2.5 has capacity in units of 512 bytes while still
299300
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);
301302

302303
gd->private_data = new;
303304
new->blkcore_priv = gd;
@@ -401,6 +402,8 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
401402
}
402403

403404
tr->blkcore_priv->rq->queuedata = tr;
405+
blk_queue_hardsect_size(tr->blkcore_priv->rq, tr->blksize);
406+
tr->blkshift = ffs(tr->blksize) - 1;
404407

405408
ret = kernel_thread(mtd_blktrans_thread, tr, CLONE_KERNEL);
406409
if (ret < 0) {

‎drivers/mtd/mtdblock.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
348348

349349
dev->mtd = mtd;
350350
dev->devnum = mtd->index;
351-
dev->blksize = 512;
351+
352352
dev->size = mtd->size >> 9;
353353
dev->tr = tr;
354354

@@ -368,6 +368,7 @@ static struct mtd_blktrans_ops mtdblock_tr = {
368368
.name = "mtdblock",
369369
.major = 31,
370370
.part_bits = 0,
371+
.blksize = 512,
371372
.open = mtdblock_open,
372373
.flush = mtdblock_flush,
373374
.release = mtdblock_release,

‎drivers/mtd/mtdblock_ro.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
4242

4343
dev->mtd = mtd;
4444
dev->devnum = mtd->index;
45-
dev->blksize = 512;
45+
4646
dev->size = mtd->size >> 9;
4747
dev->tr = tr;
4848
dev->readonly = 1;
@@ -60,6 +60,7 @@ static struct mtd_blktrans_ops mtdblock_tr = {
6060
.name = "mtdblock",
6161
.major = 31,
6262
.part_bits = 0,
63+
.blksize = 512,
6364
.readsect = mtdblock_readsect,
6465
.writesect = mtdblock_writesect,
6566
.add_mtd = mtdblock_add_mtd,

‎drivers/mtd/nftlcore.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static void nftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
6767

6868
nftl->mbd.mtd = mtd;
6969
nftl->mbd.devnum = -1;
70-
nftl->mbd.blksize = 512;
70+
7171
nftl->mbd.tr = tr;
7272

7373
if (NFTL_mount(nftl) < 0) {
@@ -797,6 +797,7 @@ static struct mtd_blktrans_ops nftl_tr = {
797797
.name = "nftl",
798798
.major = NFTL_MAJOR,
799799
.part_bits = NFTL_PARTN_BITS,
800+
.blksize = 512,
800801
.getgeo = nftl_getgeo,
801802
.readsect = nftl_readblock,
802803
#ifdef CONFIG_NFTL_RW

‎drivers/mtd/rfd_ftl.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,6 @@ static void rfd_ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
787787

788788
if (scan_header(part) == 0) {
789789
part->mbd.size = part->sector_count;
790-
part->mbd.blksize = SECTOR_SIZE;
791790
part->mbd.tr = tr;
792791
part->mbd.devnum = -1;
793792
if (!(mtd->flags & MTD_WRITEABLE))
@@ -829,6 +828,8 @@ struct mtd_blktrans_ops rfd_ftl_tr = {
829828
.name = "rfd",
830829
.major = RFD_FTL_MAJOR,
831830
.part_bits = PART_BITS,
831+
.blksize = SECTOR_SIZE,
832+
832833
.readsect = rfd_ftl_readsect,
833834
.writesect = rfd_ftl_writesect,
834835
.getgeo = rfd_ftl_getgeo,

‎include/linux/mtd/blktrans.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ struct mtd_blktrans_dev {
2424
struct mtd_info *mtd;
2525
struct mutex lock;
2626
int devnum;
27-
int blksize;
2827
unsigned long size;
2928
int readonly;
3029
void *blkcore_priv; /* gendisk in 2.5, devfs_handle in 2.4 */
@@ -36,6 +35,8 @@ struct mtd_blktrans_ops {
3635
char *name;
3736
int major;
3837
int part_bits;
38+
int blksize;
39+
int blkshift;
3940

4041
/* Access functions */
4142
int (*readsect)(struct mtd_blktrans_dev *dev,

0 commit comments

Comments
 (0)