|
相信这里一定有hotplug方面的专家,小弟请教一个问题:
最近在做多媒体播放器,嵌入linux系统(kernel2.6.5),带有USB主机的功能,希望在usb设备插入时,能自动mount到系统上。据了解,其/proc/sys/kernel/hotplug 指向 /sbin/hotplug 。
在阅读相应脚本的过程中,有个疑问一直想不明白,在脚本 hotplug.functions里,有个函数 load_drivers,如下,在红色部分,LISTER被赋为空,随后的 if 判断似乎永远不为真,是吗?
变量DRIVERS也为空,所以return走了,之后的操作就永远执行不到,对吗?
谢谢!
小弟在linux上才做了半年开发,懂得太少,如果愿意,请添加我的msn([email protected] ), 我们可以直接交流。
load_drivers ()
{
local LOADED TYPE FILENAME DESCRIPTION LISTER
DRIVERS=""
TYPE=$1
FILENAME=$2
DESCRIPTION=$3
# should we use usbmodules, pcimodules? not on 2.5+, because sysfs
# ought to expose the data we need to find all candidate drivers.
# (on 2.5.48 it does for usb; but maybe not yet for pci.)
LISTER=""
if [ "$LISTER" != "" ]; then
case $TYPE in
usb)
if [ "$DEVICE" = "" -o ! -f "$DEVICE" ]; then
LISTER=
else
DRIVERS=`$LISTER --mapfile $FILENAME --device $DEVICE`
fi ;;
pci)
echo incasepci >> invoking-functions
debug_mesg "pcimodules is scanning more than $PCI_SLOT ..."
DRIVERS=`$LISTER`
;;
esac
fi
# try parsing by shell scripts if no luck yet
if [ "$DRIVERS" = "" ]; then
${TYPE}_map_modules < $FILENAME
fi
# FIXME remove dups and blacklisted modules from $DRIVERS here
if [ "$DRIVERS" = "" ]; then
return
fi
debug_mesg Setup $DRIVERS for $DESCRIPTION
# either kernel or user mode drivers may need to be set up
for MODULE in $DRIVERS
do
# maybe driver modules need loading
LOADED=false
if ! lsmod | grep -q "^$(echo $MODULE|sed -e 's/-/_/g') " > /dev/null 2>&1; then
if grep -q "^$(echo $MODULE|sed -e 's/[-_]/[-_]/g')\$" $HOTPLUG_DIR/blacklist \
$HOTPLUG_DIR/blacklist.d/* \
>/dev/null 2>&1; then
debug_mesg "... blacklisted module: $MODULE"
continue
fi
# statically linked modules aren't shown by 'lsmod',
# and user mode drivers will ONLY have a setup script;
# it's not an error if a module doesn't exist or won't load.
if $MODPROBE -n $MODULE >/dev/null 2>&1 &&
! $MODPROBE $MODULE >/dev/null 2>&1 ; then
mesg "... can't load module $MODULE"
else
# /etc/modules.conf may have set non-default module
# parameters ... handle per-device parameters in apps
# (ioctls etc) not in setup scripts or modules.conf
LOADED=true
fi
else
# This module is already loaded
LOADED=true
fi
# always run setup scripts after any matching kernel code has had
# a chance to do its thing, no matter whether it was dynamically
# or statically linked, or if there is only a user mode driver.
# the script might re-enumerate usb devices after firmware download,
# giving kernel code another chance.
if [ -x $HOTPLUG_DIR/$TYPE/$MODULE ]; then
debug_mesg Module setup $MODULE for $DESCRIPTION
$HOTPLUG_DIR/$TYPE/$MODULE
LOADED=true
fi
if [ "$LOADED" = "false" ]; then
mesg "missing kernel or user mode driver $MODULE "
fi
if echo "$MODULE" | grep -q "usb-storage" > /dev/null 2>&1 ; then
[ -x /usr/sbin/updfstab ] && /usr/sbin/updfstab
fi
done
} |
|