+/* Recursively creates all the subdirectories of @dir, which has been created as
+ * the NTFS inode @dir_ni. */
+static int
+ntfs_3g_create_dirs_recursive(ntfs_inode *dir_ni, struct wim_dentry *dir,
+ struct ntfs_3g_apply_ctx *ctx)
+{
+ struct wim_dentry *child;
+
+ for_dentry_child(child, dir) {
+ ntfs_inode *ni;
+ int ret;
+
+ if (!(child->d_inode->i_attributes & FILE_ATTRIBUTE_DIRECTORY))
+ continue;
+ if (!will_extract_dentry(child))
+ continue;
+
+ ni = ntfs_create(dir_ni, 0, child->d_extraction_name,
+ child->d_extraction_name_nchars, S_IFDIR);
+ if (!ni) {
+ ERROR_WITH_ERRNO("Error creating \"%s\" in NTFS volume",
+ dentry_full_path(child));
+ return WIMLIB_ERR_NTFS_3G;
+ }
+
+ child->d_inode->i_mft_no = ni->mft_no;
+
+ ret = report_file_created(&ctx->common);
+ if (!ret)
+ ret = ntfs_3g_set_metadata(ni, child->d_inode, ctx);
+ if (!ret)
+ ret = ntfs_3g_create_empty_attributes(ni, child->d_inode, ctx);
+ if (!ret)
+ ret = ntfs_3g_create_dirs_recursive(ni, child, ctx);
+
+ if (ntfs_inode_close_in_dir(ni, dir_ni) && !ret) {
+ ERROR_WITH_ERRNO("Error closing \"%s\" in NTFS volume",
+ dentry_full_path(child));
+ ret = WIMLIB_ERR_NTFS_3G;
+ }
+ if (ret)
+ return ret;
+ }
+ return 0;
+}
+
+/* For each WIM dentry in the @root tree that represents a directory, create the
+ * corresponding directory in the NTFS volume @ctx->vol. */
+static int
+ntfs_3g_create_directories(struct wim_dentry *root,
+ struct list_head *dentry_list,
+ struct ntfs_3g_apply_ctx *ctx)
+{
+ ntfs_inode *root_ni;
+ int ret;
+ struct wim_dentry *dentry;
+
+ /* Create the directories using POSIX names. */
+
+ root_ni = ntfs_inode_open(ctx->vol, FILE_root);
+ if (!root_ni) {
+ ERROR_WITH_ERRNO("Can't open root of NTFS volume");
+ return WIMLIB_ERR_NTFS_3G;
+ }
+
+ root->d_inode->i_mft_no = FILE_root;