티스토리 뷰

동적으로 major number를 할당하고 device node를 생성하는 script~

 #!/bin/sh
 module="scull"
 device="scull"
 mode="664"

 # 스크립트로 전달한 모든 argument를 가지고 insmod를 호출한다.
 /sbin/insmod -f ./$module.o $* || exit 1

 # 기존에 존재하던 node를 제거한다.
 rm -f /dev/${device}[0-3]

 # /proc/devices 파일로 부터 major number를 읽어온다.
 major=`awk "\\$2==\*$module\" {print \\$1}" /proc/devices`
 # sed를 사용한 예제.
 # major=`sed -ne "/$module/s/ *\(.*\) *$module/\1/p" /proc/devices`

 mknod /dev/${device}0 c $major 0
 mknod /dev/${device}1 c $major 1
 mknod /dev/${device}2 c $major 2
 mknod /dev/${device}3 c $major 3

 group="staff"
 grep '^staff:' /etc/group > /dev/null || group="wheel"
 chgrp $group /dev/${device}[0-3]
 chmod $mode /dev/${device}[0-3]

동적으로 major number를 할당받는 device driver 예제

 result = register_chrdev( scull_major, "scull", &scull_fops);
 if( result < 0)
 {
      printk( KERN_WARNING "scull: can't get major %d\n", scull_major);
      return result;
 }
 if( scull_major == 0)
  scull_major = result; /* dynamic */

내용은 KLDP의 KTD님의 글에서 퍼왔습니다.

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함