aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-21 15:24:38 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-21 15:44:02 +0200
commit73db760b3fd2d3f2ff9186deb86589fdc36f2542 (patch)
treef0f75f2f9953a9028e4f8b77c65cb8a657c794d9 /lib
parent53bb1720f0603b185d71cc3db1194d9bf16fdbe2 (diff)
Cleanup xattr handling
- Store them in a struct instead of a hacky uint64_t with magic shifts - Split up key/value pair write function to write_key and write_value - Move the size accounting into those functions respectively Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/fstree/xattr.c20
-rw-r--r--lib/sqfs/write_xattr.c24
2 files changed, 26 insertions, 18 deletions
diff --git a/lib/fstree/xattr.c b/lib/fstree/xattr.c
index 4597d9d..2ce39f4 100644
--- a/lib/fstree/xattr.c
+++ b/lib/fstree/xattr.c
@@ -87,17 +87,15 @@ int fstree_add_xattr(fstree_t *fs, tree_node_t *node,
fs->xattr = xattr;
}
- xattr->ref[xattr->num_attr] = (uint64_t)key_idx << 32;
- xattr->ref[xattr->num_attr] |= (uint64_t)value_idx;
+ xattr->attr[xattr->num_attr].key_index = key_idx;
+ xattr->attr[xattr->num_attr].value_index = value_idx;
xattr->num_attr += 1;
return 0;
}
-static int cmp_u64(const void *lhs, const void *rhs)
+static int cmp_attr(const void *lhs, const void *rhs)
{
- uint64_t l = *((uint64_t *)lhs), r = *((uint64_t *)rhs);
-
- return l < r ? -1 : (l > r ? 1 : 0);
+ return memcmp(lhs, rhs, sizeof(((tree_xattr_t *)0)->attr[0]));
}
void fstree_xattr_reindex(fstree_t *fs)
@@ -113,8 +111,8 @@ void fstree_xattr_reindex(fstree_t *fs)
it->index = index++;
for (i = 0; i < it->num_attr; ++i) {
- key_idx = (it->ref[i] >> 32) & 0x00000000FFFFFFFF;
- value_idx = it->ref[i] & 0x00000000FFFFFFFF;
+ key_idx = it->attr[i].key_index;
+ value_idx = it->attr[i].value_index;
str_table_add_ref(&fs->xattr_keys, key_idx);
str_table_add_ref(&fs->xattr_values, value_idx);
@@ -128,7 +126,7 @@ void fstree_xattr_deduplicate(fstree_t *fs)
int diff;
for (it = fs->xattr; it != NULL; it = it->next)
- qsort(it->ref, it->num_attr, sizeof(it->ref[0]), cmp_u64);
+ qsort(it->attr, it->num_attr, sizeof(it->attr[0]), cmp_attr);
prev = NULL;
it = fs->xattr;
@@ -138,8 +136,8 @@ void fstree_xattr_deduplicate(fstree_t *fs)
if (it1->num_attr != it->num_attr)
continue;
- diff = memcmp(it1->ref, it->ref,
- it->num_attr * sizeof(it->ref[0]));
+ diff = memcmp(it1->attr, it->attr,
+ it->num_attr * sizeof(it->attr[0]));
if (diff == 0)
break;
}
diff --git a/lib/sqfs/write_xattr.c b/lib/sqfs/write_xattr.c
index 31fdf50..89c65db 100644
--- a/lib/sqfs/write_xattr.c
+++ b/lib/sqfs/write_xattr.c
@@ -38,10 +38,10 @@ bool sqfs_has_xattr(const char *key)
return get_prefix(key) >= 0;
}
-static int write_pair(meta_writer_t *mw, const char *key, const char *value)
+static int write_key(meta_writer_t *mw, const char *key, tree_xattr_t *xattr)
{
+ const char *orig_key = key;
sqfs_xattr_entry_t kent;
- sqfs_xattr_value_t vent;
int type;
type = get_prefix(key);
@@ -62,6 +62,15 @@ static int write_pair(meta_writer_t *mw, const char *key, const char *value)
if (meta_writer_append(mw, key, strlen(key)))
return -1;
+ xattr->size += sizeof(sqfs_xattr_entry_t) + strlen(orig_key);
+ return 0;
+}
+
+static int write_value(meta_writer_t *mw, const char *value,
+ tree_xattr_t *xattr)
+{
+ sqfs_xattr_value_t vent;
+
vent.size = htole32(strlen(value));
if (meta_writer_append(mw, &vent, sizeof(vent)))
@@ -69,6 +78,7 @@ static int write_pair(meta_writer_t *mw, const char *key, const char *value)
if (meta_writer_append(mw, value, strlen(value)))
return -1;
+ xattr->size += sizeof(vent) + strlen(value);
return 0;
}
@@ -79,17 +89,17 @@ static int write_kv_pairs(fstree_t *fs, meta_writer_t *mw, tree_xattr_t *xattr)
size_t i;
for (i = 0; i < xattr->num_attr; ++i) {
- key_idx = (xattr->ref[i] >> 32) & 0xFFFFFFFF;
- val_idx = xattr->ref[i] & 0xFFFFFFFF;
+ key_idx = xattr->attr[i].key_index;
+ val_idx = xattr->attr[i].value_index;
key = str_table_get_string(&fs->xattr_keys, key_idx);
value = str_table_get_string(&fs->xattr_values, val_idx);
- if (write_pair(mw, key, value))
+ if (write_key(mw, key, xattr))
return -1;
- xattr->size += sizeof(sqfs_xattr_entry_t) + strlen(key);
- xattr->size += sizeof(sqfs_xattr_value_t) + strlen(value);
+ if (write_value(mw, value, xattr))
+ return -1;
}
return 0;