Package: util-linux
Version: 2.12-10

Hi,

sfdisk -l reports invalid partition information on ARM-linux.
                                                   ~~~~~~~~~
Running sfdisk -l, I got result as follows:

# sfdisk -l /dev/hda

Disk /dev/hda: 30515 cylinders, 255 heads, 63 sectors/track
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/hda1          0+     16      17-    136521   83  Linux
/dev/hda2   ? 267349+ 267349-      0- 2147483457   1a  Unknown
                start: (c,h,s) expected (1023,254,63) found (0,42,4)
                end: (c,h,s) expected (1023,254,63) found (769,7,29)
/dev/hda3       2026   30514   28489  228837892+   5  Extended
/dev/hda4          0       -       0          0    0  Empty
/dev/hda5       2026+   2148     123-    987966   83  Linux

On the ohter hand, fdisk -l reports correctly.

# fdisk -l /dev/hda

Disk /dev/hda: 251.0 GB, 251000193024 bytes
255 heads, 63 sectors/track, 30515 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1               1          17      136521   83  Linux
/dev/hda2              18        1963    15631245   83  Linux
/dev/hda3            1964        2026      506047+  82  Linux swap
/dev/hda4            2027       30515   228837892+   5  Extended
/dev/hda5            2027        2149      987966   83  Linux
/dev/hda6            2150        4095    15631213+  83  Linux
/dev/hda7            4096        6041    15631213+  83  Linux

The partition table on MBR is as follows:

# dd if=/dev/hda bs=512 count=1 | hexdump
(snip)
00001b0 0009 0009 0009 0000 0000 0000 0000 0100
00001c0 0001 fe83 103f 003f 0000 2a92 0004 0000
00001d0 1101 fe83 ffff 2ad1 0004 071a 01dd fe00
00001e0 ffff fe82 ffff 31eb 01e1 717f 000f fe00
00001f0 ffff fe05 ffff a36a 01f0 9409 1b47 aa55


I looked the source code, sfdisk.c, found a problem.  The code assumes
that sizeof(struct partition) is 16.  On most of RISC CPU, this
assumption is not correct, because of padding or alignments.

So I made an ugry and dirty patch, as follows, and run correctly.

---8<---
--- sfdisk.c.ORIG       2005-01-27 14:18:18.000000000 +0900
+++ sfdisk.c    2005-01-27 16:17:51.887753000 +0900
@@ -55,6 +55,12 @@
 
 #define SIZE(a)        (sizeof(a)/sizeof(a[0]))
 
+#if 1 /*@@@@@*/
+#define SIZEOF_PARTITION       16
+#else
+#define SIZEOF_PARTITION       (sizeof(struct partition))
+#endif
+
 /*
  * Table of contents:
  *  A. About seeking
@@ -722,7 +728,8 @@
 
     for (pno = 0; pno < z->partno; pno++) {
        p = &(z->partitions[pno]);
-       p->offset = 0x1be + (pno%4)*sizeof(struct partition);
+       //p->offset = 0x1be + (pno%4)*sizeof(struct partition);
+       p->offset = 0x1be + (pno%4)*SIZEOF_PARTITION;
        p->sector = (p->ep ? p->ep->start : 0);
     }
 }
@@ -1350,7 +1357,8 @@
 
        next = 0;
 
-       for (i=0; i<4; i++,cp += sizeof(struct partition)) {
+       //for (i=0; i<4; i++,cp += sizeof(struct partition)) {
+       for (i=0; i<4; i++,cp += SIZEOF_PARTITION) {
            partitions[pno].sector = here;
            partitions[pno].offset = cp - s->data;
            partitions[pno].ep = ep;
@@ -1497,7 +1505,8 @@
       }
     }
 
-    for (pno=0; pno<4; pno++,cp += sizeof(struct partition)) {
+    //for (pno=0; pno<4; pno++,cp += sizeof(struct partition)) {
+    for (pno=0; pno<4; pno++,cp += SIZEOF_PARTITION) {
        partitions[pno].sector = start;
        partitions[pno].offset = cp - s->data;
        copy_to_part(cp,&pt);
---8<---

Here is the report of patched sfdisk:

# ./sfdisk -l /dev/hda
sizeof(struct partition)=24

Disk /dev/hda: 30515 cylinders, 255 heads, 63 sectors/track
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/hda1          0+     16      17-    136521   83  Linux
/dev/hda2         17    1962    1946   15631245   83  Linux
/dev/hda3       1963    2025      63     506047+  82  Linux swap
/dev/hda4       2026   30514   28489  228837892+   5  Extended
/dev/hda5       2026+   2148     123-    987966   83  Linux
/dev/hda6       2149+   4094    1946-  15631213+  83  Linux
/dev/hda7       4095+   6040    1946-  15631213+  83  Linux



My environment is:

CPU:    IQ80321(Xscale)
kernel: linux-2.6.9
Distro: Debian sarge base

Thanks.
_._. __._  _ . ... _  .___ ._. _____ _... ._ _._ _.._. .____  _ . ... _

                                                          Kunihiko IMAI




-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to