drm: reorganise drm tree to be more future proof.
[safe/jmp/linux-2.6] / fs / ecryptfs / read_write.c
index 6b7474a..75c2ea9 100644 (file)
@@ -55,7 +55,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
        set_fs(fs_save);
        if (octets_written < 0) {
                printk(KERN_ERR "%s: octets_written = [%td]; "
-                      "expected [%td]\n", __FUNCTION__, octets_written, size);
+                      "expected [%td]\n", __func__, octets_written, size);
                rc = -EINVAL;
        }
        mutex_unlock(&inode_info->lower_file_mutex);
@@ -124,6 +124,10 @@ int ecryptfs_write(struct file *ecryptfs_file, char *data, loff_t offset,
        loff_t pos;
        int rc = 0;
 
+       /*
+        * if we are writing beyond current size, then start pos
+        * at the current size - we'll fill in zeros from there.
+        */
        if (offset > ecryptfs_file_size)
                pos = ecryptfs_file_size;
        else
@@ -137,6 +141,7 @@ int ecryptfs_write(struct file *ecryptfs_file, char *data, loff_t offset,
                if (num_bytes > total_remaining_bytes)
                        num_bytes = total_remaining_bytes;
                if (pos < offset) {
+                       /* remaining zeros to write, up to destination offset */
                        size_t total_remaining_zeros = (offset - pos);
 
                        if (num_bytes > total_remaining_zeros)
@@ -148,36 +153,32 @@ int ecryptfs_write(struct file *ecryptfs_file, char *data, loff_t offset,
                        rc = PTR_ERR(ecryptfs_page);
                        printk(KERN_ERR "%s: Error getting page at "
                               "index [%ld] from eCryptfs inode "
-                              "mapping; rc = [%d]\n", __FUNCTION__,
+                              "mapping; rc = [%d]\n", __func__,
                               ecryptfs_page_idx, rc);
                        goto out;
                }
-               if (start_offset_in_page) {
-                       /* Read in the page from the lower
-                        * into the eCryptfs inode page cache,
-                        * decrypting */
-                       rc = ecryptfs_decrypt_page(ecryptfs_page);
-                       if (rc) {
-                               printk(KERN_ERR "%s: Error decrypting "
-                                      "page; rc = [%d]\n",
-                                      __FUNCTION__, rc);
-                               ClearPageUptodate(ecryptfs_page);
-                               page_cache_release(ecryptfs_page);
-                               goto out;
-                       }
-               }
                ecryptfs_page_virt = kmap_atomic(ecryptfs_page, KM_USER0);
+
+               /*
+                * pos: where we're now writing, offset: where the request was
+                * If current pos is before request, we are filling zeros
+                * If we are at or beyond request, we are writing the *data*
+                * If we're in a fresh page beyond eof, zero it in either case
+                */
+               if (pos < offset || !start_offset_in_page) {
+                       /* We are extending past the previous end of the file.
+                        * Fill in zero values to the end of the page */
+                       memset(((char *)ecryptfs_page_virt
+                               + start_offset_in_page), 0,
+                               PAGE_CACHE_SIZE - start_offset_in_page);
+               }
+
+               /* pos >= offset, we are now writing the data request */
                if (pos >= offset) {
                        memcpy(((char *)ecryptfs_page_virt
                                + start_offset_in_page),
                               (data + data_offset), num_bytes);
                        data_offset += num_bytes;
-               } else {
-                       /* We are extending past the previous end of the file.
-                        * Fill in zero values up to the start of where we
-                        * will be writing data. */
-                       memset(((char *)ecryptfs_page_virt
-                               + start_offset_in_page), 0, num_bytes);
                }
                kunmap_atomic(ecryptfs_page_virt, KM_USER0);
                flush_dcache_page(ecryptfs_page);
@@ -187,7 +188,7 @@ int ecryptfs_write(struct file *ecryptfs_file, char *data, loff_t offset,
                page_cache_release(ecryptfs_page);
                if (rc) {
                        printk(KERN_ERR "%s: Error encrypting "
-                              "page; rc = [%d]\n", __FUNCTION__, rc);
+                              "page; rc = [%d]\n", __func__, rc);
                        goto out;
                }
                pos += num_bytes;
@@ -239,7 +240,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
        set_fs(fs_save);
        if (octets_read < 0) {
                printk(KERN_ERR "%s: octets_read = [%td]; "
-                      "expected [%td]\n", __FUNCTION__, octets_read, size);
+                      "expected [%td]\n", __func__, octets_read, size);
                rc = -EINVAL;
        }
        mutex_unlock(&inode_info->lower_file_mutex);
@@ -278,6 +279,7 @@ int ecryptfs_read_lower_page_segment(struct page *page_for_ecryptfs,
        return rc;
 }
 
+#if 0
 /**
  * ecryptfs_read
  * @data: The virtual address into which to write the data read (and
@@ -311,7 +313,7 @@ int ecryptfs_read(char *data, loff_t offset, size_t size,
                printk(KERN_ERR "%s: Attempt to read data past the end of the "
                        "file; offset = [%lld]; size = [%td]; "
                       "ecryptfs_file_size = [%lld]\n",
-                      __FUNCTION__, offset, size, ecryptfs_file_size);
+                      __func__, offset, size, ecryptfs_file_size);
                goto out;
        }
        pos = offset;
@@ -329,18 +331,10 @@ int ecryptfs_read(char *data, loff_t offset, size_t size,
                        rc = PTR_ERR(ecryptfs_page);
                        printk(KERN_ERR "%s: Error getting page at "
                               "index [%ld] from eCryptfs inode "
-                              "mapping; rc = [%d]\n", __FUNCTION__,
+                              "mapping; rc = [%d]\n", __func__,
                               ecryptfs_page_idx, rc);
                        goto out;
                }
-               rc = ecryptfs_decrypt_page(ecryptfs_page);
-               if (rc) {
-                       printk(KERN_ERR "%s: Error decrypting "
-                              "page; rc = [%d]\n", __FUNCTION__, rc);
-                       ClearPageUptodate(ecryptfs_page);
-                       page_cache_release(ecryptfs_page);
-                       goto out;
-               }
                ecryptfs_page_virt = kmap_atomic(ecryptfs_page, KM_USER0);
                memcpy((data + data_offset),
                       ((char *)ecryptfs_page_virt + start_offset_in_page),
@@ -356,3 +350,4 @@ int ecryptfs_read(char *data, loff_t offset, size_t size,
 out:
        return rc;
 }
+#endif  /*  0  */