aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ecryptfs/crypto.c
diff options
context:
space:
mode:
authorTyler Hicks <tyhicks@linux.vnet.ibm.com>2009-09-16 20:04:20 -0400
committerTyler Hicks <tyhicks@linux.vnet.ibm.com>2009-09-23 10:10:34 -0400
commit96a7b9c2f5df899f302ade45cf17ad753fe130fd (patch)
tree096b67dbaad8e795344554994e28433a1e5b5de1 /fs/ecryptfs/crypto.c
parent3891959846709a19f76628e33478cd85edb0e79f (diff)
eCryptfs: Propagate vfs_read and vfs_write return codes
Errors returned from vfs_read() and vfs_write() calls to the lower filesystem were being masked as -EINVAL. This caused some confusion to users who saw EINVAL instead of ENOSPC when the disk was full, for instance. Also, the actual bytes read or written were not accessible by callers to ecryptfs_read_lower() and ecryptfs_write_lower(), which may be useful in some cases. This patch updates the error handling logic where those functions are called in order to accept positive return codes indicating success. Cc: Eric Sandeen <esandeen@redhat.com> Acked-by: Serge Hallyn <serue@us.ibm.com> Cc: ecryptfs-devel@lists.launchpad.net Signed-off-by: Tyler Hicks <tyhicks@linux.vnet.ibm.com>
Diffstat (limited to 'fs/ecryptfs/crypto.c')
-rw-r--r--fs/ecryptfs/crypto.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
index bae20ad1a50..fbb6e5eed69 100644
--- a/fs/ecryptfs/crypto.c
+++ b/fs/ecryptfs/crypto.c
@@ -509,13 +509,14 @@ int ecryptfs_encrypt_page(struct page *page)
509 + extent_offset), crypt_stat); 509 + extent_offset), crypt_stat);
510 rc = ecryptfs_write_lower(ecryptfs_inode, enc_extent_virt, 510 rc = ecryptfs_write_lower(ecryptfs_inode, enc_extent_virt,
511 offset, crypt_stat->extent_size); 511 offset, crypt_stat->extent_size);
512 if (rc) { 512 if (rc < 0) {
513 ecryptfs_printk(KERN_ERR, "Error attempting " 513 ecryptfs_printk(KERN_ERR, "Error attempting "
514 "to write lower page; rc = [%d]" 514 "to write lower page; rc = [%d]"
515 "\n", rc); 515 "\n", rc);
516 goto out; 516 goto out;
517 } 517 }
518 } 518 }
519 rc = 0;
519out: 520out:
520 if (enc_extent_page) { 521 if (enc_extent_page) {
521 kunmap(enc_extent_page); 522 kunmap(enc_extent_page);
@@ -631,7 +632,7 @@ int ecryptfs_decrypt_page(struct page *page)
631 rc = ecryptfs_read_lower(enc_extent_virt, offset, 632 rc = ecryptfs_read_lower(enc_extent_virt, offset,
632 crypt_stat->extent_size, 633 crypt_stat->extent_size,
633 ecryptfs_inode); 634 ecryptfs_inode);
634 if (rc) { 635 if (rc < 0) {
635 ecryptfs_printk(KERN_ERR, "Error attempting " 636 ecryptfs_printk(KERN_ERR, "Error attempting "
636 "to read lower page; rc = [%d]" 637 "to read lower page; rc = [%d]"
637 "\n", rc); 638 "\n", rc);
@@ -1213,14 +1214,15 @@ int ecryptfs_read_and_validate_header_region(char *data,
1213 crypt_stat->extent_size = ECRYPTFS_DEFAULT_EXTENT_SIZE; 1214 crypt_stat->extent_size = ECRYPTFS_DEFAULT_EXTENT_SIZE;
1214 rc = ecryptfs_read_lower(data, 0, crypt_stat->extent_size, 1215 rc = ecryptfs_read_lower(data, 0, crypt_stat->extent_size,
1215 ecryptfs_inode); 1216 ecryptfs_inode);
1216 if (rc) { 1217 if (rc < 0) {
1217 printk(KERN_ERR "%s: Error reading header region; rc = [%d]\n", 1218 printk(KERN_ERR "%s: Error reading header region; rc = [%d]\n",
1218 __func__, rc); 1219 __func__, rc);
1219 goto out; 1220 goto out;
1220 } 1221 }
1221 if (!contains_ecryptfs_marker(data + ECRYPTFS_FILE_SIZE_BYTES)) { 1222 if (!contains_ecryptfs_marker(data + ECRYPTFS_FILE_SIZE_BYTES)) {
1222 rc = -EINVAL; 1223 rc = -EINVAL;
1223 } 1224 } else
1225 rc = 0;
1224out: 1226out:
1225 return rc; 1227 return rc;
1226} 1228}
@@ -1315,10 +1317,11 @@ ecryptfs_write_metadata_to_contents(struct dentry *ecryptfs_dentry,
1315 1317
1316 rc = ecryptfs_write_lower(ecryptfs_dentry->d_inode, virt, 1318 rc = ecryptfs_write_lower(ecryptfs_dentry->d_inode, virt,
1317 0, virt_len); 1319 0, virt_len);
1318 if (rc) 1320 if (rc < 0)
1319 printk(KERN_ERR "%s: Error attempting to write header " 1321 printk(KERN_ERR "%s: Error attempting to write header "
1320 "information to lower file; rc = [%d]\n", __func__, 1322 "information to lower file; rc = [%d]\n", __func__, rc);
1321 rc); 1323 else
1324 rc = 0;
1322 return rc; 1325 return rc;
1323} 1326}
1324 1327
@@ -1598,7 +1601,7 @@ int ecryptfs_read_metadata(struct dentry *ecryptfs_dentry)
1598 } 1601 }
1599 rc = ecryptfs_read_lower(page_virt, 0, crypt_stat->extent_size, 1602 rc = ecryptfs_read_lower(page_virt, 0, crypt_stat->extent_size,
1600 ecryptfs_inode); 1603 ecryptfs_inode);
1601 if (!rc) 1604 if (rc >= 0)
1602 rc = ecryptfs_read_headers_virt(page_virt, crypt_stat, 1605 rc = ecryptfs_read_headers_virt(page_virt, crypt_stat,
1603 ecryptfs_dentry, 1606 ecryptfs_dentry,
1604 ECRYPTFS_VALIDATE_HEADER_SIZE); 1607 ECRYPTFS_VALIDATE_HEADER_SIZE);