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

Jim Meyering meyering at alioth.debian.org
Wed Oct 19 12:20:39 UTC 2011


 NEWS                            |    4 ++
 libparted/labels/pc98.c         |   65 +++++-----------------------------------
 tests/Makefile.am               |    1 
 tests/t2201-pc98-label-recog.sh |   41 +++++++++++++++++++++++++
 4 files changed, 55 insertions(+), 56 deletions(-)

New commits:
commit c2306bc44d2309d1acd011c156295f95d2de819c
Author: Brian C. Lane <bcl at redhat.com>
Date:   Fri Oct 7 16:53:50 2011 -0700

    tests: add tests for new pc98 signatures (#646053)
    
     * tests/t2201-pc98-label-recog.sh: New file
     * tests/Makefile.am: Add test

diff --git a/tests/Makefile.am b/tests/Makefile.am
index f70c524..5a8a539 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -28,6 +28,7 @@ TESTS = \
   t1101-busy-partition.sh \
   t1700-probe-fs.sh \
   t2200-dos-label-recog.sh \
+  t2201-pc98-label-recog.sh \
   t2300-dos-label-extended-bootcode.sh \
   t2310-dos-extended-2-sector-min-offset.sh \
   t2400-dos-hfs-partition-type.sh \
diff --git a/tests/t2201-pc98-label-recog.sh b/tests/t2201-pc98-label-recog.sh
new file mode 100755
index 0000000..6228159
--- /dev/null
+++ b/tests/t2201-pc98-label-recog.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+# Recognize PC98 labeled disks
+
+# Copyright (C) 2011 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
+
+require_512_byte_sector_size_
+
+ss=$sector_size_
+N=8192
+dev=loop-file
+
+# create a file to simulate the underlying device
+dd if=/dev/null of=$dev bs=$ss seek=$N 2> /dev/null || fail=1
+
+# label the test disk
+parted -s $dev mklabel pc98 > out 2>&1 || fail=1
+compare out /dev/null || fail=1 # expect no output
+
+parted -s $dev p | grep "^Partition Table: pc98" || fail=1
+
+for s in "Linux 98" "GRUB/98 "; do
+    printf "$s" | dd bs=1c seek=4 of=$dev conv=notrunc || fail=1
+    parted -s $dev p | grep "^Partition Table: pc98" || fail=1
+done
+
+Exit $fail

commit 0cfe1680d19f38aea275759d9df10b864c0372a0
Author: Brian C. Lane <bcl at redhat.com>
Date:   Fri Oct 7 16:53:49 2011 -0700

    libparted: make pc98 detection depend on signatures
    
    pc98 is not a common disk label. Change pc98_probe to only return true
    if one of the recognized signatures is present.
    Currently these include:
    
    IPL1
    Linux 98
    GRUB/98
    
    This prevents false-positive detection on msdos labeled disks.
    
    * libparted/labels/pc98.c (pc98_probe): Change to require signature
    (pc98_check_ipl_signature): Add more signatures
    (check_partition_consistency): Remove unused function
    Reported by Zach Carter in http://bugzilla.redhat.com/646053

diff --git a/NEWS b/NEWS
index 293dad8..b7fb56b 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,10 @@ GNU parted NEWS                                    -*- outline -*-
   libparted: works with a two-component linux kernel version number like 3.0
   [bug present since the beginning]
 
+  libparted: strengthen the pc98 test so that it is much less likely to
+  cause an MSDOS partition table to be mistakenly identified as pc98.
+  [bug present since the beginning]
+
 
 * Noteworthy changes in release 3.0 (2011-05-30) [stable]
 
diff --git a/libparted/labels/pc98.c b/libparted/labels/pc98.c
index 3afa8a2..d60843d 100644
--- a/libparted/labels/pc98.c
+++ b/libparted/labels/pc98.c
@@ -140,45 +140,20 @@ pc98_check_magic (const PC98RawTable *part_table)
 static int
 pc98_check_ipl_signature (const PC98RawTable *part_table)
 {
-	return !memcmp (part_table->boot_code + 4, "IPL1", 4);
-}
-
-static int
-check_partition_consistency (const PedDevice* dev,
-	       		     const PC98RawPartition* raw_part)
-{
-	if (raw_part->ipl_sect >= dev->hw_geom.sectors
-	   || raw_part->sector >= dev->hw_geom.sectors
-	   || raw_part->end_sector >= dev->hw_geom.sectors
-	   || raw_part->ipl_head >= dev->hw_geom.heads
-	   || raw_part->head >= dev->hw_geom.heads
-	   || raw_part->end_head >= dev->hw_geom.heads
-	   || PED_LE16_TO_CPU(raw_part->ipl_cyl) >= dev->hw_geom.cylinders
-	   || PED_LE16_TO_CPU(raw_part->cyl) >= dev->hw_geom.cylinders
-	   || PED_LE16_TO_CPU(raw_part->end_cyl) >= dev->hw_geom.cylinders
-	   || PED_LE16_TO_CPU(raw_part->cyl)
-	   	> PED_LE16_TO_CPU(raw_part->end_cyl)
-#if 0
-	   || !chs_to_sector(dev, PED_LE16_TO_CPU(raw_part->ipl_cyl),
-			     raw_part->ipl_head, raw_part->ipl_sect)
-	   || !chs_to_sector(dev, PED_LE16_TO_CPU(raw_part->cyl),
-			     raw_part->head, raw_part->sector)
-	   || !chs_to_sector(dev, PED_LE16_TO_CPU(raw_part->end_cyl),
-			     raw_part->end_head, raw_part->end_sector)
-#endif
-	   || PED_LE16_TO_CPU(raw_part->end_cyl)
-	  		< PED_LE16_TO_CPU(raw_part->cyl))
+	if (memcmp (part_table->boot_code + 4, "IPL1", 4) == 0)
+		return 1;
+	else if (memcmp (part_table->boot_code + 4, "Linux 98", 8) == 0)
+		return 1;
+	else if (memcmp (part_table->boot_code + 4, "GRUB/98 ", 8) == 0)
+		return 1;
+	else
 		return 0;
-
-	return 1;
 }
 
 static int
 pc98_probe (const PedDevice *dev)
 {
 	PC98RawTable		part_table;
-	int			empty;
-	const PC98RawPartition*	p;
 
 	PED_ASSERT (dev != NULL);
 
@@ -192,30 +167,8 @@ pc98_probe (const PedDevice *dev)
 	if (!pc98_check_magic (&part_table))
 		return 0;
 
-	/* check consistency */
-	empty = 1;
-	for (p = part_table.partitions;
-	     p < part_table.partitions + MAX_PART_COUNT;
-	     p++)
-	{
-		if (p->mid == 0 && p->sid == 0)
-			continue;
-		empty = 0;
-		if (!check_partition_consistency (dev, p))
-			return 0;
-	}
-
-	/* check boot loader */
-	if (pc98_check_ipl_signature (&part_table))
-		return 1;
-	else if (part_table.boot_code[0])	/* invalid boot loader */
-		return 0;
-
-	/* Not to mistake msdos disk map for PC-9800's empty disk map  */
-	if (empty)
-		return 0;
-
-	return 1;
+	/* check for boot loader signatures */
+	return pc98_check_ipl_signature (&part_table);
 }
 
 static PedDisk*



More information about the Parted-commits mailing list