1

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
4
  • I don't quite understand what you're trying to do, but since you're referencing a char device in the question title, the O_CREAT flag under the open() isn't making much sense to me. Have you created the char device with mknod() prior to open()? Commented Aug 4, 2016 at 10:22
  • 1
    I am using open(), to create and open the file (since file is not present already). i think this was wrong. after saw your answer, i used mknod() to create file and removed O_CREAT , now it is working as expected. Thanks. Commented Aug 4, 2016 at 10:33
  • I'll post the answer, so it may be helpful to others :) Commented Aug 4, 2016 at 10:34
  • 1
    @pah accepting the answer is new to me.. i just did that. Thanks Commented Aug 5, 2016 at 6:28

1 Answer 1

0

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.