Re: writing to a file in LKM

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

 



On Thu, Oct 02, 2003 at 10:27:28AM +0200, Jan Hudec wrote:

> On Tue, Sep 30, 2003 at 13:02:42 +0530, Pradheep K E wrote:
> > hi,
> > i'm getting a strange problem while writing to a file from a LKM.
> > could anyone tell me how exactly do we write to a file in the kernel mode.
> > this code just created the file but didn't write anything to it.
> > 
> > struct file* f= filp_open(filename, O_CREAT|O_APPEND, 0600);
> > f->f_op->write(f, "foo", 3, &f->fpos);
> > filp_close(f, NULL);
> > 
> > the write function returned -14, and i dont know why it's giving me a 
> > problem. is there anything more that i should do before writing to the 
> > file?
> 
> You really SHOULDN'T be doing this. However, it _is_doable_.

I'd like to repeat that. If you are writing to a file fromt the
kernel, you need to need to reevaluate the design. 

> First, look up the value 14 in errno.h -- EFAULT.
> Hm... that suggests the buffer is not accessible. And it is NOT, because
> it's in wrong segment. Look up the kernel_DS or some such thing. That
> will allow copy_from_user copy from kernel address space.

The grossly misnamed get_fs() and set_fs() will come in handy
here. Grep around to see how they are used. 
-- 
Muli Ben-Yehuda
http://www.mulix.org

Attachment: signature.asc
Description: Digital signature


[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