cdev动态和静态注册的理解错误
来源:互联网 发布:nba视频网络直播 编辑:程序博客网 时间:2024/05/29 03:40
先写下LDD3P59页字符设备的注册一节的原文:
我们前面提到,内核内部使用struct cdev结构来表示字符设备。。。
分配和初始化上述结构的方式有两种。如果读者打算在运行时获取一个独立的cdev结构,则应该如下编写代码:
struct cdev *my_cdev = cdev_alloc();
my_cdev->ops = &my_fops;
这时,你可以将cdev结构嵌入到自己的设备待定结构中,scull就是这样做的。这种情况下,我们需要用下面的代码来初始化已分配到的结果:
void cdev_init(struct cdev *cdev, struct file_operations *fops);
。。。
上面是部分原文,主要是”这时“让我产生了误解,以为是上面申请好后,下面进行了初始化。
查看了英文的原文:(多copy了两段)
There are two ways of allocating and initializing one of these structures. If you wish to obtain a standalone cdev structure at runtime, you may do so with code such as:
struct cdev *my_cdev = cdev_alloc( );
my_cdev->ops = &my_fops;
Chances are, however, that you will want to embed the cdev structure within a device-specific structure of your own; that is what scull does. In that case, you
should initialize the structure that you have already allocated with:
void cdev_init(struct cdev *cdev, struct file_operations *fops);
Either way, there is one other struct cdev field that you need to initialize. Like the file_operations structure, struct cdev has an owner field that should be set to
THIS_MODULE.
Once the cdev structure is set up, the final step is to tell the kernel about it with a call to:
int cdev_add(struct cdev *dev, dev_t num, unsigned int count);
找到了有疑问的那一段,查了下解释:
chances are that:可能
initialize: vt 初始化
它的意思是指你可以在运行时动态的分配一个cdev结构,也可以把cdev结构内嵌到一个自己的设备结构中然而后者就需要使用cdev_init来初始化你已分配的结构。
所以
struct cdev *my_cdev = cdev_alloc();
my_cdev->ops = &my_fops;
和
void cdev_init(struct cdev *cdev, struct file_operations *fops);
是对cdev结构的两种初始化方式。
- cdev动态和静态注册的理解错误
- 监听的动态注册和静态注册
- android—BroadcastReceiver 静态注册和动态注册Context理解
- oracle监听的静态注册,与动态注册理解
- android-fragment的静态和动态注册。
- Oracle数据库的动态注册和静态注册
- Oracle Listener的静态注册和动态注册
- Oracle Listener的静态注册和动态注册
- 赵雅智_BroadcastReceiver广播接收者的动态注册和静态注册
- ORACLE 动态注册和静态注册的区别
- Broadcast的使用(静态注册和动态注册)
- Android的广播Receiver动态注册和静态注册
- Oracle监听的静态注册和动态注册
- Android静态注册和动态注册广播的区别
- Android静态注册广播和动态注册广播的区别
- JNI方法的静态注册和动态注册RegisterNatives
- listener静态注册和动态注册总结
- Oracle listener静态注册和动态注册
- Java使用Array类创建多维数组
- Oracle创建临时表空间、表空间、用户、导入导出等命令
- Just a Numble 2117
- Mac安装Brew
- Spring注入方式二:构造器注入
- cdev动态和静态注册的理解错误
- iOS 中 CAtextLayer 类的妙用 -
- Extjs案例--员工信息填写界面布局
- 博弈基础知识总结
- 快速排序实现
- sqlserver锁表、解锁、查看销表
- 查看sqlserver被锁的表以及如何解锁
- 解压xz文件
- Java中Array与ArrayList的主要区别