]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: fix partition calculation for BLKPG_* ioctls
authorKarel Zak <kzak@redhat.com>
Wed, 6 May 2020 11:32:46 +0000 (13:32 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 6 May 2020 11:32:46 +0000 (13:32 +0200)
The include/partx.h interface we use in util-linux uses 512-byte
sectors, but libfdisk uses real sector sizes.

Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/context.c

index 153f1a8629ce4df74f9218ed7bd7718badecc12f..69038afcaef001dd4d4c52a64b1c4aa0dcebd3cf 100644 (file)
@@ -882,6 +882,7 @@ int fdisk_reread_changes(struct fdisk_context *cxt, struct fdisk_table *org)
        struct fdisk_partition **rem = NULL, **add = NULL, **upd = NULL;
        int change, rc = 0, err = 0;
        size_t nparts, i, nadds = 0, nupds = 0, nrems = 0;
+       unsigned int ssf;
 
        DBG(CXT, ul_debugobj(cxt, "rereading changes"));
 
@@ -915,6 +916,9 @@ int fdisk_reread_changes(struct fdisk_context *cxt, struct fdisk_table *org)
                        goto done;
        }
 
+       /* sector size factor -- used to recount from real to 512-byte sectors */
+       ssf = cxt->sector_size / 512;
+
        for (i = 0; i < nrems; i++) {
                pa = rem[i];
                DBG(PART, ul_debugobj(pa, "#%zu calling BLKPG_DEL_PARTITION", pa->partno));
@@ -926,7 +930,8 @@ int fdisk_reread_changes(struct fdisk_context *cxt, struct fdisk_table *org)
        for (i = 0; i < nupds; i++) {
                pa = upd[i];
                DBG(PART, ul_debugobj(pa, "#%zu calling BLKPG_RESIZE_PARTITION", pa->partno));
-               if (partx_resize_partition(cxt->dev_fd, pa->partno + 1, pa->start, pa->size) != 0) {
+               if (partx_resize_partition(cxt->dev_fd, pa->partno + 1,
+                                          pa->start * ssf, pa->size * ssf) != 0) {
                        fdisk_warn(cxt, _("Failed to update system information about partition %zu"), pa->partno + 1);
                        err++;
                }
@@ -934,7 +939,8 @@ int fdisk_reread_changes(struct fdisk_context *cxt, struct fdisk_table *org)
        for (i = 0; i < nadds; i++) {
                pa = add[i];
                DBG(PART, ul_debugobj(pa, "#%zu calling BLKPG_ADD_PARTITION", pa->partno));
-               if (partx_add_partition(cxt->dev_fd, pa->partno + 1, pa->start, pa->size) != 0) {
+               if (partx_add_partition(cxt->dev_fd, pa->partno + 1,
+                                       pa->start * ssf, pa->size * ssf) != 0) {
                        fdisk_warn(cxt, _("Failed to add partition %zu to system"), pa->partno + 1);
                        err++;
                }