*/
/*
- * Copyright (C) 2013-2016 Eric Biggers
+ * Copyright (C) 2013-2017 Eric Biggers
*
* This file is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
};
static inline const wchar_t *
-printable_path(const wchar_t *full_path)
+printable_path(const struct winnt_scan_ctx *ctx)
{
/* Skip over \\?\ or \??\ */
- return full_path + 4;
+ return ctx->params->cur_path + 4;
}
/* Description of where data is located on a Windows filesystem */
static int
read_winnt_stream_prefix(const struct windows_file *file,
- u64 size, const struct read_blob_callbacks *cbs)
+ u64 size, const struct consume_chunk_callback *cb)
{
IO_STATUS_BLOCK iosb;
UNICODE_STRING name = {
bytes_read = iosb.Information;
bytes_remaining -= bytes_read;
- ret = call_consume_chunk(buf, bytes_read, cbs);
+ ret = consume_chunk(cb, buf, bytes_read);
if (ret)
break;
}
}
struct win32_encrypted_read_ctx {
- const struct read_blob_callbacks *cbs;
+ const struct consume_chunk_callback *cb;
int wimlib_err_code;
u64 bytes_remaining;
};
if (bytes_to_consume == 0)
return ERROR_SUCCESS;
- ret = call_consume_chunk(data, bytes_to_consume, ctx->cbs);
+ ret = consume_chunk(ctx->cb, data, bytes_to_consume);
if (ret) {
ctx->wimlib_err_code = ret;
/* It doesn't matter what error code is returned here, as long
static int
read_win32_encrypted_file_prefix(const wchar_t *path, bool is_dir, u64 size,
- const struct read_blob_callbacks *cbs)
+ const struct consume_chunk_callback *cb)
{
struct win32_encrypted_read_ctx export_ctx;
DWORD err;
if (is_dir)
flags |= CREATE_FOR_DIR;
- export_ctx.cbs = cbs;
+ export_ctx.cb = cb;
export_ctx.wimlib_err_code = 0;
export_ctx.bytes_remaining = size;
if (err != ERROR_SUCCESS) {
win32_error(err,
L"Failed to open encrypted file \"%ls\" for raw read",
- printable_path(path));
+ path);
return WIMLIB_ERR_OPEN;
}
err = ReadEncryptedFileRaw(win32_encrypted_export_cb,
if (ret == 0) {
win32_error(err,
L"Failed to read encrypted file \"%ls\"",
- printable_path(path));
+ path);
ret = WIMLIB_ERR_READ;
}
} else if (export_ctx.bytes_remaining != 0) {
ERROR("Only could read %"PRIu64" of %"PRIu64" bytes from "
"encrypted file \"%ls\"",
size - export_ctx.bytes_remaining, size,
- printable_path(path));
+ path);
ret = WIMLIB_ERR_READ;
} else {
ret = 0;
* described by @blob. */
int
read_windows_file_prefix(const struct blob_descriptor *blob, u64 size,
- const struct read_blob_callbacks *cbs)
+ const struct consume_chunk_callback *cb)
{
const struct windows_file *file = blob->windows_file;
if (unlikely(file->is_encrypted)) {
bool is_dir = (blob->file_inode->i_attributes & FILE_ATTRIBUTE_DIRECTORY);
- return read_win32_encrypted_file_prefix(file->path, is_dir, size, cbs);
+ return read_win32_encrypted_file_prefix(file->path, is_dir, size, cb);
}
- return read_winnt_stream_prefix(file, size, cbs);
+ return read_winnt_stream_prefix(file, size, cb);
}
/*
*/
static noinline_for_stack int
winnt_load_security_descriptor(HANDLE h, struct wim_inode *inode,
- const wchar_t *full_path,
struct winnt_scan_ctx *ctx)
{
SECURITY_INFORMATION requestedInformation;
FREE(buf);
if (!NT_SUCCESS(status)) {
winnt_error(status, L"\"%ls\": Can't read security descriptor",
- printable_path(full_path));
+ printable_path(ctx));
return WIMLIB_ERR_STAT;
}
return 0;
/* Load a file's object ID into the corresponding WIM inode. */
static noinline_for_stack int
winnt_load_object_id(HANDLE h, struct wim_inode *inode,
- const wchar_t *full_path, struct winnt_scan_ctx *ctx)
+ struct winnt_scan_ctx *ctx)
{
FILE_OBJECTID_BUFFER buffer;
NTSTATUS status;
if (!NT_SUCCESS(status)) {
winnt_error(status, L"\"%ls\": Can't read object ID",
- printable_path(full_path));
+ printable_path(ctx));
return WIMLIB_ERR_STAT;
}
static int
winnt_build_dentry_tree_recursive(struct wim_dentry **root_ret,
HANDLE cur_dir,
- wchar_t *full_path,
- size_t full_path_nchars,
- wchar_t *relative_path,
+ const wchar_t *relative_path,
size_t relative_path_nchars,
const wchar_t *filename,
struct winnt_scan_ctx *ctx);
static int
winnt_recurse_directory(HANDLE h,
- wchar_t *full_path,
- size_t full_path_nchars,
struct wim_dentry *parent,
struct winnt_scan_ctx *ctx)
{
if (!should_ignore_filename(info->FileName,
info->FileNameLength / 2))
{
- wchar_t *p;
- wchar_t *filename;
struct wim_dentry *child;
-
- p = full_path + full_path_nchars;
- /* Only add a backslash if we don't already have
- * one. This prevents a duplicate backslash
- * from being added when the path to the capture
- * dir had a trailing backslash. */
- if (*(p - 1) != L'\\')
- *p++ = L'\\';
- filename = p;
- p = wmempcpy(filename, info->FileName,
- info->FileNameLength / 2);
- *p = '\0';
+ size_t orig_path_nchars;
+ const wchar_t *filename;
+
+ ret = WIMLIB_ERR_NOMEM;
+ filename = pathbuf_append_name(ctx->params,
+ info->FileName,
+ info->FileNameLength / 2,
+ &orig_path_nchars);
+ if (!filename)
+ goto out_free_buf;
ret = winnt_build_dentry_tree_recursive(
&child,
h,
- full_path,
- p - full_path,
filename,
info->FileNameLength / 2,
filename,
ctx);
- full_path[full_path_nchars] = L'\0';
+ pathbuf_truncate(ctx->params, orig_path_nchars);
if (ret)
goto out_free_buf;
if (unlikely(status != STATUS_NO_MORE_FILES)) {
winnt_error(status, L"\"%ls\": Can't read directory",
- printable_path(full_path));
+ printable_path(ctx));
ret = WIMLIB_ERR_READ;
}
out_free_buf:
}
static int
-winnt_rpfix_progress(struct scan_params *params, const wchar_t *path,
+winnt_rpfix_progress(struct scan_params *params,
const struct link_reparse_point *link, int scan_status)
{
size_t print_name_nchars = link->print_name_nbytes / sizeof(wchar_t);
wmemcpy(print_name0, link->print_name, print_name_nchars);
print_name0[print_name_nchars] = L'\0';
- params->progress.scan.cur_path = path;
params->progress.scan.symlink_target = print_name0;
return do_scan_progress(params, scan_status, NULL);
}
static int
winnt_try_rpfix(struct reparse_buffer_disk *rpbuf, u16 *rpbuflen_p,
- const wchar_t *path, struct scan_params *params)
+ struct scan_params *params)
{
struct link_reparse_point link;
const wchar_t *rel_target;
if (rel_target == link.substitute_name) {
/* Target points outside of the tree being captured or had an
* unrecognized path format. Don't adjust it. */
- return winnt_rpfix_progress(params, path, &link,
+ return winnt_rpfix_progress(params, &link,
WIMLIB_SCAN_DENTRY_NOT_FIXED_SYMLINK);
}
if (make_link_reparse_point(&link, rpbuf, rpbuflen_p))
return 0;
- ret = winnt_rpfix_progress(params, path, &link,
+ ret = winnt_rpfix_progress(params, &link,
WIMLIB_SCAN_DENTRY_FIXED_SYMLINK);
if (ret)
return ret;
* capture root. */
static noinline_for_stack int
winnt_load_reparse_data(HANDLE h, struct wim_inode *inode,
- const wchar_t *full_path, struct scan_params *params)
+ struct winnt_scan_ctx *ctx)
{
struct reparse_buffer_disk rpbuf;
NTSTATUS status;
if (inode->i_attributes & FILE_ATTRIBUTE_ENCRYPTED) {
/* See comment above assign_stream_types_encrypted() */
WARNING("Ignoring reparse data of encrypted file \"%ls\"",
- printable_path(full_path));
+ printable_path(ctx));
return 0;
}
NULL, 0, &rpbuf, sizeof(rpbuf), &len);
if (!NT_SUCCESS(status)) {
winnt_error(status, L"\"%ls\": Can't get reparse point",
- printable_path(full_path));
+ printable_path(ctx));
return WIMLIB_ERR_READLINK;
}
if (unlikely(rpbuflen < REPARSE_DATA_OFFSET)) {
ERROR("\"%ls\": reparse point buffer is too short",
- printable_path(full_path));
+ printable_path(ctx));
return WIMLIB_ERR_INVALID_REPARSE_DATA;
}
- if (params->add_flags & WIMLIB_ADD_FLAG_RPFIX) {
- ret = winnt_try_rpfix(&rpbuf, &rpbuflen, full_path, params);
+ if (le32_to_cpu(rpbuf.rptag) == WIM_IO_REPARSE_TAG_DEDUP) {
+ /*
+ * Windows treats Data Deduplication reparse points specially.
+ * Reads from the unnamed data stream actually return the
+ * redirected file contents, even with FILE_OPEN_REPARSE_POINT.
+ * Deduplicated files also cannot be properly restored without
+ * also restoring the "System Volume Information" directory,
+ * which wimlib excludes by default. Therefore, the logical
+ * behavior for us seems to be to ignore the reparse point and
+ * treat the file as a normal file.
+ */
+ inode->i_attributes &= ~FILE_ATTRIBUTE_REPARSE_POINT;
+ return 0;
+ }
+
+ if (ctx->params->add_flags & WIMLIB_ADD_FLAG_RPFIX) {
+ ret = winnt_try_rpfix(&rpbuf, &rpbuflen, ctx->params);
if (ret == RP_FIXED)
inode->i_rp_flags &= ~WIM_RP_FLAG_NOT_FIXED;
else if (ret)
NO_STREAM_NAME,
rpbuf.rpdata,
rpbuflen - REPARSE_DATA_OFFSET,
- params->blob_table))
+ ctx->params->blob_table))
return WIMLIB_ERR_NOMEM;
return 0;
if (err != ERROR_SUCCESS) {
win32_error(err,
L"Failed to open encrypted file \"%ls\" for raw read",
- printable_path(path));
+ path);
return WIMLIB_ERR_OPEN;
}
*size_ret = 0;
if (err != ERROR_SUCCESS) {
win32_error(err,
L"Failed to read raw encrypted data from \"%ls\"",
- printable_path(path));
+ path);
ret = WIMLIB_ERR_READ;
} else {
ret = 0;
static int
winnt_scan_efsrpc_raw_data(struct wim_inode *inode,
- wchar_t *path, size_t path_nchars,
struct winnt_scan_ctx *ctx)
{
+ wchar_t *path = ctx->params->cur_path;
+ size_t path_nchars = ctx->params->cur_path_nchars;
const bool is_dir = (inode->i_attributes & FILE_ATTRIBUTE_DIRECTORY);
struct windows_file *windows_file;
u64 size;
}
static int
-winnt_scan_data_stream(const wchar_t *path, size_t path_nchars,
- wchar_t *raw_stream_name, size_t raw_stream_name_nchars,
+winnt_scan_data_stream(wchar_t *raw_stream_name, size_t raw_stream_name_nchars,
u64 stream_size, struct wim_inode *inode,
struct winnt_scan_ctx *ctx)
{
stream_name[stream_name_nchars] = L'\0';
- windows_file = alloc_windows_file(path, path_nchars,
+ windows_file = alloc_windows_file(ctx->params->cur_path,
+ ctx->params->cur_path_nchars,
stream_name, stream_name_nchars,
ctx->snapshot, false);
return add_stream(inode, windows_file, stream_size, STREAM_TYPE_DATA,
* already present in Windows XP.
*/
static noinline_for_stack int
-winnt_scan_data_streams(HANDLE h, const wchar_t *path, size_t path_nchars,
- struct wim_inode *inode, u64 file_size,
+winnt_scan_data_streams(HANDLE h, struct wim_inode *inode, u64 file_size,
struct winnt_scan_ctx *ctx)
{
int ret;
default:
winnt_error(status,
L"\"%ls\": Failed to query stream information",
- printable_path(path));
+ printable_path(ctx));
ret = WIMLIB_ERR_READ;
goto out_free_buf;
}
info = (FILE_STREAM_INFORMATION *)buf;
for (;;) {
/* Load the stream information. */
- ret = winnt_scan_data_stream(path, path_nchars,
- info->StreamName,
+ ret = winnt_scan_data_stream(info->StreamName,
info->StreamNameLength / 2,
info->StreamSize.QuadPart,
inode, ctx);
{
wchar_t stream_name[] = L"::$DATA";
- ret = winnt_scan_data_stream(path, path_nchars, stream_name, 7,
- file_size, inode, ctx);
+ ret = winnt_scan_data_stream(stream_name, 7, file_size,
+ inode, ctx);
}
out_free_buf:
/* Free buffer if allocated on heap. */
static inline bool
should_try_to_use_wimboot_hash(const struct wim_inode *inode,
- const struct winnt_scan_ctx *ctx,
- const struct scan_params *params)
+ const struct winnt_scan_ctx *ctx)
{
/* Directories and encrypted files aren't valid for external backing. */
if (inode->i_attributes & (FILE_ATTRIBUTE_DIRECTORY |
* fixup if WOF may be attached. */
if (inode->i_attributes & FILE_ATTRIBUTE_REPARSE_POINT)
return (inode->i_reparse_tag == WIM_IO_REPARSE_TAG_WOF) &&
- (params->add_flags & WIMLIB_ADD_FLAG_WIMBOOT);
+ (ctx->params->add_flags & WIMLIB_ADD_FLAG_WIMBOOT);
return !ctx->wof_not_attached;
}
*/
static noinline_for_stack int
try_to_use_wimboot_hash(HANDLE h, struct wim_inode *inode,
- struct winnt_scan_ctx *ctx, const wchar_t *full_path)
+ struct winnt_scan_ctx *ctx)
{
struct blob_table *blob_table = ctx->params->blob_table;
struct wim_inode_stream *reparse_strm = NULL;
if (status != STATUS_SUCCESS) {
winnt_error(status,
L"\"%ls\": FSCTL_GET_EXTERNAL_BACKING failed",
- full_path);
+ printable_path(ctx));
return WIMLIB_ERR_STAT;
}
}
static void
-get_volume_information(HANDLE h, const wchar_t *full_path,
- struct winnt_scan_ctx *ctx)
+get_volume_information(HANDLE h, struct winnt_scan_ctx *ctx)
{
u8 _attr_info[sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + 128] _aligned_attribute(8);
FILE_FS_ATTRIBUTE_INFORMATION *attr_info = (void *)_attr_info;
!wmemcmp(attr_info->FileSystemName, L"NTFS", 4);
} else {
winnt_warning(status, L"\"%ls\": Can't get volume attributes",
- printable_path(full_path));
+ printable_path(ctx));
}
/* Get volume ID. */
ctx->params->capture_root_dev = vol_info.VolumeSerialNumber;
} else {
winnt_warning(status, L"\"%ls\": Can't get volume ID",
- printable_path(full_path));
+ printable_path(ctx));
}
/* Get inode number. */
ctx->params->capture_root_ino = file_info.ino;
} else {
winnt_warning(status, L"\"%ls\": Can't get file information",
- printable_path(full_path));
+ printable_path(ctx));
}
}
static int
winnt_build_dentry_tree_recursive(struct wim_dentry **root_ret,
HANDLE cur_dir,
- wchar_t *full_path,
- size_t full_path_nchars,
- wchar_t *relative_path,
+ const wchar_t *relative_path,
size_t relative_path_nchars,
const wchar_t *filename,
struct winnt_scan_ctx *ctx)
struct file_info file_info;
u64 sort_key;
- ret = try_exclude(full_path, ctx->params);
+ ret = try_exclude(ctx->params);
if (unlikely(ret < 0)) /* Excluded? */
goto out_progress;
if (unlikely(ret > 0)) /* Error? */
if (unlikely(!NT_SUCCESS(status))) {
if (status == STATUS_DELETE_PENDING) {
WARNING("\"%ls\": Deletion pending; skipping file",
- printable_path(full_path));
+ printable_path(ctx));
ret = 0;
goto out;
}
ERROR("Can't open \"%ls\":\n"
" File is in use by another process! "
"Consider using snapshot (VSS) mode.",
- printable_path(full_path));
+ printable_path(ctx));
ret = WIMLIB_ERR_OPEN;
goto out;
}
winnt_error(status, L"\"%ls\": Can't open file",
- printable_path(full_path));
+ printable_path(ctx));
if (status == STATUS_FVE_LOCKED_VOLUME)
ret = WIMLIB_ERR_FVE_LOCKED_VOLUME;
else
status = get_file_info(h, &file_info);
if (!NT_SUCCESS(status)) {
winnt_error(status, L"\"%ls\": Can't get file information",
- printable_path(full_path));
+ printable_path(ctx));
ret = WIMLIB_ERR_STAT;
goto out;
}
if (!(ctx->params->add_flags & WIMLIB_ADD_FLAG_NO_ACLS)
&& (ctx->vol_flags & FILE_PERSISTENT_ACLS))
{
- ret = winnt_load_security_descriptor(h, inode, full_path, ctx);
+ ret = winnt_load_security_descriptor(h, inode, ctx);
if (ret)
goto out;
}
/* Get the file's object ID. */
- ret = winnt_load_object_id(h, inode, full_path, ctx);
+ ret = winnt_load_object_id(h, inode, ctx);
if (ret)
goto out;
/* If this is a reparse point, load the reparse data. */
if (unlikely(inode->i_attributes & FILE_ATTRIBUTE_REPARSE_POINT)) {
- ret = winnt_load_reparse_data(h, inode, full_path, ctx->params);
+ ret = winnt_load_reparse_data(h, inode, ctx);
if (ret)
goto out;
}
* needed. */
NtClose(h);
h = NULL;
- ret = winnt_scan_efsrpc_raw_data(inode, full_path,
- full_path_nchars, ctx);
+ ret = winnt_scan_efsrpc_raw_data(inode, ctx);
if (ret)
goto out;
} else {
* the EFSRPC data and the named data stream(s)...!
*/
ret = winnt_scan_data_streams(h,
- full_path,
- full_path_nchars,
inode,
file_info.end_of_file,
ctx);
goto out;
}
- if (unlikely(should_try_to_use_wimboot_hash(inode, ctx, ctx->params))) {
- ret = try_to_use_wimboot_hash(h, inode, ctx, full_path);
+ if (unlikely(should_try_to_use_wimboot_hash(inode, ctx))) {
+ ret = try_to_use_wimboot_hash(h, inode, ctx);
if (ret)
goto out;
}
&h);
if (!NT_SUCCESS(status)) {
winnt_error(status, L"\"%ls\": Can't open directory",
- printable_path(full_path));
+ printable_path(ctx));
ret = WIMLIB_ERR_OPEN;
goto out;
}
- ret = winnt_recurse_directory(h,
- full_path,
- full_path_nchars,
- root,
- ctx);
+ ret = winnt_recurse_directory(h, root, ctx);
if (ret)
goto out;
}
out_progress:
- ctx->params->progress.scan.cur_path = full_path;
if (likely(root))
ret = do_scan_progress(ctx->params, WIMLIB_SCAN_DENTRY_OK, inode);
else
if (unlikely(ret)) {
free_dentry_tree(root, ctx->params->blob_table);
root = NULL;
- ret = report_scan_error(ctx->params, ret, full_path);
+ ret = report_scan_error(ctx->params, ret);
}
*root_ret = root;
return ret;
QUERY_FILE_LAYOUT_INCLUDE_STREAMS_WITH_NO_CLUSTERS_ALLOCATED,
.FilterType = QUERY_FILE_LAYOUT_FILTER_TYPE_NONE,
};
- const size_t outsize = 32768;
+ size_t outsize = 32768;
QUERY_FILE_LAYOUT_OUTPUT *out = NULL;
int ret;
NTSTATUS status;
goto out;
}
- out = MALLOC(outsize);
- if (!out) {
- ret = WIMLIB_ERR_NOMEM;
- goto out;
- }
+ for (;;) {
+ /* Allocate a buffer for the output of the ioctl. */
+ out = MALLOC(outsize);
+ if (!out) {
+ ret = WIMLIB_ERR_NOMEM;
+ goto out;
+ }
- while (NT_SUCCESS(status = winnt_fsctl(h, FSCTL_QUERY_FILE_LAYOUT,
- &in, sizeof(in),
- out, outsize, NULL)))
- {
- const FILE_LAYOUT_ENTRY *file =
- (const void *)out + out->FirstFileOffset;
- for (;;) {
- ret = load_one_file(file, inode_map);
- if (ret)
- goto out;
- if (file->NextFileOffset == 0)
- break;
- file = (const void *)file + file->NextFileOffset;
+ /* Execute FSCTL_QUERY_FILE_LAYOUT until it fails. */
+ while (NT_SUCCESS(status = winnt_fsctl(h,
+ FSCTL_QUERY_FILE_LAYOUT,
+ &in, sizeof(in),
+ out, outsize, NULL)))
+ {
+ const FILE_LAYOUT_ENTRY *file =
+ (const void *)out + out->FirstFileOffset;
+ for (;;) {
+ ret = load_one_file(file, inode_map);
+ if (ret)
+ goto out;
+ if (file->NextFileOffset == 0)
+ break;
+ file = (const void *)file + file->NextFileOffset;
+ }
+ in.Flags &= ~QUERY_FILE_LAYOUT_RESTART;
}
- in.Flags &= ~QUERY_FILE_LAYOUT_RESTART;
+
+ /* Enlarge the buffer if needed. */
+ if (status != STATUS_BUFFER_TOO_SMALL)
+ break;
+ FREE(out);
+ outsize *= 2;
}
/* Normally, FSCTL_QUERY_FILE_LAYOUT fails with STATUS_END_OF_FILE after
*/
static int
generate_wim_structures_recursive(struct wim_dentry **root_ret,
- wchar_t *path, size_t path_nchars,
const wchar_t *filename, bool is_primary_name,
struct ntfs_inode *ni,
struct winnt_scan_ctx *ctx,
{
ret = winnt_build_dentry_tree_recursive(&root,
NULL,
- path,
- path_nchars,
- path,
- path_nchars,
+ ctx->params->cur_path,
+ ctx->params->cur_path_nchars,
filename,
ctx);
goto out;
}
/* Test for exclusion based on path. */
- ret = try_exclude(path, ctx->params);
+ ret = try_exclude(ctx->params);
if (unlikely(ret < 0)) /* Excluded? */
goto out_progress;
if (unlikely(ret > 0)) /* Error? */
/* Create a mapping for this security ID and insert it
* into the security map. */
- status = winnt_open(path, path_nchars,
+ status = winnt_open(ctx->params->cur_path,
+ ctx->params->cur_path_nchars,
READ_CONTROL |
ACCESS_SYSTEM_SECURITY, &h);
if (!NT_SUCCESS(status)) {
winnt_error(status, L"Can't open \"%ls\" to "
"read security descriptor",
- printable_path(path));
+ printable_path(ctx));
ret = WIMLIB_ERR_OPEN;
goto out;
}
- ret = winnt_load_security_descriptor(h, inode, path, ctx);
+ ret = winnt_load_security_descriptor(h, inode, ctx);
NtClose(h);
if (ret)
goto out;
!(ctx->vol_flags & FILE_SUPPORTS_OPEN_BY_FILE_ID) ||
!(ctx->params->add_flags & WIMLIB_ADD_FLAG_FILE_PATHS_UNNEEDED))
{
- windows_file = alloc_windows_file(path,
- path_nchars,
+ windows_file = alloc_windows_file(ctx->params->cur_path,
+ ctx->params->cur_path_nchars,
ns->name,
wcslen(ns->name),
ctx->snapshot,
false);
} else {
windows_file = alloc_windows_file_for_file_id(ni->ino,
- path,
- ctx->params->capture_root_nchars + 1,
+ ctx->params->cur_path,
+ ctx->params->root_path_nchars,
ctx->snapshot);
}
const struct ntfs_dentry *nd = ni->first_child;
while (nd != NULL) {
- const size_t name_len = wcslen(nd->name);
- wchar_t *p = path + path_nchars;
+ size_t orig_path_nchars;
struct wim_dentry *child;
const struct ntfs_dentry *next = nd->next_child;
- if (*(p - 1) != L'\\')
- *p++ = L'\\';
- p = wmempcpy(p, nd->name, name_len);
- *p = '\0';
+ ret = WIMLIB_ERR_NOMEM;
+ if (!pathbuf_append_name(ctx->params, nd->name,
+ wcslen(nd->name),
+ &orig_path_nchars))
+ goto out;
ret = generate_wim_structures_recursive(
&child,
- path,
- p - path,
nd->name,
nd->is_primary,
(void *)nd - nd->offset_from_inode,
inode_map,
security_map);
- path[path_nchars] = L'\0';
+ pathbuf_truncate(ctx->params, orig_path_nchars);
if (ret)
goto out;
}
out_progress:
- ctx->params->progress.scan.cur_path = path;
if (likely(root))
ret = do_scan_progress(ctx->params, WIMLIB_SCAN_DENTRY_OK, inode);
else
}
static int
-winnt_build_dentry_tree_fast(struct wim_dentry **root_ret, wchar_t *path,
- size_t path_nchars, struct winnt_scan_ctx *ctx)
+winnt_build_dentry_tree_fast(struct wim_dentry **root_ret,
+ struct winnt_scan_ctx *ctx)
{
struct ntfs_inode_map inode_map = { .root = NULL };
struct security_map security_map = { .root = NULL };
struct ntfs_inode *root = NULL;
+ wchar_t *path = ctx->params->cur_path;
+ size_t path_nchars = ctx->params->cur_path_nchars;
bool adjust_path;
int ret;
root->num_aliases = 1;
- ret = generate_wim_structures_recursive(root_ret, path, path_nchars,
- L"", false, root, ctx,
+ ret = generate_wim_structures_recursive(root_ret, L"", false, root, ctx,
&inode_map, &security_map);
out:
ntfs_inode_map_destroy(&inode_map);
* Entry point for directory tree scans on Windows *
*----------------------------------------------------------------------------*/
-#define WINDOWS_NT_MAX_PATH 32768
-
int
win32_build_dentry_tree(struct wim_dentry **root_ret,
const wchar_t *root_disk_path,
struct scan_params *params)
{
- wchar_t *path = NULL;
struct winnt_scan_ctx ctx = { .params = params };
UNICODE_STRING ntpath;
- size_t ntpath_nchars;
HANDLE h = NULL;
NTSTATUS status;
int ret;
- /* WARNING: There is no check for overflow later when this buffer is
- * being used! But it's as long as the maximum path length understood
- * by Windows NT (which is NOT the same as MAX_PATH). */
- path = MALLOC((WINDOWS_NT_MAX_PATH + 1) * sizeof(wchar_t));
- if (!path)
- return WIMLIB_ERR_NOMEM;
-
if (params->add_flags & WIMLIB_ADD_FLAG_SNAPSHOT)
ret = vss_create_snapshot(root_disk_path, &ntpath, &ctx.snapshot);
else
goto out;
if (ntpath.Length < 4 * sizeof(wchar_t) ||
- ntpath.Length > WINDOWS_NT_MAX_PATH * sizeof(wchar_t) ||
wmemcmp(ntpath.Buffer, L"\\??\\", 4))
{
ERROR("\"%ls\": unrecognized path format", root_disk_path);
ret = WIMLIB_ERR_INVALID_PARAM;
} else {
- ntpath_nchars = ntpath.Length / sizeof(wchar_t);
- wmemcpy(path, ntpath.Buffer, ntpath_nchars);
- path[ntpath_nchars] = L'\0';
-
- params->capture_root_nchars = ntpath_nchars;
- if (path[ntpath_nchars - 1] == L'\\')
- params->capture_root_nchars--;
- ret = 0;
+ ret = pathbuf_init(params, ntpath.Buffer);
}
HeapFree(GetProcessHeap(), 0, ntpath.Buffer);
if (ret)
goto out;
- status = winnt_open(path, ntpath_nchars, FILE_READ_ATTRIBUTES, &h);
+ status = winnt_open(params->cur_path, params->cur_path_nchars,
+ FILE_READ_ATTRIBUTES, &h);
if (!NT_SUCCESS(status)) {
- winnt_error(status, L"Can't open \"%ls\"", printable_path(path));
+ winnt_error(status, L"Can't open \"%ls\"", root_disk_path);
if (status == STATUS_FVE_LOCKED_VOLUME)
ret = WIMLIB_ERR_FVE_LOCKED_VOLUME;
else
goto out;
}
- get_volume_information(h, path, &ctx);
+ get_volume_information(h, &ctx);
NtClose(h);
#ifdef ENABLE_FAST_MFT_SCAN
if (ctx.is_ntfs && !_wgetenv(L"WIMLIB_DISABLE_QUERY_FILE_LAYOUT")) {
- ret = winnt_build_dentry_tree_fast(root_ret, path,
- ntpath_nchars, &ctx);
+ ret = winnt_build_dentry_tree_fast(root_ret, &ctx);
if (ret >= 0 && ret != WIMLIB_ERR_UNSUPPORTED)
goto out;
if (ret >= 0) {
}
#endif
ret = winnt_build_dentry_tree_recursive(root_ret, NULL,
- path, ntpath_nchars,
- path, ntpath_nchars,
+ params->cur_path,
+ params->cur_path_nchars,
L"", &ctx);
out:
vss_put_snapshot(ctx.snapshot);
- FREE(path);
if (ret == 0)
winnt_do_scan_warnings(root_disk_path, &ctx);
return ret;