i am writing a driver code, to read some register values from x86., when i ran my user space application i got the below error.
ioctl:Inappropriate ioctl for device
here is the code sniff..
fd = open_drvfile();
if(ioctl(fd, IOCTL_MSR_CMDS, (long long)msr_start) == -1 ) {
perror("ioctl:");
exit (0);
}
and open_drvfile() just open(create and open) the char file as below
fd = open("/dev/" DEV_NAME, O_RDWR|O_CREAT);
if (fd == -1) {
perror("Failed to open /dev/" DEV_NAME);
}
return fd;
can some one point where i made mistake on this?
asked Aug 4, 2016 at 10:12
Sakthivel Thandabani
831 silver badge10 bronze badges
1 Answer 1
A char device implies that it shall be created with mknod(), and not with O_CREAT under open() flags (which will create a regular file, not a char device).
(see question comments).
answered Aug 4, 2016 at 10:36
pah
4,7986 gold badges31 silver badges37 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-c
mknod()prior toopen()?