使用mdev在/dev/下创建子目录放置设备节点


最近在嵌入式Linux板子上调试USB声卡,使用mdev创建设备节点时默认直接在 /dev/目录下创建,  如

  1. controlC0 pcmC0D0c seq sequencer2
  2. mixer pcmC0D0p sequencer timer
但是用户空间的程序alsa-lib, alsa-utils都是去 /dev/snd/目录下找这些设备节点, 怎么能让mdev把设备节点创建在子目录下呢?
在busybox源代码的 doc/mdev.txt 文档里面找到以下说明:
 
  1. You can rename/move device nodes by using the next optional field.
  2.         <device regex> <uid>:<gid> <permissions> [=path]
  3. So if you want to place the device node into a subdirectory, make sure the path
  4. has a trailing /. If you want to rename the device node, just place the name.
  5.         hda 0:3 660 =drives/
  6. This will move "hda" into the drives/ subdirectory.
  7.         hdb 0:3 660 =cdrom
  8. This will rename "hdb" to "cdrom".
  9.  
  10. Similarly, ">path" renames/moves the device but it also creates
  11. a direct symlink /dev/DEVNAME to the renamed/moved device.
所以, 我们只要在 /etc/mdev.conf配置文件里面加入几行就可以了:

  1. controlC[0-9] 0:0 0660 =snd/
  2. pcm.* 0:0 0660 =snd/
  3. seq.* 0:0 0660 =snd/
  4. mix.* 0:0 0660 =snd/
  5. timer 0:0 0660 =snd/
这样再运行mdev, ALSA相关的设备节点就都创建在  /dev/snd/ 目录下了。
 
后记: 内核里面 struct class 里面的 devnode 项跟设备节点所在目录好像也有关系, 有空再研究一下。

相关内容