[Parted-commits] GNU Parted Official Repository: Changes to 'master'

Jim Meyering meyering at alioth.debian.org
Sat Jun 9 17:25:45 UTC 2012


 NEWS                   |    3 +++
 cfg.mk                 |    2 ++
 libparted/labels/gpt.c |    4 ++--
 tests/print-max.c      |   10 ++++++++++
 tests/t9021-maxima.sh  |   26 +++++++++++++++++++++++++-
 5 files changed, 42 insertions(+), 3 deletions(-)

New commits:
commit e38df2d81f0a4647711ffeb92a32c99e7ce9a92d
Author: Jim Meyering <meyering at redhat.com>
Date:   Sat Jun 9 17:26:21 2012 +0200

    tests: add a test to exercise just-fixed code
    
    * tests/print-max.c: Extend to provide coverage of
    ped_disk_get_max_supported_partition_count, too.
    * tests/t9021-maxima.sh (max_n_partitions): New function, with
    naively hard-coded max-number-of-partitions-per-partition-table-type
    values.
    Use it to ensure that each expected value matches the actual one.
    * cfg.mk: Exempt this test's use of error from the syntax-check
    for unmarked diagnostics.

diff --git a/cfg.mk b/cfg.mk
index c6a00c8..45d2ac2 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -69,3 +69,5 @@ exclude_file_name_regexp--sc_prohibit_always-defined_macros = \
 
 exclude_file_name_regexp--sc_prohibit_path_max_allocation = \
   ^libparted/arch/beos\.c$$
+
+exclude_file_name_regexp--sc_unmarked_diagnostics = ^tests/print-max\.c$$
diff --git a/tests/print-max.c b/tests/print-max.c
index 7560d49..41aa8c6 100644
--- a/tests/print-max.c
+++ b/tests/print-max.c
@@ -2,9 +2,11 @@
 #include <parted/parted.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <errno.h>
 
 #include "closeout.h"
 #include "progname.h"
+#include "error.h"
 
 int
 main (int argc, char **argv)
@@ -26,8 +28,16 @@ main (int argc, char **argv)
   PedSector max_length = ped_disk_max_partition_length (disk);
   PedSector max_start_sector = ped_disk_max_partition_start_sector (disk);
 
+  if (!ped_device_open(dev))
+    error (EXIT_FAILURE, errno, "failed to open %s\n", dev_name);
+  int max_n_partitions;
+  bool ok = ped_disk_get_max_supported_partition_count (disk,
+							&max_n_partitions);
+
   printf ("max len: %llu\n", (unsigned long long) max_length);
   printf ("max start sector: %llu\n", (unsigned long long) max_start_sector);
+  printf ("max number of partitions: %d\n",
+	  ok ? max_n_partitions : -1);
 
   ped_disk_destroy (disk);
   ped_device_destroy (dev);
diff --git a/tests/t9021-maxima.sh b/tests/t9021-maxima.sh
index 0570585..ca10d17 100755
--- a/tests/t9021-maxima.sh
+++ b/tests/t9021-maxima.sh
@@ -23,6 +23,27 @@ dev=dev-file
 PATH="..:$PATH"
 export PATH
 
+max_n_partitions()
+{
+  case $1 in
+
+    # Technically, msdos partition tables have no limit on the maximum number
+    # of partitions, but we pretend it is 64 due to implementation details.
+    msdos) m=64;;
+
+    gpt) m=128;;
+    dvh) m=16;;
+    sun) m=8;;
+    mac) m=65536;;
+    bsd) m=8;;
+    amiga) m=128;;
+    loop) m=1;;
+    pc98) case $ss in 512) m=16;; *) m=64;; esac;;
+    *) warn_ invalid partition table type: $1 1>&2; exit 1;;
+  esac
+  echo $m
+}
+
 # FIXME: add aix when/if it's supported again
 for t in msdos gpt dvh sun mac bsd amiga loop pc98; do
     echo $t
@@ -40,8 +61,11 @@ for t in msdos gpt dvh sun mac bsd amiga loop pc98; do
     esac
 
     print-max $dev > out 2>&1 || fail=1
+    m=$(max_n_partitions $t) || fail=1
     printf '%s\n' "max len: $max_len" \
-	"max start sector: $max_start" > exp || fail=1
+	"max start sector: $max_start" \
+	"max number of partitions: $m" \
+      > exp || fail=1
     compare exp out || fail=1
 done
 

commit 4ac1c02b590668c93afdb48900e0858de58cda3a
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Fri Jun 8 13:19:25 2012 +0100

    gpt: fix endianness bug in gpt_get_max_supported_partition_count
    
    * libparted/labels/gpt.c (gpt_get_max_supported_partition_count):
    Take endianness of pth->FirstUsableLBA into account (64-bit,
    little endian) when calculating the maximum number of partitions.
    * NEWS (Bug fixes): Mention it.

diff --git a/NEWS b/NEWS
index 3969c44..f929b99 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,9 @@ GNU parted NEWS                                    -*- outline -*-
 
 ** Bug Fixes
 
+  libparted: gpt: fix gpt_get_max_supported_partition_count to work
+  also on little-endian systems.
+
   libparted: treat a disk with no pMBR as an msdos-labeled disk
   even when it has valid GPT headers.
 
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 91ad71a..6032e3f 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -1785,12 +1785,12 @@ gpt_get_max_supported_partition_count (const PedDisk *disk, int *max_n)
 
   if (!_header_is_valid (disk, pth, 1))
     {
-      pth->FirstUsableLBA = 34;
+      pth->FirstUsableLBA = PED_CPU_TO_LE64 (34);
       pth->SizeOfPartitionEntry
         = PED_CPU_TO_LE32 (sizeof (GuidPartitionEntry_t));
     }
 
-  *max_n = (disk->dev->sector_size * (pth->FirstUsableLBA - 2)
+  *max_n = (disk->dev->sector_size * (PED_LE64_TO_CPU (pth->FirstUsableLBA) - 2)
             / PED_LE32_TO_CPU (pth->SizeOfPartitionEntry));
   pth_free (pth);
   return true;



More information about the Parted-commits mailing list