dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

Blame SOURCES/0075-libfdisk-gpt-be-more-careful-with-64bit-constants.patch

531551
From 428be59e33d0875cdf5bf602a75328fb3d7c58ad Mon Sep 17 00:00:00 2001
531551
From: Karel Zak <kzak@redhat.com>
531551
Date: Tue, 21 Jun 2016 14:06:14 +0200
531551
Subject: [PATCH 75/84] libfdisk: (gpt) be more careful with 64bit constants
531551
531551
It's probably more robust (and readable) to be explicit when we count
531551
with constant and 64bit numbers.
531551
531551
Upstream: http://github.com/karelzak/util-linux/commit/0a7cdf80606cc0670ef7f740d37640b05932e0ce
531551
Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=1344482
531551
Signed-off-by: Karel Zak <kzak@redhat.com>
531551
---
531551
 libfdisk/src/gpt.c | 40 ++++++++++++++++++++--------------------
531551
 1 file changed, 20 insertions(+), 20 deletions(-)
531551
531551
diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c
531551
index 482d453..d3bdc2d 100644
531551
--- a/libfdisk/src/gpt.c
531551
+++ b/libfdisk/src/gpt.c
531551
@@ -53,7 +53,7 @@
531551
 #define GPT_MBR_PROTECTIVE  1
531551
 #define GPT_MBR_HYBRID      2
531551
 
531551
-#define GPT_PRIMARY_PARTITION_TABLE_LBA 0x00000001
531551
+#define GPT_PRIMARY_PARTITION_TABLE_LBA 0x00000001ULL
531551
 
531551
 #define EFI_PMBR_OSTYPE     0xEE
531551
 #define MSDOS_MBR_SIGNATURE 0xAA55
531551
@@ -364,7 +364,7 @@ static int gpt_mknew_pmbr(struct fdisk_context *cxt)
531551
 	pmbr->partition_record[0].end_track    = 0xFF;
531551
 	pmbr->partition_record[0].starting_lba = cpu_to_le32(1);
531551
 	pmbr->partition_record[0].size_in_lba  =
531551
-		cpu_to_le32(min((uint32_t) cxt->total_sectors - 1, 0xFFFFFFFF));
531551
+		cpu_to_le32((uint32_t) min(cxt->total_sectors - 1ULL, 0xFFFFFFFFULL));
531551
 
531551
 	return 0;
531551
 }
531551
@@ -379,14 +379,14 @@ static void gpt_mknew_header_common(struct fdisk_context *cxt,
531551
 	header->my_lba = cpu_to_le64(lba);
531551
 
531551
 	if (lba == GPT_PRIMARY_PARTITION_TABLE_LBA) { /* primary */
531551
-		header->alternative_lba = cpu_to_le64(cxt->total_sectors - 1);
531551
-		header->partition_entry_lba = cpu_to_le64(2);
531551
+		header->alternative_lba = cpu_to_le64(cxt->total_sectors - 1ULL);
531551
+		header->partition_entry_lba = cpu_to_le64(2ULL);
531551
 	} else { /* backup */
531551
 		uint64_t esz = le32_to_cpu(header->npartition_entries) * sizeof(struct gpt_entry);
531551
 		uint64_t esects = (esz + cxt->sector_size - 1) / cxt->sector_size;
531551
 
531551
 		header->alternative_lba = cpu_to_le64(GPT_PRIMARY_PARTITION_TABLE_LBA);
531551
-		header->partition_entry_lba = cpu_to_le64(cxt->total_sectors - 1 - esects);
531551
+		header->partition_entry_lba = cpu_to_le64(cxt->total_sectors - 1ULL - esects);
531551
 	}
531551
 }
531551
 
531551
@@ -451,8 +451,8 @@ static int gpt_mknew_header(struct fdisk_context *cxt,
531551
 	header->npartition_entries     = cpu_to_le32(GPT_NPARTITIONS);
531551
 	header->sizeof_partition_entry = cpu_to_le32(sizeof(struct gpt_entry));
531551
 
531551
-	last = cxt->total_sectors - 2 - esz;
531551
-	first = esz + 2;
531551
+	last = cxt->total_sectors - 2ULL - esz;
531551
+	first = esz + 2ULL;
531551
 
531551
 	if (first < cxt->first_lba && cxt->first_lba < last)
531551
 		/* Align according to topology */
531551
@@ -520,7 +520,7 @@ check_hybrid:
531551
 	 */
531551
 	if (ret == GPT_MBR_PROTECTIVE) {
531551
 		if (le32_to_cpu(pmbr->partition_record[0].size_in_lba) !=
531551
-		    min((uint32_t) cxt->total_sectors - 1, 0xFFFFFFFF))
531551
+		    (uint32_t) min(cxt->total_sectors - 1ULL, 0xFFFFFFFFULL))
531551
 			ret = 0;
531551
 	}
531551
 done:
531551
@@ -538,7 +538,7 @@ static uint64_t last_lba(struct fdisk_context *cxt)
531551
 	}
531551
 
531551
 	if (S_ISBLK(s.st_mode))
531551
-		return cxt->total_sectors - 1;
531551
+		return cxt->total_sectors - 1ULL;
531551
 	else if (S_ISREG(s.st_mode)) {
531551
 		uint64_t sectors = s.st_size >> cxt->sector_size;
531551
 		return (sectors / cxt->sector_size) - 1ULL;
531551
@@ -554,7 +554,7 @@ static ssize_t read_lba(struct fdisk_context *cxt, uint64_t lba,
531551
 
531551
 	if (lseek(cxt->dev_fd, offset, SEEK_SET) == (off_t) -1)
531551
 		return -1;
531551
-	return read(cxt->dev_fd, buffer, bytes) != bytes;
531551
+	return read(cxt->dev_fd, buffer, bytes) != (ssize_t) bytes;
531551
 }
531551
 
531551
 
531551
@@ -908,7 +908,7 @@ static uint64_t find_first_available(struct gpt_header *header,
531551
 			if (first < gpt_partition_start(&e[i]))
531551
 				continue;
531551
 			if (first <= gpt_partition_end(&e[i])) {
531551
-				first = gpt_partition_end(&e[i]) + 1;
531551
+				first = gpt_partition_end(&e[i]) + 1ULL;
531551
 				first_moved = 1;
531551
 			}
531551
 		}
531551
@@ -937,7 +937,7 @@ static uint64_t find_last_free(struct gpt_header *header,
531551
 		uint64_t ps = gpt_partition_start(&e[i]);
531551
 
531551
 		if (nearest_start > ps && ps > start)
531551
-			nearest_start = ps - 1;
531551
+			nearest_start = ps - 1ULL;
531551
 	}
531551
 
531551
 	return nearest_start;
531551
@@ -960,7 +960,7 @@ static uint64_t find_last_free_sector(struct gpt_header *header,
531551
 		for (i = 0; i < le32_to_cpu(header->npartition_entries); i++) {
531551
 			if ((last >= gpt_partition_start(&e[i])) &&
531551
 			    (last <= gpt_partition_end(&e[i]))) {
531551
-				last = gpt_partition_start(&e[i]) - 1;
531551
+				last = gpt_partition_start(&e[i]) - 1ULL;
531551
 				last_moved = 1;
531551
 			}
531551
 		}
531551
@@ -986,7 +986,7 @@ static uint64_t find_first_in_largest(struct gpt_header *header, struct gpt_entr
531551
 		first_sect =  find_first_available(header, e, start);
531551
 		if (first_sect != 0) {
531551
 			last_sect = find_last_free(header, e, first_sect);
531551
-			segment_size = last_sect - first_sect + 1;
531551
+			segment_size = last_sect - first_sect + 1ULL;
531551
 
531551
 			if (segment_size > selected_size) {
531551
 				selected_size = segment_size;
531551
@@ -1026,7 +1026,7 @@ static uint64_t get_free_sectors(struct fdisk_context *cxt, struct gpt_header *h
531551
 				largest_seg = segment_sz;
531551
 			totfound += segment_sz;
531551
 			num++;
531551
-			start = last_sect + 1;
531551
+			start = last_sect + 1ULL;
531551
 		}
531551
 	} while (first_sect);
531551
 
531551
@@ -1165,7 +1165,7 @@ void gpt_list_table(struct fdisk_context *cxt,
531551
 			continue;
531551
 
531551
 		/* the partition has to inside usable range */
531551
-		if (start < fu || start + size - 1 > lu)
531551
+		if (start < fu || start + size - 1ULL > lu)
531551
 			continue;
531551
 
531551
 		name = encode_to_utf8((unsigned char *)gpt->ents[i].partition_name,
531551
@@ -1266,11 +1266,11 @@ static int gpt_write_pmbr(struct fdisk_context *cxt)
531551
 	 * Set size_in_lba to the size of the disk minus one. If the size of the disk
531551
 	 * is too large to be represented by a 32bit LBA (2Tb), set it to 0xFFFFFFFF.
531551
 	 */
531551
-	if (cxt->total_sectors - 1 > 0xFFFFFFFFULL)
531551
+	if (cxt->total_sectors - 1ULL > 0xFFFFFFFFULL)
531551
 		pmbr->partition_record[0].size_in_lba = cpu_to_le32(0xFFFFFFFF);
531551
 	else
531551
 		pmbr->partition_record[0].size_in_lba =
531551
-			cpu_to_le32(cxt->total_sectors - 1UL);
531551
+			cpu_to_le32((uint32_t) (cxt->total_sectors - 1ULL));
531551
 
531551
 	offset = GPT_PMBR_LBA * cxt->sector_size;
531551
 	if (offset != lseek(cxt->dev_fd, offset, SEEK_SET))
531551
@@ -1308,7 +1308,7 @@ static int gpt_write_disklabel(struct fdisk_context *cxt)
531551
 		goto err0;
531551
 
531551
 	/* check that the backup header is properly placed */
531551
-	if (le64_to_cpu(gpt->pheader->alternative_lba) < cxt->total_sectors - 1)
531551
+	if (le64_to_cpu(gpt->pheader->alternative_lba) < cxt->total_sectors - 1ULL)
531551
 		/* TODO: correct this (with user authorization) and write */
531551
 		goto err0;
531551
 
531551
@@ -1645,7 +1645,7 @@ static int gpt_add_partition(
531551
 
531551
 		user_l = fdisk_ask_number_get_result(ask);
531551
 		if (fdisk_ask_number_is_relative(ask))
531551
-			user_l = fdisk_align_lba_in_range(cxt, user_l, user_f, dflt_l) - 1;
531551
+			user_l = fdisk_align_lba_in_range(cxt, user_l, user_f, dflt_l) - 1ULL;
531551
 		if (user_l > user_f && user_l <= disk_l)
531551
 			break;
531551
 	}
531551
-- 
531551
2.7.4
531551