当前位置: 技术问答>linux和unix
关于字符设备驱动的一个问题,谢谢!
来源: 互联网 发布时间:2016-02-12
本文导语: 我们知道通过cdev_map(static struct kobj_map *cdev_map; struct kobj_map类型全局变量)实现从设备号到cdev结构的映射(通过hash): struct cdev { struct kobject kobj; struct module *owner; struct file_operations *ops; struct list_head list...
我们知道通过cdev_map(static struct kobj_map *cdev_map; struct kobj_map类型全局变量)实现从设备号到cdev结构的映射(通过hash):
struct cdev {
struct kobject kobj;
struct module *owner;
struct file_operations *ops;
struct list_head list;
dev_t dev;
unsigned int count;
};
struct kobj_map {
struct probe {
struct probe *next;
dev_t dev;
unsigned long range;
struct module *owner;
kobj_probe_t *get;
int (*lock)(dev_t, void *);
void *data;
} *probes[255];
struct rw_semaphore *sem;
};
另一方面通过chrdevs[MAX_PROBE_HASH]实现从设备号到char_device_struct结构的映射,char_device_struct结构中包含cdev对象:
static struct char_device_struct {
struct char_device_struct *next;
unsigned int major;
unsigned int baseminor;
int minorct;
const char *name;
struct file_operations *fops;
struct cdev *cdev; /* will die */
} *chrdevs[MAX_PROBE_HASH];
那么既然能够从设备号找到char_device_struct结构,就能找到cdev,那么还要kobj_map 干什么呢? 两者功能是否有重复?谢谢!
struct cdev {
struct kobject kobj;
struct module *owner;
struct file_operations *ops;
struct list_head list;
dev_t dev;
unsigned int count;
};
struct kobj_map {
struct probe {
struct probe *next;
dev_t dev;
unsigned long range;
struct module *owner;
kobj_probe_t *get;
int (*lock)(dev_t, void *);
void *data;
} *probes[255];
struct rw_semaphore *sem;
};
另一方面通过chrdevs[MAX_PROBE_HASH]实现从设备号到char_device_struct结构的映射,char_device_struct结构中包含cdev对象:
static struct char_device_struct {
struct char_device_struct *next;
unsigned int major;
unsigned int baseminor;
int minorct;
const char *name;
struct file_operations *fops;
struct cdev *cdev; /* will die */
} *chrdevs[MAX_PROBE_HASH];
那么既然能够从设备号找到char_device_struct结构,就能找到cdev,那么还要kobj_map 干什么呢? 两者功能是否有重复?谢谢!
|
char_device_struct的cdev域只是由于历史原因留下来,以后的版本就可能没有该域,所以他有个注释:/* will die */
在2.6.21/fs/char_dev.c里面没有用到该域
在2.6.21/fs/char_dev.c里面没有用到该域