IOCTL and UNLOCK_IOCTL functions __ functions

Source: Internet
Author: User
IOCTL and UNLOCK_IOCTL functions

This article turns from: http://blog.csdn.net/punk_lover/article/details/19610643

but I may have ignored the return value type of the function as long

When I was working, I found a warning when I compiled the program.

"Warning:initialization from incompatible pointer type [enabled by default]
: Warning: (near initialization for ' Hello_fops.unlocked_ioctl ') [enabled by default]

The details are found because the function return value type is long integer

Today, a program tuned for half a day, found that the application of the ioctl cmd parameter to the driver ioctl changed. And according to "Linux device driver" This cmd should be unchanged. Since the IOCTL function pointer in the struct file_operations has been completely removed in the kernel 2.6.36, Unlocked_ioctl is replaced, so I suspect that the two are not compatible. On the Internet to check some information, a lot of articles just general talk about, said in the application IOCTL is compatible, do not have to change. The biggest effect of this pointer function in the driver is that the inode is less in the parameter, so the application IOCTL is compatible, but our IOCTL function in the driver must change, otherwise the cmd parameter will change:

The original driver

static const struct File_operations globalmem_fops=
{
. Owner=this_module,
. Llseek=globalmem_llseek,
. Open=globalmem_open,
. Read=globalmem_read,
. Write=globalmem_write,
. Ioctl=globalmem_ioctl,
. Release=globalmem_release,
};

int Globalmem_ioctl (struct inode* inode,struct file* filp, unsigned int cmd,unsigned long arg)

{

Switch (CMD)

{

Case:xxx: ...

......

}

}

After the change

static const struct File_operations globalmem_fops=
{
. Owner=this_module,
. Llseek=globalmem_llseek,
. Open=globalmem_open,
. Read=globalmem_read,
. Write=globalmem_write,
. Unlocked_ioctl=globalmem_ioctl,
. Release=globalmem_release,
};

Long Globalmem_ioctl (struct file* filp, unsigned int cmd,unsigned long arg)//no inode parameter. The return value is long.

{

Switch (CMD)

{

Case:xxx: ...

......

}

}

Summary: When IOCTL changed to Unlocked_ioctl, there were two changes: one was that the return value type changed to a long integer; the second one was less the first parameter inode;

Note that the corresponding change in file_operations to Unlocked_ioctl

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.