[SOLVED] Linux Kernel Dev - Getting 'Invalid argument' error when using IOCTL
Linux - KernelThis forum is for all discussion relating to the Linux kernel.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Linux Kernel Dev - Getting 'Invalid argument' error when using IOCTL
We have created a block driver which traces the IO operations happening on a particular block device say /dev/sdb or /dev/sdc.
It's working, so now I am trying to develop a user space application that will interact with driver (add or remove block device from userspace).
I have created a skeleton and underlying program but facing an error 'invalid argument'.
My userspace program is like this:
char path[SIZE];
printf( "Enter the path of the block device to add or remove: ");
fgets(path, SIZE, stdin);
path[strcspn(path, "\n")] = '\0';
int fd = open( path, O_RDWR );
if( fd < 0 )
{
perror( "Failed to open device" );
exit( EXIT_FAILURE );
}
while( 1 )
{
int input;
printf( "Enter a number [ 0 for add and 1 for remove ]: " );
scanf( "%d", &input );
Proposed working - We pass IOCTL commands from userspace add/remove device. So, for add ioctl device will be registered with my block driver which will start tracking the changes for ex. /dev/sdb and remove will stop the tracking.
So, do you know how can I solve this error? or if there is better approach plz feel free to give your valuable suggestions.
It would help if you edited your question and used code tags so it is properly formatted and readable. What code is giving the 'Invalid argument' error?
If you enter "/dev/sdb", you are opening "/dev/sdb" and sending it an ioctl request that it does not understand. It returns EINVAL, because it has no idea what MY_BLOCK_DEVICE_* means. You must pass the path and the request to your own driver, not to /dev/sdb.
If you enter "/dev/sdb", you are opening "/dev/sdb" and sending it an ioctl request that it does not understand. It returns EINVAL, because it has no idea what MY_BLOCK_DEVICE_* means. You must pass the path and the request to your own driver, not to /dev/sdb.
Thanks, you were right. I corrected my code and now it is working.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.