免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 738 | 回复: 0
打印 上一主题 下一主题

linux hotplug相关 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-04-24 17:27 |只看该作者 |倒序浏览
相信这里一定有hotplug方面的专家,小弟请教一个问题:
最近在做多媒体播放器,嵌入linux系统(kernel2.6.5),带有USB主机的功能,希望在usb设备插入时,能自动mount到系统上。据了解,其/proc/sys/kernel/hotplug 指向 /sbin/hotplug 。

在阅读相应脚本的过程中,有个疑问一直想不明白,在脚本 hotplug.functions里,有个函数 load_drivers,如下,在红色部分,LISTER被赋为空,随后的 if 判断似乎永远不为真,是吗?
变量DRIVERS也为空,所以return走了,之后的操作就永远执行不到,对吗?
谢谢!
小弟在linux上才做了半年开发,懂得太少,如果愿意,请添加我的msn(dchen.cn@gmail.com ), 我们可以直接交流。

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
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP