440-block2mtd_init.patch 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. --- a/drivers/mtd/devices/block2mtd.c
  2. +++ b/drivers/mtd/devices/block2mtd.c
  3. @@ -14,6 +14,7 @@
  4. #include <linux/list.h>
  5. #include <linux/init.h>
  6. #include <linux/mtd/mtd.h>
  7. +#include <linux/mtd/partitions.h>
  8. #include <linux/mutex.h>
  9. #include <linux/mount.h>
  10. #include <linux/slab.h>
  11. @@ -210,11 +211,12 @@ static void block2mtd_free_device(struct
  12. /* FIXME: ensure that mtd->size % erase_size == 0 */
  13. -static struct block2mtd_dev *add_device(char *devname, int erase_size)
  14. +static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname)
  15. {
  16. const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL;
  17. struct block_device *bdev;
  18. struct block2mtd_dev *dev;
  19. + struct mtd_partition *part;
  20. char *name;
  21. if (!devname)
  22. @@ -253,13 +255,16 @@ static struct block2mtd_dev *add_device(
  23. /* Setup the MTD structure */
  24. /* make the name contain the block device in */
  25. - name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname);
  26. + if (!mtdname)
  27. + mtdname = devname;
  28. + name = kmalloc(strlen(mtdname) + 1, GFP_KERNEL);
  29. if (!name)
  30. goto devinit_err;
  31. + strcpy(name, mtdname);
  32. dev->mtd.name = name;
  33. - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
  34. + dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK & ~(erase_size - 1);
  35. dev->mtd.erasesize = erase_size;
  36. dev->mtd.writesize = 1;
  37. dev->mtd.writebufsize = PAGE_SIZE;
  38. @@ -272,14 +277,17 @@ static struct block2mtd_dev *add_device(
  39. dev->mtd.priv = dev;
  40. dev->mtd.owner = THIS_MODULE;
  41. - if (mtd_device_register(&dev->mtd, NULL, 0)) {
  42. + part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
  43. + part->name = name;
  44. + part->offset = 0;
  45. + part->size = dev->mtd.size;
  46. + if (mtd_device_register(&dev->mtd, part, 1)) {
  47. /* Device didn't get added, so free the entry */
  48. goto devinit_err;
  49. }
  50. list_add(&dev->list, &blkmtd_device_list);
  51. INFO("mtd%d: [%s] erase_size = %dKiB [%d]", dev->mtd.index,
  52. - dev->mtd.name + strlen("block2mtd: "),
  53. - dev->mtd.erasesize >> 10, dev->mtd.erasesize);
  54. + mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
  55. return dev;
  56. devinit_err:
  57. @@ -352,9 +360,9 @@ static char block2mtd_paramline[80 + 12]
  58. static int block2mtd_setup2(const char *val)
  59. {
  60. - char buf[80 + 12]; /* 80 for device, 12 for erase size */
  61. + char buf[80 + 12 + 80]; /* 80 for device, 12 for erase size, 80 for name */
  62. char *str = buf;
  63. - char *token[2];
  64. + char *token[3];
  65. char *name;
  66. size_t erase_size = PAGE_SIZE;
  67. int i, ret;
  68. @@ -365,7 +373,7 @@ static int block2mtd_setup2(const char *
  69. strcpy(str, val);
  70. kill_final_newline(str);
  71. - for (i = 0; i < 2; i++)
  72. + for (i = 0; i < 3; i++)
  73. token[i] = strsep(&str, ",");
  74. if (str)
  75. @@ -384,8 +392,10 @@ static int block2mtd_setup2(const char *
  76. parse_err("illegal erase size");
  77. }
  78. }
  79. + if (token[2] && (strlen(token[2]) + 1 > 80))
  80. + parse_err("mtd device name too long");
  81. - add_device(name, erase_size);
  82. + add_device(name, erase_size, token[2]);
  83. return 0;
  84. }
  85. @@ -419,7 +429,7 @@ static int block2mtd_setup(const char *v
  86. module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
  87. -MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
  88. +MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>]]\"");
  89. static int __init block2mtd_init(void)
  90. {
  91. --- a/block/partition-generic.c
  92. +++ b/block/partition-generic.c
  93. @@ -548,6 +548,7 @@ int invalidate_partitions(struct gendisk
  94. return 0;
  95. }
  96. +EXPORT_SYMBOL(rescan_partitions);
  97. unsigned char *read_dev_sector(struct block_device *bdev, sector_t n, Sector *p)
  98. {