[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Yet, another question about writing a module.....



Thank you for your help!! Can you explain the code you suggested me? Where I can find prototype of functions get_fs(), set_fs() and why you use this functions?

----- Original Message -----
From: Tiziano Fagni
To: kernelnewbies@nl.linux.org
Sent: Friday, February 16, 2001 11:40 AM
Subject: Yet, another question about writing a module.....

The first thing: THANK YOU to all people that give me any tips!!
 
Ok, suppose I want to write a module and I want to access to a file in the filesystem to read and save its content into a  previous allocated kernel buffer. 
The use of module could be "modprobe module /tmp/pippo".
I think I can't use open() function because I know that I can olny call function listed in ksym.c file. It's true?
So, is there any function that I can use to read the content of a file?
Any tip will be useful.....
 
So, is there any function that I can use to read the content of a file?Any tip will be useful.....
try this

struct file *filp;

mm_segment_t old_fs;

filp = filp_open(name,flags,mode);

old_fs= getfs();

set_fs(KERNEL_DS);

filp->f_op->read(filp,buffer,count,&filp->f_pos);

But you should keep one thing in mind that before this code is executed you have the filesystem on this this particular file exists has been already mounted otherwise you risk the crashing of kernel.