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_. 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. ------------------------------------------------------------------------------- Jan 'Bulb' Hudec <bulb@ucw.cz> -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/