Skip to content

Commit

Permalink
Merge pull request #158 from alexlarsson/new-xattr-format
Browse files Browse the repository at this point in the history
Update to new xattr format using metacopy xattr for digest
  • Loading branch information
alexlarsson committed Jun 22, 2023
2 parents da68b13 + 8da16f4 commit 3e750ff
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions libcomposefs/lcfs-writer-erofs.c
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,20 @@ static int add_overlayfs_xattrs(struct lcfs_node_s *node)
int ret;

if ((node->inode.st_mode & S_IFMT) == S_IFREG && node->inode.st_size > 0) {
ret = lcfs_node_set_xattr(node, "trusted.overlay.metacopy", "", 0);
uint8_t xattr_data[4 + LCFS_DIGEST_SIZE];
size_t xattr_len = 0;

if (node->digest_set) {
xattr_len = sizeof(xattr_data);
xattr_data[0] = 0; /* version */
xattr_data[1] = xattr_len;
xattr_data[2] = 0; /* flags */
xattr_data[3] = FS_VERITY_HASH_ALG_SHA256;
memcpy(xattr_data + 4, node->digest, LCFS_DIGEST_SIZE);
}

ret = lcfs_node_set_xattr(node, "trusted.overlay.metacopy",
(const char *)xattr_data, xattr_len);
if (ret < 0)
return ret;

Expand All @@ -884,17 +897,6 @@ static int add_overlayfs_xattrs(struct lcfs_node_s *node)
if (ret < 0)
return ret;
}

if (node->digest_set) {
uint8_t xattr_data[1 + LCFS_DIGEST_SIZE];
xattr_data[0] = FS_VERITY_HASH_ALG_SHA256;
memcpy(xattr_data + 1, node->digest, LCFS_DIGEST_SIZE);
ret = lcfs_node_set_xattr(node, "trusted.overlay.verity",
(char *)xattr_data,
sizeof(xattr_data));
if (ret < 0)
return ret;
}
}

return 0;
Expand Down

0 comments on commit 3e750ff

Please sign in to comment.