Skip to content

Instantly share code, notes, and snippets.

@suedi
Last active November 7, 2015 23:05
Show Gist options
  • Save suedi/cd629567da653de45807 to your computer and use it in GitHub Desktop.
Save suedi/cd629567da653de45807 to your computer and use it in GitHub Desktop.
feed_static_nodes_kmod() {
[ -e /lib/modules/$(uname -r)/modules.devname ] || return 0
[ -x /bin/kmod ] || return 0
/bin/kmod static-nodes --format=devname --output=/proc/self/fd/1 | \
while read name path arg; do
echo "name=$name"
# strip major:minor from $arg
type=${arg:0:1}
echo "type=$type"
[ -e "$VDEV_MOUNTPOINT/$name" ] && { echo "exists in dev"; continue; }
# only process character and block devices
if [ "$type" != "c" -a "$type" != "b" ]; then
echo "Invalid device type $type" >/proc/self/fd/2
continue
fi
# look up major/minor
major=$(echo ${arg:1} | /bin/sed 's/^\([^:]\+\):.*/\1/g')
minor=$(echo ${arg:1} | /bin/sed 's/^[^:]\+:\(.*\)/\1/g')
echo "major=$major"
echo "minor=$minor"
# look up devpath and subsystem
sys_link=
devpath=
params=
case "$type" in
"c")
sys_link="/sys/dev/char/$major:$minor"
;;
"b")
sys_link="/sys/dev/block/$major:$minor"
;;
esac
echo "syslink=$sys_link"
# is there a sysfs entry for this device? there might not be...
if ! [ -L $sys_link ]; then
subsystem=$(guess_subsystem $type $path)
else
devpath=$(/bin/readlink "$sys_link" | /bin/sed 's/\.\.\///g')
devpath="/$devpath"
echo "devpath=$devpath"
subsystem=$(/bin/readlink "/sys/$devpath/subsystem" | /bin/sed "s/[^/]*\///g")
fi
echo "subsystem=$subsystem"
# build up params list
if [ -n "$devpath" ]; then
params="$params DEVPATH=$devpath"
fi
if [ -n "$subsystem" ]; then
params="$params SUBSYSTEM=$subsystem"
fi
# feed into vdevd via stdout
echo "$type $name $major $minor $params"
# keep SELinux happy
if [ -x /sbin/restorecon ]; then
/sbin/restorecon "$VDEV_MOUNTPOINT/$name"
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment