ref: a59596c45bfaa80d532ed7f9ef2c6c87f8ef5340
parent: 1cf71b8e4ad525d575ae130a658b02f67f5cc495
author: Kaho Ng <[email protected]>
date: Mon May 16 08:27:12 EDT 2016
ext4_xattr: ext4_xattr_insert_item now returns error code
--- a/src/ext4_xattr.c
+++ b/src/ext4_xattr.c
@@ -446,12 +446,17 @@
static struct ext4_xattr_item *
ext4_xattr_insert_item(struct ext4_xattr_ref *xattr_ref, uint8_t name_index,
const char *name, size_t name_len, const void *data,
- size_t data_size)
+ size_t data_size,
+ int *err)
{
struct ext4_xattr_item *item;
item = ext4_xattr_item_alloc(name_index, name, name_len);
- if (!item)
+ if (!item) {
+ if (err)
+ *err = ENOMEM;
+
return NULL;
+ }
if ((xattr_ref->ea_size + EXT4_XATTR_SIZE(data_size) +
EXT4_XATTR_LEN(item->name_len)
@@ -465,6 +470,9 @@
sizeof(struct ext4_xattr_header))) {
ext4_xattr_item_free(item);
+ if (err)
+ *err = ENOSPC;
+
return NULL;
}
item->in_inode = true;
@@ -473,13 +481,20 @@
(int32_t)EXT4_XATTR_LEN(item->name_len) < 0) {
if (xattr_ref->block_size_rem -
(int32_t)EXT4_XATTR_SIZE(data_size) -
- (int32_t)EXT4_XATTR_LEN(item->name_len) < 0)
+ (int32_t)EXT4_XATTR_LEN(item->name_len) < 0) {
+ if (err)
+ *err = ENOSPC;
+
return NULL;
+ }
item->in_inode = false;
}
if (ext4_xattr_item_alloc_data(item, data, data_size) != EOK) {
ext4_xattr_item_free(item);
+ if (err)
+ *err = ENOMEM;
+
return NULL;
}
RB_INSERT(ext4_xattr_tree, &xattr_ref->root, item);
@@ -495,6 +510,9 @@
EXT4_XATTR_LEN(item->name_len);
}
xattr_ref->dirty = true;
+ if (err)
+ *err = EOK;
+
return item;
}
@@ -918,9 +936,7 @@
goto Finish;
}
item = ext4_xattr_insert_item(ref, name_index, name, name_len,
- data, data_size);
- if (!item)
- ret = ENOMEM;
+ data, data_size, &ret);
}
Finish:
return ret;