shithub: lwext4

Download patch

ref: 0b1f3afd3b8787ea652668ed29439d4701b42765
parent: edcd44595bcb730d60d0e0cbd6c4ede76cd2f2c7
author: root <[email protected]>
date: Fri Oct 9 13:19:27 EDT 2015

FIX: ea_size accounting is not correct after resizing. (3)

--- a/lwext4/ext4_xattr.c
+++ b/lwext4/ext4_xattr.c
@@ -424,10 +424,17 @@
 {
 	int ret = EOK;
 	size_t old_data_size = item->data_size;
-	if (xattr_ref->ea_size - EXT4_XATTR_SIZE(old_data_size) +
-		EXT4_XATTR_SIZE(new_data_size) >
-	    ext4_xattr_inode_space(xattr_ref) +
-		ext4_xattr_block_space(xattr_ref)) {
+	if ((xattr_ref->ea_size - EXT4_XATTR_SIZE(old_data_size) +
+		EXT4_XATTR_SIZE(new_data_size)
+			>
+	    ext4_xattr_inode_space(xattr_ref) -
+	    	sizeof(struct ext4_xattr_ibody_header))
+		&&
+	    (xattr_ref->ea_size - EXT4_XATTR_SIZE(old_data_size) +
+		EXT4_XATTR_SIZE(new_data_size)
+			>
+	    ext4_xattr_block_space(xattr_ref) -
+	    	sizeof(struct ext4_xattr_header))) {
 
 		return ENOSPC;
 	}
@@ -437,7 +444,7 @@
 	}
 	xattr_ref->ea_size =
 	    xattr_ref->ea_size -
-	    EXT4_XATTR_SIZE(old_data_size);
+	    EXT4_XATTR_SIZE(old_data_size) +
 	    EXT4_XATTR_SIZE(new_data_size);
 	xattr_ref->dirty = true;
 	return ret;