diff mbox series

[v2,1/1] diskpart: improve partition diff logging

Message ID 20210622015231.21708-1-james.hilliard1@gmail.com
State Changes Requested
Headers show
Series [v2,1/1] diskpart: improve partition diff logging | expand

Commit Message

James Hilliard June 22, 2021, 1:52 a.m. UTC
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
Changes v1 -> v2:
  - rebase on master to handle hybrid partitions
---
 handlers/diskpart_handler.c | 56 ++++++++++++++++++++++++++++---------
 1 file changed, 43 insertions(+), 13 deletions(-)

Comments

James Hilliard July 8, 2021, 2:21 p.m. UTC | #1
FYI this shows all partition attributes when they differ, for example:
[diskpart_table_cmp] : Number of partitions differs on disk: 1 <--> requested: 4
[diskpart_partition_cmp] : Partition differ:
[diskpart_partition_info] : Original:
[diskpart_partition_info] :         Device: /dev/mmcblk0p1
[diskpart_partition_info] :         Boot: *
[diskpart_partition_info] :         Start: 34
[diskpart_partition_info] :         End: 614433
[diskpart_partition_info] :         Sectors: 614400
[diskpart_partition_info] :         Cylinders: 9601
[diskpart_partition_info] :         Size: 300M
[diskpart_partition_info] :         Id: c
[diskpart_partition_info] :         Type: W95 FAT32 (LBA)
[diskpart_partition_info] :         Start-C/H/S: 0/0/35
[diskpart_partition_info] :         End-C/H/S: 38/62/58
[diskpart_partition_info] :         Attrs: 80
[diskpart_partition_info] : New:
[diskpart_partition_info] :         Device: /dev/mmcblk0p1
[diskpart_partition_info] :         Boot: (null)
[diskpart_partition_info] :         Start: 2048
[diskpart_partition_info] :         End: 1128447
[diskpart_partition_info] :         Sectors: 1126400
[diskpart_partition_info] :         Cylinders: 17601
[diskpart_partition_info] :         Size: 550M
[diskpart_partition_info] :         Id: c
[diskpart_partition_info] :         Type: W95 FAT32 (LBA)
[diskpart_partition_info] :         Start-C/H/S: 32/0/1
[diskpart_partition_info] :         End-C/H/S: 223/3/16
[diskpart_partition_info] :         Attrs: (null)
[diskpart_write_table] : Partitions on disk differ, write to disk;

Compared to the existing logging which pretty much only shows size and name of
the partitions, even though we diff check more than just those two values:
[diskpart_table_cmp] : Number of partitions differs on disk: 1 <--> requested: 4
[diskpart_partition_cmp] : Partition differ : (614400) <--> (1126400)
[diskpart_write_table] : Partitions on disk differ, write to disk;

On Mon, Jun 21, 2021 at 7:52 PM James Hilliard
<james.hilliard1@gmail.com> wrote:
>
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> ---
> Changes v1 -> v2:
>   - rebase on master to handle hybrid partitions
> ---
>  handlers/diskpart_handler.c | 56 ++++++++++++++++++++++++++++---------
>  1 file changed, 43 insertions(+), 13 deletions(-)
>
> diff --git a/handlers/diskpart_handler.c b/handlers/diskpart_handler.c
> index acd21d4..22f005e 100644
> --- a/handlers/diskpart_handler.c
> +++ b/handlers/diskpart_handler.c
> @@ -400,10 +400,42 @@ static int diskpart_append_hybrid_pmbr(struct fdisk_label *lb, struct fdisk_tabl
>         return ret;
>  }
>
> +static void diskpart_partition_info(struct fdisk_context *cxt, const char *name, struct fdisk_partition *pa)
> +{
> +       struct fdisk_label *lb;
> +       int *ids = NULL;
> +       size_t nids = 0;
> +       size_t i;
> +       lb = fdisk_get_label(cxt, NULL);
> +       fdisk_label_get_fields_ids_all(lb, cxt, &ids, &nids);
> +       if (ids && lb) {
> +               TRACE("%s:", name);
> +               for (i = 0; i < nids; i++) {
> +                       const struct fdisk_field *field =
> +                                       fdisk_label_get_field(lb, ids[i]);
> +                       char *data = NULL;
> +                       if (!field)
> +                               continue;
> +                       if (fdisk_partition_to_string(pa, cxt, ids[i], &data))
> +                               continue;
> +                       TRACE("\t%s: %s", fdisk_field_get_name(field), data);
> +                       free(data);
> +               }
> +       } else {
> +               if (!ids)
> +                       ERROR("Failed to load field ids");
> +               if (!lb)
> +                       ERROR("Failed to load label");
> +       }
> +       if (ids)
> +               free(ids);
> +}
> +
>  /*
>   * Return true if partition differs
>   */
> -static bool diskpart_partition_cmp(struct fdisk_partition *firstpa, struct fdisk_partition *secondpa)
> +static bool diskpart_partition_cmp(struct fdisk_context *cxt, struct fdisk_partition *firstpa,
> +               struct fdisk_partition *secondpa)
>  {
>         struct fdisk_parttype *type;
>         const char *lbtype;
> @@ -432,11 +464,9 @@ static bool diskpart_partition_cmp(struct fdisk_partition *firstpa, struct fdisk
>                         fdisk_parttype_get_code(fdisk_partition_get_type(firstpa)) !=
>                         fdisk_parttype_get_code(fdisk_partition_get_type(secondpa))) ||
>                 fdisk_partition_get_size(firstpa) != fdisk_partition_get_size(secondpa))) {
> -               TRACE("Partition differ : %s(%llu) <--> %s(%llu)",
> -                       fdisk_partition_get_name (firstpa) ? fdisk_partition_get_name(firstpa) : "",
> -                       (long long unsigned)fdisk_partition_get_size(firstpa),
> -                       fdisk_partition_get_name(secondpa) ? fdisk_partition_get_name(secondpa) : "",
> -                       (long long unsigned)fdisk_partition_get_size(secondpa));
> +               TRACE("Partition differ:");
> +               diskpart_partition_info(cxt, "Original", firstpa);
> +               diskpart_partition_info(cxt, "New", secondpa);
>                 return true;
>         }
>         return false;
> @@ -566,7 +596,7 @@ static int diskpart_fill_table(struct fdisk_context *cxt, struct diskpart_table
>  /*
>   * Return 1 if table differs, 0 if table is the same, negative on error
>   */
> -static int diskpart_table_cmp(struct fdisk_table *tb, struct fdisk_table *oldtb)
> +static int diskpart_table_cmp(struct fdisk_context *cxt, struct fdisk_table *tb, struct fdisk_table *oldtb)
>  {
>         size_t numnewparts = fdisk_table_get_nents(tb);
>         size_t numpartondisk = fdisk_table_get_nents(oldtb);
> @@ -590,7 +620,7 @@ static int diskpart_table_cmp(struct fdisk_table *tb, struct fdisk_table *oldtb)
>                                 fdisk_table_next_partition (oldtb, olditr, &pa)) {
>                                 TRACE("Partition not found, something went wrong %lu !", i);
>                                 ret = -EFAULT;
> -                       } else if (diskpart_partition_cmp(pa, newpa)) {
> +                       } else if (diskpart_partition_cmp(cxt, pa, newpa)) {
>                                 ret = 1;
>                         }
>
> @@ -604,8 +634,8 @@ static int diskpart_table_cmp(struct fdisk_table *tb, struct fdisk_table *oldtb)
>         return ret;
>  }
>
> -static int diskpart_compare_tables(struct diskpart_table *tb, struct diskpart_table *oldtb,
> -               struct create_table *createtable)
> +static int diskpart_compare_tables(struct fdisk_context *cxt, struct diskpart_table *tb,
> +               struct diskpart_table *oldtb, struct create_table *createtable)
>  {
>         int ret = 0;
>
> @@ -614,7 +644,7 @@ static int diskpart_compare_tables(struct diskpart_table *tb, struct diskpart_ta
>          * to check if they differ.
>          */
>         if (!createtable->parent) {
> -               ret = diskpart_table_cmp(tb->parent, oldtb->parent);
> +               ret = diskpart_table_cmp(PARENT(cxt), tb->parent, oldtb->parent);
>                 if (ret < 0)
>                         return ret;
>                 else if (ret)
> @@ -622,7 +652,7 @@ static int diskpart_compare_tables(struct diskpart_table *tb, struct diskpart_ta
>         }
>
>         if (tb->child && !createtable->child) {
> -               ret = diskpart_table_cmp(tb->child, oldtb->child);
> +               ret = diskpart_table_cmp(cxt, tb->child, oldtb->child);
>                 if (ret < 0)
>                         return ret;
>                 else if (ret)
> @@ -844,7 +874,7 @@ static int diskpart(struct img_type *img,
>         if (ret)
>                 goto handler_exit;
>
> -       ret = diskpart_compare_tables(tb, oldtb, createtable);
> +       ret = diskpart_compare_tables(cxt, tb, oldtb, createtable);
>         if (ret)
>                 goto handler_exit;
>
> --
> 2.32.0
>
Stefano Babic July 10, 2021, 10:31 a.m. UTC | #2
Hi James,

I tried to apply V3, but it fails. Could you take a look and maybe 
rebase ? Thanks !

Best regards,
Stefano Babic

On 08.07.21 16:21, James Hilliard wrote:
> FYI this shows all partition attributes when they differ, for example:
> [diskpart_table_cmp] : Number of partitions differs on disk: 1 <--> requested: 4
> [diskpart_partition_cmp] : Partition differ:
> [diskpart_partition_info] : Original:
> [diskpart_partition_info] :         Device: /dev/mmcblk0p1
> [diskpart_partition_info] :         Boot: *
> [diskpart_partition_info] :         Start: 34
> [diskpart_partition_info] :         End: 614433
> [diskpart_partition_info] :         Sectors: 614400
> [diskpart_partition_info] :         Cylinders: 9601
> [diskpart_partition_info] :         Size: 300M
> [diskpart_partition_info] :         Id: c
> [diskpart_partition_info] :         Type: W95 FAT32 (LBA)
> [diskpart_partition_info] :         Start-C/H/S: 0/0/35
> [diskpart_partition_info] :         End-C/H/S: 38/62/58
> [diskpart_partition_info] :         Attrs: 80
> [diskpart_partition_info] : New:
> [diskpart_partition_info] :         Device: /dev/mmcblk0p1
> [diskpart_partition_info] :         Boot: (null)
> [diskpart_partition_info] :         Start: 2048
> [diskpart_partition_info] :         End: 1128447
> [diskpart_partition_info] :         Sectors: 1126400
> [diskpart_partition_info] :         Cylinders: 17601
> [diskpart_partition_info] :         Size: 550M
> [diskpart_partition_info] :         Id: c
> [diskpart_partition_info] :         Type: W95 FAT32 (LBA)
> [diskpart_partition_info] :         Start-C/H/S: 32/0/1
> [diskpart_partition_info] :         End-C/H/S: 223/3/16
> [diskpart_partition_info] :         Attrs: (null)
> [diskpart_write_table] : Partitions on disk differ, write to disk;
> 
> Compared to the existing logging which pretty much only shows size and name of
> the partitions, even though we diff check more than just those two values:
> [diskpart_table_cmp] : Number of partitions differs on disk: 1 <--> requested: 4
> [diskpart_partition_cmp] : Partition differ : (614400) <--> (1126400)
> [diskpart_write_table] : Partitions on disk differ, write to disk;
> 
> On Mon, Jun 21, 2021 at 7:52 PM James Hilliard
> <james.hilliard1@gmail.com> wrote:
>>
>> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
>> ---
>> Changes v1 -> v2:
>>    - rebase on master to handle hybrid partitions
>> ---
>>   handlers/diskpart_handler.c | 56 ++++++++++++++++++++++++++++---------
>>   1 file changed, 43 insertions(+), 13 deletions(-)
>>
>> diff --git a/handlers/diskpart_handler.c b/handlers/diskpart_handler.c
>> index acd21d4..22f005e 100644
>> --- a/handlers/diskpart_handler.c
>> +++ b/handlers/diskpart_handler.c
>> @@ -400,10 +400,42 @@ static int diskpart_append_hybrid_pmbr(struct fdisk_label *lb, struct fdisk_tabl
>>          return ret;
>>   }
>>
>> +static void diskpart_partition_info(struct fdisk_context *cxt, const char *name, struct fdisk_partition *pa)
>> +{
>> +       struct fdisk_label *lb;
>> +       int *ids = NULL;
>> +       size_t nids = 0;
>> +       size_t i;
>> +       lb = fdisk_get_label(cxt, NULL);
>> +       fdisk_label_get_fields_ids_all(lb, cxt, &ids, &nids);
>> +       if (ids && lb) {
>> +               TRACE("%s:", name);
>> +               for (i = 0; i < nids; i++) {
>> +                       const struct fdisk_field *field =
>> +                                       fdisk_label_get_field(lb, ids[i]);
>> +                       char *data = NULL;
>> +                       if (!field)
>> +                               continue;
>> +                       if (fdisk_partition_to_string(pa, cxt, ids[i], &data))
>> +                               continue;
>> +                       TRACE("\t%s: %s", fdisk_field_get_name(field), data);
>> +                       free(data);
>> +               }
>> +       } else {
>> +               if (!ids)
>> +                       ERROR("Failed to load field ids");
>> +               if (!lb)
>> +                       ERROR("Failed to load label");
>> +       }
>> +       if (ids)
>> +               free(ids);
>> +}
>> +
>>   /*
>>    * Return true if partition differs
>>    */
>> -static bool diskpart_partition_cmp(struct fdisk_partition *firstpa, struct fdisk_partition *secondpa)
>> +static bool diskpart_partition_cmp(struct fdisk_context *cxt, struct fdisk_partition *firstpa,
>> +               struct fdisk_partition *secondpa)
>>   {
>>          struct fdisk_parttype *type;
>>          const char *lbtype;
>> @@ -432,11 +464,9 @@ static bool diskpart_partition_cmp(struct fdisk_partition *firstpa, struct fdisk
>>                          fdisk_parttype_get_code(fdisk_partition_get_type(firstpa)) !=
>>                          fdisk_parttype_get_code(fdisk_partition_get_type(secondpa))) ||
>>                  fdisk_partition_get_size(firstpa) != fdisk_partition_get_size(secondpa))) {
>> -               TRACE("Partition differ : %s(%llu) <--> %s(%llu)",
>> -                       fdisk_partition_get_name (firstpa) ? fdisk_partition_get_name(firstpa) : "",
>> -                       (long long unsigned)fdisk_partition_get_size(firstpa),
>> -                       fdisk_partition_get_name(secondpa) ? fdisk_partition_get_name(secondpa) : "",
>> -                       (long long unsigned)fdisk_partition_get_size(secondpa));
>> +               TRACE("Partition differ:");
>> +               diskpart_partition_info(cxt, "Original", firstpa);
>> +               diskpart_partition_info(cxt, "New", secondpa);
>>                  return true;
>>          }
>>          return false;
>> @@ -566,7 +596,7 @@ static int diskpart_fill_table(struct fdisk_context *cxt, struct diskpart_table
>>   /*
>>    * Return 1 if table differs, 0 if table is the same, negative on error
>>    */
>> -static int diskpart_table_cmp(struct fdisk_table *tb, struct fdisk_table *oldtb)
>> +static int diskpart_table_cmp(struct fdisk_context *cxt, struct fdisk_table *tb, struct fdisk_table *oldtb)
>>   {
>>          size_t numnewparts = fdisk_table_get_nents(tb);
>>          size_t numpartondisk = fdisk_table_get_nents(oldtb);
>> @@ -590,7 +620,7 @@ static int diskpart_table_cmp(struct fdisk_table *tb, struct fdisk_table *oldtb)
>>                                  fdisk_table_next_partition (oldtb, olditr, &pa)) {
>>                                  TRACE("Partition not found, something went wrong %lu !", i);
>>                                  ret = -EFAULT;
>> -                       } else if (diskpart_partition_cmp(pa, newpa)) {
>> +                       } else if (diskpart_partition_cmp(cxt, pa, newpa)) {
>>                                  ret = 1;
>>                          }
>>
>> @@ -604,8 +634,8 @@ static int diskpart_table_cmp(struct fdisk_table *tb, struct fdisk_table *oldtb)
>>          return ret;
>>   }
>>
>> -static int diskpart_compare_tables(struct diskpart_table *tb, struct diskpart_table *oldtb,
>> -               struct create_table *createtable)
>> +static int diskpart_compare_tables(struct fdisk_context *cxt, struct diskpart_table *tb,
>> +               struct diskpart_table *oldtb, struct create_table *createtable)
>>   {
>>          int ret = 0;
>>
>> @@ -614,7 +644,7 @@ static int diskpart_compare_tables(struct diskpart_table *tb, struct diskpart_ta
>>           * to check if they differ.
>>           */
>>          if (!createtable->parent) {
>> -               ret = diskpart_table_cmp(tb->parent, oldtb->parent);
>> +               ret = diskpart_table_cmp(PARENT(cxt), tb->parent, oldtb->parent);
>>                  if (ret < 0)
>>                          return ret;
>>                  else if (ret)
>> @@ -622,7 +652,7 @@ static int diskpart_compare_tables(struct diskpart_table *tb, struct diskpart_ta
>>          }
>>
>>          if (tb->child && !createtable->child) {
>> -               ret = diskpart_table_cmp(tb->child, oldtb->child);
>> +               ret = diskpart_table_cmp(cxt, tb->child, oldtb->child);
>>                  if (ret < 0)
>>                          return ret;
>>                  else if (ret)
>> @@ -844,7 +874,7 @@ static int diskpart(struct img_type *img,
>>          if (ret)
>>                  goto handler_exit;
>>
>> -       ret = diskpart_compare_tables(tb, oldtb, createtable);
>> +       ret = diskpart_compare_tables(cxt, tb, oldtb, createtable);
>>          if (ret)
>>                  goto handler_exit;
>>
>> --
>> 2.32.0
>>
>
James Hilliard July 10, 2021, 10:54 a.m. UTC | #3
On Sat, Jul 10, 2021 at 4:31 AM Stefano Babic <sbabic@denx.de> wrote:
>
> Hi James,
>
> I tried to apply V3, but it fails. Could you take a look and maybe
> rebase ? Thanks !

Huh, I think I messed up the version numbering, this v2 should have
been a v4 I think
as it's newer than my v3, resent as v4 just now.

>
> Best regards,
> Stefano Babic
>
> On 08.07.21 16:21, James Hilliard wrote:
> > FYI this shows all partition attributes when they differ, for example:
> > [diskpart_table_cmp] : Number of partitions differs on disk: 1 <--> requested: 4
> > [diskpart_partition_cmp] : Partition differ:
> > [diskpart_partition_info] : Original:
> > [diskpart_partition_info] :         Device: /dev/mmcblk0p1
> > [diskpart_partition_info] :         Boot: *
> > [diskpart_partition_info] :         Start: 34
> > [diskpart_partition_info] :         End: 614433
> > [diskpart_partition_info] :         Sectors: 614400
> > [diskpart_partition_info] :         Cylinders: 9601
> > [diskpart_partition_info] :         Size: 300M
> > [diskpart_partition_info] :         Id: c
> > [diskpart_partition_info] :         Type: W95 FAT32 (LBA)
> > [diskpart_partition_info] :         Start-C/H/S: 0/0/35
> > [diskpart_partition_info] :         End-C/H/S: 38/62/58
> > [diskpart_partition_info] :         Attrs: 80
> > [diskpart_partition_info] : New:
> > [diskpart_partition_info] :         Device: /dev/mmcblk0p1
> > [diskpart_partition_info] :         Boot: (null)
> > [diskpart_partition_info] :         Start: 2048
> > [diskpart_partition_info] :         End: 1128447
> > [diskpart_partition_info] :         Sectors: 1126400
> > [diskpart_partition_info] :         Cylinders: 17601
> > [diskpart_partition_info] :         Size: 550M
> > [diskpart_partition_info] :         Id: c
> > [diskpart_partition_info] :         Type: W95 FAT32 (LBA)
> > [diskpart_partition_info] :         Start-C/H/S: 32/0/1
> > [diskpart_partition_info] :         End-C/H/S: 223/3/16
> > [diskpart_partition_info] :         Attrs: (null)
> > [diskpart_write_table] : Partitions on disk differ, write to disk;
> >
> > Compared to the existing logging which pretty much only shows size and name of
> > the partitions, even though we diff check more than just those two values:
> > [diskpart_table_cmp] : Number of partitions differs on disk: 1 <--> requested: 4
> > [diskpart_partition_cmp] : Partition differ : (614400) <--> (1126400)
> > [diskpart_write_table] : Partitions on disk differ, write to disk;
> >
> > On Mon, Jun 21, 2021 at 7:52 PM James Hilliard
> > <james.hilliard1@gmail.com> wrote:
> >>
> >> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> >> ---
> >> Changes v1 -> v2:
> >>    - rebase on master to handle hybrid partitions
> >> ---
> >>   handlers/diskpart_handler.c | 56 ++++++++++++++++++++++++++++---------
> >>   1 file changed, 43 insertions(+), 13 deletions(-)
> >>
> >> diff --git a/handlers/diskpart_handler.c b/handlers/diskpart_handler.c
> >> index acd21d4..22f005e 100644
> >> --- a/handlers/diskpart_handler.c
> >> +++ b/handlers/diskpart_handler.c
> >> @@ -400,10 +400,42 @@ static int diskpart_append_hybrid_pmbr(struct fdisk_label *lb, struct fdisk_tabl
> >>          return ret;
> >>   }
> >>
> >> +static void diskpart_partition_info(struct fdisk_context *cxt, const char *name, struct fdisk_partition *pa)
> >> +{
> >> +       struct fdisk_label *lb;
> >> +       int *ids = NULL;
> >> +       size_t nids = 0;
> >> +       size_t i;
> >> +       lb = fdisk_get_label(cxt, NULL);
> >> +       fdisk_label_get_fields_ids_all(lb, cxt, &ids, &nids);
> >> +       if (ids && lb) {
> >> +               TRACE("%s:", name);
> >> +               for (i = 0; i < nids; i++) {
> >> +                       const struct fdisk_field *field =
> >> +                                       fdisk_label_get_field(lb, ids[i]);
> >> +                       char *data = NULL;
> >> +                       if (!field)
> >> +                               continue;
> >> +                       if (fdisk_partition_to_string(pa, cxt, ids[i], &data))
> >> +                               continue;
> >> +                       TRACE("\t%s: %s", fdisk_field_get_name(field), data);
> >> +                       free(data);
> >> +               }
> >> +       } else {
> >> +               if (!ids)
> >> +                       ERROR("Failed to load field ids");
> >> +               if (!lb)
> >> +                       ERROR("Failed to load label");
> >> +       }
> >> +       if (ids)
> >> +               free(ids);
> >> +}
> >> +
> >>   /*
> >>    * Return true if partition differs
> >>    */
> >> -static bool diskpart_partition_cmp(struct fdisk_partition *firstpa, struct fdisk_partition *secondpa)
> >> +static bool diskpart_partition_cmp(struct fdisk_context *cxt, struct fdisk_partition *firstpa,
> >> +               struct fdisk_partition *secondpa)
> >>   {
> >>          struct fdisk_parttype *type;
> >>          const char *lbtype;
> >> @@ -432,11 +464,9 @@ static bool diskpart_partition_cmp(struct fdisk_partition *firstpa, struct fdisk
> >>                          fdisk_parttype_get_code(fdisk_partition_get_type(firstpa)) !=
> >>                          fdisk_parttype_get_code(fdisk_partition_get_type(secondpa))) ||
> >>                  fdisk_partition_get_size(firstpa) != fdisk_partition_get_size(secondpa))) {
> >> -               TRACE("Partition differ : %s(%llu) <--> %s(%llu)",
> >> -                       fdisk_partition_get_name (firstpa) ? fdisk_partition_get_name(firstpa) : "",
> >> -                       (long long unsigned)fdisk_partition_get_size(firstpa),
> >> -                       fdisk_partition_get_name(secondpa) ? fdisk_partition_get_name(secondpa) : "",
> >> -                       (long long unsigned)fdisk_partition_get_size(secondpa));
> >> +               TRACE("Partition differ:");
> >> +               diskpart_partition_info(cxt, "Original", firstpa);
> >> +               diskpart_partition_info(cxt, "New", secondpa);
> >>                  return true;
> >>          }
> >>          return false;
> >> @@ -566,7 +596,7 @@ static int diskpart_fill_table(struct fdisk_context *cxt, struct diskpart_table
> >>   /*
> >>    * Return 1 if table differs, 0 if table is the same, negative on error
> >>    */
> >> -static int diskpart_table_cmp(struct fdisk_table *tb, struct fdisk_table *oldtb)
> >> +static int diskpart_table_cmp(struct fdisk_context *cxt, struct fdisk_table *tb, struct fdisk_table *oldtb)
> >>   {
> >>          size_t numnewparts = fdisk_table_get_nents(tb);
> >>          size_t numpartondisk = fdisk_table_get_nents(oldtb);
> >> @@ -590,7 +620,7 @@ static int diskpart_table_cmp(struct fdisk_table *tb, struct fdisk_table *oldtb)
> >>                                  fdisk_table_next_partition (oldtb, olditr, &pa)) {
> >>                                  TRACE("Partition not found, something went wrong %lu !", i);
> >>                                  ret = -EFAULT;
> >> -                       } else if (diskpart_partition_cmp(pa, newpa)) {
> >> +                       } else if (diskpart_partition_cmp(cxt, pa, newpa)) {
> >>                                  ret = 1;
> >>                          }
> >>
> >> @@ -604,8 +634,8 @@ static int diskpart_table_cmp(struct fdisk_table *tb, struct fdisk_table *oldtb)
> >>          return ret;
> >>   }
> >>
> >> -static int diskpart_compare_tables(struct diskpart_table *tb, struct diskpart_table *oldtb,
> >> -               struct create_table *createtable)
> >> +static int diskpart_compare_tables(struct fdisk_context *cxt, struct diskpart_table *tb,
> >> +               struct diskpart_table *oldtb, struct create_table *createtable)
> >>   {
> >>          int ret = 0;
> >>
> >> @@ -614,7 +644,7 @@ static int diskpart_compare_tables(struct diskpart_table *tb, struct diskpart_ta
> >>           * to check if they differ.
> >>           */
> >>          if (!createtable->parent) {
> >> -               ret = diskpart_table_cmp(tb->parent, oldtb->parent);
> >> +               ret = diskpart_table_cmp(PARENT(cxt), tb->parent, oldtb->parent);
> >>                  if (ret < 0)
> >>                          return ret;
> >>                  else if (ret)
> >> @@ -622,7 +652,7 @@ static int diskpart_compare_tables(struct diskpart_table *tb, struct diskpart_ta
> >>          }
> >>
> >>          if (tb->child && !createtable->child) {
> >> -               ret = diskpart_table_cmp(tb->child, oldtb->child);
> >> +               ret = diskpart_table_cmp(cxt, tb->child, oldtb->child);
> >>                  if (ret < 0)
> >>                          return ret;
> >>                  else if (ret)
> >> @@ -844,7 +874,7 @@ static int diskpart(struct img_type *img,
> >>          if (ret)
> >>                  goto handler_exit;
> >>
> >> -       ret = diskpart_compare_tables(tb, oldtb, createtable);
> >> +       ret = diskpart_compare_tables(cxt, tb, oldtb, createtable);
> >>          if (ret)
> >>                  goto handler_exit;
> >>
> >> --
> >> 2.32.0
> >>
> >
>
>
> --
> =====================================================================
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic@denx.de
> =====================================================================
diff mbox series

Patch

diff --git a/handlers/diskpart_handler.c b/handlers/diskpart_handler.c
index acd21d4..22f005e 100644
--- a/handlers/diskpart_handler.c
+++ b/handlers/diskpart_handler.c
@@ -400,10 +400,42 @@  static int diskpart_append_hybrid_pmbr(struct fdisk_label *lb, struct fdisk_tabl
 	return ret;
 }
 
+static void diskpart_partition_info(struct fdisk_context *cxt, const char *name, struct fdisk_partition *pa)
+{
+	struct fdisk_label *lb;
+	int *ids = NULL;
+	size_t nids = 0;
+	size_t i;
+	lb = fdisk_get_label(cxt, NULL);
+	fdisk_label_get_fields_ids_all(lb, cxt, &ids, &nids);
+	if (ids && lb) {
+		TRACE("%s:", name);
+		for (i = 0; i < nids; i++) {
+			const struct fdisk_field *field =
+					fdisk_label_get_field(lb, ids[i]);
+			char *data = NULL;
+			if (!field)
+				continue;
+			if (fdisk_partition_to_string(pa, cxt, ids[i], &data))
+				continue;
+			TRACE("\t%s: %s", fdisk_field_get_name(field), data);
+			free(data);
+		}
+	} else {
+		if (!ids)
+			ERROR("Failed to load field ids");
+		if (!lb)
+			ERROR("Failed to load label");
+	}
+	if (ids)
+		free(ids);
+}
+
 /*
  * Return true if partition differs
  */
-static bool diskpart_partition_cmp(struct fdisk_partition *firstpa, struct fdisk_partition *secondpa)
+static bool diskpart_partition_cmp(struct fdisk_context *cxt, struct fdisk_partition *firstpa,
+		struct fdisk_partition *secondpa)
 {
 	struct fdisk_parttype *type;
 	const char *lbtype;
@@ -432,11 +464,9 @@  static bool diskpart_partition_cmp(struct fdisk_partition *firstpa, struct fdisk
 			fdisk_parttype_get_code(fdisk_partition_get_type(firstpa)) !=
 			fdisk_parttype_get_code(fdisk_partition_get_type(secondpa))) ||
 		fdisk_partition_get_size(firstpa) != fdisk_partition_get_size(secondpa))) {
-		TRACE("Partition differ : %s(%llu) <--> %s(%llu)",
-			fdisk_partition_get_name (firstpa) ? fdisk_partition_get_name(firstpa) : "",
-			(long long unsigned)fdisk_partition_get_size(firstpa),
-			fdisk_partition_get_name(secondpa) ? fdisk_partition_get_name(secondpa) : "",
-			(long long unsigned)fdisk_partition_get_size(secondpa));
+		TRACE("Partition differ:");
+		diskpart_partition_info(cxt, "Original", firstpa);
+		diskpart_partition_info(cxt, "New", secondpa);
 		return true;
 	}
 	return false;
@@ -566,7 +596,7 @@  static int diskpart_fill_table(struct fdisk_context *cxt, struct diskpart_table
 /*
  * Return 1 if table differs, 0 if table is the same, negative on error
  */
-static int diskpart_table_cmp(struct fdisk_table *tb, struct fdisk_table *oldtb)
+static int diskpart_table_cmp(struct fdisk_context *cxt, struct fdisk_table *tb, struct fdisk_table *oldtb)
 {
 	size_t numnewparts = fdisk_table_get_nents(tb);
 	size_t numpartondisk = fdisk_table_get_nents(oldtb);
@@ -590,7 +620,7 @@  static int diskpart_table_cmp(struct fdisk_table *tb, struct fdisk_table *oldtb)
 				fdisk_table_next_partition (oldtb, olditr, &pa)) {
 				TRACE("Partition not found, something went wrong %lu !", i);
 				ret = -EFAULT;
-			} else if (diskpart_partition_cmp(pa, newpa)) {
+			} else if (diskpart_partition_cmp(cxt, pa, newpa)) {
 				ret = 1;
 			}
 
@@ -604,8 +634,8 @@  static int diskpart_table_cmp(struct fdisk_table *tb, struct fdisk_table *oldtb)
 	return ret;
 }
 
-static int diskpart_compare_tables(struct diskpart_table *tb, struct diskpart_table *oldtb,
-		struct create_table *createtable)
+static int diskpart_compare_tables(struct fdisk_context *cxt, struct diskpart_table *tb,
+		struct diskpart_table *oldtb, struct create_table *createtable)
 {
 	int ret = 0;
 
@@ -614,7 +644,7 @@  static int diskpart_compare_tables(struct diskpart_table *tb, struct diskpart_ta
 	 * to check if they differ.
 	 */
 	if (!createtable->parent) {
-		ret = diskpart_table_cmp(tb->parent, oldtb->parent);
+		ret = diskpart_table_cmp(PARENT(cxt), tb->parent, oldtb->parent);
 		if (ret < 0)
 			return ret;
 		else if (ret)
@@ -622,7 +652,7 @@  static int diskpart_compare_tables(struct diskpart_table *tb, struct diskpart_ta
 	}
 
 	if (tb->child && !createtable->child) {
-		ret = diskpart_table_cmp(tb->child, oldtb->child);
+		ret = diskpart_table_cmp(cxt, tb->child, oldtb->child);
 		if (ret < 0)
 			return ret;
 		else if (ret)
@@ -844,7 +874,7 @@  static int diskpart(struct img_type *img,
 	if (ret)
 		goto handler_exit;
 
-	ret = diskpart_compare_tables(tb, oldtb, createtable);
+	ret = diskpart_compare_tables(cxt, tb, oldtb, createtable);
 	if (ret)
 		goto handler_exit;