Messages in this thread | | | Date | Thu, 29 Jul 1999 19:24:47 +0100 | From | Steve Dodd <> | Subject | Re: Kernel hacking ? - Can this be done? |
| |
On Thu, Jul 29, 1999 at 01:17:19PM -0400, Stanislav Krasilovskiy wrote:
> I have another short question -- is there ANY way to open/read/write > to a file from a kernel routine? Again, excuse my lack of knowledge > on the subject. What I mean to ask is that I will have a > buffer kmalloc'd in the kernel and I will want to read some data into > it from a file from, say, inside a system call routine. Can this be done > at all?
Someone (Alan? Stephen?) posted a selector trick a while back when we were discussing implementing loopback device on files without get_block (formerly known as bmap) support.
> sys_read calls the the filesystem's read function, which uses > copy_to_user (since it assumes it is invoked from user space through > a system call). There may be other problems, as well.
If someone was to change file->f_op->read so it took a read_actor_t (like do_generic_file_read does), then you could supply your own read_actor which copied the data somewhere else in kernel space. Even better, if the read_actor function could get given the struct page *, it could increment the use count on that page and you could hang on it to after the read completed, saving you an unnecessary copy.
Also, sys_sendfile could work with files that didn't use the page cache via generic_file_read.
Uh, did that make sense to anyone out there?
-- If you've been pounding nails with your forehead for years, it may feel strange the first time somebody hands you a hammer. But that doesn't mean that you should strap the hammer to a headband just to give your skull that old familiar jolt. -- Wayne Throop, during the ``TCL Wars''
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |