]> wimlib.net Git - wimlib/blobdiff - src/ntfs-capture.c
Version 1.2.1
[wimlib] / src / ntfs-capture.c
index aa4458c04095fe073b17de2591e919846eb5868d..8f123f805a9afb4d10d035fbac8aeea98c617521 100644 (file)
@@ -35,7 +35,7 @@
 
 #include "dentry.h"
 #include "lookup_table.h"
 
 #include "dentry.h"
 #include "lookup_table.h"
-#include "io.h"
+#include "buffer_io.h"
 #include <ntfs-3g/layout.h>
 #include <ntfs-3g/acls.h>
 #include <ntfs-3g/attrib.h>
 #include <ntfs-3g/layout.h>
 #include <ntfs-3g/acls.h>
 #include <ntfs-3g/attrib.h>
@@ -362,10 +362,12 @@ static int capture_ntfs_streams(struct dentry *dentry, ntfs_inode *ni,
                         * alternate data stream entries */
                        struct ads_entry *new_ads_entry;
                        size_t stream_name_utf8_len;
                         * alternate data stream entries */
                        struct ads_entry *new_ads_entry;
                        size_t stream_name_utf8_len;
-                       stream_name_utf8 = utf16_to_utf8((const char*)attr_record_name(actx->attr),
-                                                        name_length * 2,
-                                                        &stream_name_utf8_len);
-                       if (!stream_name_utf8)
+
+                       ret = utf16_to_utf8((const char*)attr_record_name(actx->attr),
+                                           name_length * 2,
+                                           &stream_name_utf8,
+                                           &stream_name_utf8_len);
+                       if (ret != 0)
                                goto out_free_lte;
                        new_ads_entry = inode_add_ads(dentry->d_inode, stream_name_utf8);
                        FREE(stream_name_utf8);
                                goto out_free_lte;
                        new_ads_entry = inode_add_ads(dentry->d_inode, stream_name_utf8);
                        FREE(stream_name_utf8);
@@ -435,12 +437,10 @@ static int wim_ntfs_capture_filldir(void *dirent, const ntfschar *name,
        if (name_type == FILE_NAME_DOS)
                return 0;
 
        if (name_type == FILE_NAME_DOS)
                return 0;
 
-       ret = -1;
-
-       utf8_name = utf16_to_utf8((const char*)name, name_len * 2,
-                                 &utf8_name_len);
-       if (!utf8_name)
-               goto out;
+       ret = utf16_to_utf8((const char*)name, name_len * 2,
+                           &utf8_name, &utf8_name_len);
+       if (ret != 0)
+               return -1;
 
        if (utf8_name[0] == '.' &&
             (utf8_name[1] == '\0' ||
 
        if (utf8_name[0] == '.' &&
             (utf8_name[1] == '\0' ||
@@ -474,7 +474,6 @@ static int wim_ntfs_capture_filldir(void *dirent, const ntfschar *name,
        ntfs_inode_close(ni);
 out_free_utf8_name:
        FREE(utf8_name);
        ntfs_inode_close(ni);
 out_free_utf8_name:
        FREE(utf8_name);
-out:
        return ret;
 }
 
        return ret;
 }
 
@@ -484,15 +483,15 @@ static int change_dentry_short_name(struct dentry *dentry,
 {
        size_t short_name_utf16_len;
        char *short_name_utf16;
 {
        size_t short_name_utf16_len;
        char *short_name_utf16;
-       short_name_utf16 = utf8_to_utf16(short_name_utf8, short_name_utf8_len,
-                                        &short_name_utf16_len);
-       if (!short_name_utf16) {
-               ERROR_WITH_ERRNO("Failed to convert short name to UTF-16");
-               return WIMLIB_ERR_NOMEM;
+       int ret;
+
+       ret = utf8_to_utf16(short_name_utf8, short_name_utf8_len,
+                           &short_name_utf16, &short_name_utf16_len);
+       if (ret == 0) {
+               dentry->short_name = short_name_utf16;
+               dentry->short_name_len = short_name_utf16_len;
        }
        }
-       dentry->short_name = short_name_utf16;
-       dentry->short_name_len = short_name_utf16_len;
-       return 0;
+       return ret;
 }
 
 /* Recursively build a WIM dentry tree corresponding to a NTFS volume.
 }
 
 /* Recursively build a WIM dentry tree corresponding to a NTFS volume.
@@ -515,7 +514,6 @@ static int build_dentry_tree_ntfs_recursive(struct dentry **root_p,
        u32 attributes;
        int mrec_flags;
        int ret;
        u32 attributes;
        int mrec_flags;
        int ret;
-       char dos_name_utf8[64];
        struct dentry *root;
 
        if (exclude_path(path, config, false)) {
        struct dentry *root;
 
        if (exclude_path(path, config, false)) {
@@ -554,15 +552,22 @@ static int build_dentry_tree_ntfs_recursive(struct dentry **root_p,
        }
 
        root = new_dentry_with_timeless_inode(path_basename(path));
        }
 
        root = new_dentry_with_timeless_inode(path_basename(path));
-       if (!root)
-               return WIMLIB_ERR_NOMEM;
+       if (!root) {
+               if (errno == EILSEQ)
+                       return WIMLIB_ERR_INVALID_UTF8_STRING;
+               else if (errno == ENOMEM)
+                       return WIMLIB_ERR_NOMEM;
+               else
+                       return WIMLIB_ERR_ICONV_NOT_AVAILABLE;
+       }
        *root_p = root;
 
        if (dir_ni && (name_type == FILE_NAME_WIN32_AND_DOS
                       || name_type == FILE_NAME_WIN32))
        {
        *root_p = root;
 
        if (dir_ni && (name_type == FILE_NAME_WIN32_AND_DOS
                       || name_type == FILE_NAME_WIN32))
        {
+               char dos_name_utf8[12 * 4 + 1] = {0};
                ret = ntfs_get_ntfs_dos_name(ni, dir_ni, dos_name_utf8,
                ret = ntfs_get_ntfs_dos_name(ni, dir_ni, dos_name_utf8,
-                                            sizeof(dos_name_utf8));
+                                            sizeof(dos_name_utf8) - 1);
                if (ret > 0) {
                        DEBUG("Changing short name of `%s'", path);
                        ret = change_dentry_short_name(root, dos_name_utf8,
                if (ret > 0) {
                        DEBUG("Changing short name of `%s'", path);
                        ret = change_dentry_short_name(root, dos_name_utf8,
@@ -716,6 +721,10 @@ out_cleanup:
        destroy_sd_set(&sd_set);
 
 out:
        destroy_sd_set(&sd_set);
 
 out:
+       ntfs_index_ctx_put(vol->secure_xsii);
+       ntfs_index_ctx_put(vol->secure_xsdh);
+       ntfs_inode_close(vol->secure_ni);
+
        if (ret) {
                if (ntfs_umount(vol, FALSE) != 0) {
                        ERROR_WITH_ERRNO("Failed to unmount NTFS volume `%s'",
        if (ret) {
                if (ntfs_umount(vol, FALSE) != 0) {
                        ERROR_WITH_ERRNO("Failed to unmount NTFS volume `%s'",