prashanth wrote:
hi ,
i want to open a file in kernel mode,after that i want to read/write a data to/from that file.
i tried using sys_open,it doesn't work.
then i tried with filp_open,it opens the file.but it returns a pointer to struct file.
now i want to read the opened file.can anyone pls tell me how to do that.
thanks in advance.
--
Prashanth. M.N.
void read_write_file_example() {
mm_segment_t oldfs,oldds;
int fd,red;
char buffer[100];
oldds = get_fs();
set_fs(get_ds());
fd = sys_open("/home/amith/logger.dat",O_RDWR | O_CREAT);
red = sys_read(fd,buffer,sizeof(buffer)); set_fs(oldds);
printk("<1> file contents = %s read %d bytes \n",buffer,red );
................
..........................
}
customize it for u r use :-) !
hth.
cheers, Amith
-- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/