From b2b3ea27e3e3ebcafda0972b999323d7683158cf Mon Sep 17 00:00:00 2001 From: Philip Tricca Date: Thu, 18 Feb 2016 21:53:36 +0000 Subject: e2fsprogs: Superseded by upstream. Signed-off-by: Philip Tricca --- .../misc-xattr-add-xattr-module-stub.patch | 57 ---- .../misc-xattr-create-xattr-block-node.patch | 175 ----------- .../e2fsprogs/misc-xattr-create-xattr-block.patch | 341 --------------------- .../e2fsprogs/misc-xattr-create-xattr-cache.patch | 181 ----------- .../mke2fs.c-create_inode.c-copy-xattrs.patch | 164 ---------- .../e2fsprogs/e2fsprogs_1.42.9.bbappend | 12 - 6 files changed, 930 deletions(-) delete mode 100644 recipes-devtools/e2fsprogs/e2fsprogs/misc-xattr-add-xattr-module-stub.patch delete mode 100644 recipes-devtools/e2fsprogs/e2fsprogs/misc-xattr-create-xattr-block-node.patch delete mode 100644 recipes-devtools/e2fsprogs/e2fsprogs/misc-xattr-create-xattr-block.patch delete mode 100644 recipes-devtools/e2fsprogs/e2fsprogs/misc-xattr-create-xattr-cache.patch delete mode 100644 recipes-devtools/e2fsprogs/e2fsprogs/mke2fs.c-create_inode.c-copy-xattrs.patch delete mode 100644 recipes-devtools/e2fsprogs/e2fsprogs_1.42.9.bbappend diff --git a/recipes-devtools/e2fsprogs/e2fsprogs/misc-xattr-add-xattr-module-stub.patch b/recipes-devtools/e2fsprogs/e2fsprogs/misc-xattr-add-xattr-module-stub.patch deleted file mode 100644 index 5a39abe..0000000 --- a/recipes-devtools/e2fsprogs/e2fsprogs/misc-xattr-add-xattr-module-stub.patch +++ /dev/null @@ -1,57 +0,0 @@ -This patch adds the structure for a module to duplicate xattr blocks as part -of copying files with the '-d' option to mke2fs. The function stubs here are -intended to be the public interface to the module. We also define a macro -for dumping debug data specific to this module. - -Signed-off-by: Philip Tricca - -Index: e2fsprogs-1.42.9/misc/xattr.c -=================================================================== ---- /dev/null -+++ e2fsprogs-1.42.9/misc/xattr.c -@@ -0,0 +1,34 @@ -+#include "xattr.h" -+ -+#include -+ -+#ifdef XATTR_DEBUG -+#define XATTR_STDERR(fmt, args...) fprintf (stderr, fmt, ##args) -+#else -+#define XATTR_STDERR(fmt, args...) do {} while (0) -+#endif -+ -+ -+/* Free remaining resources after all files have been processed. */ -+void -+xattr_cleanup () -+{ -+ XATTR_STDERR ("Cleaning up resources from xattrs.\n"); -+} -+ -+/* This is the entry point to the xattr module. This function copies the xattrs -+ * from the file at 'path' to the file system object at 'ino'. -+ * -+ * Parameters: -+ * fs: the file system object for the fs we're operating on -+ * ino: inode for the object we're labeling -+ * path: path to the object we're copying xattrs from -+ */ -+errcode_t -+set_inode_xattr (ext2_filsys fs, ext2_ino_t ino, const char *path) -+{ -+ errcode_t ret = 0; -+ -+ XATTR_STDERR ("Copying xattrs from %s to inode 0x%x.\n", path, ino); -+ return ret; -+} -Index: e2fsprogs-1.42.9/misc/xattr.h -=================================================================== ---- /dev/null -+++ e2fsprogs-1.42.9/misc/xattr.h -@@ -0,0 +1,6 @@ -+#include "et/com_err.h" -+#include "ext2fs/ext2fs.h" -+ -+/* Copy xattrs from source file to destination inode */ -+errcode_t set_inode_xattrs(ext2_filsys fs, ext2_ino_t ino, const char *name); -+void xattr_cleanup (); diff --git a/recipes-devtools/e2fsprogs/e2fsprogs/misc-xattr-create-xattr-block-node.patch b/recipes-devtools/e2fsprogs/e2fsprogs/misc-xattr-create-xattr-block-node.patch deleted file mode 100644 index f2e4582..0000000 --- a/recipes-devtools/e2fsprogs/e2fsprogs/misc-xattr-create-xattr-block-node.patch +++ /dev/null @@ -1,175 +0,0 @@ -Add two new functions to manage a cache of xattr blocks as well as a new struct -to build a linked list of xattr blocks. - -xattr_add_block: Adds a block to the cache. This function is supplied with a -pointer to the head of a linked list of xattr blocks and an xattr block to add. -The purpose of this cache is to allow sharing of what would otherwise be -duplicate xattr blocks and so duplicates are not allowed in this cache. If an -identical block is already in the cache a pointer to this block will be -returned. - -xattr_rm_block: Removes a block from the cache. This function is supplied with -a pointer to the cache and a node that shall be removed from the cache. The -cache is searched for the node and the node is removed if found. - -Both functions are integrated into the 'set_inode_xattr'. Here the logic is -rearranged to cope with associating preexisting xattr blocks with inodes as -well as creating new blocks when necessary. - -Signed-off-by: Philip Tricca - -Index: e2fsprogs-1.42.9/misc/xattr.c -=================================================================== ---- e2fsprogs-1.42.9.orig/misc/xattr.c -+++ e2fsprogs-1.42.9/misc/xattr.c -@@ -25,6 +25,19 @@ - #define XATTR_STDERR(fmt, args...) do {} while (0) - #endif - -+/* nodes for simple linked list to track xattr blocks, calling it a cache -+ * would be a stretch ... -+ */ -+typedef struct xattr_node xattr_node_t; -+ -+struct xattr_node { -+ struct ext2_ext_attr_header *header; -+ blk_t block; -+ struct xattr_node *next; -+}; -+ -+xattr_node_t *xattr_list_head = NULL; -+ - /* structure for mapping xattr name prefix data */ - typedef struct xattr_prefix { - int index; -@@ -48,6 +61,17 @@ xattr_prefix_t xattr_prefixes [] = { - { 0 }, - }; - -+/* free xattr node and the buffer holding the xattr block */ -+static void -+xattr_free_node (xattr_node_t *node) -+{ -+ if (node) { -+ if (node->header) -+ free (node->header); -+ free (node); -+ } -+} -+ - /* Free remaining resources after all files have been processed. */ - void - xattr_cleanup () -@@ -260,6 +284,28 @@ out: - return ret; - } - -+/* Add an xattr node to the list specified by head. This function will update -+ * head as necessary. It will return a pointer to the xattr_node_t added to the -+ * list. In the event that an identical xattr block is already on the list this -+ * function will return a pointer to the pre-existing node. -+ */ -+static xattr_node_t* -+xattr_add_block (xattr_node_t **head, xattr_node_t *node) -+{ -+ XATTR_STDERR ("Adding xattr to the the node list.\n"); -+ return node; -+} -+ -+/* Remove xattr node from list. Returns pointer to the node being removed. -+ * NOTE: We're not comparing the xattr blocks, just the nodes. -+ */ -+static xattr_node_t* -+xattr_rm_block (xattr_node_t **head, xattr_node_t *node) -+{ -+ XATTR_STDERR ("Removing xattr from the node list.\n"); -+ return node; -+} -+ - /* This is the entry point to the xattr module. This function copies the xattrs - * from the file at 'path' to the file system object at 'ino'. - * -@@ -274,16 +320,21 @@ set_inode_xattr (ext2_filsys fs, ext2_in - errcode_t ret = 0; - char *buf = NULL; - struct ext2_inode inode = { 0 }; -- blk_t block = 0; -- struct ext2_ext_attr_header *header = NULL; -+ xattr_node_t *node = NULL, *node_tmp = NULL; - uint32_t newcount = 0; - - XATTR_STDERR ("Copying xattrs from %s to inode 0x%x.\n", path, ino); -+ /* Create an xattr_node_t for it and add it to the cache if appropriate */ -+ if (!(node = calloc (1, sizeof (xattr_node_t)))) { -+ com_err (__func__, errno, "calloc"); -+ ret = errno; -+ goto out; -+ } - /* Populate the xattr block for the file at path */ -- if (ret = xattr_build_block (path, &header, fs->blocksize)) { -+ if (ret = xattr_build_block (path, &(node->header), fs->blocksize)) { - goto out; - } -- if (header == NULL) { -+ if (node->header == NULL) { - XATTR_STDERR ("set_inode_xattrs: no xattrs for %s\n", path); - goto out; - } -@@ -291,23 +342,38 @@ set_inode_xattr (ext2_filsys fs, ext2_in - com_err(__func__, ret, "ext2fs_read_inode"); - goto out; - } -- if (ret = ext2fs_alloc_block (fs, 0, NULL, &block)) { -- com_err(__func__, ret, "ext2fs_alloc_block: returned %d", ret); -+ if (!(node_tmp = xattr_add_block (&xattr_list_head, node))) { -+ fprintf (stderr, "Cannot add NULL node to xattr_block list.\n"); - goto out; - } -- ext2fs_mark_block_bitmap2 (fs->block_map, block); -- XATTR_STDERR ("writing xattr block 0x%x to disk:\n", block); -- if (ret = ext2fs_write_ext_attr (fs, block, header)) { -- com_err(__func__, ret, "ext2fs_write_ext_attr: returned %d", ret); -- goto out; -+ if (node == node_tmp) { -+ /* xattr block is new: add to list & write to disk */ -+ XATTR_STDERR ("no pre-existing xattr block, creating / adding\n"); -+ if (ret = ext2fs_alloc_block (fs, 0, NULL, &node->block)) { -+ com_err(__func__, ret, "ext2fs_alloc_block: returned %d", ret); -+ xattr_rm_block (&xattr_list_head, node); -+ goto out; -+ } -+ ext2fs_mark_block_bitmap2 (fs->block_map, node->block); -+ XATTR_STDERR ("writing xattr block 0x%x to disk:\n", node->block); -+ if (ret = ext2fs_write_ext_attr (fs, node->block, node->header)) { -+ com_err(__func__, ret, "ext2fs_write_ext_attr: returned %d", ret); -+ xattr_rm_block (&xattr_list_head, node); -+ goto out; -+ } -+ } else { -+ /* already have an identical xattr block, free the one we just made */ -+ XATTR_STDERR ("using xattr from existing block: 0x%x\n", node_tmp->block); -+ xattr_free_node (node); -+ node = node_tmp; - } - /* point inode for current file to xattr block, update block count and - * write inode to disk - */ -- inode.i_file_acl = block; -+ inode.i_file_acl = node->block; - if (ret = ext2fs_adjust_ea_refcount2(fs, -- block, -- (char*)header, -+ node->block, -+ (char*)(node->header), - 1, - &newcount)) - { -@@ -321,7 +387,6 @@ set_inode_xattr (ext2_filsys fs, ext2_in - if (ret = ext2fs_write_inode (fs, ino, &inode)) - com_err(__func__, ret, "ext2fs_write_inode: returned %d", ret); - out: -- if (header) -- free (header); -+ xattr_free_node (node); - return ret; - } diff --git a/recipes-devtools/e2fsprogs/e2fsprogs/misc-xattr-create-xattr-block.patch b/recipes-devtools/e2fsprogs/e2fsprogs/misc-xattr-create-xattr-block.patch deleted file mode 100644 index 5955b44..0000000 --- a/recipes-devtools/e2fsprogs/e2fsprogs/misc-xattr-create-xattr-block.patch +++ /dev/null @@ -1,341 +0,0 @@ -To build the xattr disk block we process the output from listxattr and -lgetxattr from the source file system object. This data is formated in a disk -block according to the format specified in the kernel ext2 file system driver. -See the comment block at the beginning of fs/ext2/xattr.c for details. - -Currently we only process attributes with the 'security.' prefix as our use -case is SELinux labels and IMA. Additional prefixes can likely be supported with -minimal effort but none have been tested. - -Once the xattr block has been created it is written to disk. The xattr block is -associated with the appropriate file system object through the i_file_acl inode -member and the inode is updated on disk. - -Signed-off-by: Philip Tricca - -Index: e2fsprogs-1.42.9/misc/xattr.c -=================================================================== ---- e2fsprogs-1.42.9.orig/misc/xattr.c -+++ e2fsprogs-1.42.9/misc/xattr.c -@@ -1,6 +1,23 @@ - #include "xattr.h" - -+#include -+#include -+#include -+#include -+#include -+#include - #include -+#include -+#include -+#include -+#include -+#include -+ -+#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) -+#define HEADER(ptr) ((struct ext2_ext_attr_header *)(ptr)) -+#define ENTRY(ptr) ((struct ext2_ext_attr_entry *)(ptr)) -+#define FIRST_ENTRY(ptr) ENTRY(HEADER(ptr) + 1) -+#define VALUE(hdr, ent) (((char*)hdr) + (ent->e_value_offs)) - - #ifdef XATTR_DEBUG - #define XATTR_STDERR(fmt, args...) fprintf (stderr, fmt, ##args) -@@ -8,6 +25,28 @@ - #define XATTR_STDERR(fmt, args...) do {} while (0) - #endif - -+/* structure for mapping xattr name prefix data */ -+typedef struct xattr_prefix { -+ int index; -+ char *name; -+ size_t length; -+} xattr_prefix_t; -+ -+xattr_prefix_t xattr_prefixes [] = { -+/* Only interested in security prefix. Can support others though. -+ { -+ .index = EXT2_XATTR_INDEX_USER, -+ .name = XATTR_USER_PREFIX, -+ .length = XATTR_USER_PREFIX_LEN, -+ }, -+*/ -+ { -+ .index = EXT2_XATTR_INDEX_SECURITY, -+ .name = XATTR_SECURITY_PREFIX, -+ .length = XATTR_SECURITY_PREFIX_LEN, -+ }, -+ { 0 }, -+}; - - /* Free remaining resources after all files have been processed. */ - void -@@ -16,6 +55,211 @@ xattr_cleanup () - XATTR_STDERR ("Cleaning up resources from xattrs.\n"); - } - -+/* Get value for named xattr from file at path. -+ * Returns pointer to allocated block for value and length in length param. -+ * If no value, return NULL pointer and length of 0. -+ * On error return NULL pointer and length set to -1. -+ */ -+static char* -+xattr_get_value (const char *path, const char *name, ssize_t *length) -+{ -+ char *value = NULL; -+ -+ *length = lgetxattr (path, name, NULL, 0); -+ if (*length == -1) { -+ com_err (__func__, errno, "lgetattr"); -+ goto out; -+ } -+ if (*length == 0) { -+ fprintf (stderr, "xattr %s has value length 0\n", name); -+ goto out; -+ } -+ value = calloc (1, *length); -+ if (value == NULL) { -+ com_err (__func__, errno, "calloc"); -+ goto out; -+ } -+ *length = lgetxattr (path, name, value, *length); -+ if (*length == -1) { -+ com_err (__func__, errno, "lgetattr"); -+ goto value_err; -+ } -+out: -+ return value; -+ -+value_err: -+ if (value) -+ free (value); -+ return NULL; -+} -+ -+/* Get all attribute names for file at path. Return pointer to allocated memory -+ * block holding all names and the length through parameter size. -+ * If no xattrs: return NULL and set size to 0 -+ * If error: return NULL and set size to -1 -+ */ -+static char* -+xattr_get_names (const char *path, ssize_t *size) -+{ -+ char *names = NULL; -+ -+ *size = llistxattr (path, NULL, 0); -+ if (*size == -1) { -+ com_err (__func__, errno, "llistxattr"); -+ goto out; -+ } -+ if (*size == 0) { -+ /* no xattrs */ -+ goto out; -+ } -+ names = calloc (1, *size); -+ if (names == NULL) { -+ com_err (__func__, errno, "calloc"); -+ goto out; -+ } -+ *size = llistxattr (path, names, *size); -+ if (*size == -1) { -+ com_err (__func__, errno, "llistxattr"); -+ goto cleanup; -+ } -+ if (*size == 0) { -+ fprintf (stdout, "Conflicting data, no xattrs for file: %s\n", path); -+ goto cleanup; -+ } -+out: -+ return names; -+ -+cleanup: -+ if (names) -+ free (names); -+ return NULL; -+} -+ -+/* return pointer to next string in xattr name block, don't go beyond length -+ */ -+static inline char* -+next_name (char *name, size_t length) -+{ -+ int i = 0; -+ -+ for (i = 0; i < length; ++i) -+ if (name [i] == '\0') { -+ ++i; -+ break; -+ } -+ -+ return name + i; -+} -+ -+/* Find entry in xattr_table with matching prefix. */ -+static const xattr_prefix_t* -+xattr_find_prefix (char *name, size_t length) -+{ -+ int i = 0; -+ -+ XATTR_STDERR ("find_attr_data: searching for prefix from xattr name: %s\n", name); -+ for (i = 0; xattr_prefixes[i].index != 0; ++i) { -+ if (!strncmp (name, xattr_prefixes[i].name, MIN (length, xattr_prefixes[i].length))) { -+ XATTR_STDERR ("found match in table with index: %d\n", xattr_prefixes[i].index); -+ return &xattr_prefixes[i]; -+ } -+ } -+ return NULL; -+} -+ -+/* Query file at path for attributes. build up structure the file system -+ * expects of an extended attribute disk block (header parameter). -+ * -+ * The main loop walks through the xattr names one at a time. It gets the value -+ * for each named xattr and copies the data into the xattr block pointed to by -+ * the header parameter. To do this the loop also tracks the location of the -+ * associated entry and value. Values start at the end of the buffer and grow -+ * back towards the header while the entries start immediately after the header -+ * and grow towards the end of the block. -+ * -+ * See the comment block at the beginning of the xattr.c file in the ext2 file -+ * system code in the kernel: fs/ext2/xattr.c -+ * Assume the xattr block pointed to by header parameter is initialized to 0s. -+ */ -+static int -+xattr_build_block (const char *path, -+ struct ext2_ext_attr_header **header, -+ size_t header_length) -+{ -+ struct ext2_ext_attr_entry *entry = NULL; -+ char *names = NULL, *value = NULL, *name_curr = NULL; -+ ssize_t names_length = 0, value_length = 0; -+ size_t name_length = 0, value_index = 0, len_rem = 0; -+ const xattr_prefix_t *prefix = NULL; -+ int ret = 0; -+ -+ XATTR_STDERR ("xattr_build_block for file: %s\n", path); -+ *header = NULL; -+ names = xattr_get_names (path, &names_length); -+ if (names == NULL) { -+ // no xattrs for file @ path or error -+ ret = names_length; -+ goto out; -+ } -+ *header = calloc (1, header_length); -+ if (*header == NULL) { -+ com_err (__func__, errno, "calloc"); -+ goto out; -+ } -+ (*header)->h_magic = EXT2_EXT_ATTR_MAGIC; -+ (*header)->h_blocks = 1; -+ /* Values start at end of buffer. NOTE: It must be moved before a value can -+ * be stored. -+ */ -+ value_index = header_length; -+ for (name_curr = names, entry = FIRST_ENTRY(*header), len_rem = names_length; -+ name_curr < names + names_length; -+ len_rem = names_length - (name_curr - names), -+ name_curr = next_name (name_curr, len_rem), -+ entry = EXT2_EXT_ATTR_NEXT(entry)) -+ { -+ XATTR_STDERR ("xattr_build_block: processing xattr with name %s\n", name_curr); -+ name_length = strnlen (name_curr, len_rem); -+ prefix = xattr_find_prefix (name_curr, name_length); -+ if (!prefix) { -+ fprintf (stderr, "Don't currently handle xattr: %s\n", name_curr); -+ continue; -+ } -+ value = xattr_get_value (path, name_curr, &value_length); -+ if (value == NULL) { -+ // no xattr value or error -+ fprintf (stderr, "failed to get value, skipping\n"); -+ goto next; -+ } -+ /* setup offsets and lengths for name and value */ -+ entry->e_name_len = name_length - prefix->length; -+ entry->e_name_index = prefix->index; -+ /* Can't know these till we know the length of the value. */ -+ entry->e_value_offs = value_index -= EXT2_EXT_ATTR_SIZE(value_length); -+ entry->e_value_size = value_length; -+ /* Check to be sure entry name and value don't overlap before copy. */ -+ if (EXT2_EXT_ATTR_NAME(entry) + entry->e_name_len > VALUE(*header, entry)) { -+ fprintf (stderr, "xattr entry name and value overlap! Too much xattr data."); -+ ret = -1; -+ goto out; -+ } -+ /* copy name and value data then calculate the hash */ -+ memcpy (EXT2_EXT_ATTR_NAME(entry), -+ name_curr + prefix->length, -+ entry->e_name_len); -+ memcpy (VALUE(*header, entry), value, entry->e_value_size); -+ entry->e_hash = ext2fs_ext_attr_hash_entry (entry, VALUE(*header, entry)); -+next: -+ if (value) -+ free (value); -+ } -+ XATTR_STDERR ("xattr_build_block: done building xattr buffer\n"); -+out: -+ if (names) -+ free (names); -+ return ret; -+} -+ - /* This is the entry point to the xattr module. This function copies the xattrs - * from the file at 'path' to the file system object at 'ino'. - * -@@ -28,7 +272,56 @@ errcode_t - set_inode_xattr (ext2_filsys fs, ext2_ino_t ino, const char *path) - { - errcode_t ret = 0; -+ char *buf = NULL; -+ struct ext2_inode inode = { 0 }; -+ blk_t block = 0; -+ struct ext2_ext_attr_header *header = NULL; -+ uint32_t newcount = 0; - - XATTR_STDERR ("Copying xattrs from %s to inode 0x%x.\n", path, ino); -+ /* Populate the xattr block for the file at path */ -+ if (ret = xattr_build_block (path, &header, fs->blocksize)) { -+ goto out; -+ } -+ if (header == NULL) { -+ XATTR_STDERR ("set_inode_xattrs: no xattrs for %s\n", path); -+ goto out; -+ } -+ if (ret = ext2fs_read_inode (fs, ino, &inode)) { -+ com_err(__func__, ret, "ext2fs_read_inode"); -+ goto out; -+ } -+ if (ret = ext2fs_alloc_block (fs, 0, NULL, &block)) { -+ com_err(__func__, ret, "ext2fs_alloc_block: returned %d", ret); -+ goto out; -+ } -+ ext2fs_mark_block_bitmap2 (fs->block_map, block); -+ XATTR_STDERR ("writing xattr block 0x%x to disk:\n", block); -+ if (ret = ext2fs_write_ext_attr (fs, block, header)) { -+ com_err(__func__, ret, "ext2fs_write_ext_attr: returned %d", ret); -+ goto out; -+ } -+ /* point inode for current file to xattr block, update block count and -+ * write inode to disk -+ */ -+ inode.i_file_acl = block; -+ if (ret = ext2fs_adjust_ea_refcount2(fs, -+ block, -+ (char*)header, -+ 1, -+ &newcount)) -+ { -+ com_err(__func__, ret, "ext2fs_adjust_ea_refcount"); -+ goto out; -+ } -+ if (ret = ext2fs_iblk_add_blocks (fs, &inode, 1)) { -+ com_err(__func__, ret, "ext2fs_iblk_add_blocks failed"); -+ goto out; -+ } -+ if (ret = ext2fs_write_inode (fs, ino, &inode)) -+ com_err(__func__, ret, "ext2fs_write_inode: returned %d", ret); -+out: -+ if (header) -+ free (header); - return ret; - } diff --git a/recipes-devtools/e2fsprogs/e2fsprogs/misc-xattr-create-xattr-cache.patch b/recipes-devtools/e2fsprogs/e2fsprogs/misc-xattr-create-xattr-cache.patch deleted file mode 100644 index 38e6454..0000000 --- a/recipes-devtools/e2fsprogs/e2fsprogs/misc-xattr-create-xattr-cache.patch +++ /dev/null @@ -1,181 +0,0 @@ -Implement the xattr block cache as an unsorted linked list. This requires the -add and rm functions be able to test for equality between xattr blocks. This -is implemented as two functions. The first compares individual entries and the -second compares the whole xattr block by iterating over the individual entries. - -The xattr block cache keeps memory allocated on the heap around across -invocations of the set_inode_xattr function. To free this memory we implement -an xattr_cleanup function that iterates over the cache freeing resources -associated with each node. - -Signed-off-by: Philip Tricca - -Index: e2fsprogs-1.42.9/misc/xattr.c -=================================================================== ---- e2fsprogs-1.42.9.orig/misc/xattr.c -+++ e2fsprogs-1.42.9/misc/xattr.c -@@ -5,6 +5,7 @@ - #include - #include - #include -+#include - #include - #include - #include -@@ -25,6 +26,9 @@ - #define XATTR_STDERR(fmt, args...) do {} while (0) - #endif - -+static size_t cache_hit = 0; -+static size_t cache_miss = 0; -+ - /* nodes for simple linked list to track xattr blocks, calling it a cache - * would be a stretch ... - */ -@@ -76,7 +80,18 @@ xattr_free_node (xattr_node_t *node) - void - xattr_cleanup () - { -+ xattr_node_t *curr = NULL, *tmp = NULL; -+ size_t count = 0; -+ - XATTR_STDERR ("Cleaning up resources from xattrs.\n"); -+ for (curr = xattr_list_head; curr != NULL; ++count) { -+ tmp = curr; -+ curr = curr->next; -+ xattr_free_node (tmp); -+ } -+ XATTR_STDERR ("Freed %d xattr_node_ts.\n", count); -+ XATTR_STDERR ("Cache hits: %u\n", cache_hit); -+ XATTR_STDERR ("Cache miss: %u\n", cache_miss); - } - - /* Get value for named xattr from file at path. -@@ -284,6 +299,58 @@ out: - return ret; - } - -+static bool -+xattr_entry_isequal (struct ext2_ext_attr_header *header_a, -+ struct ext2_ext_attr_entry *entry_a, -+ struct ext2_ext_attr_header *header_b, -+ struct ext2_ext_attr_entry *entry_b) -+{ -+ if (entry_a->e_hash == entry_b->e_hash || -+ entry_a->e_name_index == entry_b->e_name_index || -+ entry_a->e_name_len == entry_b->e_name_len || -+ entry_a->e_value_size == entry_b->e_value_size) -+ { -+ /* If entry header data all matches we check name and value */ -+ if (memcmp (EXT2_EXT_ATTR_NAME(entry_a), -+ EXT2_EXT_ATTR_NAME(entry_b), -+ MIN (entry_a->e_name_len, entry_b->e_name_len)) != 0) -+ return false; -+ if (memcmp (VALUE(header_a, entry_a), -+ VALUE(header_b, entry_b), -+ MIN(entry_a->e_value_size, entry_b->e_value_size)) != 0) -+ return false; -+ return true; -+ } else { -+ return false; -+ } -+} -+ -+static bool -+xattr_block_isequal (struct ext2_ext_attr_header *header_a, -+ struct ext2_ext_attr_header *header_b) -+{ -+ struct ext2_ext_attr_entry *entry_a = NULL, *entry_b = NULL; -+ -+ XATTR_STDERR ("equality test: xattr blocks at 0x%x and 0x%x\n", header_a, header_b); -+ for (entry_a = FIRST_ENTRY(header_a), entry_b = FIRST_ENTRY(header_b); -+ !EXT2_EXT_IS_LAST_ENTRY(entry_a) && !EXT2_EXT_IS_LAST_ENTRY(entry_b); -+ entry_a = EXT2_EXT_ATTR_NEXT(entry_a), entry_b = EXT2_EXT_ATTR_NEXT(entry_b)) -+ { -+ if (!xattr_entry_isequal (header_a, entry_a, header_b, entry_b)) { -+ /* bail as soon as we find entries that don't match */ -+ XATTR_STDERR ("entries do not match\n"); -+ return false; -+ } -+ } -+ /* Be sure we're on the last element from each block. */ -+ if (EXT2_EXT_IS_LAST_ENTRY(entry_a) && EXT2_EXT_IS_LAST_ENTRY(entry_b)) { -+ XATTR_STDERR ("entries match\n"); -+ return true; -+ } else { -+ return false; -+ } -+} -+ - /* Add an xattr node to the list specified by head. This function will update - * head as necessary. It will return a pointer to the xattr_node_t added to the - * list. In the event that an identical xattr block is already on the list this -@@ -292,7 +359,31 @@ out: - static xattr_node_t* - xattr_add_block (xattr_node_t **head, xattr_node_t *node) - { -+ xattr_node_t *curr_node = NULL, *prev_node = NULL; -+ - XATTR_STDERR ("Adding xattr to the the node list.\n"); -+ if (node == NULL) -+ return NULL; -+ /* list is empty, node becomes first node */ -+ if (!(*head)) { -+ *head = node; -+ return node; -+ } -+ for (curr_node = *head; curr_node != NULL; curr_node = curr_node->next) -+ { -+ /* cache hit */ -+ if (xattr_block_isequal (node->header, curr_node->header)) { -+ ++cache_hit; -+ return curr_node; -+ } -+ /* end of list */ -+ if (curr_node->next == NULL) { -+ ++cache_miss; -+ curr_node->next = node; -+ return node; -+ } -+ } -+ /* should never reach: assert? */ - return node; - } - -@@ -302,8 +393,27 @@ xattr_add_block (xattr_node_t **head, xa - static xattr_node_t* - xattr_rm_block (xattr_node_t **head, xattr_node_t *node) - { -+ xattr_node_t *curr_node = NULL, *prev_node = NULL; -+ - XATTR_STDERR ("Removing xattr from the node list.\n"); -- return node; -+ /* no list, or empty list: nothing to search though */ -+ if (!head || !(*head)) -+ return NULL; -+ -+ for (prev_node = NULL, curr_node = *head; -+ curr_node != NULL; -+ prev_node = curr_node, curr_node = curr_node->next) -+ { -+ if (node == curr_node) { -+ if (prev_node) -+ prev_node->next = curr_node->next; -+ else -+ *head = curr_node->next; -+ return curr_node; -+ } -+ } -+ /* reached end of list, no match */ -+ return NULL; - } - - /* This is the entry point to the xattr module. This function copies the xattrs -@@ -386,6 +496,7 @@ set_inode_xattr (ext2_filsys fs, ext2_in - } - if (ret = ext2fs_write_inode (fs, ino, &inode)) - com_err(__func__, ret, "ext2fs_write_inode: returned %d", ret); -+ return ret; - out: - xattr_free_node (node); - return ret; diff --git a/recipes-devtools/e2fsprogs/e2fsprogs/mke2fs.c-create_inode.c-copy-xattrs.patch b/recipes-devtools/e2fsprogs/e2fsprogs/mke2fs.c-create_inode.c-copy-xattrs.patch deleted file mode 100644 index 8b0109f..0000000 --- a/recipes-devtools/e2fsprogs/e2fsprogs/mke2fs.c-create_inode.c-copy-xattrs.patch +++ /dev/null @@ -1,164 +0,0 @@ -Insert calls into xattr module to copy xattrs for each file system object -copied by mke2fs when '-d' is specified. This requires a call to -set_inode_xattr in two places: -misc/create_inode.c: to copy xattrs as part of the recursive traversal -of the source directory -misc/mke2fs.c: to copy the xattr block associated with the root of the -file system - -Insert a call to xattr_cleanup to free any resources that need special -handling in the xattr module. - -We also add the necessary rules to Makefile.in to build the xattr module -and link it into executables as required. - -Signed-off-by: Philip Tricca - -Index: e2fsprogs-1.42.9/misc/mke2fs.c -=================================================================== ---- e2fsprogs-1.42.9.orig/misc/mke2fs.c -+++ e2fsprogs-1.42.9/misc/mke2fs.c -@@ -56,6 +56,7 @@ extern int optind; - #include "../version.h" - #include "quota/mkquota.h" - #include "create_inode.h" -+#include "xattr.h" - - #define STRIDE_LENGTH 8 - -@@ -2744,6 +2745,11 @@ no_journal: - hdlinks.count = 0; - current_fs = fs; - root = EXT2_ROOT_INO; -+ retval = set_inode_xattr (fs, EXT2_ROOT_INO, root_dir); -+ if (retval) { -+ fprintf(stderr, "%s", _("Error setting xattr for inode: 0x%x\n"), EXT2_ROOT_INO); -+ return retval; -+ } - retval = populate_fs(root, root_dir); - if (retval) { - fprintf(stderr, "%s", -@@ -2751,6 +2757,7 @@ no_journal: - return retval; - } else if (!quiet) - printf("%s", _("done\n")); -+ xattr_cleanup(); - } - - if (!quiet) -Index: e2fsprogs-1.42.9/misc/create_inode.c -=================================================================== ---- e2fsprogs-1.42.9.orig/misc/create_inode.c -+++ e2fsprogs-1.42.9/misc/create_inode.c -@@ -1,5 +1,6 @@ - #include "create_inode.h" - #include -+#include "xattr.h" - - #if __STDC_VERSION__ < 199901L - # if __GNUC__ >= 2 -@@ -549,6 +550,12 @@ errcode_t populate_fs(ext2_ino_t parent_ - return retval; - } - -+ if ((retval = set_inode_xattr (current_fs, ino, name))) { -+ com_err(__func__, retval, -+ _("while setting xattrs for \"%s\""), name); -+ return retval; -+ } -+ - /* Save the hardlink ino */ - if (save_inode) { - /* -Index: e2fsprogs-1.42.9/debugfs/Makefile.in -=================================================================== ---- e2fsprogs-1.42.9.orig/debugfs/Makefile.in -+++ e2fsprogs-1.42.9/debugfs/Makefile.in -@@ -18,7 +18,7 @@ MK_CMDS= _SS_DIR_OVERRIDE=../lib/ss ../l - - DEBUG_OBJS= debug_cmds.o debugfs.o util.o ncheck.o icheck.o ls.o \ - lsdel.o dump.o set_fields.o logdump.o htree.o unused.o e2freefrag.o \ -- filefrag.o extent_cmds.o extent_inode.o zap.o create_inode.o -+ filefrag.o extent_cmds.o extent_inode.o zap.o create_inode.o xattr.o - - RO_DEBUG_OBJS= ro_debug_cmds.o ro_debugfs.o util.o ncheck.o icheck.o ls.o \ - lsdel.o logdump.o htree.o e2freefrag.o filefrag.o extent_cmds.o \ -@@ -29,12 +29,16 @@ SRCS= debug_cmds.c $(srcdir)/debugfs.c $ - $(srcdir)/dump.c $(srcdir)/set_fields.c ${srcdir}/logdump.c \ - $(srcdir)/htree.c $(srcdir)/unused.c ${srcdir}/../misc/e2freefrag.c \ - $(srcdir)/filefrag.c $(srcdir)/extent_inode.c $(srcdir)/zap.c \ -- $(srcdir)/../misc/create_inode.c -+ $(srcdir)/../misc/create_inode.c $(srcdir)/../misc/xattr.c - - CREATE_INODE_DEPS= $(srcdir)/../misc/create_inode.h \ - $(srcdir)/../misc/create_inode.c $(top_builddir)/lib/config.h \ - $(srcdir)/../lib/ext2fs/ext2fs.h $(srcdir)/../lib/et/com_err.h \ -- $(srcdir)/../lib/e2p/e2p.h $(srcdir)/../misc/nls-enable.h -+ $(srcdir)/../lib/e2p/e2p.h $(srcdir)/../misc/nls-enable.h \ -+ $(srcdir)/../misc/xattr.h -+ -+XATTR_DEPS= $(srcdir)/../misc/xattr.h $(srcdir)/../misc/xattr.h \ -+ $(srcdir)/../lib/et/com_err.h $(srcdir)/../lib/ext2fs/ext2fs.h - - LIBS= $(LIBEXT2FS) $(LIBE2P) $(LIBSS) $(LIBCOM_ERR) $(LIBBLKID) \ - $(LIBUUID) -@@ -92,6 +96,11 @@ create_inode.o: $(CREATE_INODE_DEPS) - $(Q) $(CC) -c $(ALL_CFLAGS) -I$(srcdir) \ - $(srcdir)/../misc/create_inode.c -DDEBUGFS -o $@ - -+xattr.o: $(XATTR_DEPS) -+ $(E) " CC $@" -+ $(Q) $(CC) -c $(ALL_CFLAGS) -I$(srcdir) \ -+ $(srcdir)/../misc/xattr.c -o $@ -+ - debugfs.8: $(DEP_SUBSTITUTE) $(srcdir)/debugfs.8.in - $(E) " SUBST $@" - $(Q) $(SUBSTITUTE_UPTIME) $(srcdir)/debugfs.8.in debugfs.8 -Index: e2fsprogs-1.42.9/misc/Makefile.in -=================================================================== ---- e2fsprogs-1.42.9.orig/misc/Makefile.in -+++ e2fsprogs-1.42.9/misc/Makefile.in -@@ -43,7 +43,7 @@ LPROGS= @E2INITRD_PROG@ - TUNE2FS_OBJS= tune2fs.o util.o - MKLPF_OBJS= mklost+found.o - MKE2FS_OBJS= mke2fs.o util.o profile.o prof_err.o default_profile.o \ -- create_inode.o -+ create_inode.o xattr.o - CHATTR_OBJS= chattr.o - LSATTR_OBJS= lsattr.o - UUIDGEN_OBJS= uuidgen.o -@@ -62,7 +62,7 @@ PROFILED_TUNE2FS_OBJS= profiled/tune2fs. - PROFILED_MKLPF_OBJS= profiled/mklost+found.o - PROFILED_MKE2FS_OBJS= profiled/mke2fs.o profiled/util.o profiled/profile.o \ - profiled/prof_err.o profiled/default_profile.o \ -- profiled/create_inode.o -+ profiled/create_inode.o profiled/xattr.o - PROFILED_CHATTR_OBJS= profiled/chattr.o - PROFILED_LSATTR_OBJS= profiled/lsattr.o - PROFILED_UUIDGEN_OBJS= profiled/uuidgen.o -@@ -84,7 +84,8 @@ SRCS= $(srcdir)/tune2fs.c $(srcdir)/mklo - $(srcdir)/uuidgen.c $(srcdir)/blkid.c $(srcdir)/logsave.c \ - $(srcdir)/filefrag.c $(srcdir)/base_device.c \ - $(srcdir)/ismounted.c $(srcdir)/../e2fsck/profile.c \ -- $(srcdir)/e2undo.c $(srcdir)/e2freefrag.c $(srcdir)/create_inode.c -+ $(srcdir)/e2undo.c $(srcdir)/e2freefrag.c $(srcdir)/create_inode.c \ -+ $(srcdir)/xattr.c - - LIBS= $(LIBEXT2FS) $(LIBCOM_ERR) - DEPLIBS= $(LIBEXT2FS) $(DEPLIBCOM_ERR) -@@ -634,7 +635,8 @@ mke2fs.o: $(srcdir)/mke2fs.c $(top_build - $(srcdir)/util.h profile.h prof_err.h $(top_srcdir)/version.h \ - $(srcdir)/nls-enable.h $(top_srcdir)/lib/quota/mkquota.h $(srcdir)/create_inode.h\ - $(top_srcdir)/lib/quota/quotaio.h $(top_srcdir)/lib/quota/dqblk_v2.h \ -- $(top_srcdir)/lib/quota/quotaio_tree.h $(top_srcdir)/lib/../e2fsck/dict.h -+ $(top_srcdir)/lib/quota/quotaio_tree.h $(top_srcdir)/lib/../e2fsck/dict.h \ -+ $(srcdir)/xattr.h - chattr.o: $(srcdir)/chattr.c $(top_builddir)/lib/config.h \ - $(top_builddir)/lib/dirpaths.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \ - $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/et/com_err.h \ -@@ -716,3 +718,5 @@ create_inode.o: $(srcdir)/create_inode.h - $(top_builddir)/lib/config.h $(top_srcdir)/lib/ext2fs/ext2fs.h \ - $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/e2p/e2p.h \ - $(srcdir)/nls-enable.h -+xattr.o: $(srcdir)/xattr.h $(srcdir)/xattr.c \ -+ $(top_builddir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2fs.h diff --git a/recipes-devtools/e2fsprogs/e2fsprogs_1.42.9.bbappend b/recipes-devtools/e2fsprogs/e2fsprogs_1.42.9.bbappend deleted file mode 100644 index 2aa7902..0000000 --- a/recipes-devtools/e2fsprogs/e2fsprogs_1.42.9.bbappend +++ /dev/null @@ -1,12 +0,0 @@ -FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" - -DEPENDS += "linux-libc-headers attr" - -SRC_URI += " \ - file://misc-xattr-add-xattr-module-stub.patch \ - file://mke2fs.c-create_inode.c-copy-xattrs.patch \ - file://lib-ext2fs-ext2_ext_attr.h-add-xattr-index.patch \ - file://misc-xattr-create-xattr-block.patch \ - file://misc-xattr-create-xattr-block-node.patch \ - file://misc-xattr-create-xattr-cache.patch \ -" -- cgit v1.2.3-54-g00ecf