linux kernel print to file problem

linux kernel print to file problem

am 15.07.2005 13:36:02 von mukundjb

Dear Linux-lovers.

I am trying to build a 2.6.10 linux kernel module to print messages to a
file. I have done this 2.4 and I was successful but I am failing here.

I am using the sys_open, sys_write calls to do so.
I am getting a compilation warning and I find no .ko file created
finally instead I find an .o.ko file.

*** WARNIG: "sys_write" [/home/cf.o.ko] undefined!
Below is the module code. Please suggest me what could be the problem:-


#include
#include
#include
#include /* for O_WRONLY */
#include /* for sys_ functions */
#include /* for set_fs(), get_fs() etc. */
#include /* for string length */
#include /* for kmalloc */

MODULE_LICENSE("GPL");
/*
#define DBG
#define PRINTK(fmt,arg...) printk("DBG INFO <%s> | "
fmt,__FUNCTION__,##arg)
#else
#define PRINTK(fmt,arg...) while(0)
#endif
*/

typedef struct tagWRITE_TEST
{
unsigned long fd;
unsigned long x;

}WRITE_TEST, *PWRITE_TEST;

PWRITE_TEST ptest;

void SysPrint(char * pString, ...)
{
static char buff[1024];
va_list ap;

va_start(ap,pString);
vsprintf((char *)buff, pString, ap);
va_end(ap);

sys_write(ptest->fd,(char *)buff,(size_t)strlen(buff));
}

int init_module(void)
{

printk("<%s> invoked!\n",__FUNCTION__);
printk("File Creation Testing in Kernel Module!\n");

set_fs(get_ds());

/* allocate the memory for structre */
ptest = (PWRITE_TEST)kmalloc(sizeof(WRITE_TEST),GFP_KERNEL);
if(ptest == NULL)
{
printk("Structure Memory Allocation Fails!\n");
return -ENOMEM;
}

ptest->fd = sys_open("srcdebug.txt", O_CREAT | O_WRONLY, 644);
if (ptest->fd == 0)
{
SysPrint("File Creation Error!!!\n");
return 1;
}

SysPrint("File Creation Testing in Kernel Module!\n");
SysPrint("Srinivas Testing the File Creation\n");
sys_close(ptest->fd);

return 0;
}

void cleanup_module(void)
{
printk("Good bye!\n");

/* free the allocated memory */
kfree(ptest);
}

Regards,
Mukund jampala

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

Re: linux kernel print to file problem

am 16.07.2005 01:23:56 von Simon

hello

Mukund JB. wrote:
> Dear Linux-lovers.
>
> I am trying to build a 2.6.10 linux kernel module to print messages to a
> file. I have done this 2.4 and I was successful but I am failing here.
>
> I am using the sys_open, sys_write calls to do so.
> I am getting a compilation warning and I find no .ko file created
> finally instead I find an .o.ko file.
>
> *** WARNIG: "sys_write" [/home/cf.o.ko] undefined!
> Below is the module code. Please suggest me what could be the problem:-

system call are no longer export with 2.6 kernel...
you can find syscall address in your system.map...
if you intend to use lot of system call... you have best to find the
sys_call_table address...

it can looks like :

#define SYS_CALL_TABLE "address_in_your_system.map"

void **sys_call_table;

int (*orig_write) (int, char *, size_t);

int init_module(void)
{
[...]

sys_call_table = (void **) SYS_CALL_TABLE;

orig_write = sys_call_table[__NR_write];

[...]
}

may be there is an other problem with your example code...
have you try to run it ?
system call should be used with parameters coming from userspace...

a way to perform that : http://www.ouah.org/LKM_HACKING.html#I.4.

regards

simon
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs