[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#640943: [PATCH] dm_dev_is_safe: Handle different output formats for "dmsetup table"



The output of "dmsetup table" is formatted either as

  target: logical_start_sector num_sectors target_type target_args

or

  logical_start_sector num_sectors target_type target_args

depending on how the command is invoked.  When called with -j/-m, the target
is not supposed to be shown, but version 1.02.65 had a bug which caused the
target to be shown and therefore broke dm_dev_is_safe's parsing.

Although the format was fixed in 1.02.66, changing the parsing to handle both
formats is safer.

Signed-off-by: James Vega <jamessan@debian.org>
---
 lib/crypto-base.sh |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/crypto-base.sh b/lib/crypto-base.sh
index b3691f5..4877f51 100644
--- a/lib/crypto-base.sh
+++ b/lib/crypto-base.sh
@@ -114,8 +114,8 @@ dm_dev_is_safe() {
 	min="$2"
 
 	# First try the device itself
-	dminfo=$(dmsetup table -j$maj -m$min 2> /dev/null | \
-		 head -n1 | cut -d' ' -f3) || return 1
+	dminfo=$(dmsetup table -j$maj -m$min 2> /dev/null | head -n1 | \
+		 sed -e 's/^[^ :]*: //' | cut -d' ' -f3) || return 1
 	if [ "$dminfo" = crypt ]; then
 		return 0
 	fi
-- 
1.7.5.4




Reply to: