Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>my ultimate problem is that I want to have the exact same function execute with different variables.</p> </blockquote> <p>I assume you are already able to create the /proc files then. As <a href="https://stackoverflow.com/a/16148142/912144">Ilya</a> said, <code>create_proc_entry</code> does the job (even though there is a better alternative).</p> <blockquote> <p>The reason I'm having difficulty with this is that the function protoypes for reading/writing from proc files don't seem to allow this behavior</p> </blockquote> <p>Well actually it does. If you look at the prototype of either function:</p> <pre><code>int read_proc(char *buf, char **start, off_t offset, int count, int *eof, void *data); ^^^^^^^^^^ int write_proc(struct file *file, const char *buf, unsigned long count, void *data); ^^^^^^^^^^ </code></pre> <p>You will see a parameter called <code>data</code> which is a generic <code>void *</code>. Using this parameter, you can make the same function work with different variables.</p> <p>Now <code>create_proc_entry</code> is not the best function for this. In fact, there is a replacement for it<sup>1</sup>, which also matches a better naming scheme for /proc functions. Looking at <a href="https://github.com/torvalds/linux/blob/master/fs/proc/generic.c#L708" rel="nofollow noreferrer">the source code itself</a>, you can see the signature of <code>create_proc_data</code> and how it works. Using this function, you can provide the pointer to the working area of the /proc file. This pointer will be passed to both your read and write functions.</p> <p>This is very similar to how <code>pthread</code> work for example, and many other libraries that take function pointers as callbacks.</p> <hr> <p><sup>1</sup> If I'm not mistaken, <code>create_proc_entry</code> is deprecated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload