[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Yet, another question about writing a module.....
On Fri, 16 Feb 2001 aprasad@in.ibm.com wrote:
> >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.
>
> Regards,
> Anil
It's also worth pointing out, you almost never need to do this. If you find
yourself needing this, it's probably time for a redesign.
john
--
"Good sense is, of all things among men, the most equally distributed; for
every one thinks himself so abundantly provided with it, that those even
who are the most difficult to satisfy in everything else, do not usually
desire a larger measure of this quality than they already possess."
- Descartes
-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/
IRC Channel: irc.openprojects.net / #kernelnewbies
Web Page: http://www.surriel.com/kernelnewbies.shtml