Merge git://git.kernel.org/pub/scm/linux/kernel/git/hirofumi/fatfs-2.6
[cascardo/linux.git] / kernel / power / user.c
index a8c9621..e819e17 100644 (file)
@@ -151,6 +151,7 @@ static ssize_t snapshot_read(struct file *filp, char __user *buf,
 {
        struct snapshot_data *data;
        ssize_t res;
+       loff_t pg_offp = *offp & ~PAGE_MASK;
 
        mutex_lock(&pm_mutex);
 
@@ -159,14 +160,19 @@ static ssize_t snapshot_read(struct file *filp, char __user *buf,
                res = -ENODATA;
                goto Unlock;
        }
-       res = snapshot_read_next(&data->handle, count);
-       if (res > 0) {
-               if (copy_to_user(buf, data_of(data->handle), res))
-                       res = -EFAULT;
-               else
-                       *offp = data->handle.offset;
+       if (!pg_offp) { /* on page boundary? */
+               res = snapshot_read_next(&data->handle);
+               if (res <= 0)
+                       goto Unlock;
+       } else {
+               res = PAGE_SIZE - pg_offp;
        }
 
+       res = simple_read_from_buffer(buf, count, &pg_offp,
+                       data_of(data->handle), res);
+       if (res > 0)
+               *offp += res;
+
  Unlock:
        mutex_unlock(&pm_mutex);
 
@@ -178,18 +184,25 @@ static ssize_t snapshot_write(struct file *filp, const char __user *buf,
 {
        struct snapshot_data *data;
        ssize_t res;
+       loff_t pg_offp = *offp & ~PAGE_MASK;
 
        mutex_lock(&pm_mutex);
 
        data = filp->private_data;
-       res = snapshot_write_next(&data->handle, count);
-       if (res > 0) {
-               if (copy_from_user(data_of(data->handle), buf, res))
-                       res = -EFAULT;
-               else
-                       *offp = data->handle.offset;
+
+       if (!pg_offp) {
+               res = snapshot_write_next(&data->handle);
+               if (res <= 0)
+                       goto unlock;
+       } else {
+               res = PAGE_SIZE - pg_offp;
        }
 
+       res = simple_write_to_buffer(data_of(data->handle), res, &pg_offp,
+                       buf, count);
+       if (res > 0)
+               *offp += res;
+unlock:
        mutex_unlock(&pm_mutex);
 
        return res;