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

Jim Meyering meyering at alioth.debian.org
Tue May 26 12:50:03 UTC 2009


 include/parted/device.h              |    3 
 libparted/arch/linux.c               |  177 +++++++++++++++++++----------------
 libparted/labels/dos.c               |   98 +++++++++++++++----
 parted/parted.c                      |    2 
 tests/Makefile.am                    |    1 
 tests/t4100-msdos-starting-sector.sh |   83 ++++++++++++++++
 6 files changed, 261 insertions(+), 103 deletions(-)

New commits:
commit 560909f2452914848134376ba3c75b05c4ed6b7e
Author: Jim Meyering <meyering at redhat.com>
Date:   Tue May 26 14:36:18 2009 +0200

    tests: adjust t4100-msdos-starting-sector.sh
    
    * tests/t4100-msdos-starting-sector.sh: Use parted's -m option
    when printing, and adjust expected output to match.
    Filter out "Disk...:" part to avoid false-positive failures due
    to mount-point- related differences.

diff --git a/tests/t4100-msdos-starting-sector.sh b/tests/t4100-msdos-starting-sector.sh
index f70dbc9..6a5916b 100755
--- a/tests/t4100-msdos-starting-sector.sh
+++ b/tests/t4100-msdos-starting-sector.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-# Copyright (C) 2008 Free Software Foundation, Inc.
+# Copyright (C) 2008, 2009 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
@@ -40,38 +40,29 @@ test_expect_success 'expect no output' 'compare out /dev/null'
 # Test the output of print free with no partitions.
 fail=0
 cat <<EOF > exp || fail=1
-Model:  (file)
-Disk $(pwd)/$dev: 200s
-Sector size (logical/physical): 512B/512B
-Partition Table: msdos
-
-Number  Start  End   Size  Type  File system  Flags
-        32s    127s  96s         Free Space
-
+BYT;
+path:200s:file:512:512:msdos:;
+1:32s:127s:96s:free;
 EOF
 
 test_expect_success 'create expected output file' 'test $fail = 0'
 
 test_expect_success \
     'display output of label without partitions' \
-    'parted -s $dev unit s print free > out 2>&1'
+    'parted -m -s $dev unit s print free > out 2>&1'
 
 test_expect_success \
     'check for expected output' \
-    'compare out exp'
+    'sed "2s/^[^:]*:/path:/" < out > k; mv k out
+    compare out exp'
 
 # Test the output of print free with one partition.
 fail=0
 cat <<EOF > exp || fail=1
-Model:  (file)
-Disk $(pwd)/$dev: 200s
-Sector size (logical/physical): 512B/512B
-Partition Table: msdos
-
-Number  Start  End   Size  Type     File system  Flags
-        32s    96s   65s            Free Space
-         1      97s    195s  99s   primary
-
+BYT;
+path:200s:file:512:512:msdos:;
+1:32s:96s:65s:free;
+1:97s:195s:99s:::;
 EOF
 
 test_expect_success 'create expected output file' 'test $fail = 0'
@@ -82,10 +73,11 @@ test_expect_success \
 
 test_expect_success \
     'display output of label with partition' \
-    'parted -s $dev unit s print free > out 2>&1'
+    'parted -m -s $dev unit s print free > out 2>&1'
 
 test_expect_success \
     'check for expected output' \
-    'compare out exp; cp out /tmp/out ; cp exp /tmp/exp'
+    'sed "2s/^[^:]*:/path:/" < out > k; mv k out
+    compare out exp'
 
 test_done

commit 8c94abc3033a05be03b55a0772ecfb8b30363674
Author: Joel Granados Moreno <jgranado at redhat.com>
Date:   Wed May 13 17:24:33 2009 +0200

    Add test for msdos starting sector.
    
    * tests/t4100-msdos-starting-sector.sh : Make sure we are consistent
      when displaying starting sector for msdos lables.

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0beedd4..2931e98 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,6 +15,7 @@ TESTS = \
   t4000-sun-raid-type.sh \
   t4100-msdos-partition-limits.sh \
   t4100-dvh-partition-limits.sh \
+  t4100-msdos-starting-sector.sh \
   t4200-partprobe.sh \
   t5000-tags.sh \
   t6000-dm.sh \
diff --git a/tests/t4100-msdos-starting-sector.sh b/tests/t4100-msdos-starting-sector.sh
new file mode 100755
index 0000000..f70dbc9
--- /dev/null
+++ b/tests/t4100-msdos-starting-sector.sh
@@ -0,0 +1,91 @@
+#!/bin/sh
+
+# Copyright (C) 2008 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/>.
+
+test_description='Consistency in msdos free space starting sector.'
+
+: ${srcdir=.}
+. $srcdir/test-lib.sh
+
+######################################################################
+# parted 1.8.8.1 and earlier was inconsistent when calculating the
+# start sector for free space in msdos type lables.  parted was not
+# consistent in the use of metadata padding for msdos labels.
+######################################################################
+
+N=100
+dev=loop-file
+test_expect_success \
+    'create a file to simulate the underlying device' \
+    'dd if=/dev/zero of=$dev bs=1K count=$N 2> /dev/null'
+
+test_expect_success \
+    'label the test disk' \
+    'parted -s $dev mklabel msdos > out 2>&1'
+test_expect_success 'expect no output' 'compare out /dev/null'
+
+# Test the output of print free with no partitions.
+fail=0
+cat <<EOF > exp || fail=1
+Model:  (file)
+Disk $(pwd)/$dev: 200s
+Sector size (logical/physical): 512B/512B
+Partition Table: msdos
+
+Number  Start  End   Size  Type  File system  Flags
+        32s    127s  96s         Free Space
+
+EOF
+
+test_expect_success 'create expected output file' 'test $fail = 0'
+
+test_expect_success \
+    'display output of label without partitions' \
+    'parted -s $dev unit s print free > out 2>&1'
+
+test_expect_success \
+    'check for expected output' \
+    'compare out exp'
+
+# Test the output of print free with one partition.
+fail=0
+cat <<EOF > exp || fail=1
+Model:  (file)
+Disk $(pwd)/$dev: 200s
+Sector size (logical/physical): 512B/512B
+Partition Table: msdos
+
+Number  Start  End   Size  Type     File system  Flags
+        32s    96s   65s            Free Space
+         1      97s    195s  99s   primary
+
+EOF
+
+test_expect_success 'create expected output file' 'test $fail = 0'
+
+test_expect_success \
+    'create a partition at the end of the label' \
+    'parted -s $dev mkpart primary 50K 100K'
+
+test_expect_success \
+    'display output of label with partition' \
+    'parted -s $dev unit s print free > out 2>&1'
+
+test_expect_success \
+    'check for expected output' \
+    'compare out exp; cp out /tmp/out ; cp exp /tmp/exp'
+
+test_done

commit 353668ecdd4c09ff1bab0c801421495a2dfabb61
Author: Joel Andres Granados <jgranado at redhat.com>
Date:   Wed May 13 17:24:32 2009 +0200

    Make sure we always create msdos metadata parts.
    
    Given a disk with no partition, parted did not create metadata
    partitions for an msdos label.  This led to inconsistencies when
    reporting free space partition ranges.  This patch addresses this issue.
    
    * libparted/labels/dos.c (get_last_part): Remove function.
    * libparted/labels/dos.c (get_start_first_nonfree_part): New function.
    * libparted/labels/dos.c (get_end_last_nonfree_part): New function.
    * libparted/lables/dos.c (add_startend_metadata): Add code that
    handles disks no partitions.  Add check that prevents the metadata
    partitions from being greater than the device length.  Add check
    that prevents metadata partitions from overlapping in small devs.

diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c
index d07dcbd..f219e7d 100644
--- a/libparted/labels/dos.c
+++ b/libparted/labels/dos.c
@@ -2081,16 +2081,58 @@ add_logical_part_metadata (PedDisk* disk, const PedPartition* log_part)
 				  metadata_start, metadata_end);
 }
 
-static PedPartition*
-get_last_part (const PedDisk* disk)
+/*
+ * Find the starting sector number of the first non-free partition,
+ * set *SECTOR to that value, and return 1.
+ * If there is no non-free partition, don't modify *SECTOR and return 0.
+ */
+static int
+get_start_first_nonfree_part (const PedDisk* disk, PedSector *sector)
 {
-	PedPartition* first_part = disk->part_list;
 	PedPartition* walk;
 
-	if (!first_part)
-		return NULL;
-	for (walk = first_part; walk->next; walk = walk->next);
-	return walk;
+	// disk->part_list is the first partition on the disk.
+	if (!disk->part_list)
+		return 0;
+
+	for (walk = disk->part_list; walk; walk = walk->next) {
+		if (walk->type == PED_PARTITION_NORMAL ||
+				walk->type == PED_PARTITION_EXTENDED) {
+			*sector = walk->geom.start;
+			return 1;
+		}
+	}
+	return 0;
+}
+
+/*
+ * Find the ending sector number of the last non-free partition,
+ * set *SECTOR to that value, and return 1.
+ * If there is no non-free partition, don't modify *SECTOR and return 0.
+ */
+static int
+get_end_last_nonfree_part (const PedDisk* disk, PedSector *sector)
+{
+	PedPartition* last_part = NULL;
+	PedPartition* walk;
+
+	// disk->part_list is the first partition on the disk.
+	if (!disk->part_list)
+		return 0;
+
+	for (walk = disk->part_list; walk; walk = walk->next) {
+		if (walk->type == PED_PARTITION_NORMAL ||
+				walk->type == PED_PARTITION_EXTENDED) {
+			last_part = walk;
+		}
+	}
+
+	if (!last_part)
+		return 0;
+	else {
+		*sector = last_part->geom.end;
+		return 1;
+	}
 }
 
 /* Adds metadata placeholder partitions to cover the partition table (and
@@ -2104,25 +2146,37 @@ add_startend_metadata (PedDisk* disk)
 {
 	PedDevice* dev = disk->dev;
 	PedSector cyl_size = dev->bios_geom.sectors * dev->bios_geom.heads;
-	PedPartition* first_part = disk->part_list;
-	PedPartition* last_part = get_last_part (disk);
-	PedSector start, end;
+	PedSector init_start, init_end, final_start, final_end;
 
-	if (!first_part)
-		return 1;
+	// Ranges for the initial and final metadata partition.
+	init_start = 0;
+	if (!get_start_first_nonfree_part(disk, &init_end))
+		init_end = dev->bios_geom.sectors - 1;
+	else
+		init_end = PED_MIN (dev->bios_geom.sectors - 1, init_end - 1);
 
-	start = 0;
-	end = PED_MIN (dev->bios_geom.sectors - 1, first_part->geom.start - 1);
-	if (!add_metadata_part (disk, PED_PARTITION_NORMAL, start, end))
-		return 0;
+	if (!get_end_last_nonfree_part(disk, &final_start))
+		final_start = ped_round_down_to (dev->length, cyl_size);
+	else
+		final_start = PED_MAX (final_start + 1,
+				ped_round_down_to (dev->length, cyl_size));
+	final_end = dev->length - 1;
+
+	// Create the metadata partitions.
+	// init_end <= dev->length for devices that are _real_ small.
+	if (init_start < init_end &&
+			init_end <= dev->length &&
+			!add_metadata_part (disk, PED_PARTITION_NORMAL,
+				init_start, init_end))
+			return 0;
 
-	start = PED_MAX (last_part->geom.end + 1,
-			 ped_round_down_to (dev->length, cyl_size));
-	end = dev->length - 1;
-	if (start < end) {
-		if (!add_metadata_part (disk, PED_PARTITION_NORMAL, start, end))
+	// init_end < final_start so they dont overlap.  For very small devs.
+	if (final_start < final_end &&
+			init_end < final_start &&
+			final_end <= dev->length &&
+			!add_metadata_part (disk, PED_PARTITION_NORMAL,
+				final_start, final_end))
 			return 0;
-	}
 
 	return 1;
 }

commit b17111ef29c5f7d2e5ab1627b0a8adb6a3b32cda
Author: Joel Granados Moreno <jgranado at redhat.com>
Date:   Wed May 13 17:24:31 2009 +0200

    Improve readability in linux.c
    
    * libparted/arch/linux.c : Gather all the _is_major functions together.
    change the name of readFD to _read_fd since its not used anywhere
    else. Also rename the "_is_major_type" function to
    "_major_type_in_device" as it better expresses what we do in said
    function.

diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 7b3f3d0..ae0f8fb 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -287,43 +287,7 @@ static char* _device_get_part_path (PedDevice* dev, int num);
 static int _partition_is_mounted_by_path (const char* path);
 
 static int
-_is_ide_major (int major)
-{
-        switch (major) {
-                case IDE0_MAJOR:
-                case IDE1_MAJOR:
-                case IDE2_MAJOR:
-                case IDE3_MAJOR:
-                case IDE4_MAJOR:
-                case IDE5_MAJOR:
-                        return 1;
-
-                default:
-                        return 0;
-        }
-}
-
-static int
-_is_cpqarray_major (int major)
-{
-        return ((COMPAQ_SMART2_MAJOR <= major && major <= COMPAQ_SMART2_MAJOR7)
-             || (COMPAQ_SMART_MAJOR <= major && major <= COMPAQ_SMART_MAJOR7));
-}
-
-static int
-_is_i2o_major (int major)
-{
-        return (I2O_MAJOR1 <= major && major <= I2O_MAJOR8);
-}
-
-static int
-_is_sx8_major (int major)
-{
-        return (SX8_MAJOR1 <= major && major <= SX8_MAJOR2);
-}
-
-static int
-readFD (int fd, char **buf)
+_read_fd (int fd, char **buf)
 {
         char* p;
         size_t size = PROC_DEVICES_BUFSIZ;
@@ -359,7 +323,7 @@ readFD (int fd, char **buf)
 }
 
 static int
-_is_major_type (int major, const char* type)
+_major_type_in_devices (int major, const char* type)
 {
         int fd;
         char* buf = NULL;
@@ -372,7 +336,7 @@ _is_major_type (int major, const char* type)
         if (fd < 0)
                 return 0;
 
-        if (readFD(fd, &buf) < 0) {
+        if (_read_fd(fd, &buf) < 0) {
                 close(fd);
                 return 0;
         }
@@ -414,16 +378,52 @@ next:
 }
 
 static int
+_is_ide_major (int major)
+{
+        switch (major) {
+                case IDE0_MAJOR:
+                case IDE1_MAJOR:
+                case IDE2_MAJOR:
+                case IDE3_MAJOR:
+                case IDE4_MAJOR:
+                case IDE5_MAJOR:
+                        return 1;
+
+                default:
+                        return 0;
+        }
+}
+
+static int
+_is_cpqarray_major (int major)
+{
+        return ((COMPAQ_SMART2_MAJOR <= major && major <= COMPAQ_SMART2_MAJOR7)
+             || (COMPAQ_SMART_MAJOR <= major && major <= COMPAQ_SMART_MAJOR7));
+}
+
+static int
+_is_i2o_major (int major)
+{
+        return (I2O_MAJOR1 <= major && major <= I2O_MAJOR8);
+}
+
+static int
+_is_sx8_major (int major)
+{
+        return (SX8_MAJOR1 <= major && major <= SX8_MAJOR2);
+}
+
+static int
 _is_virtblk_major (int major)
 {
-        return _is_major_type (major, "virtblk");
+        return _major_type_in_devices (major, "virtblk");
 }
 
 #ifdef ENABLE_DEVICE_MAPPER
 static int
 _is_dm_major (int major)
 {
-        return _is_major_type (major, "device-mapper");
+        return _major_type_in_devices (major, "device-mapper");
 }
 
 static int

commit 42d3ba0f1f49f1a864aeb45528a35a7ffd8eecf8
Author: Joel Granados Moreno <jgranado at redhat.com>
Date:   Wed May 13 17:24:30 2009 +0200

    Correctly name virtio devices.
    
    * include/parted/device.h (PedDeviceType): Add a new PED_DEVICE_VIRTBLK
    type to the list.
    * libparted/arch/linux.c (_is_dm_major): Modify this function so it
    calls the new _is_major_type function with type "device-mapper".
    * libparted/arch/linux.c (_is_major_type): Searches a major number
    inside /proc/devices based on a "type" string.
    * libparted/arch/linux.c (_is_virtblk_major): New function.  Calls
    _is_major_type with type "virtblk".
    * libparted/arch/linux.c (_device_probe_type): Add a new
    PED_DEVICE_VIRTBLK case to the probe possibilities.
    * libparted/arch/linux.c (linux_new): Add a new PED_DEVICE_VIRTBLK case
    to the possible device types.
    * parted/parted.c (do_print): add the "virtblk" string to the transport
    array.

diff --git a/include/parted/device.h b/include/parted/device.h
index 5636ce8..151305f 100644
--- a/include/parted/device.h
+++ b/include/parted/device.h
@@ -45,7 +45,8 @@ typedef enum {
         PED_DEVICE_SX8          = 11,
         PED_DEVICE_DM           = 12,
         PED_DEVICE_XVD          = 13,
-        PED_DEVICE_SDMMC        = 14
+        PED_DEVICE_SDMMC        = 14,
+        PED_DEVICE_VIRTBLK      = 15
 } PedDeviceType;
 
 typedef struct _PedDevice PedDevice;
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index b113c37..7b3f3d0 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -322,45 +322,6 @@ _is_sx8_major (int major)
         return (SX8_MAJOR1 <= major && major <= SX8_MAJOR2);
 }
 
-#ifdef ENABLE_DEVICE_MAPPER
-static int
-_dm_maptype (PedDevice *dev)
-{
-        LinuxSpecific*  arch_specific = LINUX_SPECIFIC (dev);
-        struct dm_task *dmt;
-        void *next;
-        uint64_t start, length;
-        char *target_type = NULL;
-        char *params;
-        int r = -1;
-        const char* dev_dir = getenv ("DM_DEV_DIR");
-
-        if (dev_dir && *dev_dir && !dm_set_dev_dir(dev_dir))
-                return r;
-
-        if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
-                return r;
-
-        if (!dm_task_set_name(dmt, dev->path))
-                goto bad;
-
-        dm_task_no_open_count(dmt);
-
-        if (!dm_task_run(dmt))
-                goto bad;
-
-        next = dm_get_next_target(dmt, NULL, &start, &length,
-                                  &target_type, &params);
-
-        arch_specific->dmtype = strdup(target_type ? target_type : "NO-TARGET");
-        if (arch_specific->dmtype == NULL)
-                goto bad;
-        r = 0;
-bad:
-        dm_task_destroy(dmt);
-        return r;
-}
-
 static int
 readFD (int fd, char **buf)
 {
@@ -398,7 +359,7 @@ readFD (int fd, char **buf)
 }
 
 static int
-_is_dm_major (int major)
+_is_major_type (int major, const char* type)
 {
         int fd;
         char* buf = NULL;
@@ -432,7 +393,7 @@ _is_dm_major (int major)
                 }
 
                 name = strrchr(line, ' ');
-                if (!name || strcmp(name+1, "device-mapper"))
+                if (!name || strcmp(name+1, type))
                         goto next;
 
                 maj = strtol(line, &name, 10);
@@ -453,6 +414,58 @@ next:
 }
 
 static int
+_is_virtblk_major (int major)
+{
+        return _is_major_type (major, "virtblk");
+}
+
+#ifdef ENABLE_DEVICE_MAPPER
+static int
+_is_dm_major (int major)
+{
+        return _is_major_type (major, "device-mapper");
+}
+
+static int
+_dm_maptype (PedDevice *dev)
+{
+        LinuxSpecific*  arch_specific = LINUX_SPECIFIC (dev);
+        struct dm_task *dmt;
+        void *next;
+        uint64_t start, length;
+        char *target_type = NULL;
+        char *params;
+        int r = -1;
+        const char* dev_dir = getenv ("DM_DEV_DIR");
+
+        if (dev_dir && *dev_dir && !dm_set_dev_dir(dev_dir))
+                return r;
+
+        if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
+                return r;
+
+        if (!dm_task_set_name(dmt, dev->path))
+                goto bad;
+
+        dm_task_no_open_count(dmt);
+
+        if (!dm_task_run(dmt))
+                goto bad;
+
+        next = dm_get_next_target(dmt, NULL, &start, &length,
+                                  &target_type, &params);
+
+        arch_specific->dmtype = strdup(target_type ? target_type : "NO-TARGET");
+        if (arch_specific->dmtype == NULL)
+                goto bad;
+        r = 0;
+bad:
+        dm_task_destroy(dmt);
+        return r;
+}
+
+
+static int
 _probe_dm_devices ()
 {
        DIR*            mapper_dir;
@@ -561,6 +574,8 @@ _device_probe_type (PedDevice* dev)
                 dev->type = PED_DEVICE_XVD;
         } else if (dev_major == SDMMC_MAJOR && (dev_minor % 0x08 == 0)) {
                 dev->type = PED_DEVICE_SDMMC;
+        } else if (_is_virtblk_major(dev_major)) {
+                dev->type = PED_DEVICE_VIRTBLK;
         } else {
                 dev->type = PED_DEVICE_UNKNOWN;
         }
@@ -1315,6 +1330,10 @@ linux_new (const char* path)
                 if (!init_sdmmc (dev))
                         goto error_free_arch_specific;
                 break;
+        case PED_DEVICE_VIRTBLK:
+                if (!init_generic(dev, _("Virtio Block Device")))
+                        goto error_free_arch_specific;
+                break;
 
         default:
                 ped_exception_throw (PED_EXCEPTION_NO_FEATURE,
diff --git a/parted/parted.c b/parted/parted.c
index 5f2f2aa..ac1b176 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -1271,7 +1271,7 @@ do_print (PedDevice** dev)
         const char *const transport[] = {"unknown", "scsi", "ide", "dac960",
                                          "cpqarray", "file", "ataraid", "i2o",
                                          "ubd", "dasd", "viodasd", "sx8", "dm",
-                                         "xvd", "sd/mmc"};
+                                         "xvd", "sd/mmc", "virtblk"};
         char*           peek_word;
         char*           start;
         char*           end;



More information about the Parted-commits mailing list