2022-06-13 리눅스_디바이스_드라이버_4

2022. 6. 13. 01:17BE/Linux

/dev 디렉터리

 

cd /dev

 

/dev 디렉터리??

 

In Unix-like operating systems, a device file or special file is an interface to a device driver that appears in a file system as if it were an ordinary file.

 

Linux의 모든 디바이스는 /dev 디렉터리 아래에 위치하고, 모두 file로 인식된다.

 

These special files allow an application program to interact with a device by using its device driver via standard input/output system calls.

 

모든 디바이스 제어는 결국 /dev 아래 파일에 대한 입출력을 통해서 이루어진다.

 

출처 : https://en.wikipedia.org/wiki/Device_file


/dev 살펴보기

 

total 4
drwxr-xr-x 19 root root        3960 May 24 15:01 .
drwxr-xr-x 25 root root        4096 May 24 14:36 ..
crw-r--r--  1 root root     10, 235 May  5 18:18 autofs
drwxr-xr-x  2 root root         240 May  5 18:17 block
crw-rw----  1 root disk     10, 234 May  5 18:18 btrfs-control
drwxr-xr-x  3 root root          60 May  5 18:17 bus
drwxr-xr-x  2 root root        3480 May 24 15:01 char
crw-------  1 root root      5,   1 May  5 18:19 console
lrwxrwxrwx  1 root root          11 May  5 18:17 core -> /proc/kcore
drwxr-xr-x  3 root root          60 May 24 14:27 cpu
crw-------  1 root root     10,  59 May  5 18:18 cpu_dma_latency
crw-------  1 root root     10, 203 May  5 18:18 cuse
drwxr-xr-x  4 root root          80 May  5 18:17 disk
drwxr-xr-x  3 root root          80 May  5 18:18 dri
crw-------  1 root root     10,  62 May  5 18:18 ecryptfs
crw-rw----  1 root video    29,   0 May  5 18:18 fb0
lrwxrwxrwx  1 root root          13 May  5 18:17 fd -> /proc/self/fd
crw-rw-rw-  1 root root      1,   7 May  5 18:18 full
crw-rw-rw-  1 root root     10, 229 May  6 18:09 fuse
crw-------  1 root root    244,   0 May  5 18:18 hidraw0
crw-------  1 root root     10, 228 May  5 18:18 hpet
drwxr-xr-x  2 root root           0 May  5 18:18 hugepages
crw--w----  1 root tty     229,   0 May  5 18:19 hvc0
crw-------  1 root root    229,   1 May  5 18:18 hvc1
crw-------  1 root root    229,   2 May  5 18:18 hvc2
crw-------  1 root root    229,   3 May  5 18:18 hvc3
crw-------  1 root root    229,   4 May  5 18:18 hvc4
crw-------  1 root root    229,   5 May  5 18:18 hvc5
crw-------  1 root root    229,   6 May  5 18:18 hvc6
crw-------  1 root root    229,   7 May  5 18:18 hvc7
crw-------  1 root root     10, 183 May  5 18:18 hwrng
lrwxrwxrwx  1 root root          25 May  5 18:18 initctl -> /run/systemd/initctl/fifo
drwxr-xr-x  4 root root         260 May  5 18:18 input
crw-r--r--  1 root root      1,  11 May  5 18:18 kmsg
drwxr-xr-x  2 root root          60 May  5 18:17 lightnvm
lrwxrwxrwx  1 root root          28 May  5 18:18 log -> /run/systemd/journal/dev-log
brw-rw----  1 root disk      7,   0 May 24 14:35 loop0
brw-rw----  1 root disk      7,   1 May  5 18:18 loop1
brw-rw----  1 root disk      7,   2 May  5 18:18 loop2
brw-rw----  1 root disk      7,   3 May  5 18:18 loop3
brw-rw----  1 root disk      7,   4 May  5 18:18 loop4
brw-rw----  1 root disk      7,   5 May  5 18:18 loop5
brw-rw----  1 root disk      7,   6 May  5 18:18 loop6
brw-rw----  1 root disk      7,   7 May  5 18:18 loop7
crw-rw----  1 root disk     10, 237 May  6 18:09 loop-control
drwxr-xr-x  2 root root          60 May  5 18:17 mapper
crw-------  1 root root     10, 227 May  5 18:18 mcelog
crw-r-----  1 root kmem      1,   1 May  5 18:18 mem
crw-------  1 root root     10,  56 May  5 18:18 memory_bandwidth
drwxrwxrwt  2 root root          40 May  5 18:17 mqueue
drwxr-xr-x  2 root root          60 May  5 18:17 net
crw-------  1 root root     10,  58 May  5 18:18 network_latency
crw-------  1 root root     10,  57 May  5 18:18 network_throughput
crw-rw-rw-  1 root root      1,   3 May  5 18:18 null
crw-------  1 root root     99,   0 May  5 18:18 parport0
crw-r-----  1 root kmem      1,   4 May  5 18:18 port
crw-------  1 root root    108,   0 May  5 18:18 ppp
crw-------  1 root root     10,   1 May  5 18:18 psaux
crw-rw-rw-  1 root tty       5,   2 May 31 15:12 ptmx
drwxr-xr-x  2 root root           0 May  5 18:17 pts
crw-rw-rw-  1 root root      1,   8 May  5 18:18 random
crw-rw-r--  1 root netdev   10, 242 May  5 18:18 rfkill
lrwxrwxrwx  1 root root           4 May  5 18:18 rtc -> rtc0
crw-------  1 root root    249,   0 May  5 18:18 rtc0
drwxrwxrwt  2 root root          40 May 31 06:25 shm
crw-------  1 root root     10, 231 May  5 18:18 snapshot
drwxr-xr-x  2 root root          80 May  5 18:18 snd
lrwxrwxrwx  1 root root          15 May  5 18:17 stderr -> /proc/self/fd/2
lrwxrwxrwx  1 root root          15 May  5 18:17 stdin -> /proc/self/fd/0
lrwxrwxrwx  1 root root          15 May  5 18:17 stdout -> /proc/self/fd/1
crw-rw-rw-  1 root tty       5,   0 May  6 19:10 tty
crw--w----  1 root tty       4,   0 May  5 18:18 tty0
crw--w----  1 root tty       4,   1 May  5 18:19 tty1
crw--w----  1 root tty       4,  10 May 31 14:16 tty10
crw--w----  1 root tty       4,  11 May  5 18:18 tty11
crw--w----  1 root tty       4,  12 May  5 18:18 tty12

crw--w---- : character device driver

 

brw-rw---- : block device driver

 

crw--w----  1 root tty       4,  29 May  5 18:18 tty29

4는 major number다. 디바이스의 종류를 구분하는 데 사용된다.

 

29는 minor number다. 같은 종류의 디바이스가 여러개인 경우, 이들을 구분하는 용도로 사용한다.

 

ex)

major num → 프린터, 마우스, 키보드

minor num → 프린터1, 프린터2, 프린터3

 

출처 : https://awesomebit.tistory.com/30

 

mknod {/dev/...} c 241 0

mknod : 디바이스 파일을 생성하는 명령어

 

디바이스 파일은 /dev 디렉터리에 위치

 

c : 문자 디바이스 파일

b : 블록 디바이스 파일

 

Major number : 예시에서 241에 해당하는 옵션. 디바이스 드라이버의 고유 번호를 뜻한다.

Minor number : 예시에서 0에 해당하는 옵션. 디바이스 드라이버가 제어하는 장치 번호를 뜻한다.

 

일부 Major 번호와 Minor 번호는 이미 결정되어 있기 때문에, 자유롭게 쓸 수 있는 Major 번호 240~254를 이용하자.

 

출처 : https://awesomebit.tistory.com/28?category=756398