LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   writing to proc module (https://www.linuxquestions.org/questions/linux-general-1/writing-to-proc-module-68467/)

dmaxj 06-27-2003 11:13 AM

writing to proc module
 
Does anyone know how I can write a couple of integers to a file in the /proc folder???

I wrote a kernel module that does nothing, but show up in /proc. Now, I need to be able to write a couple of integers to the file I made in /proc...

I can also see my module when I 'cat /proc/modules'



Thanks

moses 06-27-2003 01:48 PM

echo "1" > /proc/filename

dmaxj 06-27-2003 03:45 PM

using c code
 
I am using c code to do this... So , now I am thinking 'how do I translate echo "1" > /proc/filename into something that my module and c compiler can understand...

Perhaps, kernel modules can use printk() ( similar to c standard out, printf() ) ???

Or maybe I can set up a file pointer???

Moses, what do you think?

Thanks

moses 06-28-2003 01:02 AM

These are just files. I think you should be able to open them as you would any file. Are you trying to write to the file with your module or from a userspace application?
Writing to the file with a userspace application would probably just mean opening the file for writing, writing to the file, closing the file. What your module does with that is different. . .
Messing with the file in your module is probably a little more complicated, but I don't really know as I haven't done any kernel hacking. It probably involves include/linux/proc_fs.h, though I would have to do a lot more research and coding to be sure.

Oh, you might also ask a moderator to move this thread to the programming forum where you may get much better help. . .

dmaxj 06-28-2003 10:30 AM

correct
 
You are right. It does involve proc_fs.h. And I am unsure whether this has to be done from user space, but I think that the answer is yes.

Here is my code so far.

#include<linux/kernel.h>
#include<linux/module.h>
#include<linux/proc_fs.h>
#define BUF_LEN 50

int read_my_clock( char *a, char **b, off_t c, int d, int e)
{
printk(KERN_ALERT, "\nread_my_clock\n") ;
/* this is the function that I write to read
the clock file info that I created in proc
*/
}

struct proc_dir_entry dc_clock_mod_file = {
0,
12,
"dc_clock_mod",
S_IFREG | S_IRUGO,
1,
0,
0,
BUF_LEN,
NULL,
read_my_clock,
NULL
};

int init_module()
{
return proc_register(&proc_root, &dc_clock_mod_file);
}

void cleanup_module()
{
proc_unregister(&proc_root, dc_clock_mod_file.low_ino) ;
}



This is nothing more than the skeleton. This code does create the module in the kernel.

moses 07-02-2003 09:44 AM

I'm running out of useful things to say -- I am not a kernel hacker, or really much of a programmer, I just hack things to make them work for me and I've never had to hack the kernel to make it work (well, once, but that had nothing to do with modules).
I suggest you request that a moderator move this post to the programming forum and ask for help there. There are some very good programmers who frequent LQ, and I'm sure you will get more useful help.


All times are GMT -5. The time now is 02:07 AM.