linux 驱动学习 常用头文件 cdev.h

#ifndef _LINUX_CDEV_H
#define _LINUX_CDEV_H

#include <linux/kobject.h
#include <linux/kdev_t.h>
#include <linux/list.h>

struct file_operations;
struct inode;
struct module;

struct cdev {
    struct kobject kobj;
    struct module *owner;
    const struct file_operations *ops;
    struct list_head list;
    dev_t dev;
    unsigned int count;
};

void cdev_init(struct cdev *, const struct file_operations *);
//初始化字符设备可以进行的文件操作——file_operations 结构体记录了所有可以对cdev结构体描述的字符设备进行的操作//初始化cdev结构体

struct cdev *cdev_alloc(void);//先申请cdev结构体

void cdev_put(struct cdev *p);//减少使用计数  

int cdev_add(struct cdev *, dev_t, unsigned);//cdev结构体初始化完事之后,就需要把设备加入到内核中了,调用cdev_add 

void cdev_del(struct cdev *);//不用cdev设备的话就调用cdev_dev

void cd_forget(struct inode *);

extern struct backing_dev_info directly_mappable_cdev_bdi;

#endif

 

posted @ 2016-12-07 16:15  星星stars  阅读(518)  评论(0编辑  收藏  举报