void create_proc(void){ struct proc_dir_entry *entry; entry= create_proc_entry("proc_f",0,NULL); entry->read_proc=f_read_proc; entry->write_proc=f_write_proc; } static int f_read_proc(char *buf,char **start,off_t pos,int count, int *eof,void *data) { return sprintf(buf,"hello wrold!\n"); } static int f_write_proc(struct file *file,const char __user *buffer, unsigned long count,void *data) { char k_buf = vmalloc(count); if (k_buf) { printk(KERN_ERR "Failed to allocate buffer \n"); return 0; } if(copy_from_user(k_buf,buffer,count)){ printk(KERN_ERR "Failed to copy data from user!\n"); return -EFAULT; } }
linux proc下创建文件
最新推荐文章于 2023-08-24 22:07:34 发布