* details.
*
* You should have received a copy of the GNU Lesser General Public License
- * along with this file; if not, see http://www.gnu.org/licenses/.
+ * along with this file; if not, see https://www.gnu.org/licenses/.
*/
/*
/* Keep in sync with wimlib.h */
#define WIMLIB_EXTRACT_MASK_PUBLIC \
(WIMLIB_EXTRACT_FLAG_NTFS | \
+ WIMLIB_EXTRACT_FLAG_RECOVER_DATA | \
WIMLIB_EXTRACT_FLAG_UNIX_DATA | \
WIMLIB_EXTRACT_FLAG_NO_ACLS | \
WIMLIB_EXTRACT_FLAG_STRICT_ACLS | \
&& (blob->out_refcnt))
{
wim_reshdr_to_desc_and_blob(&reshdr, ctx->wim, &rdesc, blob);
- ret = read_blob_with_sha1(blob, cbs);
+ ret = read_blob_with_sha1(blob, cbs,
+ ctx->extract_flags &
+ WIMLIB_EXTRACT_FLAG_RECOVER_DATA);
blob_unset_is_located_in_wim_resource(blob);
if (ret)
return ret;
tchar *name;
int raw_fd;
-#ifdef __WIN32__
+#ifdef _WIN32
retry:
name = _wtempnam(NULL, L"wimlib");
if (!name) {
FREE(name);
goto retry;
}
-#else /* __WIN32__ */
+#else /* _WIN32 */
const char *tmpdir = getenv("TMPDIR");
if (!tmpdir)
tmpdir = P_tmpdir;
return WIMLIB_ERR_NOMEM;
sprintf(name, "%s/wimlibXXXXXX", tmpdir);
raw_fd = mkstemp(name);
-#endif /* !__WIN32__ */
+#endif /* !_WIN32 */
if (raw_fd < 0) {
ERROR_WITH_ERRNO("Failed to create temporary file "
for (u32 i = 0; i < orig_blob->out_refcnt; i++) {
tmpfile_blob.inline_blob_extraction_targets[0] = targets[i];
- ret = read_blob_with_cbs(&tmpfile_blob, cbs);
+ ret = read_blob_with_cbs(&tmpfile_blob, cbs, false);
if (ret)
return ret;
}
return 0;
}
+static void
+warn_about_corrupted_file(struct wim_dentry *dentry,
+ const struct wim_inode_stream *stream)
+{
+ WARNING("Corruption in %s\"%"TS"\"! Extracting anyway since data recovery mode is enabled.",
+ stream_is_unnamed_data_stream(stream) ? "" : "alternate stream of ",
+ dentry_full_path(dentry));
+}
+
static int
end_extract_blob(struct blob_descriptor *blob, int status, void *_ctx)
{
struct apply_ctx *ctx = _ctx;
+ if ((ctx->extract_flags & WIMLIB_EXTRACT_FLAG_RECOVER_DATA) &&
+ !status && blob->corrupted) {
+ const struct blob_extraction_target *targets =
+ blob_extraction_targets(blob);
+ for (u32 i = 0; i < blob->out_refcnt; i++) {
+ struct wim_dentry *dentry =
+ inode_first_extraction_dentry(targets[i].inode);
+
+ warn_about_corrupted_file(dentry, targets[i].stream);
+ }
+ }
+
if (unlikely(filedes_valid(&ctx->tmpfile_fd))) {
filedes_close(&ctx->tmpfile_fd);
if (!status)
if (ctx->extract_flags & WIMLIB_EXTRACT_FLAG_FROM_PIPE) {
return read_blobs_from_pipe(ctx, &wrapper_cbs);
} else {
+ int flags = VERIFY_BLOB_HASHES;
+
+ if (ctx->extract_flags & WIMLIB_EXTRACT_FLAG_RECOVER_DATA)
+ flags |= RECOVER_DATA;
+
return read_blob_list(&ctx->blob_list,
offsetof(struct blob_descriptor,
extraction_list),
- &wrapper_cbs, VERIFY_BLOB_HASHES);
+ &wrapper_cbs, flags);
}
}
* unnamed data stream only. */
static int
extract_dentry_to_stdout(struct wim_dentry *dentry,
- const struct blob_table *blob_table)
+ const struct blob_table *blob_table, int extract_flags)
{
struct wim_inode *inode = dentry->d_inode;
struct blob_descriptor *blob;
struct filedes _stdout;
+ bool recover = (extract_flags & WIMLIB_EXTRACT_FLAG_RECOVER_DATA);
+ int ret;
if (inode->i_attributes & (FILE_ATTRIBUTE_REPARSE_POINT |
FILE_ATTRIBUTE_DIRECTORY |
}
filedes_init(&_stdout, STDOUT_FILENO);
- return extract_blob_to_fd(blob, &_stdout);
+ ret = extract_blob_to_fd(blob, &_stdout, recover);
+ if (ret)
+ return ret;
+ if (recover && blob->corrupted)
+ warn_about_corrupted_file(dentry,
+ inode_get_unnamed_data_stream(inode));
+ return 0;
}
static int
extract_dentries_to_stdout(struct wim_dentry **dentries, size_t num_dentries,
- const struct blob_table *blob_table)
+ const struct blob_table *blob_table,
+ int extract_flags)
{
for (size_t i = 0; i < num_dentries; i++) {
- int ret = extract_dentry_to_stdout(dentries[i], blob_table);
+ int ret = extract_dentry_to_stdout(dentries[i], blob_table,
+ extract_flags);
if (ret)
return ret;
}
FREE(blob->blob_extraction_targets);
}
-#ifdef __WIN32__
+#ifdef _WIN32
static const utf16lechar replacement_char = cpu_to_le16(0xfffd);
#else
static const utf16lechar replacement_char = cpu_to_le16('?');
return true;
for (i = 0; i < num_chars; i++) {
switch (le16_to_cpu(name[i])) {
- #ifdef __WIN32__
+ #ifdef _WIN32
case '\x01'...'\x1F':
case '\\':
case ':':
if (extract_flags & WIMLIB_EXTRACT_FLAG_NTFS)
return &ntfs_3g_apply_ops;
#endif
-#ifdef __WIN32__
+#ifdef _WIN32
return &win32_apply_ops;
#else
return &unix_apply_ops;
if (extract_flags & WIMLIB_EXTRACT_FLAG_TO_STDOUT) {
ret = extract_dentries_to_stdout(trees, num_trees,
- wim->blob_table);
+ wim->blob_table,
+ extract_flags);
goto out;
}
if (errno == EEXIST)
return 0;
-#ifdef __WIN32__
+#ifdef _WIN32
/* _wmkdir() fails with EACCES if called on a drive root directory. */
if (errno == EACCES)
return 0;
#endif
if (extract_flags & WIMLIB_EXTRACT_FLAG_WIMBOOT) {
-#ifdef __WIN32__
+#ifdef _WIN32
if (!wim->filename)
return WIMLIB_ERR_NO_FILENAME;
#else
WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS16K |
WIMLIB_EXTRACT_FLAG_COMPACT_LZX))
{
- #ifdef __WIN32__
+ #ifdef _WIN32
int count = 0;
count += ((extract_flags & WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS4K) != 0);
count += ((extract_flags & WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS8K) != 0);
}
static const tchar * const filename_forbidden_chars =
-#ifdef __WIN32__
+#ifdef _WIN32
T("<>:\"/\\|?*");
#else
T("/");