博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux驱动调试中关于ioctl的问题
阅读量:6388 次
发布时间:2019-06-23

本文共 5827 字,大约阅读时间需要 19 分钟。

1、提示:错误: 初始值设定项里有未知的字段‘ioctl’

2.6以后的内核中file_operation结构体已经删除了ioctl函数,取代的是:

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

1 struct file_operations { 2     struct module *owner; 3     loff_t (*llseek) (struct file *, loff_t, int); 4     ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); 5     ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); 6     ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t); 7     ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t); 8     int (*readdir) (struct file *, void *, filldir_t); 9     unsigned int (*poll) (struct file *, struct poll_table_struct *);10     long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);11     long (*compat_ioctl) (struct file *, unsigned int, unsigned long);12     int (*mmap) (struct file *, struct vm_area_struct *);13     int (*open) (struct inode *, struct file *);14     int (*flush) (struct file *, fl_owner_t id);15     int (*release) (struct inode *, struct file *);16     int (*fsync) (struct file *, loff_t, loff_t, int datasync);17     int (*aio_fsync) (struct kiocb *, int datasync);18     int (*fasync) (int, struct file *, int);19     int (*lock) (struct file *, int, struct file_lock *);20     ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);21     unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);22     int (*check_flags)(int);23     int (*flock) (struct file *, int, struct file_lock *);24     ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);25     ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);26     int (*setlease)(struct file *, long, struct file_lock **);27     long (*fallocate)(struct file *file, int mode, loff_t offset,28               loff_t len);29     int (*show_fdinfo)(struct seq_file *m, struct file *f);30 };
linux3.10 file_operations
1 struct file_operations { 2     struct module *owner; 3     loff_t (*llseek) (struct file *, loff_t, int); 4     ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); 5     ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); 6     ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t); 7     ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t); 8     int (*readdir) (struct file *, void *, filldir_t); 9     unsigned int (*poll) (struct file *, struct poll_table_struct *);10     int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);11     long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);12     long (*compat_ioctl) (struct file *, unsigned int, unsigned long);13     int (*mmap) (struct file *, struct vm_area_struct *);14     int (*open) (struct inode *, struct file *);15     int (*flush) (struct file *, fl_owner_t id);16     int (*release) (struct inode *, struct file *);17     int (*fsync) (struct file *, struct dentry *, int datasync);18     int (*aio_fsync) (struct kiocb *, int datasync);19     int (*fasync) (int, struct file *, int);20     int (*lock) (struct file *, int, struct file_lock *);21     ssize_t (*sendfile) (struct file *, loff_t *, size_t, read_actor_t, void *);22     ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);23     unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);24     int (*check_flags)(int);25     int (*dir_notify)(struct file *filp, unsigned long arg);26     int (*flock) (struct file *, int, struct file_lock *);27     ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);28     ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);29 };
linux2.6.22 file_operation

在file_operation 赋值处修改:

.unlocked_ioctl = xxx_ioctl

此处需注意ioctl与unlocked_ioctl函数原型的差异,否则会造成传入的cmd改变。

2、调试用到的Makefile

1 #KEVERS = $(shell uname -r) 2  3 #kernel path 配置过的 4 KEVERS := /home/liupf/work/linux-3.10.x 5 INCS := -I$(KEVERS) 6 #Kernel modules 7 obj-m += memdev.o 8  9 #EXTRA_CFAGS=-g -O010 11 kernel_modules:12     make -C $(KEVERS) M=$(CURDIR) modules13     14 test:15     #arm-linux-gcc -O2 test_can.c -o test_can 16     #Ubuntu kernel is 3.13  $(INCS)17     arm-none-linux-gnueabi-gcc  app-ioctl.c -o ioctl.out18 clean:19     make -C $(KEVERS) M=$(CURDIR) clean
Makefile

3、调试用的脚本

1 #install.sh2 rm -f /dev/memdev03 rmmod memdev.ko4 insmod memdev.ko5 mknod /dev/memdev0 c 251 0
install.sh

网上找的版本,待修改,不能直接用

1 #!/bin/sh 2 # install_mod.sh 3 module="memdev" 4 device="memdev" 5 mode="664" 6   7 # Group: since distributions do it differently, look for wheel or use staff 8 if grep '^staff:' /etc/group > /dev/null; then 9     group="staff"10 else11     group="kong"12 fi13  14 # remove stale nodes15 rm -f /dev/${device}?16  17 # invoke insmod with all arguments we got18 # and use a pathname, as newer modutils don't look in . by default19 /sbin/insmod -f ./$module.ko $* || exit 120  21 major=`cat /proc/devices | awk "\\$2==\"$module\" {print \\$1}"`22  23 mknod /dev/${device}0 c $major 024 mknod /dev/${device}1 c $major 125 ln -sf ${device}0  /dev/${device}26  27 # give appropriate group/permissions28 chgrp $group /dev/${device}[0-1]29 chmod $mode  /dev/${device}[0-1]
install_mod.sh
1 #!/bin/sh 2 # uninstall_mod.sh 3 module="memdev" 4 device="memdev" 5  6 # invoke rmmod with all arguments we got 7 /sbin/rmmod $module $* || exit 1 8  9 # Remove stale nodes10 rm -f /dev/${device}0
uninstall_mod.sh

 

linux驱动简单实例:

转载于:https://www.cnblogs.com/mofei004/p/8967662.html

你可能感兴趣的文章
layer弹出层的关闭问题
查看>>
LeetCode——3Sum & 3Sum Closest
查看>>
netstat详解
查看>>
微信小程序 --- e.currentTarget.dataset.id 获取不到值
查看>>
Introducing stapbpf – SystemTap’s new BPF backend
查看>>
详细介绍MySQL/MariaDB的锁
查看>>
0603-Zuul构建API Gateway-通过Zuul上传文件,禁用Zuul的Filter
查看>>
cocos2dx-2.x CCFileUtils文件管理分析(2)
查看>>
Emacs中多个golang项目的配置方法
查看>>
未知宽高div水平垂直居中3种方法
查看>>
Vim替换查找
查看>>
如何用sysbench做好IO性能测试
查看>>
利用线性回归模型进行卫星轨道预报
查看>>
懒加载和预加载
查看>>
前端面试题
查看>>
Python的赋值、浅拷贝、深拷贝
查看>>
用python操作mysql数据库(之代码归类)
查看>>
shell中的特殊符号
查看>>
centos安装iftop监控服务器流量
查看>>
ArcGIS Server 10.1 SP1连续查询出现Unable to complete operation错误
查看>>