Blame SOURCES/0065-libfdisk-fix-partition-calculation-for-BLKPG_-ioctls.patch

e377cc
From be29de8b5dfe15972455d25e15068dc31d4376ac Mon Sep 17 00:00:00 2001
e377cc
From: Karel Zak <kzak@redhat.com>
e377cc
Date: Wed, 6 May 2020 13:32:46 +0200
e377cc
Subject: [PATCH 65/72] libfdisk: fix partition calculation for BLKPG_* ioctls
e377cc
e377cc
The include/partx.h interface we use in util-linux uses 512-byte
e377cc
sectors, but libfdisk uses real sector sizes.
e377cc
e377cc
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2016229
e377cc
Upstream: http://github.com/util-linux/util-linux/commit/6a4d53ce6466fc97c0ee13846cd1bf7bdd7bfef0
e377cc
Signed-off-by: Karel Zak <kzak@redhat.com>
e377cc
---
e377cc
 libfdisk/src/context.c | 10 ++++++++--
e377cc
 1 file changed, 8 insertions(+), 2 deletions(-)
e377cc
e377cc
diff --git a/libfdisk/src/context.c b/libfdisk/src/context.c
e377cc
index 779a9a889..fe7eb9e7e 100644
e377cc
--- a/libfdisk/src/context.c
e377cc
+++ b/libfdisk/src/context.c
e377cc
@@ -813,6 +813,7 @@ int fdisk_reread_changes(struct fdisk_context *cxt, struct fdisk_table *org)
e377cc
 	struct fdisk_partition **rem = NULL, **add = NULL, **upd = NULL;
e377cc
 	int change, rc = 0, err = 0;
e377cc
 	size_t nparts, i, nadds = 0, nupds = 0, nrems = 0;
e377cc
+	unsigned int ssf;
e377cc
 
e377cc
 	DBG(CXT, ul_debugobj(cxt, "rereading changes"));
e377cc
 
e377cc
@@ -845,6 +846,9 @@ int fdisk_reread_changes(struct fdisk_context *cxt, struct fdisk_table *org)
e377cc
 			goto done;
e377cc
 	}
e377cc
 
e377cc
+	/* sector size factor -- used to recount from real to 512-byte sectors */
e377cc
+	ssf = cxt->sector_size / 512;
e377cc
+
e377cc
 	for (i = 0; i < nrems; i++) {
e377cc
 		pa = rem[i];
e377cc
 		DBG(PART, ul_debugobj(pa, "#%zu calling BLKPG_DEL_PARTITION", pa->partno));
e377cc
@@ -856,7 +860,8 @@ int fdisk_reread_changes(struct fdisk_context *cxt, struct fdisk_table *org)
e377cc
 	for (i = 0; i < nupds; i++) {
e377cc
 		pa = upd[i];
e377cc
 		DBG(PART, ul_debugobj(pa, "#%zu calling BLKPG_RESIZE_PARTITION", pa->partno));
e377cc
-		if (partx_resize_partition(cxt->dev_fd, pa->partno + 1, pa->start, pa->size) != 0) {
e377cc
+		if (partx_resize_partition(cxt->dev_fd, pa->partno + 1,
e377cc
+					   pa->start * ssf, pa->size * ssf) != 0) {
e377cc
 			fdisk_warn(cxt, _("Failed to update system information about partition %zu"), pa->partno + 1);
e377cc
 			err++;
e377cc
 		}
e377cc
@@ -864,7 +869,8 @@ int fdisk_reread_changes(struct fdisk_context *cxt, struct fdisk_table *org)
e377cc
 	for (i = 0; i < nadds; i++) {
e377cc
 		pa = add[i];
e377cc
 		DBG(PART, ul_debugobj(pa, "#%zu calling BLKPG_ADD_PARTITION", pa->partno));
e377cc
-		if (partx_add_partition(cxt->dev_fd, pa->partno + 1, pa->start, pa->size) != 0) {
e377cc
+		if (partx_add_partition(cxt->dev_fd, pa->partno + 1,
e377cc
+					pa->start * ssf, pa->size * ssf) != 0) {
e377cc
 			fdisk_warn(cxt, _("Failed to add partition %zu to system"), pa->partno + 1);
e377cc
 			err++;
e377cc
 		}
e377cc
-- 
e377cc
2.31.1
e377cc