In the post "Creating an ioctl command in linux " we saw the basics of ioctl, and how we can create our own ioctl commands. The functions used to create ioctls have undergone a change from the kernel version 2.6.39,and the previous functions are no longer valid.
Before 2.6.39, the ioctl calls would lock the BKL (Big kernel lock) and then execute the required functions. This was unnecessary with the new fine grained locking available in the kernel. Thus to improve the implementation of ioctl, a new operation called unlocked_ioctl was introduced and all the existing ioctls were migrated to this new implementation.
Thus stating 2.6.39 the older implementation is no longer available.
The changes required in implementation of the ioctl are.
The function in the driver has changed from
The inode is no longer passed as an argument.
The fops uses the name unlocked_ioctl
The basic working of ioctl remains same.
Here is a code that implements the above mentioned changes if the kernel version is more than 2.6.39, else uses the older interface.
Module: ioctl_basic.c
The steps of compiling and testing the module are same as shown in the post "Creating an ioctl command in linux "
Before 2.6.39, the ioctl calls would lock the BKL (Big kernel lock) and then execute the required functions. This was unnecessary with the new fine grained locking available in the kernel. Thus to improve the implementation of ioctl, a new operation called unlocked_ioctl was introduced and all the existing ioctls were migrated to this new implementation.
Thus stating 2.6.39 the older implementation is no longer available.
The changes required in implementation of the ioctl are.
The function in the driver has changed from
The inode is no longer passed as an argument.
The fops uses the name unlocked_ioctl
The basic working of ioctl remains same.
Here is a code that implements the above mentioned changes if the kernel version is more than 2.6.39, else uses the older interface.
Module: ioctl_basic.c
The steps of compiling and testing the module are same as shown in the post "Creating an ioctl command in linux "
Excellent !
ReplyDeleteThis poster is for kernel 2.6.36.
Thank you :-), yes it is for kernel versions above 2.6.36.
DeleteYou should revise your post as the prototype for ioctl function demands that the return type be long and not integer.So the initialization of ulocked_ioctl will be incompatible with int ioct_funcs. The return type should be long and not int.
ReplyDeleteThank for the correction, have modified the post.
Delete