13 Star 2 Fork 54

src-openEuler/util-linux

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-tests-functions.sh-add-a-helper-funcion-making-a-dev.patch 2.04 KB
一键复制 编辑 原始数据 按行查看 历史
From d4dea14933bc3ee750d6762a6f615d2a4fe24c34 Mon Sep 17 00:00:00 2001
From: Masatake YAMATO <yamato@redhat.com>
Date: Wed, 10 Apr 2024 18:36:47 +0900
Subject: [PATCH] tests: (functions.sh) add a helper funcion making a device
number from given major and minor nums
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 | 15 +++++++++++++++
tests/ts/lsfd/lsfd-functions.bash | 2 +-
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/tests/functions.sh b/tests/functions.sh
index 5fe5ba07f..4a00b2ff4 100644
--- a/tests/functions.sh
+++ b/tests/functions.sh
@@ -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}$'
diff --git a/tests/ts/lsfd/lsfd-functions.bash b/tests/ts/lsfd/lsfd-functions.bash
index 3a3f58f0c..533c25fae 100644
--- a/tests/ts/lsfd/lsfd-functions.bash
+++ b/tests/ts/lsfd/lsfd-functions.bash
@@ -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
--
2.33.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/util-linux.git
git@gitee.com:src-openeuler/util-linux.git
src-openeuler
util-linux
util-linux
master

搜索帮助