shithub: lwext4

Download patch

ref: b824765f6090f3051add513f72c6f73db02734af
parent: 17c247fab25759dff04070a9b81b8d008618d6f8
author: root <ngkaho1234@gmail.com>
date: Wed Oct 7 08:04:56 EDT 2015

EA entries iterating routines added.

--- a/lwext4/ext4.c
+++ b/lwext4/ext4.c
@@ -572,6 +572,19 @@
 	return false;
 }
 
+static int ext4_iterate_ea(struct ext4_xattr_ref *ref,
+			   struct ext4_xattr_item *item)
+{
+	int i;
+	ext4_dprintf(EXT4_DEBUG_INODE, "item->name: ");
+	for (i = 0;i < item->name_len;i++)
+		ext4_dprintf(EXT4_DEBUG_INODE, "%c", item->name[i]);
+
+	ext4_dprintf(EXT4_DEBUG_INODE, "\n");
+
+	return EXT4_XATTR_ITERATE_CONT;
+}
+
 /*
  * NOTICE: if filetype is equal to EXT4_DIRENTRY_UNKNOWN,
  * any filetype of the target dir entry will be accepted.
@@ -750,6 +763,8 @@
 						  test_data,
 						  EXT4_XATTR_TEST_DATA_SIZE,
 						  0);
+				ext4_fs_xattr_iterate(&xattr_ref,
+						      ext4_iterate_ea);
 				ext4_fs_put_xattr_ref(&xattr_ref);
 			}
 		}
--- a/lwext4/ext4_types.h
+++ b/lwext4/ext4_types.h
@@ -689,9 +689,15 @@
 	size_t ea_size;
 	struct ext4_fs *fs;
 
+	struct ext4_xattr_item *iter_from;
+
 	RB_HEAD(ext4_xattr_tree,
 		ext4_xattr_item) root;
 };
+
+#define EXT4_XATTR_ITERATE_CONT 0
+#define EXT4_XATTR_ITERATE_STOP 1
+#define EXT4_XATTR_ITERATE_PAUSE 2
 
 #define EXT4_GOOD_OLD_INODE_SIZE	128
 
--- a/lwext4/ext4_xattr.c
+++ b/lwext4/ext4_xattr.c
@@ -450,6 +450,11 @@
 				       name,
 				       name_len);
 	if (item) {
+		if (item == xattr_ref->iter_from)
+			xattr_ref->iter_from = RB_NEXT(ext4_xattr_tree,
+						       &xattr_ref->root,
+						       item);
+
 		RB_REMOVE(ext4_xattr_tree, &xattr_ref->root, item);
 		ext4_xattr_item_free(item);
 		xattr_ref->ea_size -= EXT4_XATTR_SIZE(item->data_size) +
@@ -727,7 +732,37 @@
 	return ret;
 }
 
+void
+ext4_fs_xattr_iterate(struct ext4_xattr_ref *ref,
+		      int (iter)(struct ext4_xattr_ref *ref,
+				 struct ext4_xattr_item *item))
+{
+	struct ext4_xattr_item *item = ref->iter_from;
+	if (!item)
+		item = RB_MIN(ext4_xattr_tree, &ref->root);
 
+	RB_FOREACH_FROM(item,
+			ext4_xattr_tree,
+			ref->iter_from) {
+		int ret = EXT4_XATTR_ITERATE_CONT;
+		if (iter)
+			iter(ref, item);
+
+		if (ret != EXT4_XATTR_ITERATE_CONT) {
+			if (ret == EXT4_XATTR_ITERATE_STOP)
+				ref->iter_from = NULL;
+
+			break;
+		}
+	}
+}
+
+static void
+ext4_fs_xattr_iterate_reset(struct ext4_xattr_ref *ref)
+{
+	ref->iter_from = NULL;
+}
+
 int ext4_fs_set_xattr(struct ext4_xattr_ref *ref,
 		      uint8_t name_index,
 		      char   *name,
@@ -830,6 +865,7 @@
 					      &fs->sb);
 	RB_INIT(&ref->root);
 	ref->ea_size = 0;
+	ref->iter_from = NULL;
 	if (xattr_block) {
 		rc = ext4_block_get(fs->bdev,
 				    &ref->block, xattr_block);
--- a/lwext4/ext4_xattr.h
+++ b/lwext4/ext4_xattr.h
@@ -31,4 +31,12 @@
 			  size_t   buf_size,
 			  size_t  *size_got);
 
+void
+ext4_fs_xattr_iterate(struct ext4_xattr_ref *ref,
+		      int (iter)(struct ext4_xattr_ref *ref,
+				 struct ext4_xattr_item *item));
+
+static void
+ext4_fs_xattr_iterate_reset(struct ext4_xattr_ref *ref);
+
 #endif