LINUX系统下的设备驱动程序 具体到LINUX系统里,设备驱动程序所提供的这组入口点由一个结构来向系统进行说明,此结构定义为:
#include struct file_operations { int (*lseek)(struct inode *inode,struct file *filp, off_t off,int pos); int (*read)(struct inode *inode,struct file *filp, char *buf, int count); int (*write)(struct inode *inode,struct file *filp, char *buf,int count); int (*readdir)(struct inode *inode,struct file *filp, struct dirent *dirent,int count); int (*select)(struct inode *inode,struct file *filp, int sel_type,select_table *wait); int (*ioctl) (struct inode *inode,struct file *filp, unsigned int cmd,unsigned int arg); int (*mmap) (void);
int (*open) (struct inode *inode, struct file *filp); void (*release) (struct inode *inode, struct file *filp); int (*fsync) (struct inode *inode, struct file *filp); };
其中,struct inode提供了关于特别设备文件/dev/driver(假设此设备名为driver)的信息,它的定义为:
#include struct inode { dev_t i_dev; unsigned long i_ino; /* Inode number */ umode_t i_mode; /* Mode of the file */ nlink_t i_nlink; uid_t i_uid; gid_t i_gid; dev_t i_rdev; /* Device major and minor numbers*/ off_t i_size; time_t i_atime; time_t i_mtime; time_t i_ctime; unsigned long i_blksize; unsigned long i_blocks; struct inode_operations * i_op; struct super_block * i_sb; struct wait_queue * i_wait; struct file_lock * i_flock; struct vm_area_struct * i_mmap; struct inode * i_next, * i_prev; struct inode * i_hash_next, * i_hash_prev; struct inode * i_bound_to, * i_bound_by; unsigned short i_count; unsigned short i_flags; /* Mount flags (see fs.h) */ unsigned char i_lock; unsigned char i_dirt; unsigned char i_pipe; unsigned char i_mount; unsigned char i_seek; unsigned char i_update; union { struct pipe_inode_info pipe_i; struct minix_inode_info minix_i; struct ext_inode_info ext_i; struct msdos_inode_info msdos_i; struct iso_inode_info isofs_i; struct nfs_inode_info nfs_i; } u; };
|