r196 - multipath-tools/trunk/kpartx

Bastian Blank waldi at costa.debian.org
Fri Sep 30 10:57:53 UTC 2005


Author: waldi
Date: Fri Sep 30 10:57:52 2005
New Revision: 196

Modified:
   multipath-tools/trunk/kpartx/byteorder.h
   multipath-tools/trunk/kpartx/dos.c
   multipath-tools/trunk/kpartx/lopart.c
Log:
Apply the following upstream fixes:
- 2be146862254c9941cb0754fadd45cb34dd05694
- 6399c88650be9835b90bad91a7b6268db8db3303
- 1d586d3a1a998b64fa27e61777478d8735d4152a
- 283cc1fbbd7a212f1f18f1cc2a5cb0c2d3aebd9b
- 1dc2104b2a9a7db25dceaa37304abf83436813de

* kpartx/byteorder.h: Use endian.h and byteswap.h.
* kpartx/dos.c
  - Don't use unalligned pointers, this is undefined behaviour.
  - Only use one loop to read all data.
* kpartx/lopart.c
  - Use kernel definition of __kernel_old_dev_t.
  - Use C99 type uintptr_t.


Modified: multipath-tools/trunk/kpartx/byteorder.h
==============================================================================
--- multipath-tools/trunk/kpartx/byteorder.h	(original)
+++ multipath-tools/trunk/kpartx/byteorder.h	Fri Sep 30 10:57:52 2005
@@ -1,15 +1,19 @@
 #ifndef BYTEORDER_H_INCLUDED
 #define BYTEORDER_H_INCLUDED
 
-#if defined (__s390__) || defined (__s390x__)
-#define le32_to_cpu(x)	( \
-		(*(((unsigned char *) &(x)))) + \
-		(*(((unsigned char *) &(x))+1) << 8) + \
-		(*(((unsigned char *) &(x))+2) << 16) + \
-		(*(((unsigned char *) &(x))+3) << 24) \
-	)
+#ifdef __linux__
+#  include <endian.h>
+#  include <byteswap.h>
 #else
-#define le32_to_cpu(x)	(x)
+#  error unsupported
+#endif
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+#  define le32_to_cpu(x) (x)
+#elif BYTE_ORDER == BIG_ENDIAN
+#  define le32_to_cpu(x) bswap_32(x)
+#else
+#  error unsupported
 #endif
 
 #endif				/* BYTEORDER_H_INCLUDED */

Modified: multipath-tools/trunk/kpartx/dos.c
==============================================================================
--- multipath-tools/trunk/kpartx/dos.c	(original)
+++ multipath-tools/trunk/kpartx/dos.c	Fri Sep 30 10:57:52 2005
@@ -1,6 +1,7 @@
 #include "kpartx.h"
 #include "byteorder.h"
 #include <stdio.h>
+#include <string.h>
 #include "dos.h"
 
 static int
@@ -12,7 +13,7 @@
 read_extended_partition(int fd, struct partition *ep,
 			struct slice *sp, int ns)
 {
-	struct partition *p;
+	struct partition p;
 	unsigned long start, here;
 	unsigned char *bp;
 	int loopct = 0;
@@ -33,14 +34,19 @@
 		if (bp[510] != 0x55 || bp[511] != 0xaa)
 			return n;
 
-		p = (struct partition *) (bp + 0x1be);
-
-		for (i=0; i<2; i++, p++) {
-			if (p->nr_sects == 0 || is_extended(p->sys_type))
-				continue;
+		for (i=0; i<2; i++) {
+			memcpy(&p, bp + 0x1be + i * sizeof (p), sizeof (p));
+			if (is_extended(p.sys_type)) {
+				if (p.nr_sects) {
+					here = start + le32_to_cpu(p.start_sect);
+					moretodo = 1;
+				}
+				else
+					continue;
+			}
 			if (n < ns) {
-				sp[n].start = here + le32_to_cpu(p->start_sect);
-				sp[n].size = le32_to_cpu(p->nr_sects);
+				sp[n].start = here + le32_to_cpu(p.start_sect);
+				sp[n].size = le32_to_cpu(p.nr_sects);
 				n++;
 			} else {
 				fprintf(stderr,
@@ -49,15 +55,6 @@
 			}
 			loopct = 0;
 		}
-
-		p -= 2;
-		for (i=0; i<2; i++, p++) {
-			if(p->nr_sects != 0 && is_extended(p->sys_type)) {
-				here = start + le32_to_cpu(p->start_sect);
-				moretodo = 1;
-				break;
-			}
-		}
 	}
 	return n;
 }
@@ -69,9 +66,9 @@
 
 int
 read_dos_pt(int fd, struct slice all, struct slice *sp, int ns) {
-	struct partition *p;
+	struct partition p;
 	unsigned long offset = all.start;
-	int i, n=0;
+	int i, n=4;
 	unsigned char *bp;
 
 	bp = (unsigned char *)getblock(fd, offset);
@@ -81,32 +78,23 @@
 	if (bp[510] != 0x55 || bp[511] != 0xaa)
 		return -1;
 
-	p = (struct partition *) (bp + 0x1be);
 	for (i=0; i<4; i++) {
-		if (is_gpt(p->sys_type)) {
-			return 0;
-		}
-		p++;
+		memcpy(&p, bp + 0x1be + i * sizeof (p), sizeof (p));
 	}
-	p = (struct partition *) (bp + 0x1be);
 	for (i=0; i<4; i++) {
-		/* always add, even if zero length */
-		if (n < ns) {
-			sp[n].start =  le32_to_cpu(p->start_sect);
-			sp[n].size = le32_to_cpu(p->nr_sects);
-			n++;
+		memcpy(&p, bp + 0x1be + i * sizeof (p), sizeof (p));
+		if (is_gpt(p.sys_type))
+			return 0;
+		if (i < ns) {
+			sp[i].start =  le32_to_cpu(p.start_sect);
+			sp[i].size = le32_to_cpu(p.nr_sects);
 		} else {
 			fprintf(stderr,
 				"dos_partition: too many slices\n");
 			break;
 		}
-		p++;
-	}
-	p = (struct partition *) (bp + 0x1be);
-	for (i=0; i<4; i++) {
-		if (is_extended(p->sys_type))
-			n += read_extended_partition(fd, p, sp+n, ns-n);
-		p++;
+		if (is_extended(p.sys_type))
+			n += read_extended_partition(fd, &p, sp+n, ns-n);
 	}
 	return n;
 }

Modified: multipath-tools/trunk/kpartx/lopart.c
==============================================================================
--- multipath-tools/trunk/kpartx/lopart.c	(original)
+++ multipath-tools/trunk/kpartx/lopart.c	Fri Sep 30 10:57:52 2005
@@ -26,29 +26,14 @@
 #include <sys/stat.h>
 #include <sys/mman.h>
 #include <sysmacros.h>
-
-#if defined(__hppa__) || defined(__powerpc64__) || defined (__alpha__) \
- || defined (__x86_64__)
-typedef unsigned long __kernel_old_dev_t;
-#elif defined(__powerpc__) || defined(__ia64__)
-typedef unsigned int __kernel_old_dev_t;
-#else
-typedef unsigned short __kernel_old_dev_t;
-#endif
-
-#define dev_t __kernel_old_dev_t
+#include <stdint.h>
 
 #include <linux/loop.h>
 
 #include "lopart.h"
 #include "xstrncpy.h"
 
-#if !defined (__alpha__) && !defined (__ia64__) && !defined (__x86_64__) \
-        && !defined (__s390x__)
-#define int2ptr(x)	((void *) ((int) x))
-#else
-#define int2ptr(x)	((void *) ((long) x))
-#endif
+#define int2ptr(x)	((void *) ((uintptr_t) x))
 
 static char *
 xstrdup (const char *s)



More information about the pkg-lvm-commits mailing list