via:http://blog.chinaunix.net/uid-20672257-id-3142809.html
1、写出open、write函数
2、告诉内核
1)、定义一个struct file_operations结构并填充好
static struct file_operations first_drv_fops = { .owner = THIS_MODULE, /* 这是一个宏,推向编译模块时自动创建的__this_module变量 */ .open = first_drv_open, .write = first_drv_write, };
major = register_chrdev(0, "first_drv", &first_drv_fops); // 注册, 告诉内核 //相关参数: //第一个,设备号,0自动分配主设备号,否则为主设备号0-255 //第二个:设备名 //第三个:struct file_operations结构体
4)、register_chrdev由谁调用(入口函数调用) static int first_drv_init(void)
原文:http://www.cnblogs.com/izhangzhne/p/4493923.html