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

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