Re: Some doubt regarding current state of Linux Hotpug

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks Kay,

I know that is an outdated script. I was trying to recreate the old
behaviour as an educational purpose. I like to know how the current
Hotplugging mechanism evolved. I was trying to recreate the old
functions.

I know the udev uses the netlink socket for kernel-user space communication.

I found that /proc/sys/kernel/hotplug is still working. I am able to
extract the environment variables using a script in that file. I
believe that script will give a good understanding of how udev is
dynamically loading the modules. But as a new comer I am unable to
understand it without actually getting that working. Just reading the
code will not give anything for me. So I went ahead and tried it
practically. But I think the kernel i not giving the argument to the
script, but I can see that it is giving the environment variables.

I am not able to understand how it is getting the following variables :

-----------------------------
  IFS=/
  set $PRODUCT ''
  usb_idVendor=$1
  usb_idProduct=$2
  IFS="$DEFAULT_IFS"
-----------------------------

Also I am not able to understand usb_map_modules function in that.

I know I am wasting your time. But for me its better to start from
simple things. That will help me to understand the current more
complex udev, I believe so. If there anyone out there can give an
algorithm or something for that script then that will help me. I am
just attaching the script, eventhogh you can explain it without
reading it :-) .


On Fri, Jul 3, 2009 at 9:15 PM, Kay Sievers<kay.sievers@xxxxxxxx> wrote:
> On Fri, Jul 3, 2009 at 17:25, unni krishnan<unnikrishnan.a@xxxxxxxxx> wrote:
>> Hi All,
>>
>>  I am trying to understand the hotplugging in Linux. I am new to
>> Linux kernel and its subsystems. I found this article on LJ
>>
>> http://www.linuxjournal.com/article/5604
>>
>> As per that, the USB device will call /sbin/hotplug with arguments
>>
>> argv [0] = hotplug_path
>> argv [1] = "usb"
>> argv [2] = 0
>>
>> Also the module auto detection script provided in that article uses
>> those arguments. I have tried that script in my system with kernel
>> 2.6.29-ARCH
>>
>> But I found that the arguments are not passing to the script through
>> /proc/...../hotplug
>>
>> Also I am not able to understand this part :
>>
>> IFS=/
>>  set $PRODUCT ''
>>  usb_idVendor=$1
>>  usb_idProduct=$2
>>  IFS="$DEFAULT_IFS"
>>
>> From where that script is getting the vendor id and product id. That
>> script is not working in this kernel, so I assume that some changes
>> happened with current Linux hotplugging. I am not able to find any
>> useful article or something to find the current changes. It will be
>> helpful, if any one help me to understand the working of script and
>> current changes that happened.
>
> Nobody is using any of this stuff since years. /sbin/hotplug is long
> dead and completely disabled, unsually in the kernel itself.
> Everything is handled by udev. There are no shell scripts, no module
> scripts, nothing like this.
>
> An also outdated, but half way to what we are doing today is here:
> http://vrfy.org/log/recent-state-of-udev.html
>
> Kay
>



-- 
---------------------
With regards,
Unni

"A candle loses nothing by lighting another candle"
5604l2

Listing 2. Example Version of /sbin/hotplug

#!/bin/bash

declare -i usb_idVendor
declare -i usb_idProduct

MAP=/lib/modules/`uname -r`/modules.usbmap

usb_map_modules ()
{
  # convert the usb_device_id fields to
  # integers as we read them
  local line module
  declare -i match_flags
  declare -i idVendor idProduct

  # look at each usb_device_id entry
  # collect all matches in $DRIVERS
  while read line
  do
    case "$line" in
      \#*) continue ;;
    esac

    set $line

    module=$1
    match_flags=$2
    idVendor=$3
    idProduct=$4

    : checkmatch $module
    : idVendor $idVendor $usb_idVendor
    if [ 0x0001 -eq $(($match_flags & 0x0001)) ] &&
       [ $idVendor -ne $usb_idVendor ]; then
      continue
    fi

    : idProduct $idProduct $usb_idProduct
    if [ 0x0002 -eq $(($match_flags & 0x0002)) ] &&
       [ $idProduct -ne $usb_idProduct ]; then
      continue
    fi

    # It was a match!
    DRIVERS="$module $DRIVERS"
    : drivers $DRIVERS
  done
}

if [ "$1" = "usb" ]; then
  IFS=/
  set $PRODUCT ''
  usb_idVendor=$1
  usb_idProduct=$2
  IFS="$DEFAULT_IFS"

  usb_map_modules < $MAP

  if [ "$ACTION" = "add" ]; then
    PROGRAM="/sbin/modprobe"
  else
    PROGRAM="/sbin/rmmod"
  fi

  for MODULE in $DRIVERS
  do
    $PROGRAM $MODULE
  done
fi


[Index of Archives]     [Linux Kernel]     [Linux DVB]     [Asterisk Internet PBX]     [DCCP]     [Netdev]     [X.org]     [Util Linux NG]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux