How to open a file in kernel modules?

Submitted by Robber
on September 6, 2004 - 4:43am

Hi,
How could I open a file in kernel modules?I have found this solution
for a long time. I am a beginner,and holp same body told me just YES or
NO to my request.

Thank you in advance.

you have found?

Anonymous
on
September 6, 2004 - 5:30am

see e.g. /usr/src/linux-2.6.8.1/sound/sound_firmware.c if you search another solution.

errno unresolved...

on
September 7, 2004 - 2:29am

Thank you a lot. But now,I have new problem in load

modules's link time.

#gcc -I/usr/src/linux/include -D__KERNEL__ -DMODULE\

-D__KERNEL_SYSCALLS__ hello.c -c -o hello.o

#insmod ./hello.o

./hello.o: unresolved symbol errno



It is a quite obvious messages that the variable 'errno' is

unresolved.

Can anybody told me how to...
BTW,To open a file in kernel module mode just for my interest.

#define MODULE
#define __KERNEL__
#define __KERNEL_SYSCALLS__
#include &ltlinux/module.h&gt
#include &ltlinux/version.h&gt
#include &ltlinux/kernel.h&gt
#include &ltlinux/fs.h&gt
#include &ltlinux/mm.h&gt
#include &ltlinux/slab.h&gt
#include &ltlinux/unistd.h&gt

int init_module(void){
    int fn=0;
                                                                                
    printk("<1>Hello, world\n");
    fn = open("/etc/inittab", 0, 0);
    if (fn == -1)
    {
        printk(KERN_INFO "Unable to load '%s'.\n", fn);
        return 0;
    }
    printk(KERN_INFO "LOAD File success!");
    close(fn);
    return 0;
}
void cleanup_module(void)  { printk("<1>Goodbye cruel world\n"); }

Include errno.h?

Anonymous
on
September 8, 2004 - 8:39am

Ah, so you are doing it by enabling system calls in kernel mode...

Have a look at this:
http://www.csee.umbc.edu/courses/undergraduate/CMSC421/fall02/burt/proje...

First glance at that page suggested to me you might want to include linux/errno.h but maybe there's something else you need...

Thanks for answering why you were doing it - I was curious because I wouldn't have thought it was necessary often. But just for interest seems like a good reason ;-)

Mark

Curious as to why?

Anonymous
on
September 6, 2004 - 5:54pm

Hi,

I'm just curious about why you want to do this...

Mark

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.