proc文件读写实现

来源:互联网 发布:mysql驱动配置 编辑:程序博客网 时间:2024/05/22 09:44

1、创建proc文件

            entry = create_proc_entry(DEVICE_PROC_NAME, 0666, NULL);

2、关联函数

              entry->read_proc = m_proc_read;
              entry->write_proc = m_proc_write;
3、读函数
              static ssize_t m_proc_read(char* page, char** start, off_t off, int count, int* eof, void*     data) {
              len = snprintf(page, PAGE_SIZE,"%d\n", val);
              return len;}

             读取命令 cat dev
4、写函数
            static ssize_t m_proc_write(struct file* filp, const char __user *buff, unsigned long len,     void* data) {

             page = (char*)__get_free_page(GFP_KERNEL);
             copy_from_user(page, buff, len)
             return len;
            }
            写命令 echo “111” >dev

5、撤销proc文件

           remove_proc_entry(DEVICE_PROC_NAME,NULL);



0 0