<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          hotplug_uevent機(jī)制

          作者: 時(shí)間:2016-11-21 來源:網(wǎng)絡(luò) 收藏
          class_device_create
          class_device_register
          class_device_add
          kobject_uevent(&class_dev->kobj, KOBJ_ADD);
          kobject_uevent_env(kobj, action, NULL);
          // action_string = "add";
          action_string = action_to_string(action);
          // 分配保存環(huán)境變量的內(nèi)存 //
          // environment values //
          buffer = kmalloc(BUFFER_SIZE, GFP_KERNEL);
          // 設(shè)置環(huán)境變量 //
          envp [i++] = scratch;
          scratch += sprintf(scratch, "ACTION=%s", action_string) + 1;
          envp [i++] = scratch;
          scratch += sprintf (scratch, "DEVPATH=%s", devpath) + 1;
          envp [i++] = scratch;
          scratch += sprintf(scratch, "SUBSYSTEM=%s", subsystem) + 1;
          // 調(diào)用應(yīng)用程序: 比如mdev //
          // 啟動(dòng)腳本 echo /sbin/mdev > /proc/sys/kernel/hotplug
          // 設(shè)置了uevent_helper為“/sbin/mdev“
          //
          argv [0] = uevent_helper; // = "/sbin/mdev"
          argv [1] = (char *)subsystem;
          argv [2] = NULL;
          call_usermodehelper (argv[0], argv, envp, 0);
          分析: busybox mdev.c
          100ask: uevent_helper = /sbin/mdev
          envp[0] = HOME=/
          envp[1] = PATH=/sbin:/bin:/usr/sbin:/usr/bin
          envp[2] = ACTION=add
          envp[3] = DEVPATH=/class/sixth_drv/buttons
          envp[4] = SUBSYSTEM=sixth_drv
          envp[5] = SEQNUM=720
          envp[6] = MAJOR=252
          envp[7] = MINOR=0
          mdev_main
          temp = /sys/class/sixth_drv/buttons
          make_device(temp, 0);
          // 確定設(shè)備文件名,類型,主次設(shè)備號(hào) //
          device_name = bb_basename(path); = "buttons"
          c == > 字符設(shè)備節(jié)點(diǎn)
          根據(jù)"/sys/class/sixth_drv/buttons/dev"的內(nèi)容確定主次設(shè)備號(hào)
          mknod(device_name, mode | type, makedev(major, minor)
          我接上U盤,想自動(dòng)掛載,怎么辦?
          mdev.conf的格式:
          : [<@|$|*> ]
          device regex:正則表達(dá)式,表示哪一個(gè)設(shè)備
          uid: owner
          gid: 組ID
          octal permissions:以八進(jìn)制表示的屬性
          @:創(chuàng)建設(shè)備節(jié)點(diǎn)之后執(zhí)行命令
          $:刪除設(shè)備節(jié)點(diǎn)之前執(zhí)行命令
          *: 創(chuàng)建設(shè)備節(jié)點(diǎn)之后 和 刪除設(shè)備節(jié)點(diǎn)之前 執(zhí)行命令
          command:要執(zhí)行的命令
          命令:vi /etc/mdev.conf
          ls -l /dev/led*
          vi /bin/add_remove_led.sh
          chmod +x /bin/add_remove_led.sh
          寫mdev.conf
          1.
          leds 0:0 777
          led1 0:0 777
          led2 0:0 777
          led3 0:0 777
          2.
          leds?[123]? 0:0 777
          3.
          leds?[123]? 0:0 777 @ echo create /dev/$MDEV > /dev/console
          4.
          leds?[123]? 0:0 777 * if [ $ACTION = "add" ]; then echo create /dev/$MDEV > /dev/console; else echo remove /dev/$MDEV > /dev/console; fi
          5.
          leds?[123]? 0:0 777 * /bin/add_remove_led.sh
          把命令寫入一個(gè)腳本:
          add_remove_led.sh
          #!/bin/sh
          if [ $ACTION = "add" ];
          then
          echo create /dev/$MDEV > /dev/console;
          else
          echo remove /dev/$MDEV > /dev/console;
          fi
          6. U盤自動(dòng)加載
          sda[1-9]+ 0:0 777 * if [ $ACTION = "add" ]; then mount /dev/$MDEV /mnt; else umount /mnt; fi
          7.
          sda[1-9]+ 0:0 777 * /bin/add_remove_udisk.sh
          add_remove_udisk.sh
          #!/bin/sh
          if [ $ACTION = "add" ];
          then
          mount /dev/$MDEV /mnt;
          else
          umount /mnt;
          fi


          關(guān)鍵詞: hotplug_uevent機(jī)

          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();