about /proc read and write functions

帅比萌擦擦* 提交于 2019-12-02 12:00:26

Your functions for proc_read and proc_write don't match the place you're using them, as the compiler pointed out with its warnings. In your struct file_operations you have:

int proc_read(char *buffer,char **buffer_location,off_t offset,int buffer_length,int 
*eof,void *data);

int proc_write(struct file *file, const char *buffer, unsigned long count,void *data);

These are both being used in a struct file_operations, but in include/linux/fs.h the function pointer types in that struct are:

ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);

If int isn't the same a ssize_t int isn't the same as size_t (unlikely since one's signed and the other isn't) then you'll see problems, but your read there has more serious problems - you have a char ** where it expects a char *.

The compiler was quite happy to take your word that this was what you meant to do, but I don't think it was.

This read looks more like read_proc_t in struct proc_dir_entry, but that's not what you're setting in your dev_proc_ops.

(As a side note I think you probably want to make the rest of your functions static also, since they're exposed via function pointers)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!