0001-diskpart-fix-adding-more-as-4-partitions.patch 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. From 9b8b498550d4571233fbee6476521c98bc397485 Mon Sep 17 00:00:00 2001
  2. From: Stefano Babic <sbabic@denx.de>
  3. Date: Wed, 29 Jul 2020 12:57:59 +0200
  4. Subject: [PATCH] diskpart: fix adding more as 4 partitions
  5. Signed-off-by: Stefano Babic <sbabic@denx.de>
  6. ---
  7. handlers/diskpart_handler.c | 41 +++++++++++++++++++++++++++----------
  8. 1 file changed, 30 insertions(+), 11 deletions(-)
  9. diff --git a/handlers/diskpart_handler.c b/handlers/diskpart_handler.c
  10. index 372412b..be570ca 100644
  11. --- a/handlers/diskpart_handler.c
  12. +++ b/handlers/diskpart_handler.c
  13. @@ -21,6 +21,11 @@
  14. void diskpart_handler(void);
  15. +/*
  16. + * This is taken from libfdisk to declare if a field is not set
  17. + */
  18. +#define LIBFDISK_INIT_UNDEF(_x) ((__typeof__(_x)) -1)
  19. +
  20. /**
  21. * Keys for the properties field in sw-description
  22. */
  23. @@ -71,16 +76,23 @@ static int diskpart_set_partition(struct fdisk_context *cxt,
  24. unsigned long sector_size = fdisk_get_sector_size(cxt);
  25. struct fdisk_label *lb;
  26. struct fdisk_parttype *parttype = NULL;
  27. - int ret;
  28. + int ret = 0;
  29. lb = fdisk_get_label(cxt, NULL);
  30. if (!sector_size)
  31. sector_size = 1;
  32. - ret = fdisk_partition_set_partno(pa, part->partno) ||
  33. - fdisk_partition_set_size(pa, part->size / sector_size) ||
  34. - fdisk_partition_set_name(pa, part->name) ||
  35. - fdisk_partition_set_start(pa, part->start);
  36. + fdisk_partition_unset_partno(pa);
  37. + fdisk_partition_unset_size(pa);
  38. + fdisk_partition_unset_start(pa);
  39. + if (part->start != LIBFDISK_INIT_UNDEF(part->start))
  40. + ret = fdisk_partition_set_start(pa, part->start);
  41. + if (part->partno != LIBFDISK_INIT_UNDEF(part->partno))
  42. + ret |= fdisk_partition_set_partno(pa, part->partno);
  43. + if (strlen(part->name))
  44. + ret |= fdisk_partition_set_name(pa, part->name);
  45. + if (part->size != LIBFDISK_INIT_UNDEF(part->size))
  46. + ret |= fdisk_partition_set_size(pa, part->size / sector_size);
  47. /*
  48. * GPT uses strings instead of hex code for partition type
  49. @@ -150,6 +162,10 @@ static int diskpart(struct img_type *img,
  50. }
  51. elem = LIST_FIRST(parts);
  52. + part->partno = LIBFDISK_INIT_UNDEF(part->partno);
  53. + part->start = LIBFDISK_INIT_UNDEF(part->start);
  54. + part->size = LIBFDISK_INIT_UNDEF(part->size);
  55. +
  56. part->partno = strtoul(entry->key + strlen("partition-"), NULL, 10);
  57. while (elem) {
  58. char *equal = index(elem->value, '=');
  59. @@ -179,10 +195,10 @@ static int diskpart(struct img_type *img,
  60. }
  61. TRACE("partition-%zu:%s size %" PRIu64 " start %zu type %s",
  62. - part->partno,
  63. - part->name,
  64. - part->size,
  65. - part->start,
  66. + part->partno != LIBFDISK_INIT_UNDEF(part->partno) ? part->partno : 0,
  67. + strlen(part->name) ? part->name : "UNDEF NAME",
  68. + part->size != LIBFDISK_INIT_UNDEF(part->size) ? part->size : 0,
  69. + part->start!= LIBFDISK_INIT_UNDEF(part->start) ? part->start : 0,
  70. part->type);
  71. /*
  72. @@ -253,10 +269,12 @@ static int diskpart(struct img_type *img,
  73. if (ret) {
  74. WARN("I cannot set all partition's parameters");
  75. }
  76. - if (fdisk_add_partition(cxt, newpa, &partno) < 0) {
  77. - ERROR("I cannot add partition %zu(%s)", part->partno, part->name);
  78. + if ((ret = fdisk_add_partition(cxt, newpa, &partno)) < 0) {
  79. + ERROR("I cannot add partition %zu(%s): %d", part->partno, part->name, ret);
  80. }
  81. fdisk_unref_partition(newpa);
  82. + if (ret < 0)
  83. + goto handler_exit;
  84. } else {
  85. ret = diskpart_set_partition(cxt, pa, part);
  86. if (ret) {
  87. @@ -267,6 +285,7 @@ static int diskpart(struct img_type *img,
  88. }
  89. fdisk_unref_partition(pa);
  90. }
  91. + fdisk_reset_partition(pa);
  92. i++;
  93. }
  94. --
  95. 2.25.1