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

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