+#ifdef HAVE_XATTR_SUPPORT
+
+static int
+apply_xattrs(struct wim_inode *inode, const void *entries,
+ size_t entries_size, struct unix_apply_ctx *ctx)
+{
+ const void * const entries_end = entries + entries_size;
+ const char *path = unix_build_inode_extraction_path(inode, ctx);
+ char name[XATTR_NAME_MAX + 1];
+
+ for (const struct wimlib_xattr_entry *entry = entries;
+ (void *)entry < entries_end; entry = xattr_entry_next(entry))
+ {
+ u16 name_len;
+ const void *value;
+ u32 value_len;
+
+ if (!valid_xattr_entry(entry, entries_end - (void *)entry)) {
+ ERROR("\"%s\": extended attribute stream is corrupt",
+ path);
+ return WIMLIB_ERR_INVALID_EXTENDED_ATTRIBUTE;
+ }
+ name_len = le16_to_cpu(entry->name_len);
+ memcpy(name, entry->name, name_len);
+ name[name_len] = '\0';
+
+ value = entry->name + name_len;
+ value_len = le32_to_cpu(entry->value_len);
+
+ if (lsetxattr(path, name, value, value_len, 0) != 0) {
+ if (ctx->common.extract_flags &
+ WIMLIB_EXTRACT_FLAG_STRICT_ACLS)
+ {
+ ERROR_WITH_ERRNO("\"%s\": unable to set "
+ "extended attribute %s",
+ path, name);
+ return WIMLIB_ERR_SET_SECURITY;
+ }
+ WARNING_WITH_ERRNO("\"%s\": unable to set extended "
+ "attribute %s", path, name);
+ }
+ }
+ return 0;
+}
+
+static int
+apply_delayed_xattrs(struct list_head *dentry_list, struct unix_apply_ctx *ctx)
+{
+ struct wim_dentry *dentry;
+
+ list_for_each_entry(dentry, dentry_list, d_extraction_list_node) {
+ struct wim_inode *inode = dentry->d_inode;
+ const struct blob_descriptor *blob;
+ const struct wim_inode_stream *strm;
+ int ret;
+
+ if (!inode_is_symlink(inode))
+ continue;
+ if (dentry != inode_first_extraction_dentry(inode))
+ continue;
+ strm = inode_get_stream(inode, STREAM_TYPE_LINUX_XATTR,
+ NO_STREAM_NAME);
+ if (!strm)
+ continue;
+ blob = lookup_blob(ctx->delayed_xattrs, stream_hash(strm));
+ if (!blob)
+ continue;
+ wimlib_assert(blob->blob_location == BLOB_IN_ATTACHED_BUFFER);
+ ret = apply_xattrs(inode, blob->attached_buffer, blob->size,
+ ctx);
+ if (ret)
+ return ret;
+ }
+ return 0;
+}
+#endif /* HAVE_XATTR_SUPPORT */
+