default:
fail:
set_errno_from_win32_error(err);
- ERROR("Failed to read security descriptor of \"%ls\"", path);
+ ERROR_WITH_ERRNO("Failed to read security descriptor of \"%ls\"", path);
ret = WIMLIB_ERR_READ;
goto out_free_buf;
}
* which we opened with FILE_FLAG_BACKUP_SEMANTICS (probably not the
* case for the FindFirstFile() API; it's not documented). */
#ifdef WITH_NTDLL
- if (func_NtQueryDirectoryFile) {
- NTSTATUS status;
- IO_STATUS_BLOCK io_status;
- const size_t bufsize = 8192;
- u8 *buf;
- BOOL restartScan = TRUE;
- const FILE_NAMES_INFORMATION *info;
+ if (!func_NtQueryDirectoryFile)
+ goto use_FindFirstFile;
- buf = MALLOC(bufsize);
- if (!buf)
- return WIMLIB_ERR_NOMEM;
- for (;;) {
- status = (*func_NtQueryDirectoryFile)(hDir, NULL, NULL, NULL,
- &io_status, buf, bufsize,
- FileNamesInformation,
- FALSE, NULL, restartScan);
- restartScan = FALSE;
- if (status != STATUS_SUCCESS) {
- if (status == STATUS_NO_MORE_FILES ||
- status == STATUS_NO_MORE_ENTRIES ||
- status == STATUS_NO_MORE_MATCHES) {
- ret = 0;
- } else {
- set_errno_from_nt_status(status);
- ERROR_WITH_ERRNO("Failed to read directory "
- "\"%ls\"", dir_path);
- ret = WIMLIB_ERR_READ;
- }
- goto out_free_buf;
+ NTSTATUS status;
+ IO_STATUS_BLOCK io_status;
+ const size_t bufsize = 8192;
+ u8 *buf;
+ BOOL restartScan = TRUE;
+ const FILE_NAMES_INFORMATION *info;
+
+ buf = MALLOC(bufsize);
+ if (!buf)
+ return WIMLIB_ERR_NOMEM;
+ for (;;) {
+ status = (*func_NtQueryDirectoryFile)(hDir, NULL, NULL, NULL,
+ &io_status, buf, bufsize,
+ FileNamesInformation,
+ FALSE, NULL, restartScan);
+ restartScan = FALSE;
+ if (status != STATUS_SUCCESS) {
+ if (status == STATUS_NO_MORE_FILES ||
+ status == STATUS_NO_MORE_ENTRIES ||
+ status == STATUS_NO_MORE_MATCHES) {
+ ret = 0;
+ } else if (status == STATUS_NOT_IMPLEMENTED ||
+ status == STATUS_NOT_SUPPORTED ||
+ status == STATUS_INVALID_INFO_CLASS) {
+ FREE(buf);
+ goto use_FindFirstFile;
+ } else {
+ set_errno_from_nt_status(status);
+ ERROR_WITH_ERRNO("Failed to read directory "
+ "\"%ls\"", dir_path);
+ ret = WIMLIB_ERR_READ;
}
- wimlib_assert(io_status.Information != 0);
- info = (const FILE_NAMES_INFORMATION*)buf;
- for (;;) {
- if (!(info->FileNameLength == 2 && info->FileName[0] == L'.') &&
- !(info->FileNameLength == 4 && info->FileName[0] == L'.' &&
- info->FileName[1] == L'.'))
- {
- wchar_t *p;
- struct wim_dentry *child;
-
- p = dir_path + dir_path_num_chars;
- *p++ = L'\\';
- p = wmempcpy(p, info->FileName,
- info->FileNameLength / 2);
- *p = '\0';
-
- ret = win32_build_dentry_tree_recursive(
- &child,
- dir_path,
- p - dir_path,
- params,
- state,
- vol_flags);
-
- dir_path[dir_path_num_chars] = L'\0';
-
- if (ret)
- goto out_free_buf;
- if (child)
- dentry_add_child(root, child);
- }
- if (info->NextEntryOffset == 0)
- break;
- info = (const FILE_NAMES_INFORMATION*)
- ((const u8*)info + info->NextEntryOffset);
+ goto out_free_buf;
+ }
+ wimlib_assert(io_status.Information != 0);
+ info = (const FILE_NAMES_INFORMATION*)buf;
+ for (;;) {
+ if (!(info->FileNameLength == 2 && info->FileName[0] == L'.') &&
+ !(info->FileNameLength == 4 && info->FileName[0] == L'.' &&
+ info->FileName[1] == L'.'))
+ {
+ wchar_t *p;
+ struct wim_dentry *child;
+
+ p = dir_path + dir_path_num_chars;
+ *p++ = L'\\';
+ p = wmempcpy(p, info->FileName,
+ info->FileNameLength / 2);
+ *p = '\0';
+
+ ret = win32_build_dentry_tree_recursive(
+ &child,
+ dir_path,
+ p - dir_path,
+ params,
+ state,
+ vol_flags);
+
+ dir_path[dir_path_num_chars] = L'\0';
+
+ if (ret)
+ goto out_free_buf;
+ if (child)
+ dentry_add_child(root, child);
}
+ if (info->NextEntryOffset == 0)
+ break;
+ info = (const FILE_NAMES_INFORMATION*)
+ ((const u8*)info + info->NextEntryOffset);
}
- out_free_buf:
- FREE(buf);
- return ret;
}
+out_free_buf:
+ FREE(buf);
+ return ret;
#endif
+
+use_FindFirstFile:
+ ;
WIN32_FIND_DATAW dat;
HANDLE hFind;
DWORD err;
goto unnamed_only;
#ifdef WITH_NTDLL
- if (func_NtQueryInformationFile) {
- buf = _buf;
- bufsize = sizeof(_buf);
+ if (!func_NtQueryInformationFile)
+ goto use_FindFirstStream;
- /* Get a buffer containing the stream information. */
- for (;;) {
- status = (*func_NtQueryInformationFile)(*hFile_p, &io_status,
- buf, bufsize,
- FileStreamInformation);
- if (status == STATUS_SUCCESS) {
- break;
- } else if (status == STATUS_BUFFER_OVERFLOW) {
- u8 *newbuf;
+ buf = _buf;
+ bufsize = sizeof(_buf);
- bufsize *= 2;
- if (buf == _buf)
- newbuf = MALLOC(bufsize);
- else
- newbuf = REALLOC(buf, bufsize);
+ /* Get a buffer containing the stream information. */
+ for (;;) {
+ status = (*func_NtQueryInformationFile)(*hFile_p, &io_status,
+ buf, bufsize,
+ FileStreamInformation);
+ if (status == STATUS_SUCCESS) {
+ break;
+ } else if (status == STATUS_BUFFER_OVERFLOW) {
+ u8 *newbuf;
- if (!newbuf) {
- ret = WIMLIB_ERR_NOMEM;
- goto out_free_buf;
- }
- buf = newbuf;
- } else {
- set_errno_from_nt_status(status);
- ERROR_WITH_ERRNO("Failed to read streams of %ls", path);
- ret = WIMLIB_ERR_READ;
+ bufsize *= 2;
+ if (buf == _buf)
+ newbuf = MALLOC(bufsize);
+ else
+ newbuf = REALLOC(buf, bufsize);
+
+ if (!newbuf) {
+ ret = WIMLIB_ERR_NOMEM;
goto out_free_buf;
}
- }
-
- if (io_status.Information == 0) {
- /* No stream information. */
- ret = 0;
+ buf = newbuf;
+ } else if (status == STATUS_NOT_IMPLEMENTED ||
+ status == STATUS_NOT_SUPPORTED ||
+ status == STATUS_INVALID_INFO_CLASS) {
+ goto use_FindFirstStream;
+ } else {
+ set_errno_from_nt_status(status);
+ ERROR_WITH_ERRNO("Failed to read streams of %ls", path);
+ ret = WIMLIB_ERR_READ;
goto out_free_buf;
}
+ }
- if (inode->i_attributes & FILE_ATTRIBUTE_ENCRYPTED) {
- /* OpenEncryptedFileRaw() seems to fail with
- * ERROR_SHARING_VIOLATION if there are any handles opened to
- * the file. */
- CloseHandle(*hFile_p);
- *hFile_p = INVALID_HANDLE_VALUE;
- }
+ if (io_status.Information == 0) {
+ /* No stream information. */
+ ret = 0;
+ goto out_free_buf;
+ }
- /* Parse one or more stream information structures. */
- info = (const FILE_STREAM_INFORMATION*)buf;
- for (;;) {
- if (info->StreamNameLength <= sizeof(dat.cStreamName) - 2) {
- dat.StreamSize = info->StreamSize;
- memcpy(dat.cStreamName, info->StreamName, info->StreamNameLength);
- dat.cStreamName[info->StreamNameLength / 2] = L'\0';
-
- /* Capture the stream. */
- ret = win32_capture_stream(path, path_num_chars, inode,
- lookup_table, &dat);
- if (ret)
- goto out_free_buf;
- }
- if (info->NextEntryOffset == 0) {
- /* No more stream information. */
- ret = 0;
- break;
- }
- /* Advance to next stream information. */
- info = (const FILE_STREAM_INFORMATION*)
- ((const u8*)info + info->NextEntryOffset);
+ if (inode->i_attributes & FILE_ATTRIBUTE_ENCRYPTED) {
+ /* OpenEncryptedFileRaw() seems to fail with
+ * ERROR_SHARING_VIOLATION if there are any handles opened to
+ * the file. */
+ CloseHandle(*hFile_p);
+ *hFile_p = INVALID_HANDLE_VALUE;
+ }
+
+ /* Parse one or more stream information structures. */
+ info = (const FILE_STREAM_INFORMATION*)buf;
+ for (;;) {
+ if (info->StreamNameLength <= sizeof(dat.cStreamName) - 2) {
+ dat.StreamSize = info->StreamSize;
+ memcpy(dat.cStreamName, info->StreamName, info->StreamNameLength);
+ dat.cStreamName[info->StreamNameLength / 2] = L'\0';
+
+ /* Capture the stream. */
+ ret = win32_capture_stream(path, path_num_chars, inode,
+ lookup_table, &dat);
+ if (ret)
+ goto out_free_buf;
}
- out_free_buf:
- /* Free buffer if allocated on heap. */
- if (buf != _buf)
- FREE(buf);
- return ret;
+ if (info->NextEntryOffset == 0) {
+ /* No more stream information. */
+ ret = 0;
+ break;
+ }
+ /* Advance to next stream information. */
+ info = (const FILE_STREAM_INFORMATION*)
+ ((const u8*)info + info->NextEntryOffset);
}
+out_free_buf:
+ /* Free buffer if allocated on heap. */
+ if (buf != _buf)
+ FREE(buf);
+ return ret;
#endif /* WITH_NTDLL */
+use_FindFirstStream:
if (win32func_FindFirstStreamW == NULL)
goto unnamed_only;
hFind = win32func_FindFirstStreamW(path, FindStreamInfoStandard, &dat, 0);
if (hFind == INVALID_HANDLE_VALUE) {
err = GetLastError();
- if (err == ERROR_CALL_NOT_IMPLEMENTED)
+ if (err == ERROR_CALL_NOT_IMPLEMENTED ||
+ err == ERROR_NOT_SUPPORTED ||
+ err == ERROR_INVALID_FUNCTION ||
+ err == ERROR_INVALID_PARAMETER)
goto unnamed_only;
/* Seems legal for this to return ERROR_HANDLE_EOF on reparse
/* FindFirstStream() API is not available, or the volume does not
* support named streams. Only capture the unnamed data stream. */
DEBUG("Only capturing unnamed data stream");
- if (!(inode->i_attributes & (FILE_ATTRIBUTE_DIRECTORY |
- FILE_ATTRIBUTE_REPARSE_POINT)))
- {
- wcscpy(dat.cStreamName, L"::$DATA");
- dat.StreamSize.QuadPart = file_size;
- ret = win32_capture_stream(path,
- path_num_chars,
- inode, lookup_table,
- &dat);
- if (ret)
- return ret;
- }
- return ret;
+ if (inode->i_attributes & (FILE_ATTRIBUTE_DIRECTORY |
+ FILE_ATTRIBUTE_REPARSE_POINT))
+ return 0;
+
+ wcscpy(dat.cStreamName, L"::$DATA");
+ dat.StreamSize.QuadPart = file_size;
+ return win32_capture_stream(path, path_num_chars,
+ inode, lookup_table, &dat);
}
static int