lkml.org 
[lkml]   [2005]   [Oct]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: 2.4 in-kernel file opening
Date
From

On Tue, 4 Oct 2005, Martin Drab wrote:

> Hi,
>
> can anybody tell me why there is no sys_open() exported in kernel/ksyms.c
> in 2.4 kernels while the sys_close() is there? And what is then the
> preferred way of opening files from within a 2.4 kernel module?
>
> Thank you,
> Martin

There is no way to open files within the kernel. Any attempt is
just a hack. The kernel is designed to perform tasks on behalf
of the caller. It doesn't have a context. It uses the caller's
context. A file-descriptor is a number that relates to the
current context. i.e., STDIN_FILENO is __different__ for you
and somebody else, even though it has the same numerical value.

To open a file in the kernel requires either a task with a
context (like a kernel thread) or you have to steal the context
of somebody which can destroy some innocent task's context.

You are never supposed to use files inside the kernel; period!
If you need to obtain file-data for a driver or receive file-
data from a driver, we have read(), write(), mmap(), and ioctl()
to accomplish these things from user-mode. A user-mode program can
write data directly to your driver using mmap(), for instance.
Or it can use a function-code you define to upload/download data
using ioctl().

This is a FAQ. Many persons have rejected this advice, only
to later on modify their drivers to correspond to the correct
way of writing Unix/Linux device drivers. This, after they've
trashed many innocent tasks.

Cheers,
Dick Johnson
Penguin : Linux version 2.6.13 on an i686 machine (5589.55 BogoMips).
Warning : 98.36% of all statistics are fiction.

****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to DeliveryErrors@analogic.com - and destroy all copies of this information, including any attachments, without reading or disclosing them.

Thank you.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-10-04 19:45    [W:0.127 / U:0.100 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site