Re: Reading a file inside the device driver.

From: Theodore Y. Ts'o (tytso@MIT.EDU)
Date: Wed Jul 26 2000 - 13:49:25 EST


   Date: Wed, 26 Jul 2000 12:06:49 -0400
   From: Jeff Garzik <jgarzik@mandrakesoft.com>

> Vinay Vernekar wrote:
> I am developing a network driver which has to read a file
> 'firmware.bin' and dump it into the modem memory. I want to know how
> can the file be opened and read inside a driver.

   It's much better to do this in userspace as Ted T'so described.

   If you must do it in the kernel, just use normal Unix syscalls...
   Inside the kernel, they are called sys_open, sys_read, etc. Make sure
   the code calling those functions doesn't mind if the called functions
   sleep.

I wouldn't recommend that approach at all. First of all, sys_open means
you're messing with a process's file descriptor table, and if another
process can get at the fd table (i.e., because of a clone system call),
they may be able to cause mischief for the kernel (the fd can get
changed to be something else, etc.). Secondly, sys_read()/sys_write()
assumes that it will be reading and writing into user memory, not kernel
memory.

There are games you can play to get around this, but such approaches are
fragile and complicated, and not what I'd recommend.

                                                        - Ted

-
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/



This archive was generated by hypermail 2b29 : Mon Jul 31 2000 - 21:00:22 EST