dcavalca / rpms / util-linux

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