]> wimlib.net Git - wimlib/blobdiff - src/ntfs-capture.c
Print each file or directory excluded
[wimlib] / src / ntfs-capture.c
index 7c04e9b85b2410797212fb2aad119acce296eea1..03c8720af1e568686e444e2bbfe5ec72f08a92cf 100644 (file)
@@ -121,7 +121,7 @@ out_error:
 static int
 capture_ntfs_streams(struct wim_dentry *dentry,
                     ntfs_inode *ni,
-                    mbchar *path,
+                    char *path,
                     size_t path_len,
                     struct wim_lookup_table *lookup_table,
                     ntfs_volume **ntfs_vol_p,
@@ -382,7 +382,7 @@ free_dos_name_tree(struct rb_node *node) {
        }
 }
 
-static void 
+static void
 destroy_dos_name_map(struct dos_name_map *map)
 {
        free_dos_name_tree(map->rb_root.rb_node);
@@ -391,7 +391,7 @@ destroy_dos_name_map(struct dos_name_map *map)
 struct readdir_ctx {
        struct wim_dentry *parent;
        ntfs_inode *dir_ni;
-       mbchar *path;
+       char *path;
        size_t path_len;
        struct wim_lookup_table *lookup_table;
        struct sd_set *sd_set;
@@ -403,8 +403,11 @@ struct readdir_ctx {
 };
 
 static int
-build_dentry_tree_ntfs_recursive(struct wim_dentry **root_p, ntfs_inode *dir_ni,
-                                ntfs_inode *ni, char path[], size_t path_len,
+build_dentry_tree_ntfs_recursive(struct wim_dentry **root_p,
+                                ntfs_inode *dir_ni,
+                                ntfs_inode *ni,
+                                char *path,
+                                size_t path_len,
                                 int name_type,
                                 struct wim_lookup_table *lookup_table,
                                 struct sd_set *sd_set,
@@ -436,12 +439,12 @@ wim_ntfs_capture_filldir(void *dirent, const ntfschar *name,
                /* Return now if an error occurred or if this is just a DOS name
                 * and not a Win32+DOS name. */
                if (ret != 0 || name_type == FILE_NAME_DOS)
-                       return ret;
+                       goto out;
        }
-       ret = utf16le_to_mbs(name, name_nbytes,
-                            &mbs_name, &mbs_name_nbytes);
-       if (ret != 0)
-               return -1;
+       ret = utf16le_to_tstr(name, name_nbytes,
+                             &mbs_name, &mbs_name_nbytes);
+       if (ret)
+               goto out;
 
        if (mbs_name[0] == '.' &&
             (mbs_name[1] == '\0' ||
@@ -459,6 +462,7 @@ wim_ntfs_capture_filldir(void *dirent, const ntfschar *name,
        ntfs_inode *ni = ntfs_inode_open(ctx->dir_ni->vol, mref);
        if (!ni) {
                ERROR_WITH_ERRNO("Failed to open NTFS inode");
+               ret = -1;
                goto out_free_mbs_name;
        }
        path_len = ctx->path_len;
@@ -478,6 +482,7 @@ wim_ntfs_capture_filldir(void *dirent, const ntfschar *name,
        ntfs_inode_close(ni);
 out_free_mbs_name:
        FREE(mbs_name);
+out:
        return ret;
 }
 
@@ -489,7 +494,7 @@ static int
 build_dentry_tree_ntfs_recursive(struct wim_dentry **root_p,
                                 ntfs_inode *dir_ni,
                                 ntfs_inode *ni,
-                                mbchar *path,
+                                char *path,
                                 size_t path_len,
                                 int name_type,
                                 struct wim_lookup_table *lookup_table,
@@ -503,10 +508,10 @@ build_dentry_tree_ntfs_recursive(struct wim_dentry **root_p,
        int ret;
        struct wim_dentry *root;
 
-       if (exclude_path(path, config, false)) {
+       if (exclude_path(path, path_len, config, false)) {
                /* Exclude a file or directory tree based on the capture
                 * configuration file */
-               if ((add_image_flags & WIMLIB_ADD_IMAGE_FLAG_VERBOSE)
+               if ((add_image_flags & WIMLIB_ADD_IMAGE_FLAG_EXCLUDE_VERBOSE)
                    && progress_func)
                {
                        union wimlib_progress_info info;
@@ -541,7 +546,8 @@ build_dentry_tree_ntfs_recursive(struct wim_dentry **root_p,
        }
 
        /* Create the new WIM dentry */
-       ret = new_dentry_with_timeless_inode(path_basename(path), &root);
+       ret = new_dentry_with_timeless_inode(path_basename_with_len(path, path_len),
+                                            &root);
        if (ret)
                return ret;
 
@@ -597,43 +603,45 @@ build_dentry_tree_ntfs_recursive(struct wim_dentry **root_p,
        if (ret != 0)
                return ret;
 
-       /* Get security descriptor */
-       char _sd[1];
-       char *sd = _sd;
-       errno = 0;
-       ret = ntfs_xattr_system_getxattr(&ctx, XATTR_NTFS_ACL,
-                                        ni, dir_ni, sd,
-                                        sizeof(sd));
-       if (ret > sizeof(sd)) {
-               sd = alloca(ret);
+       if (!(add_image_flags & WIMLIB_ADD_IMAGE_FLAG_NO_ACLS)) {
+               /* Get security descriptor */
+               char _sd[1];
+               char *sd = _sd;
+               errno = 0;
                ret = ntfs_xattr_system_getxattr(&ctx, XATTR_NTFS_ACL,
-                                                ni, dir_ni, sd, ret);
-       }
-       if (ret > 0) {
-               root->d_inode->i_security_id = sd_set_add_sd(sd_set, sd, ret);
-               if (root->d_inode->i_security_id == -1) {
-                       ERROR("Out of memory");
-                       return WIMLIB_ERR_NOMEM;
+                                                ni, dir_ni, sd,
+                                                sizeof(sd));
+               if (ret > sizeof(sd)) {
+                       sd = alloca(ret);
+                       ret = ntfs_xattr_system_getxattr(&ctx, XATTR_NTFS_ACL,
+                                                        ni, dir_ni, sd, ret);
+               }
+               if (ret > 0) {
+                       root->d_inode->i_security_id = sd_set_add_sd(sd_set, sd, ret);
+                       if (root->d_inode->i_security_id == -1) {
+                               ERROR("Out of memory");
+                               return WIMLIB_ERR_NOMEM;
+                       }
+                       DEBUG("Added security ID = %u for `%s'",
+                             root->d_inode->i_security_id, path);
+                       ret = 0;
+               } else if (ret < 0) {
+                       ERROR_WITH_ERRNO("Failed to get security information from "
+                                        "`%s'", path);
+                       ret = WIMLIB_ERR_NTFS_3G;
+               } else {
+                       root->d_inode->i_security_id = -1;
+                       DEBUG("No security ID for `%s'", path);
                }
-               DEBUG("Added security ID = %u for `%s'",
-                     root->d_inode->i_security_id, path);
-               ret = 0;
-       } else if (ret < 0) {
-               ERROR_WITH_ERRNO("Failed to get security information from "
-                                "`%s'", path);
-               ret = WIMLIB_ERR_NTFS_3G;
-       } else {
-               root->d_inode->i_security_id = -1;
-               DEBUG("No security ID for `%s'", path);
        }
        return ret;
 }
 
 int
 build_dentry_tree_ntfs(struct wim_dentry **root_p,
-                      const mbchar *device,
+                      const char *device,
                       struct wim_lookup_table *lookup_table,
-                      struct wim_security_data *sd,
+                      struct sd_set *sd_set,
                       const struct capture_config *config,
                       int add_image_flags,
                       wimlib_progress_func_t progress_func,
@@ -642,10 +650,6 @@ build_dentry_tree_ntfs(struct wim_dentry **root_p,
        ntfs_volume *vol;
        ntfs_inode *root_ni;
        int ret;
-       struct sd_set sd_set = {
-               .sd = sd,
-               .rb_root = {NULL},
-       };
        ntfs_volume **ntfs_vol_p = extra_arg;
 
        DEBUG("Mounting NTFS volume `%s' read-only", device);
@@ -680,7 +684,7 @@ build_dentry_tree_ntfs(struct wim_dentry **root_p,
 
        /* Currently we assume that all the paths fit into this length and there
         * is no check for overflow. */
-       mbchar *path = MALLOC(32768);
+       char *path = MALLOC(32768);
        if (!path) {
                ERROR("Could not allocate memory for NTFS pathname");
                ret = WIMLIB_ERR_NOMEM;
@@ -691,14 +695,13 @@ build_dentry_tree_ntfs(struct wim_dentry **root_p,
        path[1] = '\0';
        ret = build_dentry_tree_ntfs_recursive(root_p, NULL, root_ni, path, 1,
                                               FILE_NAME_POSIX, lookup_table,
-                                              &sd_set,
+                                              sd_set,
                                               config, ntfs_vol_p,
                                               add_image_flags,
                                               progress_func);
 out_cleanup:
        FREE(path);
        ntfs_inode_close(root_ni);
-       destroy_sd_set(&sd_set);
 out:
        ntfs_index_ctx_put(vol->secure_xsii);
        ntfs_index_ctx_put(vol->secure_xsdh);