dcavalca / rpms / util-linux

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