-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkernel
54 lines (46 loc) · 1.44 KB
/
kernel
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
#!/bin/bash
#
# Utilities for kernel module management.
#
function mod-recursive-rdepends()
{
if test $# -gt 0; then
declare -p MOD_RECURSE_DEPTH > /dev/null 2>&1 \
&& MOD_RECURSE_DEPTH=$(( ${MOD_RECURSE_DEPTH} + 1 )) \
|| export MOD_RECURSE_DEPTH=0
declare -p MOD_USERS > /dev/null 2>&1 || eval "$(mod-stat)"
export MOD_USERS
local OUT=""
for mod in ${MOD_USERS[$1]}; do
APPEND="$(mod-recursive-rdepends ${mod})"
test -n "${OUT}" \
&& OUT="${OUT} ${APPEND}" \
|| OUT="${APPEND}"
done
test -n "${OUT}" && OUT="${OUT} $1" || OUT="$1"
test $MOD_RECURSE_DEPTH -eq 0 \
&& unset MOD_RECURSE_DEPTH MOD_USERS \
|| MOD_RECURSE_DEPTH=$(( ${MOD_RECURSE_DEPTH} - 1 ))
echo "${OUT}"
else
echo "Usage: mod-recursive-rdepends MODNAME" > /dev/stderr
return 1
fi
}
function mod-stat()
{
echo 'declare -A MOD_USERS'
cut -d ' ' -f 1,4 /proc/modules | sed -e 's#,# #g;s#^\([^ ]\+\)\x20\+\(.\+\)$#MOD_USERS[\1]="\2"#g;s#="-"#=""#g;s# "$#"#g'
}
## Determine the number of users of the target module.
#
# \param $1 Module to count users for.
#
# \returns The number of users of the target module.
function mod-num-users()
{
declare -pA MOD_USERS > /dev/null 2>&1 || eval "$(mod-stat)"
local -a USERS
USERS=( ${MOD_USERS[$1]} )
echo ${#USERS[*]}
}