歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

使用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 項跟設備節點所在目錄好像也有關系, 有空再研究一下。
Copyright © Linux教程網 All Rights Reserved