shithub: lwext4

Download patch

ref: b3fc8b9dd5365861b4399b1dce12040ad91ba1bb
parent: 801cc44cbad8ecf24b36cc51bcce68405e81b652
author: root <[email protected]>
date: Thu Oct 8 11:55:30 EDT 2015

ext4 prefix/name string operations added.

--- a/lwext4/ext4.c
+++ b/lwext4/ext4.c
@@ -745,29 +745,6 @@
 		if (f->flags & O_APPEND)
 			f->fpos = f->fsize;
 
-		/* FIXME: Debugging code on EA. */
-		{
-			int private_ret;
-			struct ext4_xattr_ref xattr_ref;
-			private_ret = ext4_fs_get_xattr_ref(&f->mp->fs, &ref,
-							  &xattr_ref);
-			if (private_ret == EOK) {
-#define EXT4_XATTR_TEST_DATA_SIZE 20
-#define EXT4_XATTR_TEST_NAME "bad_boy"
-				static char test_data[EXT4_XATTR_TEST_DATA_SIZE] = {'a'};
-				ext4_dmask_set(EXT4_DEBUG_ALL);
-				ext4_fs_set_xattr(&xattr_ref,
-						  EXT4_XATTR_INDEX_USER,
-						  EXT4_XATTR_TEST_NAME,
-						  strlen(EXT4_XATTR_TEST_NAME),
-						  test_data,
-						  EXT4_XATTR_TEST_DATA_SIZE,
-						  0);
-				ext4_fs_xattr_iterate(&xattr_ref,
-						      ext4_iterate_ea);
-				ext4_fs_put_xattr_ref(&xattr_ref);
-			}
-		}
 	}
 
 	r = ext4_fs_put_inode_ref(&ref);
@@ -1959,6 +1936,16 @@
 	ext4_block_cache_write_back(mp->fs.bdev, 0);
 	EXT4_MP_UNLOCK(mp);
 	return r;
+}
+
+int ext4_fsetxattr(ext4_file *file,
+		   char *name,
+		   size_t name_len,
+		   void *data,
+		   size_t data_size,
+		   bool replace)
+{
+
 }
 
 /*********************************DIRECTORY OPERATION************************/
--- a/lwext4/ext4_xattr.c
+++ b/lwext4/ext4_xattr.c
@@ -757,8 +757,7 @@
 	}
 }
 
-static void
-ext4_fs_xattr_iterate_reset(struct ext4_xattr_ref *ref)
+void ext4_fs_xattr_iterate_reset(struct ext4_xattr_ref *ref)
 {
 	ref->iter_from = NULL;
 }
@@ -906,6 +905,46 @@
 	ext4_xattr_purge_items(ref);
 	ref->inode_ref = NULL;
 	ref->fs = NULL;
+}
+
+struct xattr_prefix {
+	char    *prefix;
+	uint8_t  name_index;
+} prefix_tbl [] = {
+	{"user.", EXT4_XATTR_INDEX_USER},
+	{"system.", EXT4_XATTR_INDEX_SYSTEM},
+	{"system.posix_acl_access", EXT4_XATTR_INDEX_POSIX_ACL_ACCESS},
+	{"system.posix_acl_default", EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT},
+	{NULL, 0},
+};
+
+char *ext4_extract_xattr_name(char *full_name,
+			      size_t full_name_len,
+			      uint8_t *name_index,
+			      size_t *name_len)
+{
+	int i;
+	ext4_assert(name_index);
+	if (!full_name_len)
+		return NULL;
+
+	for (i = 0;prefix_tbl[i].prefix;i++) {
+		int prefix_len = strlen(prefix_tbl[i].prefix);
+		if (full_name_len >= prefix_len &&
+		    !memcmp(full_name,
+			    prefix_tbl[i].prefix, prefix_len)) {
+			*name_index = prefix_tbl[i].name_index;
+			if (name_len)
+				*name_len = full_name_len -
+					prefix_len;
+
+			return full_name + prefix_len;
+		}
+	}
+	if (name_len)
+		*name_len = 0;
+
+	return NULL;
 }
 
 /**
--- a/lwext4/ext4_xattr.h
+++ b/lwext4/ext4_xattr.h
@@ -36,7 +36,11 @@
 		      int (iter)(struct ext4_xattr_ref *ref,
 				 struct ext4_xattr_item *item));
 
-static void
-ext4_fs_xattr_iterate_reset(struct ext4_xattr_ref *ref);
+void ext4_fs_xattr_iterate_reset(struct ext4_xattr_ref *ref);
+
+char *ext4_extract_xattr_name(char *full_name,
+			      size_t full_name_len,
+			      uint8_t *name_index,
+			      size_t *name_len);
 
 #endif