Re: writing from kernel

Olaf Dietsche (olaf.dietsche@t-online.de)
Sun, 05 Jan 2003 01:26:19 +0100


"anil vijarnia" <linux_ker@rediffmail.com> 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 majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/