]> wimlib.net Git - wimlib/blobdiff - src/ntfs-apply.c
More test cases and DOS names capture/apply fixes
[wimlib] / src / ntfs-apply.c
index e8e86c1ecd5efcd1bd5cd360079773f7fb8c1d56..108418b3444c8020b0f2d5f65d7fc2a3a1237e7f 100644 (file)
@@ -1,9 +1,8 @@
 /*
  * ntfs-apply.c
  *
- * Apply a WIM image to a NTFS volume, restoring everything we can, including
- * security data and alternate data streams.  There should be no loss of
- * information.
+ * Apply a WIM image to a NTFS volume.  We restore everything we can, including
+ * security data and alternate data streams.
  */
 
 /*
  * This file is part of wimlib, a library for working with WIM files.
  *
  * wimlib is free software; you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free
- * Software Foundation; either version 2.1 of the License, or (at your option)
+ * terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option)
  * any later version.
  *
  * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY
  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more
  * details.
  *
- * You should have received a copy of the GNU Lesser General Public License
+ * You should have received a copy of the GNU General Public License
  * along with wimlib; if not, see http://www.gnu.org/licenses/.
  */
 
@@ -49,9 +48,12 @@ struct ntfs_apply_args {
        WIMStruct *w;
 };
 
-extern int ntfs_inode_set_security(ntfs_inode *ni, u32 selection,
+
+#ifndef WITH_NEW_NTFS_3G
+extern int ntfs_set_inode_security(ntfs_inode *ni, u32 selection,
                                   const char *attr);
-extern int ntfs_inode_set_attributes(ntfs_inode *ni, s32 attrib);
+extern int ntfs_set_inode_attributes(ntfs_inode *ni, u32 attrib);
+#endif
 
 /* 
  * Extracts a WIM resource to a NTFS attribute.
@@ -119,19 +121,38 @@ static int write_ntfs_data_streams(ntfs_inode *ni, const struct dentry *dentry,
                ntfs_attr *na;
 
                lte = dentry_stream_lte(dentry, stream_idx, w->lookup_table);
-               na = ntfs_attr_open(ni, AT_DATA, stream_name, stream_name_len);
-               if (!na) {
-                       ERROR_WITH_ERRNO("Failed to open a data stream of "
-                                        "extracted file `%s'",
-                                        dentry->full_path_utf8);
-                       ret = WIMLIB_ERR_NTFS_3G;
-                       break;
+
+               if (stream_name_len) {
+                       /* Create an empty named stream. */
+                       ret = ntfs_attr_add(ni, AT_DATA, stream_name,
+                                           stream_name_len, NULL, 0);
+                       if (ret != 0) {
+                               ERROR_WITH_ERRNO("Failed to create name data "
+                                                "stream for extracted file "
+                                                "`%s'",
+                                                dentry->full_path_utf8);
+                               ret = WIMLIB_ERR_NTFS_3G;
+                               break;
+
+                       }
                }
-               if (lte)
+               /* If there's no lookup table entry, it's an empty stream.
+                * Otherwise, we must open the attribute and extract the data.
+                * */
+               if (lte) {
+                       na = ntfs_attr_open(ni, AT_DATA, stream_name, stream_name_len);
+                       if (!na) {
+                               ERROR_WITH_ERRNO("Failed to open a data stream of "
+                                                "extracted file `%s'",
+                                                dentry->full_path_utf8);
+                               ret = WIMLIB_ERR_NTFS_3G;
+                               break;
+                       }
                        ret = extract_wim_resource_to_ntfs_attr(lte, na);
-               ntfs_attr_close(na);
-               if (ret != 0)
-                       break;
+                       if (ret != 0)
+                               break;
+                       ntfs_attr_close(na);
+               }
                if (stream_idx == dentry->num_ads)
                        break;
                stream_name = (ntfschar*)dentry->ads_entries[stream_idx].stream_name;
@@ -221,7 +242,7 @@ apply_file_attributes_and_security_data(ntfs_inode *ni,
 {
        DEBUG("Setting NTFS file attributes on `%s' to %#"PRIx32,
              dentry->full_path_utf8, dentry->attributes);
-       if (!ntfs_inode_set_attributes(ni, dentry->attributes)) {
+       if (ntfs_set_inode_attributes(ni, dentry->attributes)) {
                ERROR("Failed to set NTFS file attributes on `%s'",
                       dentry->full_path_utf8);
                return WIMLIB_ERR_NTFS_3G;
@@ -239,8 +260,8 @@ apply_file_attributes_and_security_data(ntfs_inode *ni,
                                DACL_SECURITY_INFORMATION  |
                                SACL_SECURITY_INFORMATION;
                                
-               if (!ntfs_inode_set_security(ni, selection,
-                                            (const char*)sd->descriptors[dentry->security_id]))
+               if (ntfs_set_inode_security(ni, selection,
+                                           (const char*)sd->descriptors[dentry->security_id]))
                {
                        ERROR_WITH_ERRNO("Failed to set security data on `%s'",
                                        dentry->full_path_utf8);
@@ -331,7 +352,9 @@ static int preapply_dentry_with_dos_name(struct dentry *dentry,
                }
        }
        /* If there's a dentry with a DOS name, extract it first */
-       if (dentry_with_dos_name && !dentry_with_dos_name->extracted_file) {
+       if (dentry_with_dos_name
+           && !dentry_with_dos_name->extracted_file)
+       {
                char *p;
                const char *dir_name;
                char orig;
@@ -669,10 +692,18 @@ static int do_wim_apply_image_ntfs(WIMStruct *w, const char *device, int extract
 
        if (ret != 0)
                goto out;
-       DEBUG("Setting NTFS timestamps");
+       if (extract_flags & WIMLIB_EXTRACT_FLAG_VERBOSE)
+               printf("Setting timestamps of extracted files on NTFS "
+                      "volume `%s'\n", device);
        ret = for_dentry_in_tree_depth(wim_root_dentry(w),
                                       wim_apply_dentry_timestamps,
                                       &args);
+       if (ret == 0 && (extract_flags & WIMLIB_EXTRACT_FLAG_VERBOSE))
+               printf("Finished applying image %d of %s to NTFS "
+                      "volume `%s'\n",
+                      w->current_image,
+                      w->filename ? w->filename : "WIM",
+                      device);
 out:
        DEBUG("Unmounting NTFS volume `%s'", device);
        if (ntfs_umount(vol, FALSE) != 0) {