Difference between ioctl and unlock_ioctl

Publisher:Mingyue1314Latest update time:2024-08-12 Source: cnblogsKeywords:ioctl Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

I spent a lot of time debugging a program today and found that the cmd parameter of the application's ioctl passed to the driver's ioctl changed. According to "Linux Device Driver", this cmd should remain unchanged. Because the ioctl function pointer in struct file_operations has been completely deleted in kernel 2.6.36 and replaced by unlocked_ioctl, I doubt whether the two are compatible. I checked some information online, and many articles only talked about it in general, saying that ioctl in the application is compatible and does not need to be changed. The biggest impact of the change of this pointer function in the driver is that inode is missing in the parameter, so the application ioctl is compatible, but our ioctl function in the driver must be changed, otherwise the cmd parameter will change:


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,
};

int globalmem_ioctl(struct file* filp, unsigned int cmd, unsigned long arg) //No inode parameter!

{

switch (cmd)

{

case:XXX: ...

}

}


Keywords:ioctl Reference address:Difference between ioctl and unlock_ioctl

Previous article:Penmount serial touch screen loading
Next article:Add your own directory to the kernel directory

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号