Chinaunix首页 | 论坛 | 博客
  • 博客访问: 467699
  • 博文数量: 134
  • 博客积分: 3056
  • 博客等级: 中校
  • 技术积分: 1150
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-14 15:53
文章分类
文章存档

2013年(1)

2010年(133)

我的朋友

分类: LINUX

2010-08-08 21:53:41

dev_t is the type used to represent device numbers within the kernel.

#include <linux/types.h>
dev_t



Macros that extract the major and minor numbers from a device number.

int MAJOR(dev_t dev);
int MINOR(dev_t dev);



Macro that builds a dev_t data item from the major and minor numbers.

dev_t MKDEV(unsigned int major, unsigned int minor);



The “filesystem” header is the header required for writing device drivers. Many  important functions and data structures are declared in here.

#include <linux/fs.h>



Functions that allow a driver to allocate and free ranges of device numbers.  register_chrdev_region should be used when the desired major number is known  in advance; for dynamic allocation, use alloc_chrdev_region instead.

int register_chrdev_region(dev_t first, unsigned int count, char *name);
int alloc_chrdev_region(dev_t *dev, unsigned int firstminor, unsigned int count, char *name);
void unregister_chrdev_region(dev_t first, unsigned int count);



The old (pre-2.6) char device registration routine. It is emulated in the 2.6 kernel but should not be used for new code. If the major number is not 0, it is used  unchanged; otherwise a dynamic number is assigned for this device.

int register_chrdev(unsigned int major, const char *name, struct file_operations *fops);



Function that undoes a registration made with register_chrdev. Both major and  the name string must contain the same values that were used to register the  driver.

int unregister_chrdev(unsigned int major, const char *name);



Three important data structures used by most device drivers. The file_operations  structure holds a char driver’s methods; represents an open file, and struct file struct inode represents a file on disk.

struct file_operations;
struct file;
struct inode;



Functions for the management of cdev structures, which represent char devices  within the kernel.

#include <linux/cdev.h>
struct cdev *cdev_alloc(void);
void cdev_init(struct cdev *dev, struct file_operations *fops);
int cdev_add(struct cdev *dev, dev_t num, unsigned int count);
void cdev_del(struct cdev *dev);



A convenience macro that may be used to obtain a pointer to a structure from a  pointer to some other structure contained within it.

#include <linux/kernel.h>
container_of(pointer, type, field);



This include file declares functions used by kernel code to move data to and  from user space.

#include <asm/uaccess.h>



Copy data between user space and kernel space.

unsigned long copy_to_user (void *to, const void *from, unsigned long count);


阅读(614) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~