Hi,
I wanted to read from a file a line at a time & fill my data structure in my kernel module.I want something like fgets.
1 more thing.I have intercepted open system call.If the opened file is in write/append mode and if that file is in my datastructure,i want to make a copy of it.How to do it?please help me
1 way i got was to use filp function(which is exported into kernel mode)But that fails if flags=33345(which mode is it?i think its O_WRONLY|O_CREAT|O_TRUNC).
Please suggest some easy way of doing file operations in kernel mode.
Ananth
NITK
syscall in kernel mode
read this.
http://www.linux-mag.com/2000-11/gear_02.html
filp_open
filp = filp_open();
oldfs = get_fs();
set_fs(KERNEL_DS);
filp->f_op->read();
filp->f_op->write();
set_fs(oldfs);
filp_close(filp, NULL);
I wonder why you get those strange flags, it looks too large.
filp_open, f->f_op->read, error "-14"
Hello,
I wrote the below code, and install to kernel as a module. /etc/aa file exists. And i can open it correctly. But return of f->f_op->read is "-14". Why does this happen?
thank you,
Halil agin,
===================================================
f = filp_open("/etc/aa",O_RDONLY,0);
f->f_pos = 0;
if (f->f_op->read) {
readret = f->f_op->read(f, buffer, 64, f->f_pos);
printk("DEBUG : readret : %d\n", readret);
buffer[64]='\0';
printk("DEBUG : ----%s---\n", buffer);
}
===================================================
hi, the call fails because
hi,
the call fails because read expects the buffer to be in user space, not kernel space
Re: filp_open, f->f_op->read, error "-14"
It seems that you didn't allocate memory for "buffer" variable...
Opening/Writing files in
Opening/Writing files in kernel space is a very very bad idea. The kernel doesn't have a context of it's own, it runs on behalf of a user context. You should probably re-analyze your problem and try to figure out some alternate approach. This might help -
http://kernelnewbies.org/FAQ/WhyWritingFilesFromKernelIsBad
./prabir
possible panic
On an off note, it should be readret = f->f_op->read(f, buffer, 64, &f->f_pos);
The missing ampersand before f->f_pos might cause a kernel panic.
I want to get imformation of
I want to get imformation of /proc/net/arp in kernel space. how can I do? thanks.