summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sqfs/inode.h16
-rw-r--r--lib/sqfs/inode.c49
-rw-r--r--lib/sqfshelper/serialize_fstree.c31
3 files changed, 67 insertions, 29 deletions
diff --git a/include/sqfs/inode.h b/include/sqfs/inode.h
index 8b69b7e..336a394 100644
--- a/include/sqfs/inode.h
+++ b/include/sqfs/inode.h
@@ -552,6 +552,22 @@ SQFS_API int sqfs_inode_get_xattr_index(const sqfs_inode_generic_t *inode,
sqfs_u32 *out);
/**
+ * @brief Set the extended attribute index of an inode.
+ *
+ * For basic inodes, this function promes the inodes to extended inodes if the
+ * index is not 0xFFFFFFFF. If the index is 0xFFFFFFFF, the function tries to
+ * demote extended inode to a basic inode after setting the index.
+ *
+ * @param inode A pointer to an inode.
+ * @param index The extended attribute index.
+ *
+ * @return Zero on success, an @ref SQFS_ERROR_CORRUPTED if the node has
+ * an unknown type set.
+ */
+SQFS_API int sqfs_inode_set_xattr_index(sqfs_inode_generic_t *inode,
+ sqfs_u32 index);
+
+/**
* @brief Convert a basic inode to an extended inode.
*
* For inodes that already have an extended type, this is a no-op.
diff --git a/lib/sqfs/inode.c b/lib/sqfs/inode.c
index 334ffd8..4a75e64 100644
--- a/lib/sqfs/inode.c
+++ b/lib/sqfs/inode.c
@@ -64,6 +64,55 @@ int sqfs_inode_get_xattr_index(const sqfs_inode_generic_t *inode,
return 0;
}
+int sqfs_inode_set_xattr_index(sqfs_inode_generic_t *inode, sqfs_u32 index)
+{
+ int err;
+
+ if (index != 0xFFFFFFFF) {
+ err = sqfs_inode_make_extended(inode);
+ if (err)
+ return err;
+ }
+
+ switch (inode->base.type) {
+ case SQFS_INODE_DIR:
+ case SQFS_INODE_FILE:
+ case SQFS_INODE_SLINK:
+ case SQFS_INODE_BDEV:
+ case SQFS_INODE_CDEV:
+ case SQFS_INODE_FIFO:
+ case SQFS_INODE_SOCKET:
+ break;
+ case SQFS_INODE_EXT_DIR:
+ inode->data.dir_ext.xattr_idx = index;
+ break;
+ case SQFS_INODE_EXT_FILE:
+ inode->data.file_ext.xattr_idx = index;
+ break;
+ case SQFS_INODE_EXT_SLINK:
+ inode->data.slink_ext.xattr_idx = index;
+ break;
+ case SQFS_INODE_EXT_BDEV:
+ case SQFS_INODE_EXT_CDEV:
+ inode->data.dev_ext.xattr_idx = index;
+ break;
+ case SQFS_INODE_EXT_FIFO:
+ case SQFS_INODE_EXT_SOCKET:
+ inode->data.ipc_ext.xattr_idx = index;
+ break;
+ default:
+ return SQFS_ERROR_CORRUPTED;
+ }
+
+ if (index == 0xFFFFFFFF) {
+ err = sqfs_inode_make_basic(inode);
+ if (err)
+ return err;
+ }
+
+ return 0;
+}
+
int sqfs_inode_make_extended(sqfs_inode_generic_t *inode)
{
switch (inode->base.type) {
diff --git a/lib/sqfshelper/serialize_fstree.c b/lib/sqfshelper/serialize_fstree.c
index 66fa054..7a03dc9 100644
--- a/lib/sqfshelper/serialize_fstree.c
+++ b/lib/sqfshelper/serialize_fstree.c
@@ -52,47 +52,23 @@ static sqfs_inode_generic_t *tree_node_to_inode(tree_node_t *node)
inode->base.type = get_type(node);
- if (node->xattr_idx != 0xFFFFFFFF)
- sqfs_inode_make_extended(inode);
-
switch (inode->base.type) {
case SQFS_INODE_FIFO:
case SQFS_INODE_SOCKET:
inode->data.ipc.nlink = 1;
break;
- case SQFS_INODE_EXT_FIFO:
- case SQFS_INODE_EXT_SOCKET:
- inode->data.ipc_ext.nlink = 1;
- inode->data.ipc_ext.xattr_idx = node->xattr_idx;
- break;
case SQFS_INODE_SLINK:
inode->data.slink.nlink = 1;
inode->data.slink.target_size = extra;
break;
- case SQFS_INODE_EXT_SLINK:
- inode->data.slink_ext.nlink = 1;
- inode->data.slink_ext.target_size = extra;
- inode->data.slink_ext.xattr_idx = node->xattr_idx;
- break;
case SQFS_INODE_BDEV:
case SQFS_INODE_CDEV:
inode->data.dev.nlink = 1;
inode->data.dev.devno = node->data.devno;
break;
- case SQFS_INODE_EXT_BDEV:
- case SQFS_INODE_EXT_CDEV:
- inode->data.dev_ext.nlink = 1;
- inode->data.dev_ext.devno = node->data.devno;
- inode->data.dev_ext.xattr_idx = node->xattr_idx;
- break;
- default:
- goto fail;
}
return inode;
-fail:
- free(inode);
- return NULL;
}
static sqfs_inode_generic_t *write_dir_entries(sqfs_dir_writer_t *dirw,
@@ -163,11 +139,6 @@ int sqfs_serialize_fstree(sqfs_file_t *file, sqfs_super_t *super, fstree_t *fs,
} else if (S_ISREG(n->mode)) {
inode = n->data.file.user_ptr;
n->data.file.user_ptr = NULL;
-
- if (n->xattr_idx != 0xFFFFFFFF) {
- sqfs_inode_make_extended(inode);
- inode->data.file_ext.xattr_idx = n->xattr_idx;
- }
} else {
inode = tree_node_to_inode(n);
}
@@ -179,6 +150,8 @@ int sqfs_serialize_fstree(sqfs_file_t *file, sqfs_super_t *super, fstree_t *fs,
inode->base.mod_time = n->mod_time;
inode->base.inode_number = n->inode_num;
+ sqfs_inode_set_xattr_index(inode, n->xattr_idx);
+
if (sqfs_id_table_id_to_index(idtbl, n->uid,
&inode->base.uid_idx)) {
goto fail_id;