最近在嵌入式Linux板子上調試USB聲卡,使用mdev創建設備節點時默認直接在 /dev/目錄下創建, 如
- controlC0 pcmC0D0c seq sequencer2
- mixer pcmC0D0p sequencer timer
但是用戶空間的程序alsa-lib, alsa-utils都是去 /dev/snd/目錄下找這些設備節點, 怎麼能讓mdev把設備節點創建在子目錄下呢?
在busybox源代碼的 doc/mdev.txt 文檔裡面找到以下說明:
- You can rename/move device nodes by using the next optional field.
- <device regex> <uid>:<gid> <permissions> [=path]
- So if you want to place the device node into a subdirectory, make sure the path
- has a trailing /. If you want to rename the device node, just place the name.
- hda 0:3 660 =drives/
- This will move "hda" into the drives/ subdirectory.
- hdb 0:3 660 =cdrom
- This will rename "hdb" to "cdrom".
-
- Similarly, ">path" renames/moves the device but it also creates
- a direct symlink /dev/DEVNAME to the renamed/moved device.
所以, 我們只要在 /etc/mdev.conf配置文件裡面加入幾行就可以了:
- controlC[0-9] 0:0 0660 =snd/
- pcm.* 0:0 0660 =snd/
- seq.* 0:0 0660 =snd/
- mix.* 0:0 0660 =snd/
- timer 0:0 0660 =snd/
這樣再運行mdev, ALSA相關的設備節點就都創建在 /dev/snd/ 目錄下了。
後記: 內核裡面 struct class 裡面的 devnode 項跟設備節點所在目錄好像也有關系, 有空再研究一下。