나는 헤더 파일에 IOCTL - 잘못된 인수
#define IOCTL_ALLOC_MSG _IO(MAJOR_NUM, 0)
#define IOCTL_DEALLOC_MSG _IO(MAJOR_NUM, 1)
있습니다.
내가 쓴 드라이버 파일 :
struct file_operations memory_fops = {
unlocked_ioctl: device_ioctl,
open: memory_open,
release: memory_release
};
int memory_init(void) {
int result;
/* Registering device */
result = register_chrdev(MAJOR_NUM, "memory", &memory_fops);
if (result < 0) {
printk("<1>memory: cannot obtain major number %d\n", MAJOR_NUM);
return result;
}
allocfunc();
printk("<1>Inserting memory module\n");
return 0;
}
int device_ioctl(struct inode *inode, /* see include/linux/fs.h */
struct file *file, /* ditto */
unsigned int ioctl_num, /* number and param for ioctl */
unsigned long ioctl_param)
{
/*
* Switch according to the ioctl called
*/
printk ("<l> inside ioctl \n");
switch (ioctl_num) {
case IOCTL_ALLOC_MSG:
allocfunc();
break;
case IOCTL_DEALLOC_MSG:
deallocfunc();
break;
}
return 0;
}
나는
mknod /dev/memory c 60 0
같은 캐릭터 파일 내가 얻을 응용 프로그램을 실행할 때 응용 프로그램 호출이
int main(int argc, char *argv[]) {
FILE * memfile;
/* Opening the device parlelport */
memfile=fopen("memory","r+");
if (memfile <0) {
printf (" cant open file \n");
return -1;
}
/* We remove the buffer from the file i/o */
int ret_val;
if (argc > 1) {
if (strcmp (argv[1], "mem") ==0) {
ret_val = ioctl(memfile, IOCTL_ALLOC_MSG);
if (ret_val < 0) {
printf("ioctl failed. Return code: %d, meaning: %s\n", ret_val, strerror(errno));
return -1;
}
}
실패를 생성 "ioctl이 실패했습니다. 반환 코드 : -1, 의미 : 잘못된 인수"in : strerror (errno)
의 printk는 : -하지만 헛된
Inserting memory module
참고로, 나는 "는/dev/메모리" "메모리"다른 이름 및 주요 숫자 조합을 실험.
'MAJOR_NUM'의 값은 무엇입니까? 다른 드라이버가 60을 아직 사용하고 있지 않습니까? 즉 init_module() 함수는 어떻게 생겼으며'register_chrdev()'를 꼭 호출하면 결과는 무엇인가? 또한, 당신은'strerror()'에 대한 호출을 보이지 않는다. –
MAJOR_NUM은 60이며 다른 driverint에서 사용하지 않습니다. memory_init (void) { int result; /* 장치 등록 */ 결과 = register_chrdev (MAJOR_NUM, "memory", & memory_fops); if (결과 <0) { printk ("<1> 메모리 : 주요 번호 % d을 얻을 수 없습니다. \ n", MAJOR_NUM); 반품 결과; } allocfunc(); printk ("<1> 삽입 메모리 모듈 \ n"); return 0; } --- app ---------- ret_val = ioctl (memfile, IOCTL_ALLOC_MSG); if (ret_val <0) { printf ("ioctl failed"반환 코드 : % d, 의미 : % s \ n ", ret_val, strerror (errno)); 반환 -1; } – resultsway
OK, 위 코드로 편집 할 수 있습니까? 또한'fopen()'과'strerror()'호출을 포함하여 모든 코드를 추가하십시오 (특히'fopen()'에서 결과를 확인한 경우에 보여줍니다). 'ioctl()'호출이있을 때까지 모듈이로드 될 때까지 기다린다. (예를 들어, 거기에'printk()'를보고 싶다. 그리고 다른 관련 출력도. –