]> wimlib.net Git - wimlib/blobdiff - src/ntfs-apply.c
Initial rewrite of resource code
[wimlib] / src / ntfs-apply.c
index 8bc6c49b28d579917d753cd36d05a597c11395c8..994bbd275979deeb2bfef1c15c9e110586c668c6 100644 (file)
 #include <string.h>
 #include <locale.h>
 
-static int extract_wim_chunk_to_ntfs_attr(const void *buf, size_t len,
-                                         u64 offset, void *arg)
+struct ntfs_attr_extract_ctx {
+       u64 offset;
+       ntfs_attr *na;
+};
+
+static int
+extract_wim_chunk_to_ntfs_attr(const void *buf, size_t len, void *_ctx)
 {
-       ntfs_attr *na = arg;
-       if (ntfs_attr_pwrite(na, offset, len, buf) == len) {
+       struct ntfs_attr_extract_ctx *ctx = _ctx;
+       if (ntfs_attr_pwrite(ctx->na, ctx->offset, len, buf) == len) {
+               ctx->offset += len;
                return 0;
        } else {
                ERROR_WITH_ERRNO("Error extracting WIM resource to NTFS attribute");
@@ -62,8 +68,11 @@ static int
 extract_wim_resource_to_ntfs_attr(const struct wim_lookup_table_entry *lte,
                                  ntfs_attr *na)
 {
+       struct ntfs_attr_extract_ctx ctx;
+       ctx.na = na;
+       ctx.offset = 0;
        return extract_wim_resource(lte, wim_resource_size(lte),
-                                   extract_wim_chunk_to_ntfs_attr, na);
+                                   extract_wim_chunk_to_ntfs_attr, &ctx);
 }
 
 /* Writes the data streams of a WIM inode to the data attributes of a NTFS
@@ -82,8 +91,9 @@ extract_wim_resource_to_ntfs_attr(const struct wim_lookup_table_entry *lte,
  *
  * Returns 0 on success, nonzero on failure.
  */
-static int write_ntfs_data_streams(ntfs_inode *ni, const struct wim_dentry *dentry,
-                                  union wimlib_progress_info *progress_info)
+static int
+write_ntfs_data_streams(ntfs_inode *ni, const struct wim_dentry *dentry,
+                       union wimlib_progress_info *progress_info)
 {
        int ret = 0;
        unsigned stream_idx = 0;
@@ -176,10 +186,10 @@ static int write_ntfs_data_streams(ntfs_inode *ni, const struct wim_dentry *dent
 static ntfs_inode *
 dentry_open_parent_ni(const struct wim_dentry *dentry, ntfs_volume *vol)
 {
-       mbchar *p;
-       const mbchar *dir_name;
+       char *p;
+       const char *dir_name;
        ntfs_inode *dir_ni;
-       mbchar orig;
+       char orig;
 
        p = dentry->full_path + dentry->full_path_nbytes;
        do {
@@ -274,7 +284,8 @@ static int
 apply_file_attributes_and_security_data(ntfs_inode *ni,
                                        ntfs_inode *dir_ni,
                                        const struct wim_dentry *dentry,
-                                       const WIMStruct *w)
+                                       const WIMStruct *w,
+                                       int extract_flags)
 {
        int ret;
        struct SECURITY_CONTEXT ctx;
@@ -298,7 +309,9 @@ apply_file_attributes_and_security_data(ntfs_inode *ni,
                       dentry->full_path);
                return WIMLIB_ERR_NTFS_3G;
        }
-       if (inode->i_security_id != -1) {
+       if (inode->i_security_id != -1 &&
+           !(extract_flags & WIMLIB_EXTRACT_FLAG_NO_ACLS))
+       {
                const char *desc;
                const struct wim_security_data *sd;
 
@@ -325,8 +338,9 @@ apply_file_attributes_and_security_data(ntfs_inode *ni,
  * 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)
+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;
@@ -354,13 +368,13 @@ static int apply_reparse_data(ntfs_inode *ni, const struct wim_dentry *dentry,
        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)
+       ret = read_full_resource_into_buf(lte, p, false);
+       if (ret)
                return ret;
 
        ret = ntfs_set_ntfs_reparse_data(ni, (char*)reparse_data_buf,
                                         wim_resource_size(lte) + 8, 0);
-       if (ret != 0) {
+       if (ret) {
                ERROR_WITH_ERRNO("Failed to set NTFS reparse data on `%s'",
                                 dentry->full_path);
                return WIMLIB_ERR_NTFS_3G;
@@ -439,7 +453,8 @@ do_apply_dentry_ntfs(struct wim_dentry *dentry, ntfs_inode *dir_ni,
        }
 
        ret = apply_file_attributes_and_security_data(ni, dir_ni, dentry,
-                                                     args->w);
+                                                     args->w,
+                                                     args->extract_flags);
        if (ret != 0)
                goto out_close_dir_ni;
 
@@ -451,12 +466,12 @@ do_apply_dentry_ntfs(struct wim_dentry *dentry, ntfs_inode *dir_ni,
 
        /* Set DOS (short) name if given */
        if (dentry_has_short_name(dentry)) {
-               mbchar *short_name_mbs;
+               char *short_name_mbs;
                size_t short_name_mbs_nbytes;
-               ret = utf16le_to_mbs(dentry->short_name,
-                                    dentry->short_name_nbytes,
-                                    &short_name_mbs,
-                                    &short_name_mbs_nbytes);
+               ret = utf16le_to_tstr(dentry->short_name,
+                                     dentry->short_name_nbytes,
+                                     &short_name_mbs,
+                                     &short_name_mbs_nbytes);
                if (ret != 0)
                        goto out_close_dir_ni;
 
@@ -497,7 +512,8 @@ out:
 
 static int
 apply_root_dentry_ntfs(const struct wim_dentry *dentry,
-                      ntfs_volume *vol, const WIMStruct *w)
+                      ntfs_volume *vol, const WIMStruct *w,
+                      int extract_flags)
 {
        ntfs_inode *ni;
        int ret = 0;
@@ -507,7 +523,8 @@ apply_root_dentry_ntfs(const struct wim_dentry *dentry,
                ERROR_WITH_ERRNO("Could not find root NTFS inode");
                return WIMLIB_ERR_NTFS_3G;
        }
-       ret = apply_file_attributes_and_security_data(ni, ni, dentry, w);
+       ret = apply_file_attributes_and_security_data(ni, ni, dentry, w,
+                                                     extract_flags);
        if (ntfs_inode_close(ni) != 0) {
                ERROR_WITH_ERRNO("Failed to close NTFS inode for root "
                                 "directory");
@@ -529,7 +546,8 @@ apply_dentry_ntfs(struct wim_dentry *dentry, void *arg)
 
        /* Treat the root dentry specially. */
        if (dentry_is_root(dentry))
-               return apply_root_dentry_ntfs(dentry, vol, w);
+               return apply_root_dentry_ntfs(dentry, vol, w,
+                                             args->extract_flags);
 
        /* NTFS filename namespaces need careful consideration.  A name for a
         * NTFS file may be in either the POSIX, Win32, DOS, or Win32+DOS
@@ -564,7 +582,7 @@ apply_dentry_ntfs(struct wim_dentry *dentry, void *arg)
         * file.  So, this implies that the correct ordering of function calls
         * to extract a NTFS file are:
         *
-               if (file has a DOS name) {
+        *      if (file has a DOS name) {
         *              - Call ntfs_create() to create long name associated with
         *              the DOS name (this initially creates a POSIX name)
         *              - Call ntfs_set_ntfs_dos_name() to associate a DOS name