Blame SOURCES/0066-UP-dos-4k-partition-fix.patch

38852f
---
38852f
 kpartx/dos.c    |   17 ++++++++++-------
38852f
 kpartx/gpt.c    |   20 +-------------------
38852f
 kpartx/kpartx.c |   12 ++++++++++++
38852f
 kpartx/kpartx.h |    8 ++++++++
38852f
 4 files changed, 31 insertions(+), 26 deletions(-)
38852f
38852f
Index: multipath-tools-130222/kpartx/dos.c
38852f
===================================================================
38852f
--- multipath-tools-130222.orig/kpartx/dos.c
38852f
+++ multipath-tools-130222/kpartx/dos.c
38852f
@@ -26,7 +26,9 @@ read_extended_partition(int fd, struct p
38852f
 	int moretodo = 1;
38852f
 	int i, n=0;
38852f
 
38852f
-	next = start = le32_to_cpu(ep->start_sect);
38852f
+	int sector_size_mul = get_sector_size(fd)/512;
38852f
+
38852f
+	next = start = sector_size_mul * le32_to_cpu(ep->start_sect);
38852f
 
38852f
 	while (moretodo) {
38852f
 		here = next;
38852f
@@ -45,14 +47,14 @@ read_extended_partition(int fd, struct p
38852f
 			memcpy(&p, bp + 0x1be + i * sizeof (p), sizeof (p));
38852f
 			if (is_extended(p.sys_type)) {
38852f
 				if (p.nr_sects && !moretodo) {
38852f
-					next = start + le32_to_cpu(p.start_sect);
38852f
+					next = start + sector_size_mul * le32_to_cpu(p.start_sect);
38852f
 					moretodo = 1;
38852f
 				}
38852f
 				continue;
38852f
 			}
38852f
 			if (n < ns) {
38852f
-				sp[n].start = here + le32_to_cpu(p.start_sect);
38852f
-				sp[n].size = le32_to_cpu(p.nr_sects);
38852f
+				sp[n].start = here + sector_size_mul * le32_to_cpu(p.start_sect);
38852f
+				sp[n].size = sector_size_mul * le32_to_cpu(p.nr_sects);
38852f
 				n++;
38852f
 			} else {
38852f
 				fprintf(stderr,
38852f
@@ -76,6 +78,7 @@ read_dos_pt(int fd, struct slice all, st
38852f
 	unsigned long offset = all.start;
38852f
 	int i, n=4;
38852f
 	unsigned char *bp;
38852f
+	int sector_size_mul = get_sector_size(fd)/512;
38852f
 
38852f
 	bp = (unsigned char *)getblock(fd, offset);
38852f
 	if (bp == NULL)
38852f
@@ -89,8 +92,8 @@ read_dos_pt(int fd, struct slice all, st
38852f
 		if (is_gpt(p.sys_type))
38852f
 			return 0;
38852f
 		if (i < ns) {
38852f
-			sp[i].start =  le32_to_cpu(p.start_sect);
38852f
-			sp[i].size = le32_to_cpu(p.nr_sects);
38852f
+			sp[i].start =  sector_size_mul * le32_to_cpu(p.start_sect);
38852f
+			sp[i].size = sector_size_mul * le32_to_cpu(p.nr_sects);
38852f
 		} else {
38852f
 			fprintf(stderr,
38852f
 				"dos_partition: too many slices\n");
38852f
@@ -99,7 +102,7 @@ read_dos_pt(int fd, struct slice all, st
38852f
 		if (is_extended(p.sys_type)) {
38852f
 			n += read_extended_partition(fd, &p, sp+n, ns-n);
38852f
 			/* hide the extended partition itself */
38852f
-			sp[i].size = 2;
38852f
+			sp[i].size = sector_size_mul * 2;
38852f
 		}
38852f
 	}
38852f
 	return n;
38852f
Index: multipath-tools-130222/kpartx/gpt.c
38852f
===================================================================
38852f
--- multipath-tools-130222.orig/kpartx/gpt.c
38852f
+++ multipath-tools-130222/kpartx/gpt.c
38852f
@@ -38,6 +38,7 @@
38852f
 #include <byteswap.h>
38852f
 #include <linux/fs.h>
38852f
 #include "crc32.h"
38852f
+#include "kpartx.h"
38852f
 
38852f
 #if BYTE_ORDER == LITTLE_ENDIAN
38852f
 #  define __le16_to_cpu(x) (x)
38852f
@@ -116,25 +117,6 @@ is_pmbr_valid(legacy_mbr *mbr)
38852f
 
38852f
 
38852f
 /************************************************************
38852f
- * get_sector_size
38852f
- * Requires:
38852f
- *  - filedes is an open file descriptor, suitable for reading
38852f
- * Modifies: nothing
38852f
- * Returns:
38852f
- *  sector size, or 512.
38852f
- ************************************************************/
38852f
-static int
38852f
-get_sector_size(int filedes)
38852f
-{
38852f
-	int rc, sector_size = 512;
38852f
-
38852f
-	rc = ioctl(filedes, BLKSSZGET, &sector_size);
38852f
-	if (rc)
38852f
-		sector_size = 512;
38852f
-	return sector_size;
38852f
-}
38852f
-
38852f
-/************************************************************
38852f
  * _get_num_sectors
38852f
  * Requires:
38852f
  *  - filedes is an open file descriptor, suitable for reading
38852f
Index: multipath-tools-130222/kpartx/kpartx.c
38852f
===================================================================
38852f
--- multipath-tools-130222.orig/kpartx/kpartx.c
38852f
+++ multipath-tools-130222/kpartx/kpartx.c
38852f
@@ -26,6 +26,7 @@
38852f
 #include <string.h>
38852f
 #include <unistd.h>
38852f
 #include <stdint.h>
38852f
+#include <sys/ioctl.h>
38852f
 #include <sys/stat.h>
38852f
 #include <sys/types.h>
38852f
 #include <ctype.h>
38852f
@@ -606,3 +607,14 @@ getblock (int fd, unsigned int secnr) {
38852f
 
38852f
 	return bp->block;
38852f
 }
38852f
+
38852f
+int
38852f
+get_sector_size(int filedes)
38852f
+{
38852f
+	int rc, sector_size = 512;
38852f
+
38852f
+	rc = ioctl(filedes, BLKSSZGET, &sector_size);
38852f
+	if (rc)
38852f
+		sector_size = 512;
38852f
+	return sector_size;
38852f
+}
38852f
Index: multipath-tools-130222/kpartx/kpartx.h
38852f
===================================================================
38852f
--- multipath-tools-130222.orig/kpartx/kpartx.h
38852f
+++ multipath-tools-130222/kpartx/kpartx.h
38852f
@@ -2,6 +2,7 @@
38852f
 #define _KPARTX_H
38852f
 
38852f
 #include <stdint.h>
38852f
+#include <sys/ioctl.h>
38852f
 
38852f
 /*
38852f
  * For each partition type there is a routine that takes
38852f
@@ -18,6 +19,13 @@
38852f
 #define safe_sprintf(var, format, args...)	\
38852f
 	snprintf(var, sizeof(var), format, ##args) >= sizeof(var)
38852f
 
38852f
+#ifndef BLKSSZGET
38852f
+#define BLKSSZGET  _IO(0x12,104)	/* get block device sector size */
38852f
+#endif
38852f
+
38852f
+int
38852f
+get_sector_size(int filedes);
38852f
+
38852f
 /*
38852f
  * units: 512 byte sectors
38852f
  */