아직멀었구나..

 

괜히 최신커널쓴다고 오류만 난발.

오늘도 에러가..

문자 디바이스 드라이버 구조체중에 ioctl()함수가 사라지고 이두개를 사용한다고 한다.

 

.unlocked_ioctl or .compat_ioctl 사용!

 세부정보 : http://forum.falinux.com/zbxe/?document_srl=563022 FF포럼

 

long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);

long (*compat_ioctl) (struct file *, unsigned int, unsigned long);

 

인자만 한개 지워주니깐 성공. 휴.

세부사항은 검색 하십쇼!

 

디바이스 예제. //ioctl.c

#include <linux/init.h>

#include <linux/kernel.h>

#include <linux/module.h>

#include <linux/fs.h>

 

int kw_device_open(struct inode *inode, struct file *filp)

{

       printk(KERN_ALERT "kw_device open fuction called\n");

       return 0;

}

 

int kw_device_release(struct inode *inode, struct file *filp)

{

       printk(KERN_ALERT "kw_device release fuction called\n");

       return 0;

}

 

//ioctl 연산 구현 부분 기존 read, write연산 제거하고 모두 ioctl 구현

int kw_device_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)

//변형

{

       switch(cmd)

       {

       case 1: //read

             printk(KERN_ALERT "ioctl read...\n");

             break;

       case 2: //write

             printk(KERN_ALERT "ioctl write...\n");

             break;

            

       default:

             printk(KERN_ALERT "ioctl unknown command...\n");

             break;

       }

       return 0;

}

 

//동작만 살펴보기 위해 간단한 메세지만 출력하 였다.

 

static struct file_operations vd_fops ={

             .owner        = THIS_MODULE,

             .open         = kw_device_open,

             .release     = kw_device_release,

             .unlocked_ioctl     = kw_device_ioctl  //변형부분!

};

 

int __init kw_device_init(void){

       // 문자 디바이스를 등록한다.

       if(register_chrdev(250,"kw_device", &vd_fops) <0 )

             printk(KERN_ALERT "driver init failed\n");

       else

             printk(KERN_ALERT "driver init successful\n");

       return 0;

}

 

void __exit kw_device_exit(void){

       unregister_chrdev(250,"kw_device");

       printk(KERN_ALERT "driver cleanup successful!\n");

}

 

module_init(kw_device_init);

module_exit(kw_device_exit);

MODULE_LICENSE("GPL");

 

응용프로그램 //ioctl_app

 

파일 첨부..

 

ioctl.zip

                       책: 리눅스 커널 프로그래밍(한빛) 에서

                             소스작성중.

'리눅스커널 > Device Driver' 카테고리의 다른 글

USB 인사이드 muosys.egloos.com  (0) 2016.05.16
PS/2 키보드 LED제어  (0) 2015.05.13
문자디바이스 드라이버와 file_operations  (0) 2015.05.12
디바이스드라이버기초정리  (0) 2015.05.11
platform_driver  (0) 2015.04.23

+ Recent posts