Question

Recently, I developed a simple file system kernel module. So, I needed to assign my own ioctl function (.unlocked_ioctl) to the file_operation structure to implement specific commands to my file system module. The Ext4 file system has its own ioctl function, for example.

Then, I created a file using the dd command and mounted it:

# mount -t myfs -o loop simple_file /mnt/

Everything works fine, but how can I access this file system using ioctl with a user space program?

I tryed to do ioctl(fd, MY_COMMAND_1, &my_struct_t); (where fd is the file descriptor of the dev file /dev/loop[0..7]), but it returns me Invalid argument.

Was it helpful?

Solution

If you open /dev/loop0, you're accessing a loop device, and therefore you're talking to the loop driver.

The ioctl handler that you've registered for your filesystem applies to files opened on a mounted filesystem.

fd = open("/mnt/something", O_RDWR);
ioctl(fd, MY_COMMAND_1, &my_struct_t);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top