On Mon, Mar 29, 2004 at 20:55:06 +0530, Amith wrote: > hi all, > i'am new to module programming and was reading lkmpg .I > read some stuff > relating to the /proc filesystem.i have some doubts here. > > 1) struct proc_dir_entry { > .... > .... > struct file_operations * proc_fops; > .... > void *data; > read_proc_t *read_proc; > write_proc_t *write_proc; > ..... > ..... > }; > > 1) Now why do we need read_proc and write_proc here ? proc_fops can be > initialise to read,write ...etc function to read and write from the > proc file right ? then why read_proc and write_proc ? I'am sure ive > missed something here .. IIRC it's just a convenience. You can choose. Either implement your own read and write in file_ops, or use the standart ones and read_proc/write_proc. Which way you should choose is a matter of what data you have. read_proc/write_proc is convenient when you have a buffer, that is used as a variable on kernel side and you need to provide access to it, which is what most of /proc happens to do. > 2) I initialise read_proc as below . > struct proc_dir_entry *temp_proc_file; > temp_proc_file->read_proc = procfile_read; > > > int procfile_read(char *buffer, > char **buffer_location, > off_t offset, > int buffer_length, > int zero) { > > what does char **buffer_location and char *buffer mean here ? > i tried : > > *buffer_location = my_buffer; /* as given in the example */ > > it works fine when i do a cat /proc/myfile - it displays > whatever is > there in my_buffer (i.e set by me ). > > But where is **buffer_location actually ? and please let me > know what char *buffer means up there . buffer -- I'd guess you are setting it up somewhere else and it just gets passed back to you as a convenience (so you can use one function for several similar proc files). (But I didn't look in the code, actualy -- you should). buffer_location -- the read_proc method is NOT a read method, NOR is it simply invoked by read method. It is only called when user STARTS reading. You set this to the star of data, that should be (eventualy) passed to userspace. It may take several read requests to pass them and each will move this pointer to what remains. The buffer_location actualy points somewhere to the file structure or a structure associated with it. ------------------------------------------------------------------------------- Jan 'Bulb' Hudec <bulb@ucw.cz>
Attachment:
signature.asc
Description: Digital signature