* writing from kernel
@ 2003-01-04 16:11 anil vijarnia
0 siblings, 0 replies; 6+ messages in thread
From: anil vijarnia @ 2003-01-04 16:11 UTC (permalink / raw)
To: linux-kernel
can any one tell me how to write into files from kernel space.i
tried
sys_open(),sys_write() from my module but they don't work.
anil
^ permalink raw reply [flat|nested] 6+ messages in thread
* writing from kernel
@ 2003-01-04 16:05 anil vijarnia
0 siblings, 0 replies; 6+ messages in thread
From: anil vijarnia @ 2003-01-04 16:05 UTC (permalink / raw)
To: linux-kernel
can any one tell me how to write into files from kernel space.
i tried sys_open(),sys_write() from my module but they don't
work.
anil
^ permalink raw reply [flat|nested] 6+ messages in thread
* writing from kernel
@ 2003-01-04 16:02 anil vijarnia
2003-01-04 16:27 ` Christian Vogel
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: anil vijarnia @ 2003-01-04 16:02 UTC (permalink / raw)
To: linux-kernel
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.
anil
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: writing from kernel
2003-01-04 16:02 anil vijarnia
@ 2003-01-04 16:27 ` Christian Vogel
2003-01-04 22:24 ` Kasper Dupont
2003-01-05 0:26 ` Olaf Dietsche
2 siblings, 0 replies; 6+ messages in thread
From: Christian Vogel @ 2003-01-04 16:27 UTC (permalink / raw)
To: linux-kernel
Hi,
On Sat, Jan 04, 2003 at 04:02:55PM -0000, anil vijarnia wrote:
> 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 far as I understand the general oppinion on this list :-) the
preferred method is to have your module preset a character-device
to userspace. Then use a small program to do the I/O.
This normally keeps your kernel module simple and allows for
arbitrary compex I/O in userspace.
Chris
--
No keyboard present
Hit F1 to continue
Zen engineering?
-- Jim Griffith
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: writing from kernel
2003-01-04 16:02 anil vijarnia
2003-01-04 16:27 ` Christian Vogel
@ 2003-01-04 22:24 ` Kasper Dupont
2003-01-05 0:26 ` Olaf Dietsche
2 siblings, 0 replies; 6+ messages in thread
From: Kasper Dupont @ 2003-01-04 22:24 UTC (permalink / raw)
To: anil vijarnia; +Cc: linux-kernel
anil vijarnia wrote:
>
> 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.
That is rarely a good idea. But if you insist on doing it anyway,
you could use filp_open and the methods in the returned struct.
I have an old code example here:
http://www.daimi.au.dk/~kasperd/linux_kernel/kcp.c
--
Kasper Dupont -- der bruger for meget tid på usenet.
For sending spam use mailto:aaarep@daimi.au.dk
for(_=52;_;(_%5)||(_/=5),(_%5)&&(_-=2))putchar(_);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: writing from kernel
2003-01-04 16:02 anil vijarnia
2003-01-04 16:27 ` Christian Vogel
2003-01-04 22:24 ` Kasper Dupont
@ 2003-01-05 0:26 ` Olaf Dietsche
2 siblings, 0 replies; 6+ messages in thread
From: Olaf Dietsche @ 2003-01-05 0:26 UTC (permalink / raw)
To: anil vijarnia; +Cc: linux-kernel
"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--
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2003-01-05 0:18 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-04 16:11 writing from kernel anil vijarnia
-- strict thread matches above, loose matches on Subject: below --
2003-01-04 16:05 anil vijarnia
2003-01-04 16:02 anil vijarnia
2003-01-04 16:27 ` Christian Vogel
2003-01-04 22:24 ` Kasper Dupont
2003-01-05 0:26 ` Olaf Dietsche
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome