Re: Creating a file in kernel Module -- working fine

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Gaurav Dhiman (gauravd_linux@xxxxxxxxx) wrote:
> 
> Hi Jan,
> 
> Well can you put some light why this code is not good.
> I know that using the top most level functions of any
> system call in kernel (like sys_open, sys_close, any
> function whcih starts with "sys_") will put alot of
> extra overload and might not be the optimum way to do
> things in kernel, but i think functionality wise it
> will be same, as these function handle all the
> senarios need to be handled.
> 
> I think its the easiest and safest way but definitely
> not the optimum way, so we shud not use such things in
> production code, but they can be used for experimental
> or learning codes.

Jan will explain surely better than me but I think he would explain
this:
http://lxr.linux.no/source/fs/open.c#L942
http://lxr.linux.no/source/fs/open.c#L839

The 'struct files_struct' is local to the process.
struct files_struct * files = current->files;

So in this case and module_init(), it is local to 'insmod' process and
all work is done in the same time. But imagine, fd is initialize in
init_module. And the write into file is called later by another process. 
So, It is broken, because current macro will retrieve struct files 
for _the_ process with will be other than one initialize by 'insmod'.

Perhaps I say mistakes, but I am open to learn _why_ and _where_.
-- 
	~Christophe


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux