summaryrefslogtreecommitdiffstats
path: root/tests/ts/lsblk/mk-input.sh
blob: 2bbd9e35011011f254dd3c8e55a668dae45dacb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
#
# Copyright (C) 2018 Karel Zak <kzak@redhat.com>
#
# This script makes a copy of relevant files from /sys and /proc.
# The files are useful for lsblk(1) regression tests.
#
progname=$(basename $0)

if [ -z "$1" ]; then
	echo -e "\nusage: $progname <testname>\n"
	exit 1
fi

TS_DUMP="$1"
TS_NAME=$(basename ${TS_DUMP})
TS_TARBALL="$TS_DUMP.tar.xz"
TS_CMD_LSBLK=${TS_CMD_LSBLK:-"lsblk"}

#
# procfs
#
mkdir -p $TS_DUMP/proc
mkdir -p $TS_DUMP/proc/self
cp /proc/self/mountinfo ${TS_DUMP}/proc/self
cp /proc/swaps ${TS_DUMP}/proc/swaps
cp /proc/version ${TS_DUMP}/proc/version


#
# sysfs
#
mkdir -p $TS_DUMP/sys/{block,dev/block}
cp --no-dereference /sys/dev/block/* ${TS_DUMP}/sys/dev/block
cp --no-dereference /sys/block/* ${TS_DUMP}/sys/block

DEVS=$(find /sys/dev/block/ -type l)
for x in ${DEVS}; do
	DEV="/sys/dev/block/$(readlink $x)"

	mkdir -p ${TS_DUMP}/${DEV}

	# attributes
	for f in $(find ${DEV} -type f -not -path '*/trace/*' -not -path '*/uevent'); do
		if [ ! -f ${TS_DUMP}/${f} ]; then
			SUB=$(dirname $f)
			mkdir -p ${TS_DUMP}/${SUB}
			cp $f ${TS_DUMP}/$f 2> /dev/null
		fi
	done

	# symlinks (slave, holders, etc.)
	for f in $(find ${DEV} -type l -not -path '*/subsystem' -not -path '*/bdi'); do
		if [ ! -f ${TS_DUMP}/${f} ]; then
			SUB=$(dirname $f)
			mkdir -p ${TS_DUMP}/${SUB}
			cp --no-dereference $f ${TS_DUMP}/$f
		fi
	done

	# device/ files
	if [ -d ${DEV}/device/ ]; then
		for f in $(find ${DEV}/device/ -maxdepth 1 -type f -not -path '*/uevent'); do
			if [ ! -f ${TS_DUMP}/${f} ]; then
				SUB=$(dirname $f)
				cp $f ${TS_DUMP}/$f 2> /dev/null
			fi
		done
	fi

done

#
# udev a lsblk specific
#
mkdir -p $TS_DUMP/dev
DEVS=$(lsblk --noheadings --output PATH)
for d in $DEVS; do

	# udev
	udevadm info --query=property $d > $TS_DUMP/$d

	# lsblk
	echo "OWNER=$($TS_CMD_LSBLK --noheadings --nodeps --output OWNER $d)" >> $TS_DUMP/$d
	echo "GROUP=$($TS_CMD_LSBLK --noheadings --nodeps --output GROUP $d)" >> $TS_DUMP/$d
	echo "MODE=$($TS_CMD_LSBLK  --noheadings --nodeps --output MODE  $d)" >> $TS_DUMP/$d
done

function mk_output {
	local cols="NAME,${2}"
	local subname="$1"

	echo "$cols" > ${TS_DUMP}/${subname}.cols
	$TS_CMD_LSBLK -o ${cols} > ${TS_DUMP}/lsblk-${TS_NAME}-${subname}
}


LANG="POSIX"
LANGUAGE="POSIX"
LC_ALL="POSIX"
CHARSET="UTF-8"

export LANG LANGUAGE LC_ALL CHARSET

#
# lsblk info
#
$TS_CMD_LSBLK -V &> ${TS_DUMP}/version

mk_output basic KNAME,MAJ:MIN,RM,SIZE,TYPE,MOUNTPOINT
mk_output vendor MODEL,VENDOR,REV
mk_output state RO,RM,HOTPLUG,RAND,STATE,ROTA,TYPE,PKNAME,SCHED
mk_output rw RA,WSAME
mk_output topo SIZE,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,RQ-SIZE
mk_output discard DISC-ALN,DISC-GRAN,DISC-MAX,DISC-ZERO
mk_output zone ZONED


tar --xz -cvf ${TS_TARBALL} $TS_DUMP
rm -rf $TS_DUMP

echo -e "\nPlease, send ${TS_TARBALL} to util-linux upstream. Thanks!\n"