[plug] kernel programming

Peter F Bradshaw pfb at exadios.com
Wed Mar 24 23:38:00 WST 2004


Hi Parag;

On Tue, 23 Mar 2004, Parag Nemade wrote:

> hello Peter,
>            i require fopen cause i am calculating a
> string value and storing it in a file for temporary
> period and reading it by other file in kernel.

Then I suspect you do not need to write anything at all. The Linux
kernel is monolithic and all publically defined symbols are avaliable to
all source files. The normal C conventions apply (modules use
EXPORT_SYMBOL() to export symbols). Therefore it should be sufficient
your string in some globally visible char []. I'm assuming that you do
not need to keep the string across a reboot.

> 	   can i copy all header files from libc to kernel
> include directory?

No. You need to forget about the user mode libraries wrt the kernel. The
only way to write to a filesystem (that I know of) from within the kernel
is to use stuff in linux/fs.h. Even if it where possible to get the libc
stuff integrated with the kernel source you would be making system calls
from the kernel. Got no idea what that would do. Hurts my brain just
thinking about it.

If you really need to read/write from the kernel (other than
implementing a FS of course) it is far easier to write a blocking char
device, or something in the /proc file system, and getting a user mode
program to do the nasty.

In any case it is best to put as much stuff in user land as possible.
Writing user code is very much easier than writing kernel code.

> 	   I am using a red hat Linux 9.0 with kernel 2.4.
> Regards,
> Parag.
>
>
> --- Peter F Bradshaw <pfb at exadios.com> wrote:
> > Hi Parag;
> >
> > If you are talking about the fopen() function call
> > then you are talking
> > about libc - and libc is not avaliable in the
> > kernel. In fact only those
> > functions defined in the kernel (or a module) are
> > avaliable.
> >
> > Kernel programming and user mode programming are
> > quite different - the
> > enviroment and the implicit assumptions are
> > different. Its hard to know
> > why you would need to use fopen() in the kernel but
> > if you really do
> > then you may want to address what ever you are
> > trying to do by writing a
> > kernel and corresponding user mode components and
> > doing the nasty stuff
> > in user mode. There are a few ways to communicate -
> > probably using the
> > /proc file system is easiest (might be messy though
> > :-).
> >
> > You did not say which kernel version you are talking
> > about but for 2.4
> > take a look at:
> >
> > http://www.linux.org.au/LDP/LDP/lkmpg/index.html
> > and
> > http://www.linux.org.au/LDP/LDP/lki/index.html
> >
> > On Tue, 23 Mar 2004, Parag Nemade wrote:
> >
> > > hello friends,
> > > i want to modify kernel source code by adding my
> > own C
> > > files in net protocol stack but i found that some
> > C
> > > functions are not supported by kernel include
> > > directory that is fopen is not found in any of
> > header
> > > files. what can i do? Also while compiling my own
> > C
> > > files with kernel files i got warnings that
> > implicit
> > > declaration of function and function declaration
> > isn't
> > > a prototype how can i solve it?
> > > Parag.
> > >
> >
> > Cheers
> >

Cheers

-- 
Peter F Bradshaw, pfb at exadios.com, ICQ 75431157 (exadios).
http://www.exadios.com
PGP public key at http://www.exadios.com/public_key.html
"I love truth, and the way the government still uses it occasionally to
 keep us guessing.  " - Sam Kekovich.



More information about the plug mailing list