Skip to content

Commit f78b96f

Browse files
committed
test.util.util: add new getMajMinNumOfDevice function to get Major:Minor device number
Signed-off-by: Alex Jia <[email protected]>
1 parent 369b261 commit f78b96f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

test/util/util.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"fmt"
55
"strings"
66
"time"
7+
8+
"github.com/gotestyourself/gotestyourself/icmd"
79
)
810

911
// WaitTimeout wait at most timeout nanoseconds,
@@ -54,3 +56,13 @@ func TrimAllSpaceAndNewline(input string) string {
5456

5557
return output
5658
}
59+
60+
// Get major:minor device number
61+
func getMajMinNumOfDevice(device string) (string, bool) {
62+
cmd := fmt.Sprintf("lsblk -d -o MAJ:MIN %s | sed /MAJ:MIN/d | awk '{print $1}'", device)
63+
number := icmd.RunCommand("bash", "-c", cmd).Stdout()
64+
if number != "" {
65+
return strings.Trim(number, "\n"), true
66+
}
67+
return "", false
68+
}

0 commit comments

Comments
 (0)