[ale] Programming /proc

Joe Steele joe at madewell.com
Thu Nov 15 13:09:18 EST 2001


"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.

---
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