From: Eric Biggers Date: Sun, 3 Mar 2013 20:29:24 +0000 (-0600) Subject: print_lookup_table_entry(): add FILE* parameter X-Git-Tag: v1.2.6~23 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=e1ec9c16b55adb6947b4d1ff46dc847430db4746;hp=6c71ffe3bf00c347a33e7ce31458664017287abc print_lookup_table_entry(): add FILE* parameter --- diff --git a/src/dentry.c b/src/dentry.c index 81a04d2b..35a89d11 100644 --- a/src/dentry.c +++ b/src/dentry.c @@ -745,7 +745,7 @@ int print_dentry(struct wim_dentry *dentry, void *lookup_table) printf("Full Path (UTF-8) = \"%s\"\n", dentry->full_path_utf8); lte = inode_stream_lte(dentry->d_inode, 0, lookup_table); if (lte) { - print_lookup_table_entry(lte); + print_lookup_table_entry(lte, stdout); } else { hash = inode_stream_hash(inode, 0); if (hash) { @@ -766,8 +766,8 @@ int print_dentry(struct wim_dentry *dentry, void *lookup_table) print_hash(hash); putchar('\n'); } - print_lookup_table_entry(inode_stream_lte(inode, i + 1, - lookup_table)); + print_lookup_table_entry(inode_stream_lte(inode, i + 1, lookup_table), + stdout); } return 0; } diff --git a/src/lookup_table.c b/src/lookup_table.c index 7e1155b1..390f63c5 100644 --- a/src/lookup_table.c +++ b/src/lookup_table.c @@ -348,9 +348,9 @@ int read_lookup_table(WIMStruct *w) ERROR("The WIM lookup table contains two entries with the " "same SHA1 message digest!"); ERROR("The first entry is:"); - print_lookup_table_entry(duplicate_entry); + print_lookup_table_entry(duplicate_entry, stderr); ERROR("The second entry is:"); - print_lookup_table_entry(cur_entry); + print_lookup_table_entry(cur_entry, stderr); #endif ret = WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY; goto out_free_cur_entry; @@ -364,7 +364,7 @@ int read_lookup_table(WIMStruct *w) ERROR("Found uncompressed resource with original size " "not the same as compressed size"); ERROR("The lookup table entry for the resource is as follows:"); - print_lookup_table_entry(cur_entry); + print_lookup_table_entry(cur_entry, stderr); #endif ret = WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY; goto out_free_cur_entry; @@ -374,7 +374,7 @@ int read_lookup_table(WIMStruct *w) { #ifdef ENABLE_ERROR_MESSAGES ERROR("Found metadata resource with refcnt != 1:"); - print_lookup_table_entry(cur_entry); + print_lookup_table_entry(cur_entry, stderr); #endif ret = WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY; goto out_free_cur_entry; @@ -475,57 +475,58 @@ int lte_free_extracted_file(struct wim_lookup_table_entry *lte, void *ignore) return 0; } -void print_lookup_table_entry(const struct wim_lookup_table_entry *lte) +void print_lookup_table_entry(const struct wim_lookup_table_entry *lte, + FILE *out) { if (!lte) { - putchar('\n'); + putc('\n', out); return; } - printf("Offset = %"PRIu64" bytes\n", + fprintf(out, "Offset = %"PRIu64" bytes\n", lte->resource_entry.offset); - printf("Size = %"PRIu64" bytes\n", + fprintf(out, "Size = %"PRIu64" bytes\n", (u64)lte->resource_entry.size); - printf("Original size = %"PRIu64" bytes\n", + fprintf(out, "Original size = %"PRIu64" bytes\n", lte->resource_entry.original_size); - printf("Part Number = %hu\n", lte->part_number); - printf("Reference Count = %u\n", lte->refcnt); - printf("Hash = 0x"); + fprintf(out, "Part Number = %hu\n", lte->part_number); + fprintf(out, "Reference Count = %u\n", lte->refcnt); + fprintf(out, "Hash = 0x"); print_hash(lte->hash); - putchar('\n'); - printf("Flags = "); + putc('\n', out); + fprintf(out, "Flags = "); u8 flags = lte->resource_entry.flags; if (flags & WIM_RESHDR_FLAG_COMPRESSED) - fputs("WIM_RESHDR_FLAG_COMPRESSED, ", stdout); + fputs("WIM_RESHDR_FLAG_COMPRESSED, ", out); if (flags & WIM_RESHDR_FLAG_FREE) - fputs("WIM_RESHDR_FLAG_FREE, ", stdout); + fputs("WIM_RESHDR_FLAG_FREE, ", out); if (flags & WIM_RESHDR_FLAG_METADATA) - fputs("WIM_RESHDR_FLAG_METADATA, ", stdout); + fputs("WIM_RESHDR_FLAG_METADATA, ", out); if (flags & WIM_RESHDR_FLAG_SPANNED) - fputs("WIM_RESHDR_FLAG_SPANNED, ", stdout); - putchar('\n'); + fputs("WIM_RESHDR_FLAG_SPANNED, ", out); + putc('\n', out); switch (lte->resource_location) { case RESOURCE_IN_WIM: if (lte->wim->filename) { - printf("WIM file = `%s'\n", + fprintf(out, "WIM file = `%s'\n", lte->wim->filename); } break; case RESOURCE_IN_FILE_ON_DISK: - printf("File on Disk = `%s'\n", lte->file_on_disk); + fprintf(out, "File on Disk = `%s'\n", lte->file_on_disk); break; case RESOURCE_IN_STAGING_FILE: - printf("Staging File = `%s'\n", lte->staging_file_name); + fprintf(out, "Staging File = `%s'\n", lte->staging_file_name); break; default: break; } - putchar('\n'); + putc('\n', out); } static int do_print_lookup_table_entry(struct wim_lookup_table_entry *lte, - void *ignore) + void *fp) { - print_lookup_table_entry(lte); + print_lookup_table_entry(lte, (FILE*)fp); return 0; } @@ -536,7 +537,7 @@ WIMLIBAPI void wimlib_print_lookup_table(WIMStruct *w) { for_lookup_table_entry(w->lookup_table, do_print_lookup_table_entry, - NULL); + stdout); } /* Given a SHA1 message digest, return the corresponding entry in the WIM's diff --git a/src/lookup_table.h b/src/lookup_table.h index 8de9f075..92428b12 100644 --- a/src/lookup_table.h +++ b/src/lookup_table.h @@ -271,7 +271,8 @@ extern struct wim_lookup_table_entry * clone_lookup_table_entry(const struct wim_lookup_table_entry *lte); extern void -print_lookup_table_entry(const struct wim_lookup_table_entry *entry); +print_lookup_table_entry(const struct wim_lookup_table_entry *entry, + FILE *out); extern void free_lookup_table_entry(struct wim_lookup_table_entry *lte); diff --git a/src/resource.c b/src/resource.c index 3c0804b0..e8f11144 100644 --- a/src/resource.c +++ b/src/resource.c @@ -644,7 +644,7 @@ int extract_wim_resource(const struct wim_lookup_table_entry *lte, if (!hashes_equal(hash, lte->hash)) { #ifdef ENABLE_ERROR_MESSAGES ERROR("Invalid checksum on the following WIM resource:"); - print_lookup_table_entry(lte); + print_lookup_table_entry(lte, stderr); #endif return WIMLIB_ERR_INVALID_RESOURCE_HASH; } diff --git a/src/verify.c b/src/verify.c index dd9d4f7e..b6bdbe63 100644 --- a/src/verify.c +++ b/src/verify.c @@ -212,11 +212,13 @@ static int image_run_full_verifications(WIMStruct *w) static int lte_fix_refcnt(struct wim_lookup_table_entry *lte, void *ctr) { if (lte->refcnt != lte->real_refcnt) { + #ifdef ENABLE_ERROR_MESSAGES WARNING("The following lookup table entry has a reference " "count of %u, but", lte->refcnt); WARNING("We found %u references to it", lte->real_refcnt); - print_lookup_table_entry(lte); + print_lookup_table_entry(lte, stderr); + #endif lte->refcnt = lte->real_refcnt; ++*(unsigned long *)ctr; } diff --git a/src/write.c b/src/write.c index 86730ff7..1f471d6f 100644 --- a/src/write.c +++ b/src/write.c @@ -1353,8 +1353,10 @@ static int lte_overwrite_prepare(struct wim_lookup_table_entry *lte, void *arg) lte->wim == args->wim && lte->resource_entry.offset + lte->resource_entry.size > args->end_offset) { + #ifdef ENABLE_ERROR_MESSAGES ERROR("The following resource is after the XML data:"); - print_lookup_table_entry(lte); + print_lookup_table_entry(lte, stderr); + #endif return WIMLIB_ERR_RESOURCE_ORDER; }