Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 9803
b: refs/heads/master
c: 19cba8a
h: refs/heads/master
i:
  9801: b7b7967
  9799: 9b83972
v: v3
  • Loading branch information
Latchesar Ionkov authored and Linus Torvalds committed Oct 11, 2005
1 parent 3a57610 commit aefaf3f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 82 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: ad6ce87e5bd4440a6ce9aa9f8cda795b9e902eff
refs/heads/master: 19cba8abd6ca09527c194864ae651db65cbacfe1
114 changes: 33 additions & 81 deletions trunk/fs/9p/vfs_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,16 @@ static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl)
}

/**
* v9fs_read - read from a file (internal)
* v9fs_file_read - read from a file
* @filep: file pointer to read
* @data: data buffer to read data into
* @count: size of buffer
* @offset: offset at which to read data
*
*/

static ssize_t
v9fs_read(struct file *filp, char *buffer, size_t count, loff_t * offset)
v9fs_file_read(struct file *filp, char __user * data, size_t count,
loff_t * offset)
{
struct inode *inode = filp->f_dentry->d_inode;
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
Expand All @@ -194,6 +194,7 @@ v9fs_read(struct file *filp, char *buffer, size_t count, loff_t * offset)
int rsize = 0;
int result = 0;
int total = 0;
int n;

dprintk(DEBUG_VFS, "\n");

Expand All @@ -216,10 +217,15 @@ v9fs_read(struct file *filp, char *buffer, size_t count, loff_t * offset)
} else
*offset += result;

/* XXX - extra copy */
memcpy(buffer, fcall->params.rread.data, result);
n = copy_to_user(data, fcall->params.rread.data, result);
if (n) {
dprintk(DEBUG_ERROR, "Problem copying to user %d\n", n);
kfree(fcall);
return -EFAULT;
}

count -= result;
buffer += result;
data += result;
total += result;

kfree(fcall);
Expand All @@ -232,42 +238,7 @@ v9fs_read(struct file *filp, char *buffer, size_t count, loff_t * offset)
}

/**
* v9fs_file_read - read from a file
* @filep: file pointer to read
* @data: data buffer to read data into
* @count: size of buffer
* @offset: offset at which to read data
*
*/

static ssize_t
v9fs_file_read(struct file *filp, char __user * data, size_t count,
loff_t * offset)
{
int retval = -1;
int ret = 0;
char *buffer;

buffer = kmalloc(count, GFP_KERNEL);
if (!buffer)
return -ENOMEM;

retval = v9fs_read(filp, buffer, count, offset);
if (retval > 0) {
if ((ret = copy_to_user(data, buffer, retval)) != 0) {
dprintk(DEBUG_ERROR, "Problem copying to user %d\n",
ret);
retval = ret;
}
}

kfree(buffer);

return retval;
}

/**
* v9fs_write - write to a file
* v9fs_file_write - write to a file
* @filep: file pointer to write
* @data: data buffer to write data from
* @count: size of buffer
Expand All @@ -276,7 +247,8 @@ v9fs_file_read(struct file *filp, char __user * data, size_t count,
*/

static ssize_t
v9fs_write(struct file *filp, char *buffer, size_t count, loff_t * offset)
v9fs_file_write(struct file *filp, const char __user * data,
size_t count, loff_t * offset)
{
struct inode *inode = filp->f_dentry->d_inode;
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
Expand All @@ -286,30 +258,42 @@ v9fs_write(struct file *filp, char *buffer, size_t count, loff_t * offset)
int result = -EIO;
int rsize = 0;
int total = 0;
char *buf;

dprintk(DEBUG_VFS, "data %p count %d offset %x\n", buffer, (int)count,
dprintk(DEBUG_VFS, "data %p count %d offset %x\n", data, (int)count,
(int)*offset);
rsize = v9ses->maxdata - V9FS_IOHDRSZ;
if (v9fid->iounit != 0 && rsize > v9fid->iounit)
rsize = v9fid->iounit;

dump_data(buffer, count);
buf = kmalloc(v9ses->maxdata - V9FS_IOHDRSZ, GFP_KERNEL);
if (!buf)
return -ENOMEM;

do {
if (count < rsize)
rsize = count;

result =
v9fs_t_write(v9ses, fid, *offset, rsize, buffer, &fcall);
result = copy_from_user(buf, data, rsize);
if (result) {
dprintk(DEBUG_ERROR, "Problem copying from user\n");
kfree(buf);
return -EFAULT;
}

dump_data(buf, rsize);
result = v9fs_t_write(v9ses, fid, *offset, rsize, buf, &fcall);
if (result < 0) {
eprintk(KERN_ERR, "error while writing: %s(%d)\n",
FCALL_ERROR(fcall), result);
kfree(fcall);
kfree(buf);
return result;
} else
*offset += result;

kfree(fcall);
fcall = NULL;

if (result != rsize) {
eprintk(KERN_ERR,
Expand All @@ -319,46 +303,14 @@ v9fs_write(struct file *filp, char *buffer, size_t count, loff_t * offset)
}

count -= result;
buffer += result;
data += result;
total += result;
} while (count);

kfree(buf);
return total;
}

/**
* v9fs_file_write - write to a file
* @filep: file pointer to write
* @data: data buffer to write data from
* @count: size of buffer
* @offset: offset at which to write data
*
*/

static ssize_t
v9fs_file_write(struct file *filp, const char __user * data,
size_t count, loff_t * offset)
{
int ret = -1;
char *buffer;

buffer = kmalloc(count, GFP_KERNEL);
if (buffer == NULL)
return -ENOMEM;

ret = copy_from_user(buffer, data, count);
if (ret) {
dprintk(DEBUG_ERROR, "Problem copying from user\n");
ret = -EFAULT;
} else {
ret = v9fs_write(filp, buffer, count, offset);
}

kfree(buffer);

return ret;
}

struct file_operations v9fs_file_operations = {
.llseek = generic_file_llseek,
.read = v9fs_file_read,
Expand Down

0 comments on commit aefaf3f

Please sign in to comment.