error: unknownfield ‘ioctl’ specified in initializer

解决Linux内核2.6.36版本驱动移植时的ioctl初始化错误
本文详细解释了在将驱动从Linux内核2.6.32版本移植到2.6.36版本时遇到的ioctl初始化错误,并介绍了新版本中file_operations结构的变化,包括取消ioctl成员和新增unlocked_ioctl及compat_ioctl成员。文章还讨论了不兼容的指针类型初始化警告的原因,并提供了如何避免此类警告的方法。
AI助手已提取文章相关产品:

error: unknownfield ‘ioctl’ specified in initializer

异步通知的意思是:一旦设备就绪,则主动通知应用程序,这样应用程序就根本不需要查询设备的状态,

这一点非常类似于硬件上的“中断”的概念,比较准确的称谓是“信号驱动的异步I/O”。信号是在软件层次上对中断机制的一种模拟,在原理上一个进程接收到一个信号与处理器接收到一个中断请求是一样的。

1)在把驱动从2.6.32 移植到2.6.36时 报错


/home/kernel_test/globalfifo/globalfifo.c:240:2:error: unknown field 'ioctl' specified in initializer

才发现2.6.36的file_operations结构发生了重大变化。(但基本的思想还是不变的)

取消了原有的ioctl成员,添加来新的成员

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

2)/home/kernel_test/globalfifo/globalfifo.c:245:2:warning: initialization from incompatible pointer type

出现此种warnning 的原因 “不兼容的指针类型初始化”是你定义的函数类型与接口函数的类型不一样如 把 把返回值 long 定义成了 int

其中:

ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); ssize_t(*write) (struct file *, const char __user *, size_t, loff_t *);

少写const 也会引起 warning 因为在这里const所起的作用是避免函数使用指针去改变了传进来的值

237 238 /*文件操作结构体*/ 239 static const struct file_operations globalfifo_fops = { 240 .owner = THIS_MODULE, 241 .read = globalfifo_read, 242 .write = globalfifo_write, 243 //.ioctl = globalfifo_ioctl, 244 .unlocked_ioctl = globalfifo_ioctl, 245 .poll = globalfifo_poll, 246 .fasync = globalfifo_fasync, /*不要完了在这里也要加上 与内核联系的接口*/ 247 .open = globalfifo_open, 248 .release = globalfifo_release, 249 }; 250 251

您可能感兴趣的与本文相关内容

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
arp_final.c:16:0: warning: "IFNAMSIZ" redefined #define IFNAMSIZ 16 ^ In file included from arp_final.c:7:0: /usr/include/net/if.h:129:0: note: this is the location of the previous definition # define IFNAMSIZ IF_NAMESIZE ^ arp_final.c:68:8: error: redefinition of ‘struct ifreq’ struct ifreq { ^ In file included from arp_final.c:7:0: /usr/include/net/if.h:126:8: note: originally defined here struct ifreq ^ arp_final.c:69:10: error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘.’ token char ifr_name[IFNAMSIZ]; ^ arp_final.c: In function ‘if_nametoindex’: arp_final.c:125:16: error: ‘struct ifreq’ has no member named ‘ifr_ifrn’ strncpy(ifr.ifr_name, ifname, IFNAMSIZ - 1); ^ arp_final.c:134:15: error: ‘struct ifreq’ has no member named ‘ifr_ifru’ return ifr.ifr_ifru.ifru_metric; ^ arp_final.c: In function ‘get_local_mac’: arp_final.c:146:16: error: ‘struct ifreq’ has no member named ‘ifr_ifrn’ strncpy(ifr.ifr_name, ifname, IFNAMSIZ); ^ arp_final.c:153:20: error: ‘struct ifreq’ has no member named ‘ifr_ifru’ memcpy(mac, ifr.ifr_ifru.ifru_hwaddr.sa_data, MAC_LENGTH); ^ arp_final.c: In function ‘get_local_ip’: arp_final.c:166:16: error: ‘struct ifreq’ has no member named ‘ifr_ifrn’ strncpy(ifr.ifr_name, ifname, IFNAMSIZ); ^ arp_final.c:173:57: error: ‘struct ifreq’ has no member named ‘ifr_ifru’ struct sockaddr_in *sin = (struct sockaddr_in *)&ifr.ifr_ifru.ifru_addr; ^ arp_final.c: In function ‘build_arp_packet’: arp_final.c:191:25: error: ‘ETH_P_IP’ undeclared (first use in this function) arp->ar_pro = htons(ETH_P_IP); ^ arp_final.c:191:25: note: each undeclared identifier is reported only once for each function it appears in arp_final.c: In function ‘send_arp’: arp_final.c:230:12: error: variable ‘dest’ has initializer but incomplete type struct sockaddr_ll dest = { ^ arp_final.c:231:9: error: unknown field ‘sll_family’ specified in initializer .sll_family = AF_PACKET, ^ arp_final.c:232:9: error: unknown field ‘sll_protocol’ specified in initializer .sll_protocol = htons(ETH_P_ARP), ^ arp_final.c:232:25: warning: excess elements in struct initializer .sll_protocol = htons(ETH_P_ARP), ^ arp_final.c:232:25: note: (near initialization for ‘dest’) arp_final.c:233:9: error: unknown field ‘sll_ifindex’ specified in initializer .sll_ifindex = if_nametoindex(ifname), ^ arp_final.c:233:24: warning: excess elements in struct initializer .sll_ifindex = if_nametoindex(ifname), ^ arp_final.c:233:24: note: (near initialization for ‘dest’) arp_final.c:234:9: error: unknown field ‘sll_halen’ specified in initializer .sll_halen = ETH_ALEN, ^ arp_final.c:24:18: warning: excess elements in struct initializer #define ETH_ALEN 6 ^ arp_final.c:234:22: note: in expansion of macro ‘ETH_ALEN’ .sll_halen = ETH_ALEN, ^ arp_final.c:24:18: note: (near initialization for ‘dest’) #define ETH_ALEN 6 ^ arp_final.c:234:22: note: in expansion of macro ‘ETH_ALEN’ .sll_halen = ETH_ALEN, ^ arp_final.c:235:9: error: unknown field ‘sll_addr’ specified in initializer .sll_addr = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} // 广播地址 ^ arp_final.c:235:21: error: extra brace group at end of initializer .sll_addr = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} // 广播地址 ^ arp_final.c:235:21: note: (near initialization for ‘dest’) arp_final.c:235:21: warning: excess elements in struct initializer arp_final.c:235:21: note: (near initialization for ‘dest’) arp_final.c:230:24: error: storage size of ‘dest’ isn’t known struct sockaddr_ll dest = { ^ arp_final.c: In function ‘find_or_create_node’: arp_final.c:275:5: warning: implicit declaration of function ‘list_for_each’ [-Wimplicit-function-declaration] list_for_each(pos, &arp_result_head) { ^ arp_final.c:275:42: error: expected ‘;’ before ‘{’ token list_for_each(pos, &arp_result_head) { ^ arp_final.c: In function ‘cleanup_thread’: arp_final.c:373:9: warning: implicit declaration of function ‘list_for_each_safe’ [-Wimplicit-function-declaration] list_for_each_safe(pos, next, &arp_result_head) { ^ arp_final.c:373:57: error: expected ‘;’ before ‘{’ token list_for_each_safe(pos, next, &arp_result_head) { ^ arp_final.c: In function ‘print_arp_table’: arp_final.c:403:42: error: expected ‘;’ before ‘{’ token list_for_each(pos, &arp_result_head) { 报错如上
08-28
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值