Skip to contentSkip to conversation

How to read file in kernel module?

DISCUSSION linux lover 6 participants 6 messages Feb 7, 2005

lore
Share & tools
lore
#0 lore raw

Hello,
I have written one /proc file creation kernel
module. This module creates /proc/file and defied operations on it. Also i have written user program that will read & write to /proc files from user space. Now what i want is to use same bufproc_read & bufproc_write functions defined in /proc file handling kernel module to be used in another kernel module to read that /proc/file in kernel module.The second kernel module only used to read /proc file in kernel. I am not understanding how can i open that /proc/file in second kenrel module to read in kernel? regards,
linux_lover.

__________________________________
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
http://promotions.yahoo.com/new_mail

#1 lore raw
Quoted 5 lines · linux lover

Hello,
I have written one /proc file creation kernel
module. This module creates /proc/file and defied operations on it. Also i have written user program that will read & write to /proc files from user space.

Quoted 8 lines

Now what i want is to use same bufproc_read & bufproc_write functions defined in /proc file handling kernel module to be used in another kernel module to read that /proc/file in kernel module.The second kernel module only used to read /proc file in kernel. I am not understanding how can i open that /proc/file in second kenrel module to read in kernel? regards,

the answer really is that you should not read files from kernel modules; /proc or otherwise.

#2 lore raw

Hi,

Quoted 13 lines
Quoted 4 lines

I have written one /proc file creation kernel
module. This module creates /proc/file and defied operations on it. Also i have written user program that will read & write to /proc files from user space.

Quoted 8 lines

Now what i want is to use same bufproc_read & bufproc_write functions defined in /proc file handling kernel module to be used in another kernel module to read that /proc/file in kernel module.The second kernel module only used to read /proc file in kernel. I am not understanding how can i open that /proc/file in second kenrel module to read in kernel? regards,

Quoted 2 lines

the answer really is that you should not read files from kernel modules; /proc or otherwise.

the only thing that is may needed by a kernel driver should be an external firmware file and for that we have request_firmware(). For everything else you are on the wrong track.

Regards

Marcel

#3 lore raw
In reply to Arjan van de Ven

Am 2005-02-07 07:38:36, schrieb Arjan van de Ven:

Quoted 2 lines

the answer really is that you should not read files from kernel modules; /proc or otherwise.

I think, he mean something like

    echo "1" >/proc/sys/net/ipv4/ip_forward

Where you can (de)activate Kernel functions.

Greetings
Michelle

Signature · 4 lines
Linux-User #280138 with the Linux Counter, http://counter.li.org/ 
Michelle Konzack   Apt. 917                  ICQ #328449886
                   50, rue de Soultz         MSM LinuxMichi
0033/3/88452356    67100 Strasbourg/France   IRC #Debian (irc.icq.com)
#4 lore raw
In reply to Arjan van de Ven
Quoted 11 lines · Arjan van de Ven
Quoted 8 lines · linux lover

Now what i want is to use same bufproc_read & bufproc_write functions defined in /proc file handling kernel module to be used in another kernel module to read that /proc/file in kernel module.The second kernel module only used to read /proc file in kernel. I am not understanding how can i open that /proc/file in second kenrel module to read in kernel? regards,

Quoted 2 lines

the answer really is that you should not read files from kernel modules; /proc or otherwise.

As Arjan said - what you probably want to be doing instead is changing the code in your first module that provides the bufproc_* functions so that they're wrappers around some code that does the "real work", and then call the real_work function from your second module. Most likely, what you *really* want to be passing around is some 'struct *foo', and the bufproc_* functions are converting to/from a struct foo and a linear byte stream. (In the limiting case where it's just one variable, why not just 'EXPORT_SYMBOL(variable)' in the first module and then just assign or read the variable from the second module?)

#5 lore raw
In reply to linux lover
Quoted 7 lines · linux lover

Now what i want is to use same bufproc_read & bufproc_write functions defined in /proc file handling kernel module to be used in another kernel module to read that /proc/file in kernel module.The second kernel module only used to read /proc file in kernel. I am not understanding how can i open that /proc/file in second kenrel module to read in kernel?

Look at kernel_read() in fs/exec.c and fs/binfmt_*.c

Regards, Olaf.