065-block2mtd_init.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. Index: linux-2.6.21.7/drivers/mtd/devices/block2mtd.c
  2. ===================================================================
  3. --- linux-2.6.21.7.orig/drivers/mtd/devices/block2mtd.c
  4. +++ linux-2.6.21.7/drivers/mtd/devices/block2mtd.c
  5. @@ -16,6 +16,7 @@
  6. #include <linux/list.h>
  7. #include <linux/init.h>
  8. #include <linux/mtd/mtd.h>
  9. +#include <linux/mtd/partitions.h>
  10. #include <linux/buffer_head.h>
  11. #include <linux/mutex.h>
  12. #include <linux/mount.h>
  13. @@ -288,10 +289,11 @@ static void block2mtd_free_device(struct
  14. /* FIXME: ensure that mtd->size % erase_size == 0 */
  15. -static struct block2mtd_dev *add_device(char *devname, int erase_size)
  16. +static struct block2mtd_dev *add_device(char *devname, int erase_size, char *mtdname)
  17. {
  18. struct block_device *bdev;
  19. struct block2mtd_dev *dev;
  20. + struct mtd_partition *part;
  21. if (!devname)
  22. return NULL;
  23. @@ -330,14 +332,18 @@ static struct block2mtd_dev *add_device(
  24. /* Setup the MTD structure */
  25. /* make the name contain the block device in */
  26. - dev->mtd.name = kmalloc(sizeof("block2mtd: ") + strlen(devname),
  27. - GFP_KERNEL);
  28. +
  29. + if (!mtdname)
  30. + mtdname = devname;
  31. +
  32. + dev->mtd.name = kmalloc(strlen(mtdname) + 1, GFP_KERNEL);
  33. +
  34. if (!dev->mtd.name)
  35. goto devinit_err;
  36. +
  37. + strcpy(dev->mtd.name, mtdname);
  38. - sprintf(dev->mtd.name, "block2mtd: %s", devname);
  39. -
  40. - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
  41. + dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK & ~(erase_size - 1);
  42. dev->mtd.erasesize = erase_size;
  43. dev->mtd.writesize = 1;
  44. dev->mtd.type = MTD_RAM;
  45. @@ -349,15 +355,18 @@ static struct block2mtd_dev *add_device(
  46. dev->mtd.read = block2mtd_read;
  47. dev->mtd.priv = dev;
  48. dev->mtd.owner = THIS_MODULE;
  49. -
  50. - if (add_mtd_device(&dev->mtd)) {
  51. +
  52. + part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
  53. + part->name = dev->mtd.name;
  54. + part->offset = 0;
  55. + part->size = dev->mtd.size;
  56. + if (add_mtd_partitions(&dev->mtd, part, 1)) {
  57. /* Device didnt get added, so free the entry */
  58. goto devinit_err;
  59. }
  60. list_add(&dev->list, &blkmtd_device_list);
  61. INFO("mtd%d: [%s] erase_size = %dKiB [%d]", dev->mtd.index,
  62. - dev->mtd.name + strlen("blkmtd: "),
  63. - dev->mtd.erasesize >> 10, dev->mtd.erasesize);
  64. + mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
  65. return dev;
  66. devinit_err:
  67. @@ -430,9 +439,9 @@ static __initdata char block2mtd_paramli
  68. static int block2mtd_setup2(const char *val)
  69. {
  70. - char buf[80 + 12]; /* 80 for device, 12 for erase size */
  71. + char buf[80 + 12 + 80]; /* 80 for device, 12 for erase size, 80 for name */
  72. char *str = buf;
  73. - char *token[2];
  74. + char *token[3];
  75. char *name;
  76. size_t erase_size = PAGE_SIZE;
  77. int i, ret;
  78. @@ -443,7 +452,7 @@ static int block2mtd_setup2(const char *
  79. strcpy(str, val);
  80. kill_final_newline(str);
  81. - for (i = 0; i < 2; i++)
  82. + for (i = 0; i < 3; i++)
  83. token[i] = strsep(&str, ",");
  84. if (str)
  85. @@ -463,8 +472,10 @@ static int block2mtd_setup2(const char *
  86. parse_err("illegal erase size");
  87. }
  88. }
  89. + if (token[2] && (strlen(token[2]) + 1 > 80))
  90. + parse_err("mtd device name too long");
  91. - add_device(name, erase_size);
  92. + add_device(name, erase_size, token[2]);
  93. return 0;
  94. }
  95. @@ -498,7 +509,7 @@ static int block2mtd_setup(const char *v
  96. module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
  97. -MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
  98. +MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>]]\"");
  99. static int __init block2mtd_init(void)
  100. {