]> wimlib.net Git - wimlib/blob - src/ntfs-apply.c
Update version to 1.3.2
[wimlib] / src / ntfs-apply.c
1 /*
2  * ntfs-apply.c
3  *
4  * Apply a WIM image to a NTFS volume.  Restore as much information as possible,
5  * including security data, file attributes, DOS names, and alternate data
6  * streams.
7  */
8
9 /*
10  * Copyright (C) 2012, 2013 Eric Biggers
11  *
12  * This file is part of wimlib, a library for working with WIM files.
13  *
14  * wimlib is free software; you can redistribute it and/or modify it under the
15  * terms of the GNU General Public License as published by the Free
16  * Software Foundation; either version 3 of the License, or (at your option)
17  * any later version.
18  *
19  * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY
20  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
21  * A PARTICULAR PURPOSE. See the GNU General Public License for more
22  * details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with wimlib; if not, see http://www.gnu.org/licenses/.
26  */
27
28
29 #include "config.h"
30
31 #include <ntfs-3g/endians.h>
32 #include <ntfs-3g/types.h>
33
34 #include "wimlib_internal.h"
35 #include "buffer_io.h"
36 #include "dentry.h"
37 #include "lookup_table.h"
38
39 #include <ntfs-3g/attrib.h>
40 #include <ntfs-3g/security.h> /* security.h before xattrs.h */
41 #include <ntfs-3g/reparse.h>
42 #include <ntfs-3g/xattrs.h>
43 #include <string.h>
44 #include <locale.h>
45
46 static int
47 extract_wim_chunk_to_ntfs_attr(const void *buf, size_t len,
48                                u64 offset, void *arg)
49 {
50         ntfs_attr *na = arg;
51         if (ntfs_attr_pwrite(na, offset, len, buf) == len) {
52                 return 0;
53         } else {
54                 ERROR_WITH_ERRNO("Error extracting WIM resource to NTFS attribute");
55                 return WIMLIB_ERR_WRITE;
56         }
57 }
58
59 /*
60  * Extracts a WIM resource to a NTFS attribute.
61  */
62 static int
63 extract_wim_resource_to_ntfs_attr(const struct wim_lookup_table_entry *lte,
64                                   ntfs_attr *na)
65 {
66         return extract_wim_resource(lte, wim_resource_size(lte),
67                                     extract_wim_chunk_to_ntfs_attr, na);
68 }
69
70 /* Writes the data streams of a WIM inode to the data attributes of a NTFS
71  * inode.
72  *
73  * @ni:      The NTFS inode to which the streams are to be extracted.
74  *
75  * @dentry:  The WIM dentry being extracted.  The @d_inode member points to the
76  *           corresponding WIM inode that contains the streams being extracted.
77  *           The WIM dentry itself is only needed to provide a file path for
78  *           better error messages.
79  *
80  * @progress_info:  Progress information for the image application.  The number
81  *                  of extracted bytes will be incremented by the uncompressed
82  *                  size of each stream extracted.
83  *
84  * Returns 0 on success, nonzero on failure.
85  */
86 static int
87 write_ntfs_data_streams(ntfs_inode *ni, const struct wim_dentry *dentry,
88                         union wimlib_progress_info *progress_info)
89 {
90         int ret = 0;
91         unsigned stream_idx = 0;
92         ntfschar *stream_name = AT_UNNAMED;
93         u32 stream_name_nbytes = 0;
94         const struct wim_inode *inode = dentry->d_inode;
95         struct wim_lookup_table_entry *lte;
96
97         DEBUG("Writing %u NTFS data stream%s for `%s'",
98               inode->i_num_ads + 1,
99               (inode->i_num_ads == 0 ? "" : "s"),
100               dentry->full_path);
101
102         lte = inode->i_lte;
103         while (1) {
104                 if (stream_name_nbytes) {
105                         /* Skip special UNIX data entries (see documentation for
106                          * WIMLIB_ADD_IMAGE_FLAG_UNIX_DATA) */
107                         if (stream_name_nbytes == WIMLIB_UNIX_DATA_TAG_UTF16LE_NBYTES
108                             && !memcmp(stream_name,
109                                        WIMLIB_UNIX_DATA_TAG_UTF16LE,
110                                        WIMLIB_UNIX_DATA_TAG_UTF16LE_NBYTES))
111                                 goto cont;
112
113                         /* Create an empty named stream. */
114                         ret = ntfs_attr_add(ni, AT_DATA, stream_name,
115                                             stream_name_nbytes / 2, NULL, 0);
116                         if (ret != 0) {
117                                 ERROR_WITH_ERRNO("Failed to create named data "
118                                                  "stream for extracted file "
119                                                  "`%s'",
120                                                  dentry->full_path);
121                                 ret = WIMLIB_ERR_NTFS_3G;
122                                 break;
123
124                         }
125                 }
126
127                 /* If there's no lookup table entry, it's an empty stream.
128                  * Otherwise, open the attribute and extract the data. */
129                 if (lte) {
130                         ntfs_attr *na;
131
132                         na = ntfs_attr_open(ni, AT_DATA, stream_name,
133                                             stream_name_nbytes / 2);
134                         if (!na) {
135                                 ERROR_WITH_ERRNO("Failed to open a data stream of "
136                                                  "extracted file `%s'",
137                                                  dentry->full_path);
138                                 ret = WIMLIB_ERR_NTFS_3G;
139                                 break;
140                         }
141
142                         /* The WIM lookup table entry provides the stream
143                          * length, so the NTFS attribute should be resized to
144                          * this length before starting to extract the data. */
145                         ret = ntfs_attr_truncate_solid(na, wim_resource_size(lte));
146                         if (ret != 0) {
147                                 ntfs_attr_close(na);
148                                 break;
149                         }
150
151                         /* Actually extract the stream */
152                         ret = extract_wim_resource_to_ntfs_attr(lte, na);
153
154                         /* Close the attribute */
155                         ntfs_attr_close(na);
156                         if (ret != 0)
157                                 break;
158
159                         /* Record the number of bytes of uncompressed data that
160                          * have been extracted. */
161                         progress_info->extract.completed_bytes += wim_resource_size(lte);
162                 }
163         cont:
164                 if (stream_idx == inode->i_num_ads) /* Has the last stream been extracted? */
165                         break;
166
167                 /* Get the name and lookup table entry for the next stream. */
168                 stream_name = inode->i_ads_entries[stream_idx].stream_name;
169                 stream_name_nbytes = inode->i_ads_entries[stream_idx].stream_name_nbytes;
170                 lte = inode->i_ads_entries[stream_idx].lte;
171                 stream_idx++;
172         }
173         return ret;
174 }
175
176 /* Open the NTFS inode that corresponds to the parent of a WIM dentry.  Returns
177  * the opened inode, or NULL on failure. */
178 static ntfs_inode *
179 dentry_open_parent_ni(const struct wim_dentry *dentry, ntfs_volume *vol)
180 {
181         char *p;
182         const char *dir_name;
183         ntfs_inode *dir_ni;
184         char orig;
185
186         p = dentry->full_path + dentry->full_path_nbytes;
187         do {
188                 p--;
189         } while (*p != '/');
190
191         orig = *p;
192         *p = '\0';
193         dir_name = dentry->full_path;
194         dir_ni = ntfs_pathname_to_inode(vol, NULL, dir_name);
195         if (!dir_ni) {
196                 ERROR_WITH_ERRNO("Could not find NTFS inode for `%s'",
197                                  dir_name);
198         }
199         *p = orig;
200         return dir_ni;
201 }
202
203 /*
204  * Makes a NTFS hard link.
205  *
206  * The hard link is named @from_dentry->file_name and is located under the
207  * directory specified by @dir_ni, and it is made to point to the previously
208  * extracted file located at @inode->i_extracted_file.
209  *
210  * Or, in other words, this adds a new name @from_dentry->full_path to an
211  * existing NTFS inode which already has a name @inode->i_extracted_file.
212  *
213  * The new name is made in the POSIX namespace (this is the behavior of
214  * ntfs_link()).
215  *
216  * Return 0 on success, nonzero on failure.  dir_ni is closed either way.
217  */
218 static int
219 apply_ntfs_hardlink(const struct wim_dentry *from_dentry,
220                     const struct wim_inode *inode,
221                     ntfs_inode *dir_ni)
222 {
223         int ret;
224         ntfs_inode *to_ni;
225         ntfs_volume *vol;
226
227         vol = dir_ni->vol;
228         ret = ntfs_inode_close(dir_ni);
229         if (ret != 0) {
230                 ERROR_WITH_ERRNO("Error closing directory");
231                 return WIMLIB_ERR_NTFS_3G;
232         }
233
234         DEBUG("Extracting NTFS hard link `%s' => `%s'",
235               from_dentry->full_path, inode->i_extracted_file);
236
237         to_ni = ntfs_pathname_to_inode(vol, NULL, inode->i_extracted_file);
238         if (!to_ni) {
239                 ERROR_WITH_ERRNO("Could not find NTFS inode for `%s'",
240                                  inode->i_extracted_file);
241                 return WIMLIB_ERR_NTFS_3G;
242         }
243
244         dir_ni = dentry_open_parent_ni(from_dentry, vol);
245         if (!dir_ni) {
246                 ntfs_inode_close(to_ni);
247                 return WIMLIB_ERR_NTFS_3G;
248         }
249
250         ret = ntfs_link(to_ni, dir_ni,
251                         from_dentry->file_name,
252                         from_dentry->file_name_nbytes / 2);
253         ret |= ntfs_inode_close(dir_ni);
254         ret |= ntfs_inode_close(to_ni);
255         if (ret) {
256                 ERROR_WITH_ERRNO("Could not create hard link `%s' => `%s'",
257                                  from_dentry->full_path,
258                                  inode->i_extracted_file);
259                 ret = WIMLIB_ERR_NTFS_3G;
260         }
261         return ret;
262 }
263
264 /* Transfers file attributes and possibly a security descriptor from a WIM inode
265  * to a NTFS inode.
266  *
267  * @ni:      The NTFS inode to apply the metadata to.
268  * @dir_ni:  The NTFS inode for a directory containing @ni.
269  * @dentry:  The WIM dentry whose inode contains the metadata to apply.
270  * @w:       The WIMStruct for the WIM, through which the table of security
271  *              descriptors can be accessed.
272  *
273  * Returns 0 on success, nonzero on failure.
274  */
275 static int
276 apply_file_attributes_and_security_data(ntfs_inode *ni,
277                                         ntfs_inode *dir_ni,
278                                         const struct wim_dentry *dentry,
279                                         const WIMStruct *w,
280                                         int extract_flags)
281 {
282         int ret;
283         struct SECURITY_CONTEXT ctx;
284         u32 attributes_le32;
285         const struct wim_inode *inode;
286
287         inode = dentry->d_inode;
288
289         DEBUG("Setting NTFS file attributes on `%s' to %#"PRIx32,
290               dentry->full_path, inode->i_attributes);
291
292         attributes_le32 = cpu_to_le32(inode->i_attributes);
293         memset(&ctx, 0, sizeof(ctx));
294         ctx.vol = ni->vol;
295         ret = ntfs_xattr_system_setxattr(&ctx, XATTR_NTFS_ATTRIB,
296                                          ni, dir_ni,
297                                          (const char*)&attributes_le32,
298                                          sizeof(u32), 0);
299         if (ret != 0) {
300                 ERROR("Failed to set NTFS file attributes on `%s'",
301                        dentry->full_path);
302                 return WIMLIB_ERR_NTFS_3G;
303         }
304         if (inode->i_security_id != -1 &&
305             !(extract_flags & WIMLIB_EXTRACT_FLAG_NOACLS))
306         {
307                 const char *desc;
308                 const struct wim_security_data *sd;
309
310                 sd = wim_const_security_data(w);
311                 wimlib_assert(inode->i_security_id < sd->num_entries);
312                 desc = (const char *)sd->descriptors[inode->i_security_id];
313                 DEBUG("Applying security descriptor %d to `%s'",
314                       inode->i_security_id, dentry->full_path);
315
316                 ret = ntfs_xattr_system_setxattr(&ctx, XATTR_NTFS_ACL,
317                                                  ni, dir_ni, desc,
318                                                  sd->sizes[inode->i_security_id], 0);
319
320                 if (ret != 0) {
321                         ERROR_WITH_ERRNO("Failed to set security data on `%s'",
322                                         dentry->full_path);
323                         return WIMLIB_ERR_NTFS_3G;
324                 }
325         }
326         return 0;
327 }
328
329 /*
330  * Transfers the reparse data from a WIM inode (which must represent a reparse
331  * point) to a NTFS inode.
332  */
333 static int
334 apply_reparse_data(ntfs_inode *ni, const struct wim_dentry *dentry,
335                    union wimlib_progress_info *progress_info)
336 {
337         struct wim_lookup_table_entry *lte;
338         int ret = 0;
339
340         lte = inode_unnamed_lte_resolved(dentry->d_inode);
341
342         DEBUG("Applying reparse data to `%s'", dentry->full_path);
343
344         if (!lte) {
345                 ERROR("Could not find reparse data for `%s'",
346                       dentry->full_path);
347                 return WIMLIB_ERR_INVALID_DENTRY;
348         }
349
350         if (wim_resource_size(lte) >= 0xffff) {
351                 ERROR("Reparse data of `%s' is too long (%"PRIu64" bytes)",
352                       dentry->full_path, wim_resource_size(lte));
353                 return WIMLIB_ERR_INVALID_DENTRY;
354         }
355
356         u8 reparse_data_buf[8 + wim_resource_size(lte)];
357         u8 *p = reparse_data_buf;
358         p = put_u32(p, dentry->d_inode->i_reparse_tag); /* ReparseTag */
359         DEBUG("ReparseTag = %#x", dentry->d_inode->i_reparse_tag);
360         p = put_u16(p, wim_resource_size(lte)); /* ReparseDataLength */
361         p = put_u16(p, 0); /* Reserved */
362
363         ret = read_full_wim_resource(lte, p, 0);
364         if (ret != 0)
365                 return ret;
366
367         ret = ntfs_set_ntfs_reparse_data(ni, (char*)reparse_data_buf,
368                                          wim_resource_size(lte) + 8, 0);
369         if (ret != 0) {
370                 ERROR_WITH_ERRNO("Failed to set NTFS reparse data on `%s'",
371                                  dentry->full_path);
372                 return WIMLIB_ERR_NTFS_3G;
373         }
374         progress_info->extract.completed_bytes += wim_resource_size(lte);
375         return 0;
376 }
377
378 /*
379  * Applies a WIM dentry to a NTFS filesystem.
380  *
381  * @dentry:  The WIM dentry to apply
382  * @dir_ni:  The NTFS inode for the parent directory
383  *
384  * @return:  0 on success; nonzero on failure.
385  */
386 static int
387 do_apply_dentry_ntfs(struct wim_dentry *dentry, ntfs_inode *dir_ni,
388                      struct apply_args *args)
389 {
390         int ret = 0;
391         mode_t type;
392         ntfs_inode *ni = NULL;
393         struct wim_inode *inode = dentry->d_inode;
394         dentry->is_extracted = 1;
395
396         if (inode->i_attributes & FILE_ATTRIBUTE_DIRECTORY) {
397                 type = S_IFDIR;
398         } else {
399                 type = S_IFREG;
400                 if (inode->i_nlink > 1) {
401                         /* Inode has multiple dentries referencing it. */
402                         if (inode->i_extracted_file) {
403                                 /* Already extracted another dentry in the hard
404                                  * link group.  Make a hard link instead of
405                                  * extracting the file data. */
406                                 ret = apply_ntfs_hardlink(dentry, inode, dir_ni);
407                                 /* dir_ni was closed */
408                                 goto out;
409                         } else {
410                                 /* None of the dentries of this inode have been
411                                  * extracted yet, so go ahead and extract the
412                                  * first one. */
413                                 FREE(inode->i_extracted_file);
414                                 inode->i_extracted_file = STRDUP(dentry->full_path);
415                                 if (!inode->i_extracted_file) {
416                                         ret = WIMLIB_ERR_NOMEM;
417                                         goto out_close_dir_ni;
418                                 }
419                         }
420                 }
421         }
422
423         /* Create a NTFS directory or file.
424          *
425          * Note: For symbolic links that are not directory junctions, S_IFREG is
426          * passed here, since the reparse data and file attributes are set
427          * later. */
428         ni = ntfs_create(dir_ni, 0, dentry->file_name,
429                          dentry->file_name_nbytes / 2, type);
430
431         if (!ni) {
432                 ERROR_WITH_ERRNO("Could not create NTFS inode for `%s'",
433                                  dentry->full_path);
434                 ret = WIMLIB_ERR_NTFS_3G;
435                 goto out_close_dir_ni;
436         }
437
438         /* Write the data streams, unless this is a directory or reparse point
439          * */
440         if (!(inode->i_attributes & (FILE_ATTRIBUTE_REPARSE_POINT |
441                                    FILE_ATTRIBUTE_DIRECTORY))) {
442                 ret = write_ntfs_data_streams(ni, dentry, &args->progress);
443                 if (ret != 0)
444                         goto out_close_dir_ni;
445         }
446
447         ret = apply_file_attributes_and_security_data(ni, dir_ni, dentry,
448                                                       args->w,
449                                                       args->extract_flags);
450         if (ret != 0)
451                 goto out_close_dir_ni;
452
453         if (inode->i_attributes & FILE_ATTR_REPARSE_POINT) {
454                 ret = apply_reparse_data(ni, dentry, &args->progress);
455                 if (ret != 0)
456                         goto out_close_dir_ni;
457         }
458
459         /* Set DOS (short) name if given */
460         if (dentry_has_short_name(dentry)) {
461                 char *short_name_mbs;
462                 size_t short_name_mbs_nbytes;
463                 ret = utf16le_to_tstr(dentry->short_name,
464                                       dentry->short_name_nbytes,
465                                       &short_name_mbs,
466                                       &short_name_mbs_nbytes);
467                 if (ret != 0)
468                         goto out_close_dir_ni;
469
470                 DEBUG("Setting short (DOS) name of `%s' to %s",
471                       dentry->full_path, short_name_mbs);
472
473                 ret = ntfs_set_ntfs_dos_name(ni, dir_ni, short_name_mbs,
474                                              short_name_mbs_nbytes, 0);
475                 FREE(short_name_mbs);
476                 if (ret != 0) {
477                         ERROR_WITH_ERRNO("Could not set DOS (short) name for `%s'",
478                                          dentry->full_path);
479                         ret = WIMLIB_ERR_NTFS_3G;
480                 }
481                 /* inodes have been closed by ntfs_set_ntfs_dos_name(). */
482                 goto out;
483         }
484 out_close_dir_ni:
485         if (dir_ni) {
486                 if (ni) {
487                         if (ntfs_inode_close_in_dir(ni, dir_ni)) {
488                                 if (ret == 0)
489                                         ret = WIMLIB_ERR_NTFS_3G;
490                                 ERROR_WITH_ERRNO("Failed to close inode for `%s'",
491                                                  dentry->full_path);
492                         }
493                 }
494                 if (ntfs_inode_close(dir_ni)) {
495                         if (ret == 0)
496                                 ret = WIMLIB_ERR_NTFS_3G;
497                         ERROR_WITH_ERRNO("Failed to close inode of directory "
498                                          "containing `%s'", dentry->full_path);
499                 }
500         }
501 out:
502         return ret;
503 }
504
505 static int
506 apply_root_dentry_ntfs(const struct wim_dentry *dentry,
507                        ntfs_volume *vol, const WIMStruct *w,
508                        int extract_flags)
509 {
510         ntfs_inode *ni;
511         int ret = 0;
512
513         ni = ntfs_pathname_to_inode(vol, NULL, "/");
514         if (!ni) {
515                 ERROR_WITH_ERRNO("Could not find root NTFS inode");
516                 return WIMLIB_ERR_NTFS_3G;
517         }
518         ret = apply_file_attributes_and_security_data(ni, ni, dentry, w,
519                                                       extract_flags);
520         if (ntfs_inode_close(ni) != 0) {
521                 ERROR_WITH_ERRNO("Failed to close NTFS inode for root "
522                                  "directory");
523                 ret = WIMLIB_ERR_NTFS_3G;
524         }
525         return ret;
526 }
527
528 /* Applies a WIM dentry to the NTFS volume */
529 int
530 apply_dentry_ntfs(struct wim_dentry *dentry, void *arg)
531 {
532         struct apply_args *args = arg;
533         ntfs_volume *vol = args->vol;
534         WIMStruct *w = args->w;
535         struct wim_dentry *orig_dentry;
536         struct wim_dentry *other;
537         int ret;
538
539         /* Treat the root dentry specially. */
540         if (dentry_is_root(dentry))
541                 return apply_root_dentry_ntfs(dentry, vol, w,
542                                               args->extract_flags);
543
544         /* NTFS filename namespaces need careful consideration.  A name for a
545          * NTFS file may be in either the POSIX, Win32, DOS, or Win32+DOS
546          * namespaces.  A NTFS file (a.k.a. inode) may have multiple names in
547          * multiple directories (i.e. hard links); however, a NTFS file can have
548          * at most 1 DOS name total.  Furthermore, a Win32 name is always
549          * associated with a DOS name (either as a Win32+DOS name, or a Win32
550          * name and a DOS name separately), which implies that a NTFS file can
551          * have at most 1 Win32 name.
552          *
553          * A WIM dentry just contains a "long name", which wimlib makes sure is
554          * non-empty, and a "short name", which may be empty.  So, wimlib must
555          * map these to the correct NTFS names.  wimlib collects all WIM
556          * dentries that map to the same NTFS inode and factors out the common
557          * information into a 'struct wim_inode', so this should make the
558          * mapping a little more obvious.  As a NTFS file can have at most 1 DOS
559          * name, a WIM inode cannot have more than 1 dentry with a non-empty
560          * short name, and this is checked in the verify_inode() function in
561          * verify.c.  Furthermore, a WIM dentry, if any, that has a DOS name
562          * must have a long name that corresponds to a Win32 name or Win32+DOS
563          * name.
564          *
565          * WIM dentries that have a long name but no associated short name are
566          * assumed to be in the POSIX namespace.
567          *
568          * So, given a WIM inode that is to map to a NTFS inode, we must apply
569          * the Win32 and DOS or Win32+DOS names, if they exist, then any
570          * additional (POSIX) names.  A caveat when actually doing this:  as
571          * confirmed by the libntfs-3g authors, ntfs_set_ntfs_dos_name() is only
572          * guaranteed to associate a DOS name with the appropriate long name if
573          * it's called when that long name is the only one in existence for that
574          * file.  So, this implies that the correct ordering of function calls
575          * to extract a NTFS file are:
576          *
577          *      if (file has a DOS name) {
578          *              - Call ntfs_create() to create long name associated with
579          *              the DOS name (this initially creates a POSIX name)
580          *              - Call ntfs_set_ntfs_dos_name() to associate a DOS name
581          *              with the long name just created.  This either changes
582          *              the POSIX name to Win32+DOS, or changes the POSIX name
583          *              to Win32 and creates a separate DOS name.
584          *      } else {
585          *              - Call ntfs_create() to create the first link to the
586          *              file in the POSIX namespace
587          *      }
588          *      - Call ntfs_link() to create the other names of the file, in the
589          *      POSIX namespace.
590          */
591 again:
592         orig_dentry = NULL;
593         if (!dentry->d_inode->i_dos_name_extracted &&
594             !dentry_has_short_name(dentry))
595         {
596                 inode_for_each_dentry(other, dentry->d_inode) {
597                         if (dentry_has_short_name(other)) {
598                                 orig_dentry = dentry;
599                                 dentry = other;
600                                 break;
601                         }
602                 }
603         }
604         dentry->d_inode->i_dos_name_extracted = 1;
605         ntfs_inode *dir_ni = dentry_open_parent_ni(dentry, vol);
606         if (dir_ni) {
607                 ret = do_apply_dentry_ntfs(dentry, dir_ni, arg);
608                 if (ret == 0 && orig_dentry != NULL) {
609                         dentry = orig_dentry;
610                         goto again;
611                 }
612         } else {
613                 ret = WIMLIB_ERR_NTFS_3G;
614         }
615         return ret;
616 }
617
618 /* Transfers the 100-nanosecond precision timestamps from a WIM dentry to a NTFS
619  * inode */
620 int
621 apply_dentry_timestamps_ntfs(struct wim_dentry *dentry, void *arg)
622 {
623         struct apply_args *args = arg;
624         ntfs_volume *vol = args->vol;
625         u8 *p;
626         u8 buf[24];
627         ntfs_inode *ni;
628         int ret;
629
630         DEBUG("Setting timestamps on `%s'", dentry->full_path);
631
632         ni = ntfs_pathname_to_inode(vol, NULL, dentry->full_path);
633         if (!ni) {
634                 ERROR_WITH_ERRNO("Could not find NTFS inode for `%s'",
635                                  dentry->full_path);
636                 return WIMLIB_ERR_NTFS_3G;
637         }
638
639         p = buf;
640         p = put_u64(p, dentry->d_inode->i_creation_time);
641         p = put_u64(p, dentry->d_inode->i_last_write_time);
642         p = put_u64(p, dentry->d_inode->i_last_access_time);
643         ret = ntfs_inode_set_times(ni, (const char*)buf, 3 * sizeof(u64), 0);
644         if (ret != 0) {
645                 ERROR_WITH_ERRNO("Failed to set NTFS timestamps on `%s'",
646                                  dentry->full_path);
647                 ret = WIMLIB_ERR_NTFS_3G;
648         }
649
650         if (ntfs_inode_close(ni) != 0) {
651                 if (ret == 0)
652                         ret = WIMLIB_ERR_NTFS_3G;
653                 ERROR_WITH_ERRNO("Failed to close NTFS inode for `%s'",
654                                  dentry->full_path);
655         }
656         return ret;
657 }
658
659 void
660 libntfs3g_global_init()
661 {
662         ntfs_set_char_encoding(setlocale(LC_ALL, ""));
663 }