Altera_Forum
Honored Contributor
17 years agoIoctl problem
Hi,
I'm writing a device driver and I have problems with the ioctl function. When I run my user application associated with the driver in the terminal, "printks" that are inside my module functions appeared in a wrong order, I use "printk" to know where I am. Besides "printk" that are inside ioctl code of the module appeared without having make a call of ioctl. Maby the computer has reorganized the order of the instructions and ioctl always starts when I run a new application? I have used in my user code a file_pointer instead of a file_descriptor, althought I have used function fileno to have a file_descriptor because it is one of the paremeters of the function ioctl. I don't know how to solution these problems. Thanks Code_User_ApplicationFILE *leds;
.
.
.
printf("Fitxer obert Usuari\n");
descriptor_leds=fileno(leds);
fwrite(Dada,sizeof(char),1,leds);
ioctl(descriptor_leds,LEDS_IOCSETD,&Dada_ioctl);
printf("IOCTL_Usuari_Superat\n\n");Module_Code static int Leds_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg){
static int data;
printk("\nSuper_ioctl\n");
printk("Valor_cmd:%d\n",cmd);
switch(cmd){
case LEDS_IOCSETD:
if (copy_from_user(&data,(int *)arg, sizeof(int)))
return -EFAULT;
printk("Ioct_Valor: %d\n",data);
return 0;
default:
printk("Ioctl_Cap_opcio\n");
return -ENOTTY;
}
}Thanks