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

Jim Meyering meyering at alioth.debian.org
Wed Feb 10 16:48:57 UTC 2010


 NEWS                                       |   15 +++++
 libparted/arch/linux.c                     |   42 ++++++++++----
 libparted/device.c                         |   30 ++++++++--
 libparted/labels/dasd.c                    |    2 
 parted/parted.c                            |   87 ++++++++++++++++++++++++++---
 tests/t0220-gpt-msftres.sh                 |    4 -
 tests/t0280-gpt-corrupt.sh                 |    6 +-
 tests/t2100-mkswap.sh                      |   14 ++--
 tests/t2200-dos-label-recog.sh             |   11 ++-
 tests/t2300-dos-label-extended-bootcode.sh |   12 ++--
 tests/t3000-resize-fs.sh                   |    4 -
 tests/t4100-msdos-partition-limits.sh      |   18 ------
 tests/t4100-msdos-starting-sector.sh       |   10 +--
 tests/t5000-tags.sh                        |    6 +-
 tests/t8000-loop.sh                        |    1 
 tests/t9021-maxima.sh                      |    1 
 16 files changed, 190 insertions(+), 73 deletions(-)

New commits:
commit b854c9e0e0b56b560a692548b77a942a57856e1a
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Wed Feb 10 14:13:01 2010 +0100

    dasd: don't dereference a NULL pointer in dasd_read
    
    * libparted/labels/dasd.c (dasd_read): Avoid NULL pointer dereference.

diff --git a/libparted/labels/dasd.c b/libparted/labels/dasd.c
index 4b5840b..516d189 100644
--- a/libparted/labels/dasd.c
+++ b/libparted/labels/dasd.c
@@ -399,7 +399,7 @@ dasd_read (PedDisk* disk)
 
 		if (strncmp(PART_TYPE_SWAP, str, 6) == 0) {
 			fs = ped_file_system_probe(&part->geom);
-			if (is_linux_swap(fs->name)) {
+			if (fs && is_linux_swap(fs->name)) {
 				dasd_data->system = PARTITION_LINUX_SWAP;
 				PDEBUG;
 			}

commit 78e0b016ba4ab0ab9a650ae4b8db8549cfd6e10b
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Wed Feb 10 15:19:18 2010 +0100

    parted: change default alignment to "optimal"
    
    * NEWS (Changes in behavior): Mention it.
    * parted/parted.c: Change --align default value to optimal.
    * tests/t2100-mkswap.sh: Adjust for alignment changes where necessary.
    * tests/t0220-gpt-msftres.sh: Likewise.
    * tests/t0280-gpt-corrupt.sh: Likewise.
    * tests/t2200-dos-label-recog.sh: Likewise.
    * tests/t2300-dos-label-extended-bootcode.sh: Likewise.
    * tests/t3000-resize-fs.sh: Likewise.
    * tests/t4100-msdos-partition-limits.sh: Likewise.
    * tests/t4100-msdos-starting-sector.sh: Likewise.
    * tests/t5000-tags.sh: Likewise.
    * tests/t8000-loop.sh: Likewise.
    * tests/t9021-maxima.sh: Likewise.

diff --git a/NEWS b/NEWS
index f13eba5..96ea96c 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,11 @@ GNU parted NEWS                                    -*- outline -*-
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** Changes in behavior
+
+  The default alignment (--align option) for newly created partitions has
+  been changed to optimal.
+
 ** New features
 
   The ped_device_get_*_alignment() functions now return a sane default
diff --git a/parted/parted.c b/parted/parted.c
index 2c7b469..44f8255 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -133,7 +133,7 @@ int     pretend_input_tty = 0;
 int     opt_machine_mode = 0;
 int     disk_is_modified = 0;
 int     is_toggle_mode = 0;
-int     alignment = ALIGNMENT_CYLINDER;
+int     alignment = ALIGNMENT_OPTIMAL;
 
 static const char* number_msg = N_(
 "NUMBER is the partition number used by Linux.  On MS-DOS disk labels, the "
diff --git a/tests/t0220-gpt-msftres.sh b/tests/t0220-gpt-msftres.sh
index 8ef885f..bbc415b 100755
--- a/tests/t0220-gpt-msftres.sh
+++ b/tests/t0220-gpt-msftres.sh
@@ -35,8 +35,8 @@ NTFS
 reiserfs
 '
 
-start=200
-part_size=100
+start=2048
+part_size=2048
 n_types=$(echo "$fs_types"|wc -w)
 
 # Create a "disk" with enough room for one partition per FS type,
diff --git a/tests/t0280-gpt-corrupt.sh b/tests/t0280-gpt-corrupt.sh
index 28c9035..5c48116 100755
--- a/tests/t0280-gpt-corrupt.sh
+++ b/tests/t0280-gpt-corrupt.sh
@@ -43,7 +43,7 @@ poke()
 dev=loop-file
 
 ss=$sector_size_
-n_sectors=200
+n_sectors=5000
 
 fail=0
 dd if=/dev/null of=$dev bs=$ss seek=$n_sectors || fail=1
@@ -62,7 +62,7 @@ printf "BYT;\n$dev:${n_sectors}s:file:$sector_size_:$sector_size_:gpt:;\n" \
 compare exp out || fail=1
 
 # create a partition
-parted -s $dev mkpart sw linux-swap 60s 100s > empty 2>&1 || fail=1
+parted -s $dev mkpart sw linux-swap 2048s 4095s > empty 2>&1 || fail=1
 compare /dev/null empty || fail=1
 
 # We're going to change the name of the first partition,
@@ -123,7 +123,7 @@ compare exp err || fail=1
 parted -m -s $dev u s print > out 2>&1 || fail=1
 
 # check for expected output
-printf "BYT;\nfile\n1:60s:100s:41s::foo:;\n" > exp || fail=1
+printf "BYT;\nfile\n1:2048s:4095s:2048s::foo:;\n" > exp || fail=1
 sed "s/.*gpt:;/file/" out > k && mv k out || fail=1
 compare exp out || fail=1
 
diff --git a/tests/t2100-mkswap.sh b/tests/t2100-mkswap.sh
index 1462e5d..1e4c444 100755
--- a/tests/t2100-mkswap.sh
+++ b/tests/t2100-mkswap.sh
@@ -27,7 +27,7 @@ require_512_byte_sector_size_
 # table, ensure that the proper file system type (0x82) is used.
 # Some releases, e.g. parted-1.8.8 would mistakenly use 0x83.
 ######################################################################
-N=1M
+N=2M
 dev=loop-file
 dev2=loop-file-2
 test_expect_success \
@@ -41,7 +41,7 @@ test_expect_success 'expect no output' 'compare out /dev/null'
 
 test_expect_success \
     'create a partition' \
-    'parted -s $dev mkpart primary 0 1 > out 2>&1'
+    'parted -s $dev mkpart primary 2048s 4095s > out 2>&1'
 test_expect_success 'expect no output' 'compare out /dev/null'
 
 test_expect_success \
@@ -66,7 +66,7 @@ test_expect_success 'expect no output' 'compare out /dev/null'
 
 test_expect_success \
     'create another partition' \
-    'parted -s $dev2 mkpart primary 0 1 > out 2>&1'
+    'parted -s $dev2 mkpart primary 2048s 4095s > out 2>&1'
 test_expect_success 'expect no output' 'compare out /dev/null'
 
 test_expect_success \
@@ -74,13 +74,13 @@ test_expect_success \
     'parted -s $dev2 mkfs 1 "linux-swap(v1)" > out 2>&1'
 test_expect_success 'expect no output' 'compare out /dev/null'
 
-# partition starts at offset 16384; swap UUID is 1036 bytes in
+# partition starts at offset 1048576; swap UUID is 1036 bytes in
 test_expect_success \
     'extract UUID 1' \
-    'od -t x1 -An -j17420 -N16 $dev > uuid1'
+    'od -t x1 -An -j1049612 -N16 $dev > uuid1'
 test_expect_success \
     'extract UUID 2' \
-    'od -t x1 -An -j17420 -N16 $dev2 > uuid2'
+    'od -t x1 -An -j1049612 -N16 $dev2 > uuid2'
 test_expect_failure \
     'two linux-swap file systems have different UUIDs' \
     'compare uuid1 uuid2'
@@ -92,7 +92,7 @@ test_expect_success 'expect no output' 'compare out /dev/null'
 
 test_expect_success \
     'extract new UUID 2' \
-    'od -t x1 -An -j17420 -N16 $dev2 > uuid2-new'
+    'od -t x1 -An -j1049612 -N16 $dev2 > uuid2-new'
 test_expect_success \
     'check preserves linux-swap UUID' \
     'compare uuid2 uuid2-new'
diff --git a/tests/t2200-dos-label-recog.sh b/tests/t2200-dos-label-recog.sh
index 1254226..92e6d42 100755
--- a/tests/t2200-dos-label-recog.sh
+++ b/tests/t2200-dos-label-recog.sh
@@ -25,11 +25,12 @@ test_description='improved MSDOS partition-table recognition'
 # parted 1.8.8.1.29 and earlier would fail to recognize a DOS
 # partition table.
 ######################################################################
-N=10M
+ss=$sector_size_
+N=8192
 dev=loop-file
 test_expect_success \
     'create a file to simulate the underlying device' \
-    'dd if=/dev/null of=$dev bs=1 seek=$N 2> /dev/null'
+    'dd if=/dev/null of=$dev bs=$ss seek=$N 2> /dev/null'
 
 test_expect_success \
     'label the test disk' \
@@ -39,8 +40,8 @@ test_expect_success 'expect no output' 'compare out /dev/null'
 test_expect_success \
     'create two partition' \
     '
-    parted -s $dev mkpart primary  1s 40s > out 2>&1 &&
-    parted -s $dev mkpart primary 41s 80s >> out 2>&1
+    parted -s $dev mkpart primary 2048s 4095s > out 2>&1 &&
+    parted -s $dev mkpart primary 4096s 8191s >> out 2>&1
 
     '
 test_expect_success 'expect no output' 'compare out /dev/null'
@@ -54,7 +55,7 @@ test_expect_success \
     '
     parted -m -s $dev unit s p > out &&
     tail -2 out > k && mv k out &&
-    printf "1:1s:40s:40s:::;\n2:41s:80s:40s:::;\n" > exp
+    printf "1:2048s:4095s:2048s:::;\n2:4096s:8191s:4096s:::;\n" > exp
 
     '
 test_expect_success 'expect two partitions' 'compare out exp'
diff --git a/tests/t2300-dos-label-extended-bootcode.sh b/tests/t2300-dos-label-extended-bootcode.sh
index 6f2b219..73fa45b 100755
--- a/tests/t2300-dos-label-extended-bootcode.sh
+++ b/tests/t2300-dos-label-extended-bootcode.sh
@@ -27,7 +27,7 @@ bootcode_size=446
 
 test_expect_success \
   'Create the test file' \
-  'dd if=/dev/zero of=$dev bs=1024c count=100 >/dev/null 2>&1'
+  'dd if=/dev/zero of=$dev bs=1M count=4 >/dev/null 2>&1'
 
 test_expect_success \
   'Create msdos label' \
@@ -36,23 +36,23 @@ test_expect_success 'Expect no output' 'compare out /dev/null'
 
 test_expect_success \
   'Create extended partition' \
-  'parted -s $dev mkpart extended 32s 127s > out 2>&1'
+  'parted -s $dev mkpart extended 2048s 8191s > out 2>&1'
 test_expect_success 'Expect no output' 'compare out /dev/null'
 
 test_expect_success \
   'Create logical partition' \
-  'parted -s $dev mkpart logical 64s 127s > out 2>&1'
+  'parted -s $dev mkpart logical 4096s 8191s > out 2>&1'
 test_expect_success 'Expect no output' 'compare out /dev/null'
 
 test_expect_success \
   'Install fake bootcode' \
   'printf %0${bootcode_size}d 0 > in &&
-   dd if=in of=$dev bs=1c seek=16384 count=$bootcode_size \
+   dd if=in of=$dev bs=1c seek=1M count=$bootcode_size \
       conv=notrunc > /dev/null 2>&1'
 
 test_expect_success \
   'Save fake bootcode for later comparison' \
-  'dd if=$dev of=before bs=1 skip=16384 count=$bootcode_size > /dev/null 2>&1'
+  'dd if=$dev of=before bs=1 skip=1M count=$bootcode_size > /dev/null 2>&1'
 
 test_expect_success \
   'Do something to the label' \
@@ -61,7 +61,7 @@ test_expect_success 'Expect no output' 'compare out /dev/null'
 
 test_expect_success \
   'Extract the bootcode for comparison' \
-  'dd if=$dev of=after bs=1 skip=16384 count=$bootcode_size > /dev/null 2>&1'
+  'dd if=$dev of=after bs=1 skip=1M count=$bootcode_size > /dev/null 2>&1'
 
 test_expect_success \
   'Expect bootcode has not changed' \
diff --git a/tests/t3000-resize-fs.sh b/tests/t3000-resize-fs.sh
index 2abc71b..d6af67d 100755
--- a/tests/t3000-resize-fs.sh
+++ b/tests/t3000-resize-fs.sh
@@ -64,8 +64,8 @@ for fs_type in hfs+ fat32; do
 
   # create an empty $fs_type partition, cylinder aligned, size > 256 MB
   parted -s $dev mkpart primary $fs_type $start $default_end > out 2>&1 || fail=1
-  # expect no output
-  compare out /dev/null || fail=1
+  echo "Warning: The resulting partition is not properly aligned for best performance." > exp
+  compare out exp || fail=1
 
   # print partition table
   parted -m -s $dev u s p > out 2>&1 || fail=1
diff --git a/tests/t4100-msdos-partition-limits.sh b/tests/t4100-msdos-partition-limits.sh
index 54cb73b..b63a534 100755
--- a/tests/t4100-msdos-partition-limits.sh
+++ b/tests/t4100-msdos-partition-limits.sh
@@ -102,27 +102,13 @@ test_expect_success \
     'check for new diagnostic' \
     'bad_part_length 4294967296 > exp && diff -u err exp'
 
-# FIXME: investigate this.
-# Unexpectedly to me, both of these failed with this same diagnostic:
-#
-#   Error: partition length of 4294967296 sectors exceeds the \
-#   DOS-partition-table-imposed maximum of 2^32-1" > exp &&
-#
-# I expected the one below to fail with a length of _4294967297_.
-# Debugging, I see that _check_partition *does* detect this,
-# but the diagnostic doesn't get displayed because of the wonders
-# of parted's exception mechanism.
-
 test_expect_failure \
     "$table_type: a partition length of 2^32+1 sectors provokes failure." \
     'do_mkpart $n $(echo $n+2^32|bc) > err 2>&1'
 
-# FIXME: odd that we asked for 2^32+1, yet the diagnostic says 2^32
-# FIXME: Probably due to constraints.
-# FIXME: For now, just accept the current output.
 test_expect_success \
     'check for new diagnostic' \
-    'bad_part_length 4294967296 > exp && diff -u err exp'
+    'bad_part_length 4294967297 > exp && diff -u err exp'
 
 # =========================================================
 # Now consider partition starting sector numbers.
@@ -164,7 +150,7 @@ test_expect_failure \
     'do_mkpart_start_and_len $(echo 2^32+1|bc) 1000 > err 2>&1'
 test_expect_success \
     'check for new diagnostic' \
-    'bad_start_sector 4294967296 > exp && diff -u err exp'
+    'bad_start_sector 4294967297 > exp && diff -u err exp'
 
 done
 
diff --git a/tests/t4100-msdos-starting-sector.sh b/tests/t4100-msdos-starting-sector.sh
index 7761e75..3d0233b 100755
--- a/tests/t4100-msdos-starting-sector.sh
+++ b/tests/t4100-msdos-starting-sector.sh
@@ -27,7 +27,7 @@ ss=$sector_size_
 # consistent in the use of metadata padding for msdos labels.
 ######################################################################
 
-N=200 # number of sectors
+N=4096 # number of sectors
 dev=loop-file
 test_expect_success \
     'create a file to simulate the underlying device' \
@@ -43,7 +43,7 @@ fail=0
 cat <<EOF > exp || fail=1
 BYT;
 path:${N}s:file:$ss:$ss:msdos:;
-1:32s:127s:96s:free;
+1:32s:4095s:4064s:free;
 EOF
 
 test_expect_success 'create expected output file' 'test $fail = 0'
@@ -62,15 +62,15 @@ fail=0
 cat <<EOF > exp || fail=1
 BYT;
 path:${N}s:file:$ss:$ss:msdos:;
-1:32s:50s:19s:free;
-1:51s:199s:149s:::;
+1:32s:2047s:2016s:free;
+1:2048s:4095s:2048s:::;
 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 51s 199s'
+    'parted -s $dev mkpart primary 2048s 4095s'
 
 test_expect_success \
     'display output of label with partition' \
diff --git a/tests/t5000-tags.sh b/tests/t5000-tags.sh
index d1e9533..9b0a1cc 100755
--- a/tests/t5000-tags.sh
+++ b/tests/t5000-tags.sh
@@ -22,10 +22,10 @@ test_description="test bios_grub flag in gpt labels"
 ss=$sector_size_
 
 dev=loop-file
-N=300 # number of sectors
+N=4200 # number of sectors
 
-part_sectors=128
-start_sector=60
+part_sectors=2048
+start_sector=2048
 end_sector=$(expr $start_sector + $part_sectors - 1)
 
 test_expect_success \
diff --git a/tests/t8000-loop.sh b/tests/t8000-loop.sh
index 313e3b8..cba3454 100755
--- a/tests/t8000-loop.sh
+++ b/tests/t8000-loop.sh
@@ -25,6 +25,7 @@ fi
 . $srcdir/t-lib.sh
 
 require_root_
+lvm_init_root_dir_
 
 d1= f1=
 cleanup_()
diff --git a/tests/t9021-maxima.sh b/tests/t9021-maxima.sh
index eb44eea..f408810 100755
--- a/tests/t9021-maxima.sh
+++ b/tests/t9021-maxima.sh
@@ -26,6 +26,7 @@ fi
 ss=$sector_size_
 
 fail=0
+ss=$sector_size_
 dev=dev-file
 PATH="..:$PATH"
 export PATH

commit d931c6d515702c8402a2fbf8552e55d8a28a2aa4
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Wed Feb 10 14:12:59 2010 +0100

    parted: change warnings when initial constrained mkpart fails
    
    In do_mkpart we first try to create a partition using a constraint
    derived from the user input intersected with the devices alignment
    needs. And if that fails we try again without any constraint.
    
    However the warning given when this happens only takes into account
    the user not getting what he asked for, while the alignment might be
    a problem too (or even the only problem). So this patch adds a check
    to see if the user really did not get what he asked before giving that
    warning, and adds a new check + warning to see if the created partition
    is properly aligned.
    *parted/parted.c (do_mkpart,do_mkpartfs): change warnings when initial
    constrained mkpart fails.

diff --git a/parted/parted.c b/parted/parted.c
index 69451a8..2c7b469 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -178,6 +178,8 @@ static TimerContext timer_context;
 
 static int _print_list ();
 static void _done (PedDevice* dev);
+static bool partition_align_check (PedDisk const *disk,
+                        PedPartition const *part, enum AlignmentType a_type);
 
 static void
 _timer_handler (PedTimer* timer, void* context)
@@ -833,7 +835,12 @@ do_mkpart (PedDevice** dev)
                 added_ok = ped_disk_add_partition (disk, part,
                                                         constraint_any);
                 ped_constraint_destroy (constraint_any);
-                if (added_ok) {
+
+                if (!added_ok)
+                        goto error_remove_part;
+
+                if (!ped_geometry_test_sector_inside(range_start, part->geom.start) ||
+                    !ped_geometry_test_sector_inside(range_end, part->geom.end)) {
                         start_usr = ped_unit_format (*dev, start);
                         end_usr   = ped_unit_format (*dev, end);
                         start_sol = ped_unit_format (*dev, part->geom.start);
@@ -867,8 +874,23 @@ do_mkpart (PedDevice** dev)
                                         /* undo partition addition */
                                         goto error_remove_part;
                         }
-                } else {
-                        goto error_remove_part;
+                }
+
+                if ((alignment == ALIGNMENT_OPTIMAL &&
+                     !partition_align_check(disk, part, PA_OPTIMUM)) ||
+                    (alignment == ALIGNMENT_MINIMAL &&
+                     !partition_align_check(disk, part, PA_MINIMUM))) {
+                        if (ped_exception_throw(
+                                PED_EXCEPTION_WARNING,
+                                (opt_script_mode
+                                 ? PED_EXCEPTION_OK
+                                 : PED_EXCEPTION_IGNORE_CANCEL),
+                                _("The resulting partition is not properly "
+                                  "aligned for best performance.")) ==
+                            PED_EXCEPTION_CANCEL) {
+                                /* undo partition addition */
+                                goto error_remove_part;
+                        }
                 }
         } else {
                 ped_exception_leave_all();
@@ -1018,8 +1040,16 @@ do_mkpartfs (PedDevice** dev)
         if (!added_ok) {
                 ped_exception_leave_all();
 
-                if (ped_disk_add_partition (disk, part,
-                                        ped_constraint_any (*dev))) {
+                PedConstraint *constraint_any = ped_constraint_any (*dev);
+                bool added_ok = ped_disk_add_partition (disk, part,
+                                                        constraint_any);
+                ped_constraint_destroy (constraint_any);
+
+                if (!added_ok)
+                        goto error_remove_part;
+
+                if (!ped_geometry_test_sector_inside(range_start, part->geom.start) ||
+                    !ped_geometry_test_sector_inside(range_end, part->geom.end)) {
                         start_usr = ped_unit_format (*dev, start);
                         end_usr   = ped_unit_format (*dev, end);
                         start_sol = ped_unit_format (*dev, part->geom.start);
@@ -1048,8 +1078,23 @@ do_mkpartfs (PedDevice** dev)
                                         /* undo partition addition */
                                         goto error_remove_part;
                         }
-                } else {
-                        goto error_remove_part;
+                }
+
+                if ((alignment == ALIGNMENT_OPTIMAL &&
+                     !partition_align_check(disk, part, PA_OPTIMUM)) ||
+                    (alignment == ALIGNMENT_MINIMAL &&
+                     !partition_align_check(disk, part, PA_MINIMUM))) {
+                        if (ped_exception_throw(
+                                PED_EXCEPTION_WARNING,
+                                (opt_script_mode
+                                 ? PED_EXCEPTION_OK
+                                 : PED_EXCEPTION_IGNORE_CANCEL),
+                                _("The resulting partition is not properly "
+                                  "aligned for best performance.")) ==
+                            PED_EXCEPTION_CANCEL) {
+                                /* undo partition addition */
+                                goto error_remove_part;
+                        }
                 }
         } else {
                 ped_exception_leave_all();

commit e7d2c001d060b81e4055fcd567fc96b523d93f08
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Sat Jan 30 17:53:50 2010 +0100

    parted: honor --align option also in mkpartfs, resize and print cmds
    
    * parted/parted.c (do_mkpartfs,do_print,do_resize): Honor --align.

diff --git a/parted/parted.c b/parted/parted.c
index 06b9f6c..69451a8 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -949,6 +949,11 @@ do_mkpartfs (PedDevice** dev)
         if (!disk)
                 goto error;
 
+        if (ped_disk_is_flag_available(disk, PED_DISK_CYLINDER_ALIGNMENT))
+                if (!ped_disk_set_flag(disk, PED_DISK_CYLINDER_ALIGNMENT,
+                                       alignment == ALIGNMENT_CYLINDER))
+                        goto error_destroy_disk;
+
         if (!ped_disk_type_check_feature (disk->type, PED_DISK_TYPE_EXTENDED)) {
                 part_type = PED_PARTITION_NORMAL;
         } else {
@@ -989,7 +994,14 @@ do_mkpartfs (PedDevice** dev)
                                                                 range_end);
         PED_ASSERT (user_constraint != NULL, return 0);
 
-        dev_constraint = ped_device_get_constraint (*dev);
+        if (alignment == ALIGNMENT_OPTIMAL)
+                dev_constraint =
+                        ped_device_get_optimal_aligned_constraint(*dev);
+        else if (alignment == ALIGNMENT_MINIMAL)
+                dev_constraint =
+                        ped_device_get_minimal_aligned_constraint(*dev);
+        else
+                dev_constraint = ped_device_get_constraint(*dev);
         PED_ASSERT (dev_constraint != NULL, return 0);
 
         final_constraint = ped_constraint_intersect (user_constraint,
@@ -1352,6 +1364,11 @@ do_print (PedDevice** dev)
         if (!disk)
                 goto error;
 
+        if (ped_disk_is_flag_available(disk, PED_DISK_CYLINDER_ALIGNMENT))
+                if (!ped_disk_set_flag(disk, PED_DISK_CYLINDER_ALIGNMENT,
+                                       alignment == ALIGNMENT_CYLINDER))
+                        goto error_destroy_disk;
+
         peek_word = command_line_peek_word ();
         if (peek_word) {
                 if (strncmp (peek_word, "devices", 7) == 0) {
@@ -1634,6 +1651,8 @@ do_print (PedDevice** dev)
 
         return 1;
 
+error_destroy_disk:
+        ped_disk_destroy (disk);
 error:
         return 0;
 }
@@ -1861,6 +1880,11 @@ do_resize (PedDevice** dev)
         if (!disk)
                 goto error;
 
+        if (ped_disk_is_flag_available(disk, PED_DISK_CYLINDER_ALIGNMENT))
+                if (!ped_disk_set_flag(disk, PED_DISK_CYLINDER_ALIGNMENT,
+                                       alignment == ALIGNMENT_CYLINDER))
+                        goto error_destroy_disk;
+
         if (!command_line_get_partition (_("Partition number?"), disk, &part))
                 goto error_destroy_disk;
         if (part->type != PED_PARTITION_EXTENDED) {

commit 5fd88ebfcf9d2fd4c312e26fc69b8e4f09a7e1d5
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Sat Jan 30 17:53:49 2010 +0100

    linux: handle incomplete topology information
    
    The topology information returned by libblkid is not always complete
    (as the kernel does not always have complete information).
    This patch makes the linux_get_*_alignment() alignment functions handle
    this. The algorithm used for linux_get_optimum_alignment is:
    1) Always use the reported aligment offset as offset
    2a)If optimal io size is present in the topology info use that as grain
    2b)If optimal io size is not present in topology info and aligment
       offset is 0 and minimum io size is a power of 2, use the device.c
       default optimal alignment (grain 1MiB).
    2c) If neither 2a and 2b, use the minimum io size, or if that is not
       defined, use the physical sector size as grain (iow the minimum
       alignment).
    The algorithm used for linux_get_minimum_alignment is:
    1) Always use the reported aligment offset as offset
    2) Use the minimum io size, or if that is not defined the physical
       sector size as grain.
    * libparted/arch/linux.c (linux_get_*_alignment): Handle incomplete
    topology information.

diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 4b7b9f5..a083028 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2564,9 +2564,14 @@ PedAlignment*
 linux_get_minimum_alignment(const PedDevice *dev)
 {
         blkid_topology tp = LINUX_SPECIFIC(dev)->topology;
+        if (!tp)
+                return NULL;
 
-        if (!tp || blkid_topology_get_minimum_io_size(tp) == 0)
-                return NULL; /* ped_alignment_none */
+        if (blkid_topology_get_minimum_io_size(tp) == 0)
+                return ped_alignment_new(
+                        blkid_topology_get_alignment_offset(tp) /
+                                dev->sector_size,
+                        dev->phys_sector_size / dev->sector_size);
 
         return ped_alignment_new(
                 blkid_topology_get_alignment_offset(tp) / dev->sector_size,
@@ -2577,9 +2582,21 @@ PedAlignment*
 linux_get_optimum_alignment(const PedDevice *dev)
 {
         blkid_topology tp = LINUX_SPECIFIC(dev)->topology;
+        if (!tp)
+                return NULL;
+
+        /* If optimal_io_size is 0 _and_ alignment_offset is 0 _and_
+           minimum_io_size is a power of 2 then go with the device.c default */
+        unsigned long minimum_io_size = blkid_topology_get_minimum_io_size(tp);
+        if (blkid_topology_get_optimal_io_size(tp) == 0 &&
+            blkid_topology_get_alignment_offset(tp) == 0 &&
+            (minimum_io_size & (minimum_io_size - 1)) == 0)
+                return NULL;
 
-        if (!tp || blkid_topology_get_optimal_io_size(tp) == 0)
-                return NULL; /* ped_alignment_none */
+        /* If optimal_io_size is 0 and we don't meet the other criteria
+           for using the device.c default, return the minimum alignment. */
+        if (blkid_topology_get_optimal_io_size(tp) == 0)
+                return linux_get_minimum_alignment(dev);
 
         return ped_alignment_new(
                 blkid_topology_get_alignment_offset(tp) / dev->sector_size,

commit e493fba67b26f14f5bfd2ffaceb22a9c26b7a194
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Sat Jan 30 17:53:48 2010 +0100

    libparted: Give device_get_*_alignment sane defaults
    
    When the topology info is incomplete or non existent, return something
    more sensible than NULL (which ends up being interpreted as
    PedAlignmentAny in most cases). The default minimum alignment aligns to
    physical sector size, the default optimal alignment is 1 MiB, which is
    what vista and windows 7 do.
    * libparted/device.c (device_get_*_alignment): Add default aligments.
    * NEWS (New features): Mention it.

diff --git a/NEWS b/NEWS
index dcbc817..f13eba5 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,13 @@ GNU parted NEWS                                    -*- outline -*-
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** New features
+
+  The ped_device_get_*_alignment() functions now return a sane default
+  value instead of NULL when the so called topology information is incomplete.
+  The default minimum alignment aligns to physical sector size, the default
+  optimal alignment is 1MiB, which is what vista and windows 7 do.
+
 ** Bug fixes
 
   Parted no longer uses a physical sector size of 0 or of any other
diff --git a/libparted/device.c b/libparted/device.c
index dda8d74..0f36a03 100644
--- a/libparted/device.c
+++ b/libparted/device.c
@@ -501,10 +501,16 @@ ped_device_get_optimal_aligned_constraint(const PedDevice *dev)
 PedAlignment*
 ped_device_get_minimum_alignment(const PedDevice *dev)
 {
+        PedAlignment *align = NULL;
+
         if (ped_architecture->dev_ops->get_minimum_alignment)
-                return ped_architecture->dev_ops->get_minimum_alignment(dev);
+                align = ped_architecture->dev_ops->get_minimum_alignment(dev);
+
+        if (align == NULL)
+                align = ped_alignment_new(0,
+                                dev->phys_sector_size / dev->sector_size);
 
-        return NULL; /* ped_alignment_none */
+        return align;
 }
 
 /**
@@ -521,10 +527,26 @@ ped_device_get_minimum_alignment(const PedDevice *dev)
 PedAlignment*
 ped_device_get_optimum_alignment(const PedDevice *dev)
 {
+        PedAlignment *align = NULL;
+
         if (ped_architecture->dev_ops->get_optimum_alignment)
-                return ped_architecture->dev_ops->get_optimum_alignment(dev);
+                align = ped_architecture->dev_ops->get_optimum_alignment(dev);
+
+        /* If the arch specific code could not give as an alignment
+           return a default value based on the type of device. */
+        if (align == NULL) {
+                switch (dev->type) {
+                case PED_DEVICE_DASD:
+                        align = ped_device_get_minimum_alignment(dev);
+                        break;
+                default:
+                        /* Align to a grain of 1MiB (like vista / win7) */
+                        align = ped_alignment_new(0,
+                                                  1048576 / dev->sector_size);
+                }
+        }
 
-        return NULL; /* ped_alignment_none */
+        return align;
 }
 
 /** @} */

commit 92c7aa408ec950ffc8e0823df6a333dd77920643
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Sat Jan 30 17:53:47 2010 +0100

    linux: correct phys_sector_size setting
    
    1) Use the logical sector size as physical sector size instead of 512
       when not compiled with libblkid support, this fixes problems
       with logical sector size > physical sector size.
    2) blkid_topology_get_physical_sector_size() returns 0 when it fails
       to determine the physical sector size, handle this.
    * libparted/arch/linux.c (_device_set_sector_size): Correct
    phys_sector_size setting.
    * NEWS (Bug fixes): Mention it.

diff --git a/NEWS b/NEWS
index e6a491c..dcbc817 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,9 @@ GNU parted NEWS                                    -*- outline -*-
 
 ** Bug fixes
 
+  Parted no longer uses a physical sector size of 0 or of any other
+  value smaller than the logical sector size.
+
   gpt: read-only operation could clobber MBR part of hybrid GPT+MBR table
   [bug introduced in parted-2.1]
 
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index f3b54f0..4b7b9f5 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -654,22 +654,27 @@ _device_set_sector_size (PedDevice* dev)
                         dev->path, strerror (errno), PED_SECTOR_SIZE_DEFAULT);
         } else {
                 dev->sector_size = (long long)sector_size;
+                dev->phys_sector_size = dev->sector_size;
         }
 
 #if USE_BLKID
         get_blkid_topology(arch_specific);
         if (!arch_specific->topology) {
-                ped_exception_throw (
-                        PED_EXCEPTION_WARNING,
-                        PED_EXCEPTION_OK,
-                        _("Could not determine minimum io size for %s: %s.\n"
-                          "Using the default size (%lld)."),
-                        dev->path, strerror (errno), PED_SECTOR_SIZE_DEFAULT);
+                dev->phys_sector_size = 0;
         } else {
                 dev->phys_sector_size =
                         blkid_topology_get_physical_sector_size(
                                 arch_specific->topology);
         }
+        if (dev->phys_sector_size == 0) {
+                ped_exception_throw (
+                        PED_EXCEPTION_WARNING,
+                        PED_EXCEPTION_OK,
+                        _("Could not determine physical sector size for %s.\n"
+                          "Using the logical sector size (%lld)."),
+                        dev->path, dev->sector_size);
+                dev->phys_sector_size = dev->sector_size;
+        }
 #endif
 
 #if defined __s390__ || defined __s390x__



More information about the Parted-commits mailing list