On 12/06/2011 04:50 PM, Jim Meyering wrote: > Thanks for the reminder. > Can you write a test to exercise that patch, now? > > IMHO, any significant bug-fix or change in parted > should be accompanied by a test suite addition that exercises it.
How does this look?
From 2ad7e382da8bb193c8178c4d733096735231599a Mon Sep 17 00:00:00 2001 From: Phillip Susi <[email protected]> Date: Tue, 6 Dec 2011 23:20:50 -0500 Subject: [PATCH] Add partition separator only when required Device mapper type should not automatically mean add 'p' before the partition number. Fall back to adding it only if the previous character is a digit. This complies with kpartx behavior and linux behavior "since the dawn of time". --- libparted/arch/linux.c | 6 ++- tests/Makefile.am | 1 + tests/t6001-psep.sh | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 tests/t6001-psep.sh diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c index 69878e3..e7166a8 100644 --- a/libparted/arch/linux.c +++ b/libparted/arch/linux.c @@ -2241,7 +2241,6 @@ _device_get_part_path (PedDevice *dev, int num) char const *p = (dev->type == PED_DEVICE_DAC960 || dev->type == PED_DEVICE_CPQARRAY || dev->type == PED_DEVICE_ATARAID - || dev->type == PED_DEVICE_DM || isdigit (dev->path[path_len - 1]) ? "p" : ""); result = zasprintf ("%s%s%d", dev->path, p, num); @@ -2793,7 +2792,10 @@ _dm_add_partition (PedDisk* disk, PedPartition* part) dev_name = dm_task_get_name (task); - if ( ! (vol_name = zasprintf ("%sp%d", dev_name, part->num))) + if (isdigit (dev_name[strlen (dev_name) - 1])) { + if ( ! (vol_name = zasprintf ("%sp%d", dev_name, part->num))) + goto err; + } else if ( ! (vol_name = zasprintf ("%s%d", dev_name, part->num))) goto err; /* Caution: dm_task_destroy frees dev_name. */ diff --git a/tests/Makefile.am b/tests/Makefile.am index 616684e..89162ba 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -49,6 +49,7 @@ TESTS = \ t4300-nilfs2-tiny.sh \ t5000-tags.sh \ t6000-dm.sh \ + t6001-psep.sh \ t6100-mdraid-partitions.sh \ t7000-scripting.sh \ t8000-loop.sh \ diff --git a/tests/t6001-psep.sh b/tests/t6001-psep.sh new file mode 100644 index 0000000..45cdc3c --- /dev/null +++ b/tests/t6001-psep.sh @@ -0,0 +1,87 @@ +#!/bin/sh +# ensure that parted names partitions on dm disks correctly + +# Copyright (C) 2008-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_root_ +lvm_init_root_dir_ + +test "x$ENABLE_DEVICE_MAPPER" = xyes \ + || skip_ "no device-mapper support" + +# Device maps names - should be random to not conflict with existing ones on +# the system +linear_=plinear-$$ +linear2_=plinear-$$foo + +d1= d2= +f1= f2= +cleanup_fn_() { + dmsetup remove ${linear_}p1 + dmsetup remove $linear_ + dmsetup remove ${linear2_}1 + dmsetup remove $linear2_ + test -n "$d1" && losetup -d "$d1" + test -n "$d2" && losetup -d "$d2" + rm -f "$f1 $f2"; +} + +# create a file of size N bytes +N=10M + +# create the test file +f1=$(pwd)/1; dd if=/dev/null of=$f1 bs=1 seek=$N 2> /dev/null || fail=1 +f2=$(pwd)/2; dd if=/dev/null of=$f2 bs=1 seek=$N 2> /dev/null || fail=1 + +d1=$(loop_setup_ "$f1") \ + || skip_ "is this partition mounted with 'nodev'?" + +d2=$(loop_setup_ "$f2") \ + || skip_ "is this partition mounted with 'nodev'?" + +dmsetup_cmd="0 `blockdev --getsz $d1` linear $d1 0" +# setup: create a mapping +echo "$dmsetup_cmd" | dmsetup create "$linear_" || fail=1 +dev="$DM_DEV_DIR/mapper/$linear_" + +# Create msdos partition table +parted -s $dev mklabel msdos > out 2>&1 || fail=1 +compare /dev/null out || fail=1 + +parted -s $dev mkpart primary fat32 1m 5m > out 2>&1 || fail=1 +compare /dev/null out || fail=1 + +#make sure device name is correct +test -e ${dev}p1 || fail=1 + +#repeat on name not ending in a digit +# setup: create a mapping +echo "$dmsetup_cmd" | dmsetup create "$linear2_" || fail=1 +dev="$DM_DEV_DIR/mapper/$linear2_" + +# Create msdos partition table +parted -s $dev mklabel msdos > out 2>&1 || fail=1 +compare /dev/null out || fail=1 + +parted -s $dev mkpart primary fat32 1m 5m > out 2>&1 || fail=1 +compare /dev/null out || fail=1 + +#make sure device name is correct +test -e ${dev}1 || fail=1 + +Exit $fail -- 1.7.5.4
signature.asc
Description: OpenPGP digital signature

