+/* Transfers file attributes and possibly a security descriptor from a WIM inode
+ * to a NTFS inode.
+ *
+ * @ni: The NTFS inode to apply the metadata to.
+ * @dir_ni: The NTFS inode for a directory containing @ni.
+ * @dentry: The WIM dentry whose inode contains the metadata to apply.
+ * @w: The WIMStruct for the WIM, through which the table of security
+ * descriptors can be accessed.
+ *
+ * Returns 0 on success, nonzero on failure.
+ */
+static int
+apply_file_attributes_and_security_data(ntfs_inode *ni,
+ ntfs_inode *dir_ni,
+ const struct wim_dentry *dentry,
+ const WIMStruct *w)
+{
+ int ret;
+ struct SECURITY_CONTEXT ctx;
+ u32 attributes_le32;
+ const struct wim_inode *inode;
+
+ inode = dentry->d_inode;
+
+ DEBUG("Setting NTFS file attributes on `%s' to %#"PRIx32,
+ dentry->full_path_utf8, inode->i_attributes);
+
+ attributes_le32 = cpu_to_le32(inode->i_attributes);
+ memset(&ctx, 0, sizeof(ctx));
+ ctx.vol = ni->vol;
+ ret = ntfs_xattr_system_setxattr(&ctx, XATTR_NTFS_ATTRIB,
+ ni, dir_ni,
+ (const char*)&attributes_le32,
+ sizeof(u32), 0);
+ if (ret != 0) {
+ ERROR("Failed to set NTFS file attributes on `%s'",
+ dentry->full_path_utf8);
+ return WIMLIB_ERR_NTFS_3G;
+ }
+ if (inode->i_security_id != -1) {
+ const char *desc;
+ const struct wim_security_data *sd;
+
+ sd = wim_const_security_data(w);
+ wimlib_assert(inode->i_security_id < sd->num_entries);
+ desc = (const char *)sd->descriptors[inode->i_security_id];
+ DEBUG("Applying security descriptor %d to `%s'",
+ inode->i_security_id, dentry->full_path_utf8);
+
+ ret = ntfs_xattr_system_setxattr(&ctx, XATTR_NTFS_ACL,
+ ni, dir_ni, desc,
+ sd->sizes[inode->i_security_id], 0);
+
+ if (ret != 0) {
+ ERROR_WITH_ERRNO("Failed to set security data on `%s'",
+ dentry->full_path_utf8);
+ return WIMLIB_ERR_NTFS_3G;
+ }
+ }
+ return 0;
+}
+
+/*
+ * Transfers the reparse data from a WIM inode (which must represent a reparse
+ * point) to a NTFS inode.
+ */
+static int apply_reparse_data(ntfs_inode *ni, const struct wim_dentry *dentry,
+ union wimlib_progress_info *progress_info)
+{
+ struct wim_lookup_table_entry *lte;
+ int ret = 0;
+
+ lte = inode_unnamed_lte_resolved(dentry->d_inode);
+
+ DEBUG("Applying reparse data to `%s'", dentry->full_path_utf8);
+
+ if (!lte) {
+ ERROR("Could not find reparse data for `%s'",
+ dentry->full_path_utf8);
+ return WIMLIB_ERR_INVALID_DENTRY;
+ }
+
+ if (wim_resource_size(lte) >= 0xffff) {
+ ERROR("Reparse data of `%s' is too long (%"PRIu64" bytes)",
+ dentry->full_path_utf8, wim_resource_size(lte));
+ return WIMLIB_ERR_INVALID_DENTRY;
+ }
+
+ u8 reparse_data_buf[8 + wim_resource_size(lte)];
+ u8 *p = reparse_data_buf;
+ p = put_u32(p, dentry->d_inode->i_reparse_tag); /* ReparseTag */
+ p = put_u16(p, wim_resource_size(lte)); /* ReparseDataLength */
+ p = put_u16(p, 0); /* Reserved */
+
+ ret = read_full_wim_resource(lte, p, 0);
+ if (ret != 0)
+ return ret;
+
+ ret = ntfs_set_ntfs_reparse_data(ni, (char*)reparse_data_buf,
+ wim_resource_size(lte) + 8, 0);
+ if (ret != 0) {
+ ERROR_WITH_ERRNO("Failed to set NTFS reparse data on `%s'",
+ dentry->full_path_utf8);
+ return WIMLIB_ERR_NTFS_3G;
+ }
+ progress_info->extract.completed_bytes += wim_resource_size(lte);
+ return 0;
+}
+
+/*