lkml.org 
[lkml]   [1999]   [Apr]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectPlease help with copy_from_user
I'm trying to implement a weird filesystem feature - storing data on a
secondary media. Basically my modified filesystem can have a file who's
data is not present on a filesystem, but instead is dynamically restored
from elsewhere when the file is being opened.
The way I'm trying to do it is in 'open' if a file does not have data it
communicates with a user-level program (via pipe like in userfs) that it
needs the data. It then gets a userspace address. At this point I'm
calling a write with the same 'struct file *filp' that was passed to
open and a userspace pointer pl.p that was communicated to kernel from a
different process:

if (!access_ok(VERIFY_READ, (char *)pl.p, pl.l)) {
printk("tfs: cannot read from address %lx\n",
(unsigned long)pl.p);
return -ETFSRFAIL;
}
if ((ret = filp->f_op->write(filp,(char *)pl.p,pl.l,&filp->f_pos))
!= pl.l)
printk("tfs: WARNING write failed, %d\n", ret);

This fails inside the 'write' (and write returns -EFAULT) because the call
to copy_from_user returns the same number as it was requested to copy from
user space (despite access_ok returning true):

c -= copy_from_user (bh->b_data + offset, buf, c);
if (!c) {
brelse(bh);
if (!written) {
printk("tfs_file_write: -EFAULT, bytes read=%d,
written=%d\n",
c, written);
written = -EFAULT;
}
break;
}

I understand that this probably happens because the buffer with data that
I'm trying to write to the file belongs to a different process then the
file descriptor (and current). My question is how do i make this
copy_from_user to actually copy the data, or is there a better (i.e.
working) way?

Thanks for any help!

Dennis Gerasimov


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

\
 
 \ /
  Last update: 2005-03-22 13:51    [W:0.037 / U:0.064 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site