struct win32_encrypted_extract_ctx {
void *file_ctx;
int wimlib_err_code;
+ int win32_err_code;
bool done;
pthread_cond_t cond;
pthread_mutex_t mutex;
{
struct win32_encrypted_extract_ctx *ctx = _ctx;
unsigned long len = *len_p;
+ int ret;
pthread_mutex_lock(&ctx->mutex);
while (len) {
size_t bytes_to_copy;
-
DEBUG("Importing up to %lu more bytes of raw encrypted data", len);
+
+ if (ctx->done && ctx->win32_err_code != ERROR_SUCCESS)
+ goto err;
while (ctx->buf_filled == 0) {
if (ctx->done)
- goto out;
+ goto err;
pthread_cond_wait(&ctx->cond, &ctx->mutex);
}
bytes_to_copy = min(len, ctx->buf_filled);
memmove(ctx->buf, ctx->buf + bytes_to_copy, ctx->buf_filled);
pthread_cond_signal(&ctx->cond);
}
+ ret = ERROR_SUCCESS;
+ goto out;
+err:
+ ret = ctx->win32_err_code;
out:
*len_p -= len;
pthread_mutex_unlock(&ctx->mutex);
- return ERROR_SUCCESS;
+ return ret;
}
/* Extract ("Import") an encrypted file in a different thread. */
if (ret == ERROR_SUCCESS) {
ctx->wimlib_err_code = 0;
} else {
+ ERROR("Failed to extract raw encrypted file");
win32_error(ret);
ctx->wimlib_err_code = WIMLIB_ERR_WRITE;
}
while (len) {
DEBUG("Extracting up to %zu more bytes of encrypted data", len);
pthread_mutex_lock(&ctx->mutex);
+ if (ctx->done)
+ goto out_unlock;
while (ctx->buf_filled == WIM_CHUNK_SIZE) {
- if (ctx->done) {
- pthread_mutex_unlock(&ctx->mutex);
- return ctx->wimlib_err_code;
- }
pthread_cond_wait(&ctx->cond, &ctx->mutex);
+ if (ctx->done)
+ goto out_unlock;
}
bytes_to_copy = min(len, WIM_CHUNK_SIZE - ctx->buf_filled);
memcpy(&ctx->buf[ctx->buf_filled], buf, bytes_to_copy);
pthread_mutex_unlock(&ctx->mutex);
}
return 0;
+out_unlock:
+ pthread_mutex_unlock(&ctx->mutex);
+ return ctx->wimlib_err_code;
}
/* Create an encrypted file and extract the raw encrypted data to it.
ret = extract_wim_resource(lte, wim_resource_size(lte),
win32_extract_raw_encrypted_chunk, &ctx);
pthread_mutex_lock(&ctx.mutex);
+ if (ret)
+ ctx.win32_err_code = ERROR_READ_FAULT;
+ else
+ ctx.win32_err_code = ERROR_SUCCESS;
ctx.done = true;
pthread_cond_signal(&ctx.cond);
pthread_mutex_unlock(&ctx.mutex);