6 * Copyright (C) 2012, 2013 Eric Biggers
8 * This file is part of wimlib, a library for working with WIM files.
10 * wimlib is free software; you can redistribute it and/or modify it under the
11 * terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 3 of the License, or (at your option)
15 * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY
16 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 * A PARTICULAR PURPOSE. See the GNU General Public License for more
20 * You should have received a copy of the GNU General Public License
21 * along with wimlib; if not, see http://www.gnu.org/licenses/.
26 #if defined(__CYGWIN__) || defined(__WIN32__)
33 # include "security.h"
36 # include <sys/stat.h>
37 # include "timestamp.h"
44 #include "wimlib_internal.h"
46 #include "lookup_table.h"
63 #define WIMLIB_ADD_IMAGE_FLAG_ROOT 0x80000000
64 #define WIMLIB_ADD_IMAGE_FLAG_SOURCE 0x40000000
67 * Adds the dentry tree and security data for a new image to the image metadata
68 * array of the WIMStruct.
70 int add_new_dentry_tree(WIMStruct *w, struct wim_dentry *root_dentry,
71 struct wim_security_data *sd)
73 struct wim_lookup_table_entry *metadata_lte;
74 struct wim_image_metadata *imd;
75 struct wim_image_metadata *new_imd;
77 wimlib_assert(root_dentry != NULL);
79 DEBUG("Reallocating image metadata array for image_count = %u",
80 w->hdr.image_count + 1);
81 imd = CALLOC((w->hdr.image_count + 1), sizeof(struct wim_image_metadata));
84 ERROR("Failed to allocate memory for new image metadata array");
88 memcpy(imd, w->image_metadata,
89 w->hdr.image_count * sizeof(struct wim_image_metadata));
91 metadata_lte = new_lookup_table_entry();
95 metadata_lte->resource_entry.flags = WIM_RESHDR_FLAG_METADATA;
96 random_hash(metadata_lte->hash);
97 lookup_table_insert(w->lookup_table, metadata_lte);
99 new_imd = &imd[w->hdr.image_count];
101 new_imd->root_dentry = root_dentry;
102 new_imd->metadata_lte = metadata_lte;
103 new_imd->security_data = sd;
104 new_imd->modified = 1;
106 FREE(w->image_metadata);
107 w->image_metadata = imd;
108 w->hdr.image_count++;
113 return WIMLIB_ERR_NOMEM;
117 #if defined(__CYGWIN__) || defined(__WIN32__)
119 static u64 FILETIME_to_u64(const FILETIME *ft)
121 return ((u64)ft->dwHighDateTime << 32) | (u64)ft->dwLowDateTime;
125 static int build_dentry_tree(struct wim_dentry **root_ret,
126 const char *root_disk_path,
127 struct wim_lookup_table *lookup_table,
128 struct wim_security_data *sd,
129 const struct capture_config *config,
131 wimlib_progress_func_t progress_func,
134 static int win32_get_short_name(struct wim_dentry *dentry,
135 const wchar_t *path_utf16)
137 WIN32_FIND_DATAW dat;
138 if (FindFirstFileW(path_utf16, &dat) &&
139 dat.cAlternateFileName[0] != L'\0')
141 size_t short_name_len = wcslen(dat.cAlternateFileName) * 2;
142 size_t n = short_name_len + sizeof(wchar_t);
143 dentry->short_name = MALLOC(n);
144 if (!dentry->short_name)
145 return WIMLIB_ERR_NOMEM;
146 memcpy(dentry->short_name, dat.cAlternateFileName, n);
147 dentry->short_name_len = short_name_len;
152 static int win32_get_security_descriptor(struct wim_dentry *dentry,
153 struct sd_set *sd_set,
154 const wchar_t *path_utf16)
156 SECURITY_INFORMATION requestedInformation;
161 requestedInformation = DACL_SECURITY_INFORMATION |
162 SACL_SECURITY_INFORMATION |
163 OWNER_SECURITY_INFORMATION |
164 GROUP_SECURITY_INFORMATION;
165 /* Request length of security descriptor */
166 status = GetFileSecurityW(path_utf16, requestedInformation,
167 NULL, 0, &lenNeeded);
168 err = GetLastError();
169 if (!status && err == ERROR_INSUFFICIENT_BUFFER) {
170 DWORD len = lenNeeded;
172 if (GetFileSecurityW(path_utf16, requestedInformation,
173 (PSECURITY_DESCRIPTOR)buf, len, &lenNeeded))
175 int security_id = sd_set_add_sd(sd_set, buf, len);
177 return WIMLIB_ERR_NOMEM;
179 dentry->d_inode->i_security_id = security_id;
183 err = GetLastError();
186 ERROR("Win32 API: Failed to read security descriptor of \"%ls\"",
189 return WIMLIB_ERR_READ;
192 /* Reads the directory entries of directory using a Win32 API and recursively
193 * calls build_dentry_tree() on them. */
194 static int win32_recurse_directory(struct wim_dentry *root,
195 const char *root_disk_path,
196 struct wim_lookup_table *lookup_table,
197 struct wim_security_data *sd,
198 const struct capture_config *config,
200 wimlib_progress_func_t progress_func,
201 struct sd_set *sd_set,
202 const wchar_t *path_utf16,
203 size_t path_utf16_nchars)
205 WIN32_FIND_DATAW dat;
211 /* Begin reading the directory by calling FindFirstFileW.
212 * Unlike UNIX opendir(), FindFirstFileW has file globbing built
213 * into it. But this isn't what we actually want, so just add a
214 * dummy glob to get all entries. */
215 wchar_t pattern_buf[path_utf16_nchars + 3];
216 memcpy(pattern_buf, path_utf16,
217 path_utf16_nchars * sizeof(wchar_t));
218 pattern_buf[path_utf16_nchars] = L'/';
219 pattern_buf[path_utf16_nchars + 1] = L'*';
220 pattern_buf[path_utf16_nchars + 2] = L'\0';
221 hFind = FindFirstFileW(pattern_buf, &dat);
223 if (hFind == INVALID_HANDLE_VALUE) {
224 err = GetLastError();
225 if (err == ERROR_FILE_NOT_FOUND) {
228 ERROR("Win32 API: Failed to read directory \"%s\"",
231 return WIMLIB_ERR_READ;
236 /* Skip . and .. entries */
237 if (!(dat.cFileName[0] == L'.' &&
238 (dat.cFileName[1] == L'\0' ||
239 (dat.cFileName[1] == L'.' && dat.cFileName[2] == L'\0'))))
241 struct wim_dentry *child;
244 size_t utf8_name_nbytes;
245 ret = utf16_to_utf8((const char*)dat.cFileName,
246 wcslen(dat.cFileName) * sizeof(wchar_t),
252 char name[strlen(root_disk_path) + 1 + utf8_name_nbytes + 1];
253 sprintf(name, "%s/%s", root_disk_path, utf8_name);
255 ret = build_dentry_tree(&child, name, lookup_table,
256 sd, config, add_image_flags,
257 progress_func, sd_set);
261 dentry_add_child(root, child);
263 } while (FindNextFileW(hFind, &dat));
264 err = GetLastError();
265 if (err != ERROR_NO_MORE_FILES) {
266 ERROR("Win32 API: Failed to read directory \"%s\"", root_disk_path);
269 ret = WIMLIB_ERR_READ;
276 /* Load a reparse point into a WIM inode. It is just stored in memory.
278 * @hFile: Open handle to a reparse point, with permission to read the reparse
281 * @inode: WIM inode for the reparse point.
283 * @lookup_table: Stream lookup table for the WIM; an entry will be added to it
284 * for the reparse point unless an entry already exists for
285 * the exact same data stream.
287 * @path: External path to the parse point (UTF-8). Used for error messages
290 * Returns 0 on success; nonzero on failure. */
291 static int win32_capture_reparse_point(HANDLE hFile,
292 struct wim_inode *inode,
293 struct wim_lookup_table *lookup_table,
296 /* "Reparse point data, including the tag and optional GUID,
297 * cannot exceed 16 kilobytes." - MSDN */
298 char reparse_point_buf[16 * 1024];
301 if (!DeviceIoControl(hFile, FSCTL_GET_REPARSE_POINT,
302 NULL, 0, reparse_point_buf,
303 sizeof(reparse_point_buf), &bytesReturned, NULL))
305 DWORD err = GetLastError();
306 ERROR("Win32 API: Failed to get reparse data of \"%s\"", path);
308 return WIMLIB_ERR_READ;
310 if (bytesReturned < 8) {
311 ERROR("Reparse data on \"%s\" is invalid", path);
312 return WIMLIB_ERR_READ;
314 inode->i_reparse_tag = *(u32*)reparse_point_buf;
315 return inode_add_ads_with_data(inode, "",
316 (const u8*)reparse_point_buf + 8,
317 bytesReturned - 8, lookup_table);
320 /* Calculate the SHA1 message digest of a Win32 data stream, which may be either
321 * an unnamed or named data stream.
323 * @path: Path to the file, with the stream noted at the end for named
324 * streams. UTF-16LE encoding.
326 * @hash: On success, the SHA1 message digest of the stream is written to
329 * Returns 0 on success; nonzero on failure.
331 static int win32_sha1sum(const wchar_t *path, u8 hash[SHA1_HASH_SIZE])
339 hFile = win32_open_file_readonly(path);
340 if (hFile == INVALID_HANDLE_VALUE)
341 return WIMLIB_ERR_OPEN;
345 if (!ReadFile(hFile, buf, sizeof(buf), &bytesRead, NULL)) {
346 ret = WIMLIB_ERR_READ;
347 goto out_close_handle;
351 sha1_update(&ctx, buf, bytesRead);
354 sha1_final(hash, &ctx);
360 /* Scans an unnamed or named stream of a Win32 file (not a reparse point
361 * stream); calculates its SHA1 message digest and either creates a `struct
362 * wim_lookup_table_entry' in memory for it, or uses an existing 'struct
363 * wim_lookup_table_entry' for an identical stream.
365 * @path_utf16: Path to the file (UTF-16LE).
367 * @path_utf16_nchars: Number of 2-byte characters in @path_utf16.
369 * @inode: WIM inode to save the stream into.
371 * @lookup_table: Stream lookup table for the WIM.
373 * @dat: A `WIN32_FIND_STREAM_DATA' structure that specifies the
376 * Returns 0 on success; nonzero on failure.
378 static int win32_capture_stream(const wchar_t *path_utf16,
379 size_t path_utf16_nchars,
380 struct wim_inode *inode,
381 struct wim_lookup_table *lookup_table,
382 WIN32_FIND_STREAM_DATA *dat)
384 struct wim_ads_entry *ads_entry;
385 u8 hash[SHA1_HASH_SIZE];
386 struct wim_lookup_table_entry *lte;
389 bool is_named_stream;
394 /* The stream name should be returned as :NAME:TYPE */
395 p = dat->cStreamName;
397 goto out_invalid_stream_name;
399 colon = wcschr(p, L':');
401 goto out_invalid_stream_name;
403 if (wcscmp(colon + 1, L"$DATA")) {
404 /* Not a DATA stream */
409 is_named_stream = (p != colon);
410 if (is_named_stream) {
411 /* Allocate an ADS entry for the named stream. */
412 char *utf8_stream_name;
413 size_t utf8_stream_name_len;
414 ret = utf16_to_utf8((const char *)p,
415 (colon - p) * sizeof(wchar_t),
417 &utf8_stream_name_len);
420 ads_entry = inode_add_ads(inode, utf8_stream_name);
421 FREE(utf8_stream_name);
423 ret = WIMLIB_ERR_NOMEM;
428 /* Create a UTF-16 string @spath that gives the filename, then a colon,
429 * then the stream name. Or, if it's an unnamed stream, just the
430 * filename. It is MALLOC()'ed so that it can be saved in the
431 * wim_lookup_table_entry if needed. */
433 spath_nchars = path_utf16_nchars;
435 spath_nchars += colon - p + 1;
437 spath = MALLOC((spath_nchars + 1) * sizeof(wchar_t));
438 memcpy(spath, path_utf16, path_utf16_nchars * sizeof(wchar_t));
439 if (is_named_stream) {
440 spath[path_utf16_nchars] = L':';
441 memcpy(&spath[path_utf16_nchars + 1], p, (colon - p) * sizeof(wchar_t));
443 spath[spath_nchars] = L'\0';
445 ret = win32_sha1sum(spath, hash);
447 err = GetLastError();
448 ERROR("Win32 API: Failed to read \"%ls\" to calculate SHA1sum",
454 lte = __lookup_resource(lookup_table, hash);
456 /* Use existing wim_lookup_table_entry that has the same SHA1
460 /* Make a new wim_lookup_table_entry */
461 lte = new_lookup_table_entry();
463 ret = WIMLIB_ERR_NOMEM;
466 lte->file_on_disk = (char*)spath;
468 lte->resource_location = RESOURCE_WIN32;
469 lte->resource_entry.original_size = (uint64_t)dat->StreamSize.QuadPart;
470 lte->resource_entry.size = (uint64_t)dat->StreamSize.QuadPart;
471 copy_hash(lte->hash, hash);
472 lookup_table_insert(lookup_table, lte);
475 ads_entry->lte = lte;
482 out_invalid_stream_name:
483 ERROR("Invalid stream name: \"%ls:%ls\"", path_utf16, dat->cStreamName);
484 ret = WIMLIB_ERR_READ;
488 /* Scans a Win32 file for unnamed and named data streams (not reparse point
491 * @path_utf16: Path to the file (UTF-16LE).
493 * @path_utf16_nchars: Number of 2-byte characters in @path_utf16.
495 * @inode: WIM inode to save the stream into.
497 * @lookup_table: Stream lookup table for the WIM.
499 * Returns 0 on success; nonzero on failure.
501 static int win32_capture_streams(const wchar_t *path_utf16,
502 size_t path_utf16_nchars,
503 struct wim_inode *inode,
504 struct wim_lookup_table *lookup_table)
506 WIN32_FIND_STREAM_DATA dat;
511 hFind = FindFirstStreamW(path_utf16, FindStreamInfoStandard, &dat, 0);
512 if (hFind == INVALID_HANDLE_VALUE) {
513 err = GetLastError();
515 /* Seems legal for this to return ERROR_HANDLE_EOF on reparse
516 * points and directories */
517 if ((inode->i_attributes &
518 (FILE_ATTRIBUTE_REPARSE_POINT | FILE_ATTRIBUTE_DIRECTORY))
519 && err == ERROR_HANDLE_EOF)
523 ERROR("Win32 API: Failed to look up data streams of \"%ls\"",
526 return WIMLIB_ERR_READ;
530 ret = win32_capture_stream(path_utf16,
536 } while (FindNextStreamW(hFind, &dat));
537 err = GetLastError();
538 if (err != ERROR_HANDLE_EOF) {
539 ERROR("Win32 API: Error reading data streams from \"%ls\"", path_utf16);
541 ret = WIMLIB_ERR_READ;
551 * build_dentry_tree():
552 * Recursively builds a tree of WIM dentries from an on-disk directory
555 * @root_ret: Place to return a pointer to the root of the dentry tree. Only
556 * modified if successful. Set to NULL if the file or directory was
557 * excluded from capture.
559 * @root_disk_path: The path to the root of the directory tree on disk (UTF-8).
561 * @lookup_table: The lookup table for the WIM file. For each file added to the
562 * dentry tree being built, an entry is added to the lookup table,
563 * unless an identical stream is already in the lookup table.
564 * These lookup table entries that are added point to the path of
567 * @sd: Ignored. (Security data only captured in NTFS mode.)
570 * Configuration for files to be excluded from capture.
572 * @add_flags: Bitwise or of WIMLIB_ADD_IMAGE_FLAG_*
574 * @extra_arg: Ignored in UNIX builds; used to pass sd_set pointer in Windows
577 * @return: 0 on success, nonzero on failure. It is a failure if any of
578 * the files cannot be `stat'ed, or if any of the needed
579 * directories cannot be opened or read. Failure to add the files
580 * to the WIM may still occur later when trying to actually read
581 * the on-disk files during a call to wimlib_write() or
582 * wimlib_overwrite().
584 static int build_dentry_tree(struct wim_dentry **root_ret,
585 const char *root_disk_path,
586 struct wim_lookup_table *lookup_table,
587 struct wim_security_data *sd,
588 const struct capture_config *config,
590 wimlib_progress_func_t progress_func,
593 struct wim_dentry *root = NULL;
595 struct wim_inode *inode;
597 if (exclude_path(root_disk_path, config, true)) {
598 if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_ROOT) {
599 ERROR("Cannot exclude the root directory from capture");
600 ret = WIMLIB_ERR_INVALID_CAPTURE_CONFIG;
603 if ((add_image_flags & WIMLIB_ADD_IMAGE_FLAG_VERBOSE)
606 union wimlib_progress_info info;
607 info.scan.cur_path = root_disk_path;
608 info.scan.excluded = true;
609 progress_func(WIMLIB_PROGRESS_MSG_SCAN_DENTRY, &info);
614 if ((add_image_flags & WIMLIB_ADD_IMAGE_FLAG_VERBOSE)
617 union wimlib_progress_info info;
618 info.scan.cur_path = root_disk_path;
619 info.scan.excluded = false;
620 progress_func(WIMLIB_PROGRESS_MSG_SCAN_DENTRY, &info);
623 #if !defined(__CYGWIN__) && !defined(__WIN32__)
624 /* UNIX version of capturing a directory tree */
625 struct stat root_stbuf;
626 int (*stat_fn)(const char *restrict, struct stat *restrict);
627 if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_DEREFERENCE)
632 ret = (*stat_fn)(root_disk_path, &root_stbuf);
634 ERROR_WITH_ERRNO("Failed to stat `%s'", root_disk_path);
638 if ((add_image_flags & WIMLIB_ADD_IMAGE_FLAG_ROOT) &&
639 !S_ISDIR(root_stbuf.st_mode))
641 /* Do a dereference-stat in case the root is a symbolic link.
642 * This case is allowed, provided that the symbolic link points
644 ret = stat(root_disk_path, &root_stbuf);
646 ERROR_WITH_ERRNO("Failed to stat `%s'", root_disk_path);
647 ret = WIMLIB_ERR_STAT;
650 if (!S_ISDIR(root_stbuf.st_mode)) {
651 ERROR("`%s' is not a directory", root_disk_path);
652 ret = WIMLIB_ERR_NOTDIR;
656 if (!S_ISREG(root_stbuf.st_mode) && !S_ISDIR(root_stbuf.st_mode)
657 && !S_ISLNK(root_stbuf.st_mode)) {
658 ERROR("`%s' is not a regular file, directory, or symbolic link.",
660 ret = WIMLIB_ERR_SPECIAL_FILE;
664 root = new_dentry_with_timeless_inode(path_basename(root_disk_path));
667 ret = WIMLIB_ERR_INVALID_UTF8_STRING;
668 else if (errno == ENOMEM)
669 ret = WIMLIB_ERR_NOMEM;
671 ret = WIMLIB_ERR_ICONV_NOT_AVAILABLE;
675 inode = root->d_inode;
677 #ifdef HAVE_STAT_NANOSECOND_PRECISION
678 inode->i_creation_time = timespec_to_wim_timestamp(&root_stbuf.st_mtim);
679 inode->i_last_write_time = timespec_to_wim_timestamp(&root_stbuf.st_mtim);
680 inode->i_last_access_time = timespec_to_wim_timestamp(&root_stbuf.st_atim);
682 inode->i_creation_time = unix_timestamp_to_wim(root_stbuf.st_mtime);
683 inode->i_last_write_time = unix_timestamp_to_wim(root_stbuf.st_mtime);
684 inode->i_last_access_time = unix_timestamp_to_wim(root_stbuf.st_atime);
686 /* Leave the inode number at 0 for directories. */
687 if (!S_ISDIR(root_stbuf.st_mode)) {
688 if (sizeof(ino_t) >= 8)
689 inode->i_ino = (u64)root_stbuf.st_ino;
691 inode->i_ino = (u64)root_stbuf.st_ino |
692 ((u64)root_stbuf.st_dev <<
693 ((sizeof(ino_t) * 8) & 63));
695 inode->i_resolved = 1;
696 if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_UNIX_DATA) {
697 ret = inode_set_unix_data(inode, root_stbuf.st_uid,
701 UNIX_DATA_ALL | UNIX_DATA_CREATE);
705 add_image_flags &= ~(WIMLIB_ADD_IMAGE_FLAG_ROOT | WIMLIB_ADD_IMAGE_FLAG_SOURCE);
706 if (S_ISREG(root_stbuf.st_mode)) { /* Archiving a regular file */
708 struct wim_lookup_table_entry *lte;
709 u8 hash[SHA1_HASH_SIZE];
711 inode->i_attributes = FILE_ATTRIBUTE_NORMAL;
713 /* Empty files do not have to have a lookup table entry. */
714 if (root_stbuf.st_size == 0)
717 /* For each regular file, we must check to see if the file is in
718 * the lookup table already; if it is, we increment its refcnt;
719 * otherwise, we create a new lookup table entry and insert it.
722 ret = sha1sum(root_disk_path, hash);
726 lte = __lookup_resource(lookup_table, hash);
729 DEBUG("Add lte reference %u for `%s'", lte->refcnt,
732 char *file_on_disk = STRDUP(root_disk_path);
734 ERROR("Failed to allocate memory for file path");
735 ret = WIMLIB_ERR_NOMEM;
738 lte = new_lookup_table_entry();
741 ret = WIMLIB_ERR_NOMEM;
744 lte->file_on_disk = file_on_disk;
745 lte->resource_location = RESOURCE_IN_FILE_ON_DISK;
746 lte->resource_entry.original_size = root_stbuf.st_size;
747 lte->resource_entry.size = root_stbuf.st_size;
748 copy_hash(lte->hash, hash);
749 lookup_table_insert(lookup_table, lte);
751 root->d_inode->i_lte = lte;
752 } else if (S_ISDIR(root_stbuf.st_mode)) { /* Archiving a directory */
754 inode->i_attributes = FILE_ATTRIBUTE_DIRECTORY;
757 struct dirent entry, *result;
758 struct wim_dentry *child;
760 dir = opendir(root_disk_path);
762 ERROR_WITH_ERRNO("Failed to open the directory `%s'",
764 ret = WIMLIB_ERR_OPEN;
768 /* Buffer for names of files in directory. */
769 size_t len = strlen(root_disk_path);
770 char name[len + 1 + FILENAME_MAX + 1];
771 memcpy(name, root_disk_path, len);
774 /* Create a dentry for each entry in the directory on disk, and recurse
775 * to any subdirectories. */
778 ret = readdir_r(dir, &entry, &result);
780 ret = WIMLIB_ERR_READ;
781 ERROR_WITH_ERRNO("Error reading the "
788 if (result->d_name[0] == '.' && (result->d_name[1] == '\0'
789 || (result->d_name[1] == '.' && result->d_name[2] == '\0')))
791 strcpy(name + len + 1, result->d_name);
792 ret = build_dentry_tree(&child, name, lookup_table,
793 NULL, config, add_image_flags,
794 progress_func, NULL);
798 dentry_add_child(root, child);
801 } else { /* Archiving a symbolic link */
802 inode->i_attributes = FILE_ATTRIBUTE_REPARSE_POINT;
803 inode->i_reparse_tag = WIM_IO_REPARSE_TAG_SYMLINK;
805 /* The idea here is to call readlink() to get the UNIX target of
806 * the symbolic link, then turn the target into a reparse point
807 * data buffer that contains a relative or absolute symbolic
808 * link (NOT a junction point or *full* path symbolic link with
812 char deref_name_buf[4096];
813 ssize_t deref_name_len;
815 deref_name_len = readlink(root_disk_path, deref_name_buf,
816 sizeof(deref_name_buf) - 1);
817 if (deref_name_len >= 0) {
818 deref_name_buf[deref_name_len] = '\0';
819 DEBUG("Read symlink `%s'", deref_name_buf);
820 ret = inode_set_symlink(root->d_inode, deref_name_buf,
824 * Unfortunately, Windows seems to have the
825 * concept of "file" symbolic links as being
826 * different from "directory" symbolic links...
827 * so FILE_ATTRIBUTE_DIRECTORY needs to be set
828 * on the symbolic link if the *target* of the
829 * symbolic link is a directory.
832 if (stat(root_disk_path, &stbuf) == 0 &&
833 S_ISDIR(stbuf.st_mode))
835 inode->i_attributes |= FILE_ATTRIBUTE_DIRECTORY;
839 ERROR_WITH_ERRNO("Failed to read target of "
840 "symbolic link `%s'", root_disk_path);
841 ret = WIMLIB_ERR_READLINK;
845 /* Win32 version of capturing a directory tree */
848 size_t path_utf16_nchars;
849 struct sd_set *sd_set;
852 if (extra_arg == NULL) {
853 sd_set = alloca(sizeof(struct sd_set));
854 sd_set->rb_root.rb_node = NULL,
860 ret = utf8_to_utf16(root_disk_path, strlen(root_disk_path),
861 (char**)&path_utf16, &path_utf16_nchars);
863 goto out_destroy_sd_set;
864 path_utf16_nchars /= sizeof(wchar_t);
866 HANDLE hFile = win32_open_file_readonly(path_utf16);
867 if (hFile == INVALID_HANDLE_VALUE) {
868 err = GetLastError();
869 ERROR("Win32 API: Failed to open \"%s\"", root_disk_path);
871 ret = WIMLIB_ERR_OPEN;
872 goto out_free_path_utf16;
875 BY_HANDLE_FILE_INFORMATION file_info;
876 if (!GetFileInformationByHandle(hFile, &file_info)) {
877 err = GetLastError();
878 ERROR("Win32 API: Failed to get file information for \"%s\"",
881 ret = WIMLIB_ERR_STAT;
882 goto out_close_handle;
885 /* Create a WIM dentry */
886 root = new_dentry_with_timeless_inode(path_basename(root_disk_path));
889 ret = WIMLIB_ERR_INVALID_UTF8_STRING;
890 else if (errno == ENOMEM)
891 ret = WIMLIB_ERR_NOMEM;
893 ret = WIMLIB_ERR_ICONV_NOT_AVAILABLE;
894 goto out_close_handle;
897 /* Start preparing the associated WIM inode */
898 inode = root->d_inode;
900 inode->i_attributes = file_info.dwFileAttributes;
901 inode->i_creation_time = FILETIME_to_u64(&file_info.ftCreationTime);
902 inode->i_last_write_time = FILETIME_to_u64(&file_info.ftLastWriteTime);
903 inode->i_last_access_time = FILETIME_to_u64(&file_info.ftLastAccessTime);
904 inode->i_ino = ((u64)file_info.nFileIndexHigh << 32) |
905 (u64)file_info.nFileIndexLow;
907 inode->i_resolved = 1;
908 add_image_flags &= ~(WIMLIB_ADD_IMAGE_FLAG_ROOT | WIMLIB_ADD_IMAGE_FLAG_SOURCE);
910 /* Get DOS name and security descriptor (if any). */
911 ret = win32_get_short_name(root, path_utf16);
913 goto out_close_handle;
914 ret = win32_get_security_descriptor(root, sd_set, path_utf16);
916 goto out_close_handle;
918 if (inode_is_directory(inode)) {
919 /* Directory (not a reparse point) --- recurse to children */
921 /* But first... directories may have alternate data streams that
922 * need to be captured. */
923 ret = win32_capture_streams(path_utf16,
928 goto out_close_handle;
929 ret = win32_recurse_directory(root,
939 } else if (inode->i_attributes & FILE_ATTRIBUTE_REPARSE_POINT) {
940 /* Reparse point: save the reparse tag and data */
941 ret = win32_capture_reparse_point(hFile,
946 /* Not a directory, not a reparse point; capture the default
947 * file contents and any alternate data streams. */
948 ret = win32_capture_streams(path_utf16,
958 if (extra_arg == NULL)
959 destroy_sd_set(sd_set);
961 /* The below lines of code are common to both UNIX and Win32 builds. It
962 * simply returns the captured directory tree if the capture was
963 * successful, or frees it if the capture was unsuccessful. */
968 free_dentry_tree(root, lookup_table);
976 COMPRESSION_EXCLUSION_LIST,
980 #define COMPAT_DEFAULT_CONFIG
982 /* Default capture configuration file when none is specified. */
983 static const char *default_config =
984 #ifdef COMPAT_DEFAULT_CONFIG /* XXX: This policy is being moved to library
985 users. The next ABI-incompatible library
986 version will default to the empty string here. */
991 "\\System Volume Information\n"
995 "[CompressionExclusionList]\n"
999 "\\WINDOWS\\inf\\*.pnf\n";
1004 static void destroy_pattern_list(struct pattern_list *list)
1009 static void destroy_capture_config(struct capture_config *config)
1011 destroy_pattern_list(&config->exclusion_list);
1012 destroy_pattern_list(&config->exclusion_exception);
1013 destroy_pattern_list(&config->compression_exclusion_list);
1014 destroy_pattern_list(&config->alignment_list);
1015 FREE(config->config_str);
1016 FREE(config->prefix);
1017 memset(config, 0, sizeof(*config));
1020 static int pattern_list_add_pattern(struct pattern_list *list,
1021 const char *pattern)
1024 if (list->num_pats >= list->num_allocated_pats) {
1025 pats = REALLOC(list->pats,
1026 sizeof(list->pats[0]) * (list->num_allocated_pats + 8));
1028 return WIMLIB_ERR_NOMEM;
1029 list->num_allocated_pats += 8;
1032 list->pats[list->num_pats++] = pattern;
1036 /* Parses the contents of the image capture configuration file and fills in a
1037 * `struct capture_config'. */
1038 static int init_capture_config(struct capture_config *config,
1039 const char *_config_str, size_t config_len)
1045 size_t bytes_remaining;
1046 enum pattern_type type = NONE;
1048 unsigned long line_no = 0;
1050 DEBUG("config_len = %zu", config_len);
1051 bytes_remaining = config_len;
1052 memset(config, 0, sizeof(*config));
1053 config_str = MALLOC(config_len);
1055 ERROR("Could not duplicate capture config string");
1056 return WIMLIB_ERR_NOMEM;
1059 memcpy(config_str, _config_str, config_len);
1060 next_p = config_str;
1061 config->config_str = config_str;
1062 while (bytes_remaining) {
1065 eol = memchr(p, '\n', bytes_remaining);
1067 ERROR("Expected end-of-line in capture config file on "
1068 "line %lu", line_no);
1069 ret = WIMLIB_ERR_INVALID_CAPTURE_CONFIG;
1074 bytes_remaining -= (next_p - p);
1078 if (*(eol - 1) == '\r')
1082 /* Translate backslash to forward slash */
1083 for (char *pp = p; pp != eol; pp++)
1087 /* Remove drive letter */
1088 if (eol - p > 2 && isalpha(*p) && *(p + 1) == ':')
1092 if (strcmp(p, "[ExclusionList]") == 0)
1093 type = EXCLUSION_LIST;
1094 else if (strcmp(p, "[ExclusionException]") == 0)
1095 type = EXCLUSION_EXCEPTION;
1096 else if (strcmp(p, "[CompressionExclusionList]") == 0)
1097 type = COMPRESSION_EXCLUSION_LIST;
1098 else if (strcmp(p, "[AlignmentList]") == 0)
1099 type = ALIGNMENT_LIST;
1100 else if (p[0] == '[' && strrchr(p, ']')) {
1101 ERROR("Unknown capture configuration section `%s'", p);
1102 ret = WIMLIB_ERR_INVALID_CAPTURE_CONFIG;
1103 } else switch (type) {
1104 case EXCLUSION_LIST:
1105 DEBUG("Adding pattern \"%s\" to exclusion list", p);
1106 ret = pattern_list_add_pattern(&config->exclusion_list, p);
1108 case EXCLUSION_EXCEPTION:
1109 DEBUG("Adding pattern \"%s\" to exclusion exception list", p);
1110 ret = pattern_list_add_pattern(&config->exclusion_exception, p);
1112 case COMPRESSION_EXCLUSION_LIST:
1113 DEBUG("Adding pattern \"%s\" to compression exclusion list", p);
1114 ret = pattern_list_add_pattern(&config->compression_exclusion_list, p);
1116 case ALIGNMENT_LIST:
1117 DEBUG("Adding pattern \"%s\" to alignment list", p);
1118 ret = pattern_list_add_pattern(&config->alignment_list, p);
1121 ERROR("Line %lu of capture configuration is not "
1122 "in a block (such as [ExclusionList])",
1124 ret = WIMLIB_ERR_INVALID_CAPTURE_CONFIG;
1132 destroy_capture_config(config);
1136 static int capture_config_set_prefix(struct capture_config *config,
1137 const char *_prefix)
1139 char *prefix = STRDUP(_prefix);
1142 return WIMLIB_ERR_NOMEM;
1143 FREE(config->prefix);
1144 config->prefix = prefix;
1145 config->prefix_len = strlen(prefix);
1149 static bool path_matches_pattern(const char *path, const char *pattern)
1152 return PathMatchSpecA(path, pattern);
1154 return fnmatch(pattern, path, FNM_PATHNAME
1162 static bool match_pattern(const char *path, const char *path_basename,
1163 const struct pattern_list *list)
1165 for (size_t i = 0; i < list->num_pats; i++) {
1166 const char *pat = list->pats[i];
1169 /* Absolute path from root of capture */
1172 if (strchr(pat, '/'))
1173 /* Relative path from root of capture */
1176 /* A file name pattern */
1177 string = path_basename;
1180 if (path_matches_pattern(string, pat)) {
1181 DEBUG("`%s' matches the pattern \"%s\"",
1189 /* Return true if the image capture configuration file indicates we should
1190 * exclude the filename @path from capture.
1192 * If @exclude_prefix is %true, the part of the path up and including the name
1193 * of the directory being captured is not included in the path for matching
1194 * purposes. This allows, for example, a pattern like /hiberfil.sys to match a
1195 * file /mnt/windows7/hiberfil.sys if we are capturing the /mnt/windows7
1198 bool exclude_path(const char *path, const struct capture_config *config,
1199 bool exclude_prefix)
1201 const char *basename = path_basename(path);
1202 if (exclude_prefix) {
1203 wimlib_assert(strlen(path) >= config->prefix_len);
1204 if (memcmp(config->prefix, path, config->prefix_len) == 0
1205 && path[config->prefix_len] == '/')
1206 path += config->prefix_len;
1208 return match_pattern(path, basename, &config->exclusion_list) &&
1209 !match_pattern(path, basename, &config->exclusion_exception);
1213 /* Strip leading and trailing forward slashes from a string. Modifies it in
1214 * place and returns the stripped string. */
1215 static const char *canonicalize_target_path(char *target_path)
1218 if (target_path == NULL)
1221 if (*target_path == '\0')
1223 else if (*target_path == '/')
1229 p = target_path + strlen(target_path) - 1;
1235 #if defined(__CYGWIN__) || defined(__WIN32__)
1236 static void zap_backslashes(char *s)
1246 /* Strip leading and trailing slashes from the target paths */
1247 static void canonicalize_targets(struct wimlib_capture_source *sources,
1250 while (num_sources--) {
1251 DEBUG("Canonicalizing { source: \"%s\", target=\"%s\"}",
1252 sources->fs_source_path,
1253 sources->wim_target_path);
1254 #if defined(__CYGWIN__) || defined(__WIN32__)
1255 /* The Windows API can handle forward slashes. Just get rid of
1256 * backslashes to avoid confusing other parts of the library
1258 zap_backslashes(sources->fs_source_path);
1259 if (sources->wim_target_path)
1260 zap_backslashes(sources->wim_target_path);
1262 sources->wim_target_path =
1263 (char*)canonicalize_target_path(sources->wim_target_path);
1264 DEBUG("Canonical target: \"%s\"", sources->wim_target_path);
1269 static int capture_source_cmp(const void *p1, const void *p2)
1271 const struct wimlib_capture_source *s1 = p1, *s2 = p2;
1272 return strcmp(s1->wim_target_path, s2->wim_target_path);
1275 /* Sorts the capture sources lexicographically by target path. This occurs
1276 * after leading and trailing forward slashes are stripped.
1278 * One purpose of this is to make sure that target paths that are inside other
1279 * target paths are added after the containing target paths. */
1280 static void sort_sources(struct wimlib_capture_source *sources,
1283 qsort(sources, num_sources, sizeof(sources[0]), capture_source_cmp);
1286 static int check_sorted_sources(struct wimlib_capture_source *sources,
1287 size_t num_sources, int add_image_flags)
1289 if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_NTFS) {
1290 if (num_sources != 1) {
1291 ERROR("Must specify exactly 1 capture source "
1292 "(the NTFS volume) in NTFS mode!");
1293 return WIMLIB_ERR_INVALID_PARAM;
1295 if (sources[0].wim_target_path[0] != '\0') {
1296 ERROR("In NTFS capture mode the target path inside "
1297 "the image must be the root directory!");
1298 return WIMLIB_ERR_INVALID_PARAM;
1300 } else if (num_sources != 0) {
1301 /* This code is disabled because the current code
1302 * unconditionally attempts to do overlays. So, duplicate
1303 * target paths are OK. */
1305 if (num_sources > 1 && sources[0].wim_target_path[0] == '\0') {
1306 ERROR("Cannot specify root target when using multiple "
1307 "capture sources!");
1308 return WIMLIB_ERR_INVALID_PARAM;
1310 for (size_t i = 0; i < num_sources - 1; i++) {
1311 size_t len = strlen(sources[i].wim_target_path);
1313 const char *target1 = sources[i].wim_target_path;
1315 const char *target2 = sources[j].wim_target_path;
1316 DEBUG("target1=%s, target2=%s",
1318 if (strncmp(target1, target2, len) ||
1321 if (target2[len] == '/') {
1322 ERROR("Invalid target `%s': is a prefix of `%s'",
1324 return WIMLIB_ERR_INVALID_PARAM;
1326 if (target2[len] == '\0') {
1327 ERROR("Invalid target `%s': is a duplicate of `%s'",
1329 return WIMLIB_ERR_INVALID_PARAM;
1331 } while (++j != num_sources);
1339 /* Creates a new directory to place in the WIM image. This is to create parent
1340 * directories that are not part of any target as needed. */
1341 static struct wim_dentry *
1342 new_filler_directory(const char *name)
1344 struct wim_dentry *dentry;
1345 DEBUG("Creating filler directory \"%s\"", name);
1346 dentry = new_dentry_with_inode(name);
1348 /* Leave the inode number as 0 for now. The final inode number
1349 * will be assigned later by assign_inode_numbers(). */
1350 dentry->d_inode->i_resolved = 1;
1351 dentry->d_inode->i_attributes = FILE_ATTRIBUTE_DIRECTORY;
1356 /* Transfers the children of @branch to @target. It is an error if @target is
1357 * not a directory or if both @branch and @target contain a child dentry with
1359 static int do_overlay(struct wim_dentry *target, struct wim_dentry *branch)
1361 struct rb_root *rb_root;
1363 DEBUG("Doing overlay %s => %s",
1364 branch->file_name_utf8, target->file_name_utf8);
1366 if (!dentry_is_directory(target)) {
1367 ERROR("Cannot overlay directory `%s' over non-directory",
1368 branch->file_name_utf8);
1369 return WIMLIB_ERR_INVALID_OVERLAY;
1372 rb_root = &branch->d_inode->i_children;
1373 while (rb_root->rb_node) { /* While @branch has children... */
1374 struct wim_dentry *child = rbnode_dentry(rb_root->rb_node);
1375 /* Move @child to the directory @target */
1376 unlink_dentry(child);
1377 if (!dentry_add_child(target, child)) {
1378 /* Revert the change to avoid leaking the directory tree
1379 * rooted at @child */
1380 dentry_add_child(branch, child);
1381 ERROR("Overlay error: file `%s' already exists "
1382 "as a child of `%s'",
1383 child->file_name_utf8, target->file_name_utf8);
1384 return WIMLIB_ERR_INVALID_OVERLAY;
1387 free_dentry(branch);
1392 /* Attach or overlay a branch onto the WIM image.
1395 * Pointer to the root of the WIM image, or pointer to NULL if it has not
1400 * Path in the WIM image to add the branch, with leading and trailing
1403 static int attach_branch(struct wim_dentry **root_p,
1404 struct wim_dentry *branch,
1408 struct wim_dentry *dentry, *parent, *target;
1410 DEBUG("Attaching branch \"%s\" => \"%s\"",
1411 branch->file_name_utf8, target_path);
1413 if (*target_path == '\0') {
1414 /* Target: root directory */
1416 /* Overlay on existing root */
1417 return do_overlay(*root_p, branch);
1425 /* Adding a non-root branch. Create root if it hasn't been created
1428 *root_p = new_filler_directory("");
1430 return WIMLIB_ERR_NOMEM;
1433 /* Walk the path to the branch, creating filler directories as needed.
1436 while ((slash = strchr(target_path, '/'))) {
1438 dentry = get_dentry_child_with_name(parent, target_path);
1440 dentry = new_filler_directory(target_path);
1442 return WIMLIB_ERR_NOMEM;
1443 dentry_add_child(parent, dentry);
1446 target_path = slash;
1447 /* Skip over slashes. Note: this cannot overrun the length of
1448 * the string because the last character cannot be a slash, as
1449 * trailing slashes were tripped. */
1452 } while (*target_path == '/');
1455 /* If the target path already existed, overlay the branch onto it.
1456 * Otherwise, set the branch as the target path. */
1457 target = get_dentry_child_with_name(parent, branch->file_name_utf8);
1459 return do_overlay(target, branch);
1461 dentry_add_child(parent, branch);
1466 WIMLIBAPI int wimlib_add_image_multisource(WIMStruct *w,
1467 struct wimlib_capture_source *sources,
1470 const char *config_str,
1472 int add_image_flags,
1473 wimlib_progress_func_t progress_func)
1475 int (*capture_tree)(struct wim_dentry **, const char *,
1476 struct wim_lookup_table *,
1477 struct wim_security_data *,
1478 const struct capture_config *,
1479 int, wimlib_progress_func_t, void *);
1481 struct wim_dentry *root_dentry;
1482 struct wim_dentry *branch;
1483 struct wim_security_data *sd;
1484 struct capture_config config;
1485 struct wim_image_metadata *imd;
1488 if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_NTFS) {
1490 if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_DEREFERENCE) {
1491 ERROR("Cannot dereference files when capturing directly from NTFS");
1492 return WIMLIB_ERR_INVALID_PARAM;
1494 if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_UNIX_DATA) {
1495 ERROR("Capturing UNIX owner and mode not supported "
1496 "when capturing directly from NTFS");
1497 return WIMLIB_ERR_INVALID_PARAM;
1499 capture_tree = build_dentry_tree_ntfs;
1500 extra_arg = &w->ntfs_vol;
1502 ERROR("wimlib was compiled without support for NTFS-3g, so\n"
1503 " cannot capture a WIM image directly from a NTFS volume!");
1504 return WIMLIB_ERR_UNSUPPORTED;
1507 capture_tree = build_dentry_tree;
1511 #if defined(__CYGWIN__) || defined(__WIN32__)
1512 if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_UNIX_DATA) {
1513 ERROR("Capturing UNIX-specific data is not supported on Windows");
1514 return WIMLIB_ERR_INVALID_PARAM;
1516 if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_DEREFERENCE) {
1517 ERROR("Dereferencing symbolic links is not supported on Windows");
1518 return WIMLIB_ERR_INVALID_PARAM;
1522 if (!name || !*name) {
1523 ERROR("Must specify a non-empty string for the image name");
1524 return WIMLIB_ERR_INVALID_PARAM;
1527 if (w->hdr.total_parts != 1) {
1528 ERROR("Cannot add an image to a split WIM");
1529 return WIMLIB_ERR_SPLIT_UNSUPPORTED;
1532 if (wimlib_image_name_in_use(w, name)) {
1533 ERROR("There is already an image named \"%s\" in `%s'",
1535 return WIMLIB_ERR_IMAGE_NAME_COLLISION;
1539 DEBUG("Using default capture configuration");
1540 config_str = default_config;
1541 config_len = strlen(default_config);
1543 ret = init_capture_config(&config, config_str, config_len);
1547 DEBUG("Allocating security data");
1548 sd = CALLOC(1, sizeof(struct wim_security_data));
1550 ret = WIMLIB_ERR_NOMEM;
1551 goto out_destroy_capture_config;
1553 sd->total_length = 8;
1556 DEBUG("Using %zu capture sources", num_sources);
1557 canonicalize_targets(sources, num_sources);
1558 sort_sources(sources, num_sources);
1559 ret = check_sorted_sources(sources, num_sources, add_image_flags);
1561 ret = WIMLIB_ERR_INVALID_PARAM;
1562 goto out_free_security_data;
1565 DEBUG("Building dentry tree.");
1566 if (num_sources == 0) {
1567 root_dentry = new_filler_directory("");
1569 ret = WIMLIB_ERR_NOMEM;
1570 goto out_free_security_data;
1575 #if defined(__CYGWIN__) || defined(__WIN32__)
1576 win32_acquire_privilege(SE_BACKUP_NAME);
1577 win32_acquire_privilege(SE_SECURITY_NAME);
1578 win32_acquire_privilege(SE_TAKE_OWNERSHIP_NAME);
1584 union wimlib_progress_info progress;
1586 DEBUG("Building dentry tree for source %zu of %zu "
1587 "(\"%s\" => \"%s\")", i + 1, num_sources,
1588 sources[i].fs_source_path,
1589 sources[i].wim_target_path);
1590 if (progress_func) {
1591 memset(&progress, 0, sizeof(progress));
1592 progress.scan.source = sources[i].fs_source_path;
1593 progress.scan.wim_target_path = sources[i].wim_target_path;
1594 progress_func(WIMLIB_PROGRESS_MSG_SCAN_BEGIN, &progress);
1596 ret = capture_config_set_prefix(&config,
1597 sources[i].fs_source_path);
1599 goto out_free_dentry_tree;
1600 flags = add_image_flags | WIMLIB_ADD_IMAGE_FLAG_SOURCE;
1601 if (!*sources[i].wim_target_path)
1602 flags |= WIMLIB_ADD_IMAGE_FLAG_ROOT;
1603 ret = (*capture_tree)(&branch, sources[i].fs_source_path,
1604 w->lookup_table, sd,
1607 progress_func, extra_arg);
1609 ERROR("Failed to build dentry tree for `%s'",
1610 sources[i].fs_source_path);
1611 goto out_free_dentry_tree;
1614 /* Use the target name, not the source name, for
1615 * the root of each branch from a capture
1616 * source. (This will also set the root dentry
1617 * of the entire image to be unnamed.) */
1618 ret = set_dentry_name(branch,
1619 path_basename(sources[i].wim_target_path));
1621 goto out_free_branch;
1623 ret = attach_branch(&root_dentry, branch,
1624 sources[i].wim_target_path);
1626 goto out_free_branch;
1629 progress_func(WIMLIB_PROGRESS_MSG_SCAN_END, &progress);
1630 } while (++i != num_sources);
1633 DEBUG("Calculating full paths of dentries.");
1634 ret = for_dentry_in_tree(root_dentry, calculate_dentry_full_path, NULL);
1636 goto out_free_dentry_tree;
1638 ret = add_new_dentry_tree(w, root_dentry, sd);
1640 goto out_free_dentry_tree;
1642 imd = &w->image_metadata[w->hdr.image_count - 1];
1644 ret = dentry_tree_fix_inodes(root_dentry, &imd->inode_list);
1646 goto out_destroy_imd;
1648 DEBUG("Assigning hard link group IDs");
1649 assign_inode_numbers(&imd->inode_list);
1651 ret = xml_add_image(w, name);
1653 goto out_destroy_imd;
1655 if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_BOOT)
1656 wimlib_set_boot_idx(w, w->hdr.image_count);
1658 goto out_destroy_capture_config;
1660 destroy_image_metadata(&w->image_metadata[w->hdr.image_count - 1],
1662 w->hdr.image_count--;
1665 free_dentry_tree(branch, w->lookup_table);
1666 out_free_dentry_tree:
1667 free_dentry_tree(root_dentry, w->lookup_table);
1668 out_free_security_data:
1669 free_security_data(sd);
1670 out_destroy_capture_config:
1671 destroy_capture_config(&config);
1673 #if defined(__CYGWIN__) || defined(__WIN32__)
1674 win32_release_privilege(SE_BACKUP_NAME);
1675 win32_release_privilege(SE_SECURITY_NAME);
1676 win32_release_privilege(SE_TAKE_OWNERSHIP_NAME);
1681 WIMLIBAPI int wimlib_add_image(WIMStruct *w, const char *source,
1682 const char *name, const char *config_str,
1683 size_t config_len, int add_image_flags,
1684 wimlib_progress_func_t progress_func)
1686 if (!source || !*source)
1687 return WIMLIB_ERR_INVALID_PARAM;
1689 char *fs_source_path = STRDUP(source);
1691 struct wimlib_capture_source capture_src = {
1692 .fs_source_path = fs_source_path,
1693 .wim_target_path = NULL,
1696 ret = wimlib_add_image_multisource(w, &capture_src, 1, name,
1697 config_str, config_len,
1698 add_image_flags, progress_func);
1699 FREE(fs_source_path);