色婷婷AⅤ一区二区三区|亚洲精品第一国产综合亚AV|久久精品官方网视频|日本28视频香蕉

          新聞中心

          hotplug_uevent機制

          作者: 時間: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 //
          // 啟動腳本 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è)備號 //
          device_name = bb_basename(path); = "buttons"
          c == > 字符設(shè)備節(jié)點
          根據(jù)"/sys/class/sixth_drv/buttons/dev"的內(nèi)容確定主次設(shè)備號
          mknod(device_name, mode | type, makedev(major, minor)
          我接上U盤,想自動掛載,怎么辦?
          mdev.conf的格式:
          : [<@|$|*> ]
          device regex:正則表達式,表示哪一個設(shè)備
          uid: owner
          gid: 組ID
          octal permissions:以八進制表示的屬性
          @:創(chuàng)建設(shè)備節(jié)點之后執(zhí)行命令
          $:刪除設(shè)備節(jié)點之前執(zhí)行命令
          *: 創(chuàng)建設(shè)備節(jié)點之后 和 刪除設(shè)備節(jié)點之前 執(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
          把命令寫入一個腳本:
          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盤自動加載
          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機

          評論


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

          關(guān)閉