writing from 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
Hi,
Quoted 3 lines · anil vijarnia
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
Signature · 4 lines
No keyboard present Hit F1 to continue Zen engineering? -- Jim Griffith
PATCH 1/1 Root Raid Support for DAC960 Driver
In reply to anil vijarniaHi,
Patch below will allow for mounting of root from a DAC960 raid device This has been submitted before (Leonard,Oliver,others), but I'll submit it again.
Reason:
Needed to boot of a DAC960 raid device
Precedents/Justification for Patch:
Root support for compaq raid is included
Root support for ata raid is included
DAC960 driver is included but root support is not
Cheers
Rick
init/do_mounts.c Sat Jan 4 23:59:06 2003 renamed from init/do_mounts.c Fri Nov 29 10:53:15 2002 +18 -0
@@ -164,6 +164,24 @@ { "dasdg", (DASD_MAJOR << MINORBITS) + (6 << 2) }, { "dasdh", (DASD_MAJOR << MINORBITS) + (7 << 2) }, #endif +#if defined(CONFIG_BLK_DEV_DAC960) || defined(CONFIG_BLK_DEV_DAC960_MODULE) + { "rd/c0d0p",0x3000 }, + { "rd/c0d1p",0x3008 }, + { "rd/c0d2p",0x3010 }, + { "rd/c0d3p",0x3018 }, + { "rd/c0d4p",0x3020 }, + { "rd/c0d5p",0x3028 }, + { "rd/c0d6p",0x3030 }, + { "rd/c0d7p",0x3038 }, + { "rd/c0d8p",0x3040 }, + { "rd/c0d9p",0x3048 }, + { "rd/c0d10p",0x3050 }, + { "rd/c0d11p",0x3058 }, + { "rd/c0d12p",0x3060 }, + { "rd/c0d13p",0x3068 }, + { "rd/c0d14p",0x3070 }, + { "rd/c0d15p",0x3078 }, +#endif #if defined(CONFIG_BLK_CPQ_DA) || defined(CONFIG_BLK_CPQ_DA_MODULE) { "ida/c0d0p",0x4800 }, { "ida/c0d1p",0x4810 },
Quoted 4 lines · anil vijarnia
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
Signature · 3 lines
Kasper Dupont -- der bruger for meget tid på usenet. For sending spam use mailto:[email protected] for(_=52;_;(_%5)||(_/=5),(_%5)&&(_-=2))putchar(_);
Quoted 4 lines · anil vijarnia
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--