[ale] Programming /proc

Benjamin Dixon beatle at arches.uga.edu
Thu Nov 15 13:20:34 EST 2001



Right, I believe the example file you refer to works under 2.2 and has
since been changed under 2.4 but the documentation has not been kept up I
guess. I do see your point with the create_proc_entry(...) call, I do use
that in my code but I go about setting up the functions I want executed
for read, write, permissions, etc a bit differently. That part of the code
works great. The only problem now is I don't know how to specify EOF on
using the new function prototype, which looks like this (recalling from
memory because I'm away from the code right now):

ssize_t output(struct file* file, char* buf, size_t len, loff_t* offset);

Notice I don't have simple access to *eof as in the function prototype you
mentioned. So I don't know how to setup the EOF condition. I am certain
though that the module will work the way I have it setup if only I can get
past this last hurdle.

Ben


On Thu, 15 Nov 2001, Joe Steele wrote:

> "struct file" is defined in include/linux/fs.h (which is 
> automatically included with include/linux/sched.h).  
> 
> If you haven't tried it already, a quick way of finding such 
> definitions is through one of the linux kernel cross reference sites, 
> either at http://lxr.linux.no/source/ or  
> http://innominate.org/~graichen/projects/lxr/source.  Select your 
> kernel, then click identifier search.
> 
> I've never attempted what you are doing, so feel free to disregard my 
> potentially errant ramblings which follow--
> 
> In looking at procfs_example.c, it seems that, contrary to what 
> you've said, there is no need to register your read function in a 
> "file_operations" structure.  Instead, the example shows initializing 
> a variable of type "struct proc_dir_entry":
> 
>    struct proc_dir_entry *foo_file = create_proc_entry("foo", 0644, 
>    example_dir);
> 
> followed with an initialization of its "read_proc" member:
> 
>    foo_file->read_proc = proc_read_foobar;
> 
> where "proc_read_foobar" is the name of your output function 
> (actually called "output" in your case).
> 
> >From there, whenever the kernel needs to call your output function, 
> it does so by calling "foo_file->read_proc" from within the 
> "proc_file_read" function defined in fs/proc/generic.c.  A pointer to 
> the "proc_file_read" function is stored in "proc_file_operations" 
> (declared in generic.c) which is of type "struct file_operations".  
> So as I see it, your output function is accessed (indirectly) through 
> an existing "struct file_operations" variable.  No additional "struct 
> file_operations" declarations should be necessary.
> 
> As for your output function's use of the "struct file" argument--
> 
> The procfs_example.c file shows a different declaration of your 
> output function which does not use a "struct file" argument:
> 
>    static int proc_read_foobar(char *page, char **start, off_t off, 
>    int count, int *eof, void *data) 
> 
> It seems to me that this should be the format of your output function 
> declaration.  
> 
> --Joe
> 
> -----Original Message-----
> From:	Benjamin Dixon [SMTP:beatle at arches.uga.edu]
> Sent:	Thursday, November 15, 2001 1:58 AM
> To:	ale at ale.org
> Subject:	[ale] Programming /proc
> 
> 
> Hi all,
> 
> I'm trying to write a kernel module that has proc support but I don't
> fully understand the new calling procedures under 2.4. I have successfully
> set up my module code (easy enough) and now I want to let the user access
> some information using my output function which I register for "read" in a
> file_operations structure. So my function prototype looks like this:
> 
> static ssize_t output(struct file *file, char *buffer, size_t len,
>                       loff_t *offset);
> 
> My only problem is, I'm not entirely sure how to handle the *file. Does
> anyone know where that structure is defined? I've searched through the
> kernel, specifically includes, but can't find it. And more generally, does
> anyone know of a good resource for *2.4 kernel* /proc programming, its a
> bit different from 2.2 and previous kernels and I can't find any updated
> information. (BTW, I did find a procfs_example.c file in the Documentation
> directory but it doesn't tell me what I want to know, which is what those
> structures look like).
> 
> Ben
> 
> 
> ---
> This message has been sent through the ALE general discussion list.
> See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
> sent to listmaster at ale dot org.
> 

Today's Random Quote--------------------------------------

 Most people don't need a great deal of love nearly so much as
they need a steady supply.

-----------------------------------------------------------


---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.






More information about the Ale mailing list