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

Jim Meyering meyering at alioth.debian.org
Sat Jul 17 20:14:07 UTC 2010


 NEWS                                    |    5 ++
 gnulib                                  |    2 
 libparted/labels/dos.c                  |   75 ++++++++++++++++++++++++++++++++
 tests/Makefile.am                       |    1 
 tests/init.cfg                          |   12 +++++
 tests/t1101-busy-partition.sh           |    2 
 tests/t3400-whole-disk-FAT-partition.sh |   32 +++++++++++++
 7 files changed, 127 insertions(+), 2 deletions(-)

New commits:
commit 616a2a1659d89ff90f9834016a451da8722df509
Author: Jim Meyering <meyering at redhat.com>
Date:   Wed Jul 14 19:16:14 2010 -0500

    libparted: avoid regression when processing a whole-disk FAT partition
    
    Without this change, we would improperly classify a whole-disk partition
    containing a FAT file system as a DOS partition table with no partitions.
    Introduced by commit d732a2b7 on 2008-05-28.
    * libparted/labels/dos.c (maybe_FAT): New function.
    (msdos_probe): Use it.
    Reported by ChenMin in
    http://thread.gmane.org/gmane.comp.gnu.parted.bugs/10115
    * NEWS (Bug fixes): Mention it.
    * tests/t3400-whole-disk-FAT-partition.sh: New file.  Test for the bug.
    * tests/Makefile.am (TESTS): Add it.

diff --git a/NEWS b/NEWS
index d300e8b..45bd2bf 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,11 @@ GNU parted NEWS                                    -*- outline -*-
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** Bug fixes
+
+  libparted once again recognizes a whole-disk FAT partition
+  [bug introduced in parted-1.9.0]
+
 
 * Noteworthy changes in release 2.3 (2010-05-28) [stable]
 
diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c
index f66ca47..d9e7d4a 100644
--- a/libparted/labels/dos.c
+++ b/libparted/labels/dos.c
@@ -164,6 +164,73 @@ typedef struct {
 
 static PedDiskType msdos_disk_type;
 
+#if 0
+From http://www.win.tue.nl/~aeb/linux/fs/fat/fat-1.html
+
+The 2-byte numbers are stored little endian (low order byte first).
+
+Here the FAT12 version, that is also the common part of the FAT12, FAT16 and FAT32 boot sectors. See further below.
+
+Bytes   Content
+0-2     Jump to bootstrap (E.g. eb 3c 90; on i86: JMP 003E NOP.
+        One finds either eb xx 90, or e9 xx xx.
+        The position of the bootstrap varies.)
+3-10    OEM name/version (E.g. "IBM  3.3", "IBM 20.0", "MSDOS5.0", "MSWIN4.0".
+        Various format utilities leave their own name, like "CH-FOR18".
+        Sometimes just garbage. Microsoft recommends "MSWIN4.1".)
+        /* BIOS Parameter Block starts here */
+11-12   Number of bytes per sector (512)
+        Must be one of 512, 1024, 2048, 4096.
+13      Number of sectors per cluster (1)
+        Must be one of 1, 2, 4, 8, 16, 32, 64, 128.
+        A cluster should have at most 32768 bytes. In rare cases 65536 is OK.
+14-15   Number of reserved sectors (1)
+        FAT12 and FAT16 use 1. FAT32 uses 32.
+16      Number of FAT copies (2)
+17-18   Number of root directory entries (224)
+        0 for FAT32. 512 is recommended for FAT16.
+19-20   Total number of sectors in the filesystem (2880)
+        (in case the partition is not FAT32 and smaller than 32 MB)
+21      Media descriptor type (f0: 1.4 MB floppy, f8: hard disk; see below)
+22-23   Number of sectors per FAT (9)
+        0 for FAT32.
+24-25   Number of sectors per track (12)
+26-27   Number of heads (2, for a double-sided diskette)
+28-29   Number of hidden sectors (0)
+        Hidden sectors are sectors preceding the partition.
+        /* BIOS Parameter Block ends here */
+30-509  Bootstrap
+510-511 Signature 55 aa
+#endif
+
+/* There is a significant risk of misclassifying (as msdos)
+   a disk that is composed solely of a single FAT partition.
+   Return false if sector S could not be a valid FAT boot sector.
+   Otherwise, return true.  */
+static bool
+maybe_FAT (unsigned char const *s)
+{
+  if (! (s[0] == 0xeb || s[0] == 0xe9))
+    return false;
+
+  unsigned int sector_size = PED_LE16_TO_CPU (*(uint16_t *) (s + 11));
+  switch (sector_size)
+    {
+    case 512:
+    case 1024:
+    case 2048:
+    case 4096:
+      break;
+    default:
+      return false;
+    }
+
+  if (! (s[21] == 0xf0 || s[21] == 0xf8))
+    return false;
+
+  return true;
+}
+
 static int
 msdos_probe (const PedDevice *dev)
 {
@@ -191,12 +258,20 @@ msdos_probe (const PedDevice *dev)
 	 * and ensure that each partition has a boot indicator that is
 	 * either 0 or 0x80.
 	 */
+	unsigned int n_active = 0;
 	for (i = 0; i < DOS_N_PRI_PARTITIONS; i++) {
+		if (part_table->partitions[i].boot_ind == 0x80)
+			++n_active;
 		if (part_table->partitions[i].boot_ind != 0
 		    && part_table->partitions[i].boot_ind != 0x80)
 			goto probe_fail;
 	}
 
+	/* If there are no active partitions and this is probably
+	   a FAT file system, do not classify it as msdos.  */
+	if (n_active == 0 && maybe_FAT (label))
+	  goto probe_fail;
+
 	/* If this is a GPT disk, fail here */
 	for (i = 0; i < DOS_N_PRI_PARTITIONS; i++) {
 		if (part_table->partitions[i].type == PARTITION_GPT)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a1ab0d8..b31a513 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -30,6 +30,7 @@ TESTS = \
   t3200-type-change.sh \
   t3300-palo-prep.sh \
   t3310-flags.sh \
+  t3400-whole-disk-FAT-partition.sh \
   t4000-sun-raid-type.sh \
   t4001-sun-vtoc.sh \
   t4100-msdos-partition-limits.sh \
diff --git a/tests/t3400-whole-disk-FAT-partition.sh b/tests/t3400-whole-disk-FAT-partition.sh
new file mode 100755
index 0000000..929d690
--- /dev/null
+++ b/tests/t3400-whole-disk-FAT-partition.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+# Ensure that a whole-disk FAT partition is detected.
+
+# Copyright (C) 2010 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_
+
+dev_file=dev-file
+
+echo '1:0s:81919s:81920s:fat16::;' > exp || framework_failure_
+dd if=/dev/null of=$dev_file bs=1 seek=40M || framework_failure_
+mkfs.vfat -F 16 $dev_file || skip_ "mkfs.vfat failed"
+
+parted -m -s $dev_file u s print > out 2>&1 || fail=1
+grep '^1:' out > k; mv k out
+compare out exp || fail=1
+
+Exit $fail

commit 6f7c0f1232df60075df920abd436cca0acfc6008
Author: Jim Meyering <meyering at redhat.com>
Date:   Sat Jul 17 07:20:54 2010 -0500

    tests: use init.cfg; required for init.sh-using tests
    
    * tests/init.cfg: New file.
    (require_512_byte_sector_size_): Slightly different function
    than the one in test-lib.sh.
    
    * tests/init.cfg: New file.

diff --git a/tests/init.cfg b/tests/init.cfg
new file mode 100644
index 0000000..395da1b
--- /dev/null
+++ b/tests/init.cfg
@@ -0,0 +1,12 @@
+# This file is sourced by init.sh, *before* its initialization.
+
+# This goes hand in hand with the "exec 9>&2;" in tests/Makefile.am's
+# TESTS_ENVIRONMENT definition.
+stderr_fileno_=9
+
+sector_size_=${PARTED_SECTOR_SIZE:-512}
+
+require_512_byte_sector_size_()
+{
+  test $sector_size_ = 512 || skip_ 'FS test with sector size != 512'
+}

commit cf8a238082f7c9ad26ef717f98ca91c3410e80f3
Author: Jim Meyering <meyering at redhat.com>
Date:   Wed Jul 14 16:39:05 2010 -0500

    build: update gnulib submodule to latest

diff --git a/gnulib b/gnulib
index 1261942..afc6cbe 160000
--- a/gnulib
+++ b/gnulib
@@ -1 +1 @@
-Subproject commit 12619428c2ef7601f014af01048a28274de7a36c
+Subproject commit afc6cbe4fe4892c5ee4166cab87fede6f294a27d

commit d574086269402e2b2a62f6ced295fc4f75a584f6
Author: Jim Meyering <meyering at redhat.com>
Date:   Fri Jul 16 19:21:44 2010 -0500

    maint: remove trailing blank
    
    * tests/t1101-busy-partition.sh: Remove trailing blank.

diff --git a/tests/t1101-busy-partition.sh b/tests/t1101-busy-partition.sh
index a132275..33b6fe6 100755
--- a/tests/t1101-busy-partition.sh
+++ b/tests/t1101-busy-partition.sh
@@ -58,7 +58,7 @@ parted -s "$dev" mkpartfs primary fat32 1 40 > out 2>&1 || fail=1
 # expect warning
 compare out exp-warning || fail=1
 
-parted -s "$dev" mkpartfs primary fat32 40 80 > out 2>&1 || fail=1 
+parted -s "$dev" mkpartfs primary fat32 40 80 > out 2>&1 || fail=1
 
 # wait for new partition device to appear
 wait_for_dev_to_appear_ ${dev}2



More information about the Parted-commits mailing list