[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: file/device i/o in the kernel

Hi joshi..
First of all kernel is not a process.
It is not a good way to invoke open system call  sitting inside a
kernel.These system calls are ment for user process to perform logical file
operation.If u invoke it in kernel, u r going backwards against standards of

One more thing is that,what ever file descriptor open system call returns is
bound to user process.
Krenel is not a process, so fd doesn't not make any sense in kernel space.

    The reason why u r getting bad file descriptor error,
because what ever argument u pass to these system calls, kernel assumes that
they are in user space . Since u have invoked the same system call sitting
in kernel, all the arguments are in kernel space,naturally u will get that
  So what u have to do is to force the kernel, to make it point to kernel
data segment before invoking the system call. U can make use of  set_fs and
get_fs .

  Any how this not a good way at all. ..
 Best way, export the functions defined in tty_io.c and access them


----- Original Message -----
From: "Sharad Joshi" <sharad.joshi@xxxxxxxxx>
To: <linux-india-programmers@xxxxxxxxxxxxxxxxxxxxx>
Sent: Thursday, June 15, 2000 10:43 PM
Subject: [LIP] file/device i/o in the kernel

> Hio,
> Any idea how to do file i/o in kernel? Typically, i am opening a device
> file (/dev/ttyS0) with sys_open(). Now i do sys_read/write on the returned
> fd. But the problem is, if i try to do it again after some time (uh... i
> come back to do read/write) both these return with 'Bad file Descriptor'
> error. If i try to do sys_open() again (ok, i close the former fd), it
> returns 0. I have scanned thru all the relevent source of the kernel, but
> find no clue as to why this happens. Any idea?
> What is the better way to do device i/o above the driver? If a kernel
> module wants to do some device i/o using underlying driver, is the above
> method ok, or i need to do something else?
> 'using 2.2.13k on Celeron (Mendocino) 400 MHz here.
> TIA,
> Sharad.
> -----------------------------------------------------------------------
> For information on this and other Linux India mailing lists check out
> http://lists.linux-india.org/