]> err.no Git - util-linux/commitdiff
tests: add functions for label, uuid and fstype detection
authorKarel Zak <kzak@redhat.com>
Thu, 17 May 2007 18:16:25 +0000 (20:16 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 18 May 2007 11:09:12 +0000 (13:09 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
configure.ac
tests/commands.sh.in
tests/functions.sh

index 983ceab32bafa78f7cb46948dc6e4cf432eedff1..68ff7b01fd9804188712d3fbbfb3a57064890553 100644 (file)
@@ -29,6 +29,8 @@ AC_GNU_SOURCE
 AC_PROG_LIBTOOL
 
 AC_PATH_PROG(PERL, perl)
+AC_PATH_PROG(BLKID, blkid, [], [$PATH:/sbin])
+AC_PATH_PROG(VOLID, vol_id, [], [$PATH:/lib/udev])
 
 AC_SYS_LARGEFILE
 
index 9ed88a9c222340035394b1d92885c6ef93452096..26c7779182ec61859ba676523d292308a2144e1d 100644 (file)
@@ -4,6 +4,10 @@ TS_TOPDIR=$TOPDIR/tests
 # helpers
 TS_HELPER_SYSINFO="$TS_TOPDIR/helpers/mnt_test_sysinfo"
 
+# external commands
+TS_ECMD_BLKID="@BLKID@"
+TS_ECMD_VOLID="@VOLID@"
+
 # paths to commands
 TS_CMD_MOUNT=${TS_CMD_MOUNT:-"$TOPDIR/mount/mount"}
 TS_CMD_UMOUNT=${TS_CMD_UMOUNT:-"$TOPDIR/mount/umount"}
index 6c0658b1b29f55eb85a532a1ff116d9c07315671..7cb3743068eadc85c0a36fe17d654404bb7e0a48 100644 (file)
@@ -111,4 +111,53 @@ function ts_udev_loop_support {
        return 0
 }
 
-               
+function ts_uuid_by_devname {
+       local DEV="$1"
+       local UUID=""
+       if [ -x "$TS_ECMD_BLKID" ]; then
+               UUID=$($TS_ECMD_BLKID -c /dev/null -w /dev/null -s "UUID" $DEV | sed 's/.*UUID="//g; s/"//g')
+       elif [ -x "$TS_ECMD_VOLID" ]; then
+               UUID=$($TS_ECMD_VOLID -u $DEV)
+       fi
+       echo $UUID
+}
+
+function ts_label_by_devname {
+       local DEV="$1"
+       local TYPE=""
+       if [ -x "$TS_ECMD_BLKID" ]; then
+               LABEL=$($TS_ECMD_BLKID -c /dev/null -w /dev/null -s "LABEL" $DEV | sed 's/.*LABEL="//g; s/"//g')
+       elif [ -x "$TS_ECMD_VOLID" ]; then
+               LABEL=$($TS_ECMD_VOLID -l $DEV)
+       fi
+       echo $LABEL
+}
+
+function ts_fstype_by_devname {
+       local DEV="$1"
+       local TYPE=""
+       if [ -x "$TS_ECMD_BLKID" ]; then
+               TYPE=$($TS_ECMD_BLKID -c /dev/null -w /dev/null -s "TYPE" $DEV | sed 's/.*TYPE="//g; s/"//g')
+       elif [ -x "$TS_ECMD_VOLID" ]; then
+               TYPE=$($TS_ECMD_VOLID -t $DEV)
+       fi
+       echo $TYPE
+}
+
+function ts_device_has {
+       local TAG="$1"
+       local VAL="$2"
+       local DEV="$3"
+
+       case $TAG in
+               "TYPE") vl=$(ts_fstype_by_devname $DEV);;
+               "LABEL") vl=$(ts_label_by_devname $DEV);;
+               "UUID") vl=$(ts_uuid_by_devname $DEV);;
+               *) return 1;;
+       esac
+
+       if [ "$vl" == "$VAL" ]; then
+               return 0
+       fi
+       return 1
+}