]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: (functions.sh) add a helper funcion making a device number from given major...
authorMasatake YAMATO <yamato@redhat.com>
Wed, 10 Apr 2024 09:36:47 +0000 (18:36 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Mon, 15 Apr 2024 09:17:09 +0000 (18:17 +0900)
Fixes #2919.
Suggested by Karel Zak <kzak@redhat.com>.

The original code used an obsolete formula to make a device number from
given major and minor numbers.

ts_device_make is a new helper function based on the formula of
__SYSMACROS_DEFINE_MAKEDEV macro defined in
/usr/include/bits/sysmacros.h of GNU libc.

Suggested by Karel Zak <kzak@redhat.com> in #2919.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
tests/functions.sh
tests/ts/lsfd/lsfd-functions.bash

index 5fe5ba07fd90c59dae993e73b5fe7de24fec26c2..4a00b2ff4e97db9bbb1f267c51260860ac2de1f6 100644 (file)
@@ -788,6 +788,21 @@ function ts_device_has {
        return $res
 }
 
+# Based on __SYSMACROS_DEFINE_MAKEDEV macro
+# defined in /usr/include/bits/sysmacros.h of GNU libc.
+function ts_makedev
+{
+       local major="$1"
+       local minor="$2"
+       local dev
+
+       dev=$((      ( major & 0x00000fff ) <<  8))
+       dev=$((dev | ( major & 0xfffff000 ) << 32))
+       dev=$((dev | ( minor & 0x000000ff ) <<  0))
+       dev=$((dev | ( minor & 0xffffff00 ) << 12))
+       echo $dev
+}
+
 function ts_is_uuid()
 {
        printf "%s\n" "$1" | grep -E -q '^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$'
index 3a3f58f0c890fd34718205a39986200b7c53455e..533c25faed7977759f9d6a7395045fa95b7cbc20 100644 (file)
@@ -44,7 +44,7 @@ function lsfd_compare_dev {
     echo 'DEV[RUN]:' $?
     local MAJ=${DEV%:*}
     local MIN=${DEV#*:}
-    local DEVNUM=$(( ( MAJ << 8 ) + MIN ))
+    local DEVNUM=$(ts_makedev "$MAJ" "$MIN")
     local STAT_DEVNUM=$(stat -c "%d" "$FILE")
     echo 'STAT[RUN]:' $?
     if [ "${DEVNUM}" == "${STAT_DEVNUM}" ]; then