]> wimlib.net Git - wimlib/blob - src/ntfs-capture.c
Fix various NTFS capture issues
[wimlib] / src / ntfs-capture.c
1 /*
2  * ntfs-capture.c
3  *
4  * Capture a WIM image from a NTFS volume.  We capture everything we can,
5  * including security data and alternate data streams.  There should be no loss
6  * of information.
7  */
8
9 /*
10  * Copyright (C) 2012 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 Lesser General Public License as published by the Free
16  * Software Foundation; either version 2.1 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 Lesser General Public License for more
22  * details.
23  *
24  * You should have received a copy of the GNU Lesser General Public License
25  * along with wimlib; if not, see http://www.gnu.org/licenses/.
26  */
27
28 #include "config.h"
29 #include "wimlib_internal.h"
30
31
32 #ifdef WITH_NTFS_3G
33 #include "dentry.h"
34 #include "lookup_table.h"
35 #include "io.h"
36 #include <ntfs-3g/layout.h>
37 #include <ntfs-3g/acls.h>
38 #include <ntfs-3g/attrib.h>
39 #include <ntfs-3g/misc.h>
40 #include <ntfs-3g/reparse.h>
41 #include <ntfs-3g/security.h>
42 #include <ntfs-3g/volume.h>
43 #include <stdlib.h>
44 #include <unistd.h>
45
46 extern int ntfs_inode_get_security(ntfs_inode *ni, u32 selection, char *buf,
47                                    u32 buflen, u32 *psize);
48
49 extern int ntfs_inode_get_attributes(ntfs_inode *ni);
50
51 /* Structure that allows searching the security descriptors by SHA1 message
52  * digest. */
53 struct sd_set {
54         struct wim_security_data *sd;
55         struct sd_node *root;
56 };
57
58 /* Binary tree node of security descriptors, indexed by the @hash field. */
59 struct sd_node {
60         int security_id;
61         u8 hash[SHA1_HASH_SIZE];
62         struct sd_node *left;
63         struct sd_node *right;
64 };
65
66 static void free_sd_tree(struct sd_node *root)
67 {
68         if (root) {
69                 free_sd_tree(root->left);
70                 free_sd_tree(root->right);
71                 FREE(root);
72         }
73 }
74 /* Frees a security descriptor index set. */
75 static void destroy_sd_set(struct sd_set *sd_set)
76 {
77         free_sd_tree(sd_set->root);
78 }
79
80 /* Inserts a a new node into the security descriptor index tree. */
81 static void insert_sd_node(struct sd_node *new, struct sd_node *root)
82 {
83         int cmp = hashes_cmp(new->hash, root->hash);
84         if (cmp < 0) {
85                 if (root->left)
86                         insert_sd_node(new, root->left);
87                 else 
88                         root->left = new;
89         } else if (cmp > 0) {
90                 if (root->right)
91                         insert_sd_node(new, root->right);
92                 else 
93                         root->right = new;
94         } else {
95                 wimlib_assert(0);
96         }
97 }
98
99 /* Returns the security ID of the security data having a SHA1 message digest of
100  * @hash in the security descriptor index tree rooted at @root. 
101  *
102  * If not found, return -1. */
103 static int lookup_sd(const u8 hash[SHA1_HASH_SIZE], struct sd_node *root)
104 {
105         int cmp;
106         if (!root)
107                 return -1;
108         cmp = hashes_cmp(hash, root->hash);
109         if (cmp < 0)
110                 return lookup_sd(hash, root->left);
111         else if (cmp > 0)
112                 return lookup_sd(hash, root->right);
113         else
114                 return root->security_id;
115 }
116
117 /*
118  * Adds a security descriptor to the indexed security descriptor set as well as
119  * the corresponding `struct wim_security_data', and returns the new security
120  * ID; or, if there is an existing security descriptor that is the same, return
121  * the security ID for it.  If a new security descriptor cannot be allocated,
122  * return -1.
123  */
124 static int sd_set_add_sd(struct sd_set *sd_set, const char descriptor[],
125                          size_t size)
126 {
127         u8 hash[SHA1_HASH_SIZE];
128         int security_id;
129         struct sd_node *new;
130         u8 **descriptors;
131         u64 *sizes;
132         u8 *descr_copy;
133         struct wim_security_data *sd;
134
135         sha1_buffer((const u8*)descriptor, size, hash);
136
137         security_id = lookup_sd(hash, sd_set->root);
138         if (security_id >= 0)
139                 return security_id;
140
141         new = MALLOC(sizeof(*new));
142         if (!new)
143                 goto out;
144         descr_copy = MALLOC(size);
145         if (!descr_copy)
146                 goto out_free_node;
147
148         sd = sd_set->sd;
149
150         memcpy(descr_copy, descriptor, size);
151         new->security_id = sd->num_entries;
152         new->left = NULL;
153         new->right = NULL;
154         copy_hash(new->hash, hash);
155
156
157         descriptors = REALLOC(sd->descriptors,
158                               (sd->num_entries + 1) * sizeof(sd->descriptors[0]));
159         if (!descriptors)
160                 goto out_free_descr;
161         sd->descriptors = descriptors;
162         sizes = REALLOC(sd->sizes,
163                         (sd->num_entries + 1) * sizeof(sd->sizes[0]));
164         if (!sizes)
165                 goto out_free_descr;
166         sd->sizes = sizes;
167         sd->descriptors[sd->num_entries] = descr_copy;
168         sd->sizes[sd->num_entries] = size;
169         sd->num_entries++;
170         DEBUG("There are now %d security descriptors", sd->num_entries);
171         sd->total_length += size + sizeof(sd->sizes[0]);
172
173         if (sd_set->root)
174                 insert_sd_node(new, sd_set->root);
175         else
176                 sd_set->root = new;
177         return new->security_id;
178 out_free_descr:
179         FREE(descr_copy);
180 out_free_node:
181         FREE(new);
182 out:
183         return -1;
184 }
185
186 static inline ntfschar *attr_record_name(ATTR_RECORD *ar)
187 {
188         return (ntfschar*)((u8*)ar + le16_to_cpu(ar->name_offset));
189 }
190
191 /* Calculates the SHA1 message digest of a NTFS attribute. 
192  *
193  * @ni:  The NTFS inode containing the attribute.
194  * @ar:  The ATTR_RECORD describing the attribute.
195  * @md:  If successful, the returned SHA1 message digest.
196  * @reparse_tag_ret:    Optional pointer into which the first 4 bytes of the
197  *                              attribute will be written (to get the reparse
198  *                              point ID)
199  *
200  * Return 0 on success or nonzero on error.
201  */
202 static int ntfs_attr_sha1sum(ntfs_inode *ni, ATTR_RECORD *ar,
203                              u8 md[SHA1_HASH_SIZE],
204                              u32 *reparse_tag_ret)
205 {
206         s64 pos = 0;
207         s64 bytes_remaining;
208         char buf[4096];
209         ntfs_attr *na;
210         SHA_CTX ctx;
211
212         na = ntfs_attr_open(ni, ar->type, attr_record_name(ar),
213                             ar->name_length);
214         if (!na) {
215                 ERROR_WITH_ERRNO("Failed to open NTFS attribute");
216                 return WIMLIB_ERR_NTFS_3G;
217         }
218
219         bytes_remaining = na->data_size;
220         sha1_init(&ctx);
221
222         DEBUG2("Calculating SHA1 message digest (%"PRIu64" bytes)",
223                bytes_remaining);
224
225         while (bytes_remaining) {
226                 s64 to_read = min(bytes_remaining, sizeof(buf));
227                 if (ntfs_attr_pread(na, pos, to_read, buf) != to_read) {
228                         ERROR_WITH_ERRNO("Error reading NTFS attribute");
229                         return WIMLIB_ERR_NTFS_3G;
230                 }
231                 if (bytes_remaining == na->data_size && reparse_tag_ret)
232                         *reparse_tag_ret = le32_to_cpu(*(u32*)buf);
233                 sha1_update(&ctx, buf, to_read);
234                 pos += to_read;
235                 bytes_remaining -= to_read;
236         }
237         sha1_final(md, &ctx);
238         ntfs_attr_close(na);
239         return 0;
240 }
241
242 /* Load the streams from a WIM file or reparse point in the NTFS volume into the
243  * WIM lookup table */
244 static int capture_ntfs_streams(struct dentry *dentry, ntfs_inode *ni,
245                                 char path[], size_t path_len,
246                                 struct lookup_table *lookup_table,
247                                 ntfs_volume **ntfs_vol_p,
248                                 ATTR_TYPES type)
249 {
250
251         ntfs_attr_search_ctx *actx;
252         u8 attr_hash[SHA1_HASH_SIZE];
253         struct ntfs_location *ntfs_loc = NULL;
254         int ret = 0;
255         struct lookup_table_entry *lte;
256
257         DEBUG2("Capturing NTFS data streams from `%s'", path);
258
259         /* Get context to search the streams of the NTFS file. */
260         actx = ntfs_attr_get_search_ctx(ni, NULL);
261         if (!actx) {
262                 ERROR_WITH_ERRNO("Cannot get NTFS attribute search "
263                                  "context");
264                 return WIMLIB_ERR_NTFS_3G;
265         }
266
267         /* Capture each data stream or reparse data stream. */
268         while (!ntfs_attr_lookup(type, NULL, 0,
269                                  CASE_SENSITIVE, 0, NULL, 0, actx))
270         {
271                 char *stream_name_utf8;
272                 size_t stream_name_utf16_len;
273                 u32 reparse_tag;
274                 u64 data_size = ntfs_get_attribute_value_length(actx->attr);
275
276                 if (data_size == 0) { 
277                         if (errno != 0) {
278                                 ERROR_WITH_ERRNO("Failed to get size of attribute of "
279                                                  "`%s'", path);
280                                 ret = WIMLIB_ERR_NTFS_3G;
281                                 goto out_put_actx;
282                         }
283                         /* Empty stream.  No lookup table entry is needed. */
284                         lte = NULL;
285                 } else {
286                         if (type == AT_REPARSE_POINT && data_size < 8) {
287                                 ERROR("`%s': reparse point buffer too small");
288                                 ret = WIMLIB_ERR_NTFS_3G;
289                                 goto out_put_actx;
290                         }
291                         /* Checksum the stream. */
292                         ret = ntfs_attr_sha1sum(ni, actx->attr, attr_hash, &reparse_tag);
293                         if (ret != 0)
294                                 goto out_put_actx;
295
296                         /* Make a lookup table entry for the stream, or use an existing
297                          * one if there's already an identical stream. */
298                         lte = __lookup_resource(lookup_table, attr_hash);
299                         ret = WIMLIB_ERR_NOMEM;
300                         if (lte) {
301                                 lte->refcnt++;
302                         } else {
303                                 ntfs_loc = CALLOC(1, sizeof(*ntfs_loc));
304                                 if (!ntfs_loc)
305                                         goto out_put_actx;
306                                 ntfs_loc->ntfs_vol_p = ntfs_vol_p;
307                                 ntfs_loc->path_utf8 = MALLOC(path_len + 1);
308                                 if (!ntfs_loc->path_utf8)
309                                         goto out_free_ntfs_loc;
310                                 memcpy(ntfs_loc->path_utf8, path, path_len + 1);
311                                 ntfs_loc->stream_name_utf16 = MALLOC(actx->attr->name_length * 2);
312                                 if (!ntfs_loc->stream_name_utf16)
313                                         goto out_free_ntfs_loc;
314                                 memcpy(ntfs_loc->stream_name_utf16,
315                                        attr_record_name(actx->attr),
316                                        actx->attr->name_length * 2);
317
318                                 ntfs_loc->stream_name_utf16_num_chars = actx->attr->name_length;
319                                 lte = new_lookup_table_entry();
320                                 if (!lte)
321                                         goto out_free_ntfs_loc;
322                                 lte->ntfs_loc = ntfs_loc;
323                                 lte->resource_location = RESOURCE_IN_NTFS_VOLUME;
324                                 if (type == AT_REPARSE_POINT) {
325                                         dentry->reparse_tag = reparse_tag;
326                                         ntfs_loc->is_reparse_point = true;
327                                         lte->resource_entry.original_size = data_size - 8;
328                                         lte->resource_entry.size = data_size - 8;
329                                 } else {
330                                         ntfs_loc->is_reparse_point = false;
331                                         lte->resource_entry.original_size = data_size;
332                                         lte->resource_entry.size = data_size;
333                                 }
334                                 ntfs_loc = NULL;
335                                 DEBUG("Add resource for `%s' (size = %zu)",
336                                         dentry->file_name_utf8,
337                                         lte->resource_entry.original_size);
338                                 copy_hash(lte->hash, attr_hash);
339                                 lookup_table_insert(lookup_table, lte);
340                         }
341                 }
342                 if (actx->attr->name_length == 0) {
343                         /* Unnamed data stream.  Put the reference to it in the
344                          * dentry. */
345                         if (dentry->lte) {
346                                 ERROR("Found two un-named data streams for "
347                                       "`%s'", path);
348                                 ret = WIMLIB_ERR_NTFS_3G;
349                                 goto out_free_lte;
350                         }
351                         dentry->lte = lte;
352                 } else {
353                         /* Named data stream.  Put the reference to it in the
354                          * alternate data stream entries */
355                         struct ads_entry *new_ads_entry;
356                         size_t stream_name_utf8_len;
357                         stream_name_utf8 = utf16_to_utf8((const char*)attr_record_name(actx->attr),
358                                                          actx->attr->name_length,
359                                                          &stream_name_utf8_len);
360                         if (!stream_name_utf8)
361                                 goto out_free_lte;
362                         new_ads_entry = dentry_add_ads(dentry, stream_name_utf8);
363                         FREE(stream_name_utf8);
364                         if (!new_ads_entry)
365                                 goto out_free_lte;
366                                 
367                         new_ads_entry->lte = lte;
368                 }
369         }
370         ret = 0;
371         goto out_put_actx;
372 out_free_lte:
373         free_lookup_table_entry(lte);
374 out_free_ntfs_loc:
375         if (ntfs_loc) {
376                 FREE(ntfs_loc->path_utf8);
377                 FREE(ntfs_loc->stream_name_utf16);
378                 FREE(ntfs_loc);
379         }
380 out_put_actx:
381         ntfs_attr_put_search_ctx(actx);
382         if (ret == 0)
383                 DEBUG2("Successfully captured NTFS streams from `%s'", path);
384         else
385                 ERROR("Failed to capture NTFS streams from `%s", path);
386         return ret;
387 }
388
389 struct readdir_ctx {
390         struct dentry       *parent;
391         ntfs_inode          *dir_ni;
392         char                *path;
393         size_t               path_len;
394         struct lookup_table *lookup_table;
395         struct sd_set       *sd_set;
396         const struct capture_config *config;
397         ntfs_volume        **ntfs_vol_p;
398         int                  flags;
399 };
400
401 static int
402 build_dentry_tree_ntfs_recursive(struct dentry **root_p, ntfs_inode *ni,
403                                  char path[], size_t path_len,
404                                  struct lookup_table *lookup_table,
405                                  struct sd_set *sd_set,
406                                  const struct capture_config *config,
407                                  ntfs_volume **ntfs_vol_p,
408                                  int flags);
409
410 static int wim_ntfs_capture_filldir(void *dirent, const ntfschar *name,
411                                     const int name_len, const int name_type,
412                                     const s64 pos, const MFT_REF mref,
413                                     const unsigned dt_type)
414 {
415         struct readdir_ctx *ctx;
416         size_t utf8_name_len;
417         char *utf8_name;
418         struct dentry *child = NULL;
419         int ret;
420         size_t path_len;
421
422         if (name_type == FILE_NAME_DOS)
423                 return 0;
424
425         ret = -1;
426
427         utf8_name = utf16_to_utf8((const char*)name, name_len * 2,
428                                   &utf8_name_len);
429         if (!utf8_name)
430                 goto out;
431
432         if (utf8_name[0] == '.' &&
433              (utf8_name[1] == '\0' ||
434               (utf8_name[1] == '.' && utf8_name[2] == '\0'))) {
435                 ret = 0;
436                 goto out_free_utf8_name;
437         }
438
439         ctx = dirent;
440
441         ntfs_inode *ni = ntfs_inode_open(ctx->dir_ni->vol, mref);
442         if (!ni) {
443                 ERROR_WITH_ERRNO("Failed to open NTFS inode");
444                 ret = 1;
445         }
446         path_len = ctx->path_len;
447         if (path_len != 1)
448                 ctx->path[path_len++] = '/';
449         memcpy(ctx->path + path_len, utf8_name, utf8_name_len + 1);
450         path_len += utf8_name_len;
451         ret = build_dentry_tree_ntfs_recursive(&child, ni, ctx->path, path_len,
452                                                ctx->lookup_table, ctx->sd_set,
453                                                ctx->config, ctx->ntfs_vol_p,
454                                                ctx->flags);
455
456         if (child)
457                 link_dentry(child, ctx->parent);
458
459         ntfs_inode_close(ni);
460 out_free_utf8_name:
461         FREE(utf8_name);
462 out:
463         return ret;
464 }
465
466 /* Recursively build a WIM dentry tree corresponding to a NTFS volume.
467  * At the same time, update the WIM lookup table with lookup table entries for
468  * the NTFS streams, and build an array of security descriptors.
469  */
470 static int build_dentry_tree_ntfs_recursive(struct dentry **root_p,
471                                             ntfs_inode *ni,
472                                             char path[],
473                                             size_t path_len,
474                                             struct lookup_table *lookup_table,
475                                             struct sd_set *sd_set,
476                                             const struct capture_config *config,
477                                             ntfs_volume **ntfs_vol_p,
478                                             int flags)
479 {
480         u32 attributes;
481         int mrec_flags;
482         u32 sd_size = 0;
483         int ret = 0;
484         struct dentry *root;
485
486         mrec_flags = ni->mrec->flags;
487         attributes = ntfs_inode_get_attributes(ni);
488
489         if (exclude_path(path, config, false)) {
490                 if (flags & WIMLIB_ADD_IMAGE_FLAG_VERBOSE) {
491                         const char *file_type;
492                         if (attributes & MFT_RECORD_IS_DIRECTORY)
493                                 file_type = "directory";
494                         else
495                                 file_type = "file";
496                         printf("Excluding %s `%s' from capture\n",
497                                file_type, path);
498                 }
499                 *root_p = NULL;
500                 return 0;
501         }
502
503         if (flags & WIMLIB_ADD_IMAGE_FLAG_VERBOSE)
504                 printf("Scanning `%s'\n", path);
505
506         root = new_dentry(path_basename(path));
507         if (!root)
508                 return WIMLIB_ERR_NOMEM;
509
510         *root_p = root;
511         root->creation_time    = le64_to_cpu(ni->creation_time);
512         root->last_write_time  = le64_to_cpu(ni->last_data_change_time);
513         root->last_access_time = le64_to_cpu(ni->last_access_time);
514         root->attributes       = le32_to_cpu(attributes);
515         root->link_group_id    = ni->mft_no;
516         root->resolved         = true;
517
518         if (attributes & FILE_ATTR_REPARSE_POINT) {
519                 /* Junction point, symbolic link, or other reparse point */
520                 ret = capture_ntfs_streams(root, ni, path, path_len,
521                                            lookup_table, ntfs_vol_p,
522                                            AT_REPARSE_POINT);
523         } else if (mrec_flags & MFT_RECORD_IS_DIRECTORY) {
524
525                 /* Normal directory */
526                 s64 pos = 0;
527                 struct readdir_ctx ctx = {
528                         .parent       = root,
529                         .dir_ni       = ni,
530                         .path         = path,
531                         .path_len     = path_len,
532                         .lookup_table = lookup_table,
533                         .sd_set       = sd_set,
534                         .config       = config,
535                         .ntfs_vol_p   = ntfs_vol_p,
536                         .flags        = flags,
537                 };
538                 ret = ntfs_readdir(ni, &pos, &ctx, wim_ntfs_capture_filldir);
539                 if (ret != 0) {
540                         ERROR_WITH_ERRNO("ntfs_readdir()");
541                         ret = WIMLIB_ERR_NTFS_3G;
542                 }
543         } else {
544                 /* Normal file */
545                 ret = capture_ntfs_streams(root, ni, path, path_len,
546                                            lookup_table, ntfs_vol_p,
547                                            AT_DATA);
548         }
549         if (ret != 0)
550                 return ret;
551
552         ret = ntfs_inode_get_security(ni,
553                                       OWNER_SECURITY_INFORMATION |
554                                       GROUP_SECURITY_INFORMATION |
555                                       DACL_SECURITY_INFORMATION  |
556                                       SACL_SECURITY_INFORMATION,
557                                       NULL, 0, &sd_size);
558         char sd[sd_size];
559         ret = ntfs_inode_get_security(ni,
560                                       OWNER_SECURITY_INFORMATION |
561                                       GROUP_SECURITY_INFORMATION |
562                                       DACL_SECURITY_INFORMATION  |
563                                       SACL_SECURITY_INFORMATION,
564                                       sd, sd_size, &sd_size);
565         if (ret == 0) {
566                 ERROR_WITH_ERRNO("Failed to get security information from "
567                                  "`%s'", path);
568                 ret = WIMLIB_ERR_NTFS_3G;
569         } else {
570                 if (ret > 0) {
571                         /*print_security_descriptor(sd, sd_size);*/
572                         root->security_id = sd_set_add_sd(sd_set, sd, sd_size);
573                         if (root->security_id == -1) {
574                                 ERROR("Out of memory");
575                                 return WIMLIB_ERR_NOMEM;
576                         }
577                         DEBUG("Added security ID = %u for `%s'",
578                               root->security_id, path);
579                 } else { 
580                         root->security_id = -1;
581                         DEBUG("No security ID for `%s'", path);
582                 }
583                 ret = 0;
584         }
585         return ret;
586 }
587
588 static int build_dentry_tree_ntfs(struct dentry **root_p,
589                                   const char *device,
590                                   struct lookup_table *lookup_table,
591                                   struct wim_security_data *sd,
592                                   const struct capture_config *config,
593                                   int flags,
594                                   void *extra_arg)
595 {
596         ntfs_volume *vol;
597         ntfs_inode *root_ni;
598         int ret = 0;
599         struct sd_set sd_set = {
600                 .sd = sd,
601                 .root = NULL,
602         };
603         ntfs_volume **ntfs_vol_p = extra_arg;
604
605         DEBUG("Mounting NTFS volume `%s' read-only", device);
606         
607         vol = ntfs_mount(device, MS_RDONLY);
608         if (!vol) {
609                 ERROR_WITH_ERRNO("Failed to mount NTFS volume `%s' read-only",
610                                  device);
611                 return WIMLIB_ERR_NTFS_3G;
612         }
613         ntfs_open_secure(vol);
614
615         /* We don't want to capture the special NTFS files such as $Bitmap.  Not
616          * to be confused with "hidden" or "system" files which are real files
617          * that we do need to capture.  */
618         NVolClearShowSysFiles(vol);
619
620         DEBUG("Opening root NTFS dentry");
621         root_ni = ntfs_inode_open(vol, FILE_root);
622         if (!root_ni) {
623                 ERROR_WITH_ERRNO("Failed to open root inode of NTFS volume "
624                                  "`%s'", device);
625                 ret = WIMLIB_ERR_NTFS_3G;
626                 goto out;
627         }
628
629         /* Currently we assume that all the UTF-8 paths fit into this length and
630          * there is no check for overflow. */
631         char *path = MALLOC(32768);
632         if (!path) {
633                 ERROR("Could not allocate memory for NTFS pathname");
634                 goto out_cleanup;
635         }
636
637         path[0] = '/';
638         path[1] = '\0';
639         ret = build_dentry_tree_ntfs_recursive(root_p, root_ni, path, 1,
640                                                lookup_table, &sd_set,
641                                                config, ntfs_vol_p, flags);
642 out_cleanup:
643         FREE(path);
644         ntfs_inode_close(root_ni);
645         destroy_sd_set(&sd_set);
646
647 out:
648         if (ret) {
649                 if (ntfs_umount(vol, FALSE) != 0) {
650                         ERROR_WITH_ERRNO("Failed to unmount NTFS volume `%s'",
651                                          device);
652                         if (ret == 0)
653                                 ret = WIMLIB_ERR_NTFS_3G;
654                 }
655         } else {
656                 /* We need to leave the NTFS volume mounted so that we can read
657                  * the NTFS files again when we are actually writing the WIM */
658                 *ntfs_vol_p = vol;
659         }
660         return ret;
661 }
662
663
664
665 WIMLIBAPI int wimlib_add_image_from_ntfs_volume(WIMStruct *w,
666                                                 const char *device,
667                                                 const char *name,
668                                                 const char *config_str,
669                                                 size_t config_len,
670                                                 int flags)
671 {
672         if (flags & (WIMLIB_ADD_IMAGE_FLAG_DEREFERENCE)) {
673                 ERROR("Cannot dereference files when capturing directly from NTFS");
674                 return WIMLIB_ERR_INVALID_PARAM;
675         }
676         return do_add_image(w, device, name, config_str, config_len, flags,
677                             build_dentry_tree_ntfs, &w->ntfs_vol);
678 }
679
680 #else /* WITH_NTFS_3G */
681 WIMLIBAPI int wimlib_add_image_from_ntfs_volume(WIMStruct *w,
682                                                 const char *device,
683                                                 const char *name,
684                                                 const char *config_str,
685                                                 size_t config_len,
686                                                 int flags)
687 {
688         ERROR("wimlib was compiled without support for NTFS-3g, so");
689         ERROR("we cannot capture a WIM image directly from a NTFS volume");
690         return WIMLIB_ERR_UNSUPPORTED;
691 }
692 #endif /* WITH_NTFS_3G */