1 / 17

모듈 사용 횟수 관리

모듈 사용 횟수 관리. 커널 2.4 MOD_INT_USE_COUNT : 모듈 사용 횟수를 증가시킨다 . MOD_DEC_USE_COUNT : 모듈 사용 횟수 감소시킨다 . MOD_IN_USE : 모듈 사용 횟수가 0 이 아니면 참값을 반환한다. 커널 2.6 Try_module_get(THIS_MODULE) : 모듈 사용 횟수를 증가시킨다 . Module_put(THIS_MODULE) : 모듈 사용 횟수 감소시킨다. 모듈 사용횟수 관리 함수. 문자 디바이스 드라이버 동작. read.

sylvie
Download Presentation

모듈 사용 횟수 관리

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 모듈 사용 횟수 관리 • 커널 2.4 • MOD_INT_USE_COUNT : 모듈 사용 횟수를 증가시킨다. • MOD_DEC_USE_COUNT : 모듈사용 횟수 감소시킨다. • MOD_IN_USE : 모듈 사용 횟수가 0이 아니면 참값을 반환한다. • 커널 2.6 • Try_module_get(THIS_MODULE) : 모듈 사용 횟수를 증가시킨다. • Module_put(THIS_MODULE) : 모듈사용 횟수 감소시킨다. 모듈 사용횟수 관리 함수

  2. 문자 디바이스 드라이버 동작 read dev-read 응용 프로그램 장치파일 문자 디바이스 드라이버 하드웨어 return return * 단일 방식의 호출규칙을 통해 다양한 개념과 다양한 형태의 하드웨어를 제어 가능하다

  3. 문자 디바이스 드라이버 동작 * 커널은 디바이스 파일에 기록된 디바이스 타입과 주번호를 이용해 커널 내에 등록된 디바이스 드라이버 함수를 연결한다. * 문자 디바이스 드라이버의 경우 커널 2.6에서 fs/char_dev.c에 chrdevs라는 전역변수를 다음과 같이 정의한다. static struct char_device_struct { //커널 2.6.20에서 문자 디바이스 드라이버를 관리하는 구조체 struct char_devi ce_struct *next; unsigned int major; unsigned int baseminor; int minorct; char name[64]; struct file_operations fops; struct cdev *cdev; } * chrdevs[CHRDEV_MAJOR_HASH_SIZE]; • 응용 프로그램에서 open으로 장치 파일을 열어 타입 정보와 주번호를 얻는다. • 이 정보를 이용하여 chrdevs 변수에 등록된 디바이스 드라이버의 인덱스를 얻는다. • 이 인덱스값으로 chrdevs 변수에 등록된 file_operation 구조체 주소를 얻는다.

  4. 커널 2.6의 파일 오퍼레이션 구조체 struct file_operations { struct module *owner; int (*open)(struct inode *, struct file *); . . . } * 디바이스 드라이버의 file_operations에서정의되지 않았거나 NULL로 채워진 필드는 커널에 의해서 default 처리를 한다.

  5. 문자 디바이스 드라이버의 등록과 해제 및 구성 <linux/fs.h>를 추가하고 int register_chrdev(unsigned int major, const char *name, struct file_operations *fops); 를 이용해 커널에 디바이스 드라이버의 file_operations을 등록한다.(중요!!!) *디바이스 드라이버가 등록된다는 것은 주번호에 연관된 file_operations 구조체가 커널에 등록된다는 의미. int unregister_chrdev(unsigned int major, const char *name); 를 이용해 등록된 디바이스 드라이버를 해제한다. 주번호는 응용 프로그램에서 디바이스 파일을 이용해 디바이스 드라이버를 찾을 때 사용 디바이스 드라이브명은 proc 파일 시스템이나 오류정보를 커널에 나타내기 위해 사용한다. 디바이스 드라이버를 제거할때 구별자로도 사용된다. * 두값을 모두 비교해서 해제할 디바이스 드라이버를 선택한다.

  6. #include <linux/init.h> #include <linux/module.h> #include <linux/fs.h> #include <linux/errno.h> #include <linux/types.h> #inlcude <linux/fcntl.h> int xxx_open (struct inode *inode, struct file *filp) { } int xxx_release(struct inode *inode, struct file *filp) { } struct file_operations xxx_fops = { .owner = THIS_MODULE, .open = xxx_open, .release = xxx_release, }; int xxx_init(void) { register_chrdev(240, “char_dev”, &xxx_fops); } void xxx_exit(void) { unreister_chrdev(240, “char_dev”); } module_init(xxx_init); module_exit(xxx_exit);

More Related