Hello, this is my first post to this list, so it's the best time to introduce myself: My name is Johannes Held and I'm a 23 year old student of computer sience. Please don't be annoyed if some sentences might read 'strange' - I'm german but I try to write as good English as possible. In my studentjob I have to code a gateway-module for some embedded linux devices. Good Thing: There's already code for that. Bad Thing: It _worked_. Past Time. :-) And now, I'm to fix this. We take heavy use of /proc. Datasizes beyond pagesize are passed to our module an read from it (mainly information about the routing..). Writing into the procfile works without problems. But reading isn't as normal as it should. First, in the code, the proc-functions are these "filelike"-function, with which you could ceck permissions and more stuff. Cause we don't check permissions feel free to show me better function-signatures. perhaps this one: > int (*read_proc)(char *page, char **start, off_t offset, int count, int *eof, void *data) instead of this one: > ssize_t (*read_proc)(struct file *file_, char __user *user_, size_t size_, loff_t *off_) Perhaps you can tell me, what data is passed in *off; I attached the stripped down part of the code. I pen&papered it. It's working. If all data is written, I return 0 to signal EOF. But - and here's the problem - cat or joe don't bother. They start reading again (but without opening the file again). I did some printks. And right after returning 0, the function is called again in an endless loop. Now I've written a very simple programm to read form a file until read says: "O. You reached EOF." AND: It works. I write two lines (~54Bytes) into my file and read the data back. cat gives me millions of lines.. and joe "dies" by filling his internal buffer. So, what's the problem in this code? I hope I properly described my problem. Please feel free to request any other information you need. -- Gruß, Johannes http://www.hehejo.de
struct proc_dir_entry *f_i2ep; char n_i2ep[NAME_S] = "id2ext_ports"; module_param_string(i2ep, n_i2ep, sizeof(n_i2ep), 0); char* i2ep_buf = NULL; #define I_EP_LINE_S \ sizeof("node_=__ext_port_=_65535_") + \ sizeof(faps_id_t) int i_ep_use = 0; int i_ep_open(struct inode *inode_, struct file *file_) { i_ep_use = 1; return 0; } int i_ep_release(struct inode *inode_, struct file *file_) { i_ep_use = 0; return 0; } // user reads out procfile ssize_t i_ep_out(struct file *file_, char __user *user_, size_t size_, loff_t *off_) { static char* buf = NULL; static int len = 0; //signal eof if (len >= f_i2ep->size) { len = 0; kfree(buf); return 0; } //hashtable -> string if new transfer if (i_ep_use == 1) { // create buf.... // snipped out code } //transfer if (len + size_ > f_i2ep->size) { size_ = f_i2ep->size - len; } copy_to_user(user_, buf + len, size_); len += size_; return size_; }