[lkml]   [2003]   [Jan]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: writing from kernel
"anil  vijarnia" <> writes:

> can anyone tell me how to write into i file from kernel space.
> i tried sys_open,sys_write functions bbbbbut they don't work
> from
> my module.

As others already pointed out, it's not always a good idea to do this
from kernel space. However, if you still want to do it, see snippet
below. If you want to write, you have to copy kernel_read() from
fs/exec.c and modify it for writing.

Regards, Olaf.

--cut here-->8--
#include <linux/fs.h>

struct file *filp;
unsigned long offset = 0;
char buf[1024];
int n;

filp = filp_open("/path/to/some/file", O_RDONLY, 0);
if (!filp || IS_ERR(filp)) {
/* do some error handling */

n = kernel_read(filp, offset, buf, sizeof(buf));
if (n != sizeof(buf)) {
/* do some checking */

filp_close(filp, 0);
--8<--cut here--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:32    [W:0.060 / U:1.120 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site