在内部, scull 使用一个 struct scull_dev 类型的结构表示每个设备. 这个结构定义为:

struct scull_dev {

struct scull_qset *data;  /* Pointer to first quantum set */ int quantum;              /* the current quantum size */

int qset;  /* the current array size */

unsigned long size;  /* amount of data stored here */

unsigned int access_key;  /* used by sculluid and scullpriv */ struct semaphore sem;         /* mutual exclusion semaphore  */ struct cdev cdev; /* Char device structure */

};

我们在遇到它们时讨论结构中的各个成员, 但是现在, 我们关注于 cdev, 我们的设备与内 核接口的 struct cdev. 这个结构必须初始化并且如上所述添加到系统中; 处理这个任务 的 scull 代码是:

static void scull_setup_cdev(struct scull_dev *dev, int index)

{

int err, devno = MKDEV(scull_major, scull_minor + index);

cdev_init(&dev->cdev, &scull_fops); dev->cdev.owner = THIS_MODULE;

dev->cdev.ops = &scull_fops;

err = cdev_add (&dev->cdev, devno, 1);

/* Fail gracefully if need be */ if (err)

printk(KERN_NOTICE
"Error %d adding scull%d", err, index);

}

因为 cdev 结构嵌在 struct scull_dev 里面, cdev_init 必须调用来进行那个结构的初
始化.

linux scull 中的设备注册的更多相关文章

  1. scull 中的设备注册

    在内部, scull 使用一个 struct scull_dev 类型的结构表示每个设备. 这个结构定义为: struct scull_dev { struct scull_qset *data;  ...

  2. Linux系统中存储设备的两种表示方法

    转:https://blog.csdn.net/holybin/article/details/38637381 一.对于IDE接口的硬盘的两种表示方法: 1.IDE接口硬盘,对于整块硬盘的两种表示方 ...

  3. linux scull 中的读写代码

    读和写方法都进行类似的任务, 就是, 从和到应用程序代码拷贝数据. 因此, 它们的原型 相当相似, 可以同时介绍它们: ssize_t read(struct file *filp, char   u ...

  4. linux scull 中的缺陷

    让我们快速看一段 scull 内存管理代码. 在写逻辑的深处, scull 必须决定它请求的内 存是否已经分配. 处理这个任务的代码是: if (!dptr->data[s_pos]) { dp ...

  5. 重新指派usb转串口模块在linux系统中的设备调用名称

    How to remap /dev/ttyUSB* to a specific name to be called by my program. How to map /dev/ttyUSB* to ...

  6. Linux 内核中的 Device Mapper 机制

    本文结合具体代码对 Linux 内核中的 device mapper 映射机制进行了介绍.Device mapper 是 Linux 2.6 内核中提供的一种从逻辑设备到物理设备的映射框架机制,在该机 ...

  7. [platform]新旧内核的device设备注册对比

    转自:http://blog.chinaunix.net/uid-7332782-id-3268801.html 1. Version2.6内核启动过程 start_kernel( ) //板子上电启 ...

  8. 【Linux驱动】字符设备驱动

    一.linux系统将设备分为3类:字符设备.块设备.网络设备.使用驱动程序: 1.字符设备:是指只能一个字节一个字节读写的设备,不能随机读取设备内存中的某一数据,读取数据需要按照先后数据.字符设备是面 ...

  9. [转] Linux 内核中的 Device Mapper 机制

    本文结合具体代码对 Linux 内核中的 device mapper 映射机制进行了介绍.Device mapper 是 Linux 2.6 内核中提供的一种从逻辑设备到物理设备的映射框架机制,在该机 ...

随机推荐

  1. python ndarray相关操作:切分

  2. Permutations 全排列 回溯

    Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...

  3. hpacucli工具linux系统下重做阵列

    需要安装hpacucli-8.0-14.noarch.rpm 这个工具 hpacucli ctrl all show   查看卡位  图上slot 2 下面命令上要使用到的 查看硬盘类型 hpacuc ...

  4. PyChram创建虚拟环境

    目录 1. python创建虚拟环境 2. pycharm中添加python虚拟环境 1. python创建虚拟环境 首先要安装virtualenv模块.打开命令行,输入pip install vir ...

  5. jQuery动态加载动画spin.js

    在线演示 本地下载

  6. 微信公众号系统在Linux下的部署操作

    ps -ef | grep tomcat 查看tomcat进程

  7. day39-Spring 17-Spring的JDBC模板:完成增删改的操作

    JdbcTemplate根DBUtils非常类似,你要是有非常多的Dao,你每一个Dao都需要写它 /*在Dao层注入JDBC模板*/ private JdbcTemplate jdbcTemplat ...

  8. linux的简单操作

    查看当前用户who am i 创建用户:sudo adduser lilei然后输入密码 查看用户:ls /home 用新用户登陆:su -l lilei 查看所属用户组:groups 用户名 新建文 ...

  9. 小爬爬6.scrapy回顾和手动请求发送

    1.数据结构回顾 #栈def push(self,item) def pop(self) #队列 def enqueue(self,item) def dequeue(self) #列表 def ad ...

  10. SDUT-2138_判断可达性

    数据结构实验之图论三:判断可达性 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 在古老的魔兽传说中,有两个军团,一个叫 ...