分类: LINUX
2009-03-23 13:27:11
static int __init gobalvar_init(void) { if (register_chrdev(MAJOR_NUM, " gobalvar ", &gobalvar_fops)) { //…注册失败 } else { //…注册成功 } } |
static void __exit gobalvar_exit(void) { if (unregister_chrdev(MAJOR_NUM, " gobalvar ")) { //…卸载失败 } else { //…卸载成功 } } |
int (*open)(struct inode * ,struct file *); |
void (*release) (struct inode * ,struct file *) ; |
ssize_t (*read) (struct file *, char *, size_t, loff_t *); |
static ssize_t globalvar_read(struct file *filp, char *buf, size_t len, loff_t *off) { … copy_to_user(buf, &global_var, sizeof(int)); … } |
ssize_t (*write) (struct file *, const char *, size_t, loff_t *); |
static ssize_t globalvar_write(struct file *filp, const char *buf, size_t len, loff_t *off) { … copy_from_user(&global_var, buf, sizeof(int)); … } |
int (*ioctl) (struct inode * ,struct file * ,unsigned int ,unsigned long); |
loff_t (*llseek) (struct file *, loff_t, int); |
unsigned int (*poll) (struct file *, struct poll_table_struct *); |