- 论坛徽章:
- 0
|
在Linux2.6内核中一个字符设备用cdev结构来描述,其定义如下:
struct cdev {
struct kobject kobj;
struct module *owner; //所属模块
const struct file_operations *ops;
//文件操作结构,在写驱动时,其结构体内的大部分函数要被实现
struct list_head list;
dev_t dev; //设备号,int 类型,高12位为主设备号,低20位为次设备号
unsigned int count;
};
可以使用如下宏调用来获得主、次设备号:
MAJOR(dev_t dev)
MINOR(dev_t dev)
MKDEV(int major,int minor) //通过主次设备号来生成dev_t
以上宏调用在内核源码中如此定义:
#define MINORBITS 20
#define MINORMASK ((1U > MINORBITS))
#define MINOR(dev) ((unsigned int) ((dev) & MINORMASK))
#define MKDEV(ma,mi) (((ma) cdev_add() //此过程在加载模块中
cdev_del()-->unregister_chrdev_region() //此过程在卸载模块中
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/110644/showart_2165877.html |
|