]> wimlib.net Git - wimlib/blobdiff - src/ntfs-capture.c
Hard link disambiguation
[wimlib] / src / ntfs-capture.c
index 751ce50f759e9f3e70b23666df451a02b236cdec..1a2b4963ce1f0197f3f7d501a871c5abc8ef8c20 100644 (file)
@@ -63,15 +63,19 @@ struct sd_node {
        struct sd_node *right;
 };
 
-/* Frees a security descriptor index tree. */
-static void free_sd_set(struct sd_node *root)
+static void free_sd_tree(struct sd_node *root)
 {
        if (root) {
-               free_sd_set(root->left);
-               free_sd_set(root->right);
+               free_sd_tree(root->left);
+               free_sd_tree(root->right);
                FREE(root);
        }
 }
+/* Frees a security descriptor index set. */
+static void destroy_sd_set(struct sd_set *sd_set)
+{
+       free_sd_tree(sd_set->root);
+}
 
 /* Inserts a a new node into the security descriptor index tree. */
 static void insert_sd_node(struct sd_node *new, struct sd_node *root)
@@ -356,13 +360,13 @@ struct readdir_ctx {
        ntfs_volume        **ntfs_vol_p;
 };
 
-static int __build_dentry_tree_ntfs(struct dentry **root_p, ntfs_inode *ni,
-                                   char path[], size_t path_len,
-                                   struct lookup_table *lookup_table,
-                                   struct sd_set *sd_set,
-                                   const struct capture_config *config,
-                                   ntfs_volume **ntfs_vol_p);
-
+static int
+build_dentry_tree_ntfs_recursive(struct dentry **root_p, ntfs_inode *ni,
+                                char path[], size_t path_len,
+                                struct lookup_table *lookup_table,
+                                struct sd_set *sd_set,
+                                const struct capture_config *config,
+                                ntfs_volume **ntfs_vol_p);
 
 static int wim_ntfs_capture_filldir(void *dirent, const ntfschar *name,
                                    const int name_len, const int name_type,
@@ -408,9 +412,9 @@ static int wim_ntfs_capture_filldir(void *dirent, const ntfschar *name,
                ctx->path[path_len++] = '/';
        memcpy(ctx->path + path_len, utf8_name, utf8_name_len + 1);
        path_len += utf8_name_len;
-       ret = __build_dentry_tree_ntfs(&child, ni, ctx->path, path_len,
-                                      ctx->lookup_table, ctx->sd_set,
-                                      ctx->config, ctx->ntfs_vol_p);
+       ret = build_dentry_tree_ntfs_recursive(&child, ni, ctx->path, path_len,
+                                              ctx->lookup_table, ctx->sd_set,
+                                              ctx->config, ctx->ntfs_vol_p);
 
        if (child) {
                DEBUG("Linking dentry `%s' with parent `%s'",
@@ -429,12 +433,13 @@ out:
  * At the same time, update the WIM lookup table with lookup table entries for
  * the NTFS streams, and build an array of security descriptors.
  */
-static int __build_dentry_tree_ntfs(struct dentry **root_p, ntfs_inode *ni,
-                                   char path[], size_t path_len,
-                                   struct lookup_table *lookup_table,
-                                   struct sd_set *sd_set,
-                                   const struct capture_config *config,
-                                   ntfs_volume **ntfs_vol_p)
+static int build_dentry_tree_ntfs_recursive(struct dentry **root_p,
+                                           ntfs_inode *ni,
+                                           char path[], size_t path_len,
+                                           struct lookup_table *lookup_table,
+                                           struct sd_set *sd_set,
+                                           const struct capture_config *config,
+                                           ntfs_volume **ntfs_vol_p)
 {
        u32 attributes;
        int mrec_flags;
@@ -455,13 +460,14 @@ static int __build_dentry_tree_ntfs(struct dentry **root_p, ntfs_inode *ni,
        if (!root)
                return WIMLIB_ERR_NOMEM;
 
+       *root_p = root;
        root->creation_time    = le64_to_cpu(ni->creation_time);
        root->last_write_time  = le64_to_cpu(ni->last_data_change_time);
        root->last_access_time = le64_to_cpu(ni->last_access_time);
        root->security_id      = le32_to_cpu(ni->security_id);
        root->attributes       = le32_to_cpu(attributes);
-       root->hard_link  = ni->mft_no;
-       root->resolved = true;
+       root->hard_link        = ni->mft_no;
+       root->resolved         = true;
 
        if (attributes & FILE_ATTR_REPARSE_POINT) {
                DEBUG("Reparse point `%s'", path);
@@ -528,7 +534,6 @@ static int __build_dentry_tree_ntfs(struct dentry **root_p, ntfs_inode *ni,
                }
                ret = 0;
        }
-       *root_p = root;
        return ret;
 }
 
@@ -543,9 +548,9 @@ static int build_dentry_tree_ntfs(struct dentry **root_p,
        ntfs_volume *vol;
        ntfs_inode *root_ni;
        int ret = 0;
-       struct sd_set tree;
-       tree.sd = sd;
-       tree.root = NULL;
+       struct sd_set sd_set;
+       sd_set.sd = sd;
+       sd_set.root = NULL;
        ntfs_volume **ntfs_vol_p = extra_arg;
 
        DEBUG("Mounting NTFS volume `%s' read-only", device);
@@ -567,13 +572,20 @@ static int build_dentry_tree_ntfs(struct dentry **root_p,
                ret = WIMLIB_ERR_NTFS_3G;
                goto out;
        }
-       char path[4096];
+       char *path = MALLOC(32769);
+       if (!path) {
+               ERROR("Could not allocate memory for NTFS pathname");
+               goto out_cleanup;
+       }
        path[0] = '/';
        path[1] = '\0';
-       ret = __build_dentry_tree_ntfs(root_p, root_ni, path, 1,
-                                      lookup_table, &tree, config,
-                                      ntfs_vol_p);
+       ret = build_dentry_tree_ntfs_recursive(root_p, root_ni, path, 1,
+                                              lookup_table, &sd_set,
+                                              config, ntfs_vol_p);
+out_cleanup:
+       FREE(path);
        ntfs_inode_close(root_ni);
+       destroy_sd_set(&sd_set);
 
 out:
        if (ret) {