Linux驱动开发④--unknown field ‘ioctl’ specified in initializer .ioctl = xxx

本文介绍了在Linux 2.6.36内核中file_operations结构的重要变化,特别是ioctl成员函数的变化。原有的ioctl被拆分为unlocked_ioctl和compat_ioctl两个函数,以支持新的API调用方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在linux-2.6.36内核上加载编译驱动时,出现

error:unknown field 'ioctl' specified in initializer

原因是:在2.6.36内核上file_operations发生了重大的改变:

原先的

  int (*ioctl)(struct inode*, struct file*, unsigned int, unsigned long);

被改为了       

  long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
  long (*compat_ioctl) (struct file *, unsigned int, unsigned long);

因而在实际驱动中,我们需要将原先的写的ioctl函数头给改成下面的unlocked_ioctl,在file_operations结构体的填充中也是一样。


k1@k1:~/work/CDemo$ gcc 170.c 170.c: In function ‘main’: 170.c:147:12: error: variable ‘phdr’ has initializer but incomplete type struct pseudo_udp_header phdr = { ^ 170.c:148:9: error: unknown field ‘src_ip’ specified in initializer .src_ip = ip_hdr->saddr, ^ 170.c:148:19: warning: excess elements in struct initializer .src_ip = ip_hdr->saddr, ^ 170.c:148:19: note: (near initialization for ‘phdr’) 170.c:149:9: error: unknown field ‘dst_ip’ specified in initializer .dst_ip = ip_hdr->daddr, ^ 170.c:149:19: warning: excess elements in struct initializer .dst_ip = ip_hdr->daddr, ^ 170.c:149:19: note: (near initialization for ‘phdr’) 170.c:150:9: error: unknown field ‘zero’ specified in initializer .zero = 0, ^ 170.c:150:17: warning: excess elements in struct initializer .zero = 0, ^ 170.c:150:17: note: (near initialization for ‘phdr’) 170.c:151:9: error: unknown field ‘protocol’ specified in initializer .protocol = IPPROTO_UDP, ^ 170.c:152:9: error: unknown field ‘length’ specified in initializer .length = udp_hdr->len ^ 170.c:152:19: warning: excess elements in struct initializer .length = udp_hdr->len ^ 170.c:152:19: note: (near initialization for ‘phdr’) 170.c:147:30: error: storage size of ‘phdr’ isn’t known struct pseudo_udp_header phdr = { ^ 170.c:284:24: error: variable ‘ack_phdr’ has initializer but incomplete type struct pseudo_udp_header ack_phdr = { ^ 170.c:285:21: error: unknown field ‘src_ip’ specified in initializer .src_ip = ack_ip->saddr, ^ 170.c:285:31: warning: excess elements in struct initializer .src_ip = ack_ip->saddr, ^ 170.c:285:31: note: (near initialization for ‘ack_phdr’) 170.c:286:21: error: unknown field ‘dst_ip’ specified in initializer .dst_ip = ack_ip->daddr, ^ 170.c:286:31: warning: excess elements in struct initializer .dst_ip = ack_ip->daddr, ^ 170.c:286:31: note: (near initialization for ‘ack_phdr’) 170.c:287:21: error: unknown field ‘zero’ specified in initializer .zero = 0, ^ 170.c:287:29: warning: excess elements in struct initializer .zero = 0, ^ 170.c:287:29: note: (near initialization for ‘ack_phdr’) 170.c:288:21: error: unknown field ‘protocol’ specified in initializer .protocol = IPPROTO_UDP, ^ 170.c:289:21: error: unknown field ‘length’ specified in initializer .length = ack_udp->len ^ 170.c:289:31: warning: excess elements in struct initializer .length = ack_udp->len ^ 170.c:289:31: note: (near initialization for ‘ack_phdr’) 170.c:284:42: error: storage size of ‘ack_phdr’ isn’t known struct pseudo_udp_header ack_phdr = { ^ k1@k1:~/work/CDemo$
最新发布
08-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值