From f2372aa229c5c766d627b4997f14b91373efff21 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sun, 5 May 2013 00:30:55 -0500 Subject: [PATCH] read_header(): Print WIM name in error messages --- src/header.c | 34 ++++++++++++++++++---------------- src/wim.c | 2 +- src/wimlib_internal.h | 3 ++- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/header.c b/src/header.c index 70abf2f2..ef0e5783 100644 --- a/src/header.c +++ b/src/header.c @@ -33,7 +33,8 @@ static const u8 wim_magic_chars[WIM_MAGIC_LEN] = { /* Reads the header from a WIM file. */ int -read_header(int in_fd, struct wim_header *hdr, int open_flags) +read_header(const tchar *filename, int in_fd, + struct wim_header *hdr, int open_flags) { size_t bytes_read; u8 buf[WIM_HEADER_DISK_SIZE]; @@ -43,35 +44,35 @@ read_header(int in_fd, struct wim_header *hdr, int open_flags) u32 wim_version; u32 chunk_size; - DEBUG("Reading WIM header."); + DEBUG("Reading WIM header from \"%"TS"\".", filename); bytes_read = full_pread(in_fd, buf, WIM_HEADER_DISK_SIZE, 0); if (bytes_read != WIM_HEADER_DISK_SIZE) { - ERROR_WITH_ERRNO("Error reading WIM header"); + ERROR_WITH_ERRNO("\"%"TS"\": Error reading header", filename); return WIMLIB_ERR_READ; } p = buf; if (memcmp(p, wim_magic_chars, WIM_MAGIC_LEN)) { - ERROR("Invalid magic characters in WIM header"); + ERROR("\"%"TS"\": Invalid magic characters in header", filename); return WIMLIB_ERR_NOT_A_WIM_FILE; } /* Byte 8 */ p = get_u32(p + 8, &hdr_size); if (hdr_size != WIM_HEADER_DISK_SIZE) { - ERROR("Header is %u bytes (expected %u bytes)", - hdr_size, WIM_HEADER_DISK_SIZE); + ERROR("\"%"TS"\": Header is %u bytes (expected %u bytes)", + filename, hdr_size, WIM_HEADER_DISK_SIZE); return WIMLIB_ERR_INVALID_HEADER_SIZE; } /* Byte 12 */ p = get_u32(buf + WIM_MAGIC_LEN + sizeof(u32), &wim_version); if (wim_version != WIM_VERSION) { - ERROR("The WIM header says the WIM version is %u, but wimlib " - "only knows about version %u", - wim_version, WIM_VERSION); + ERROR("\"%"TS"\": The WIM header says the WIM version is %u, " + "but wimlib only knows about version %u", + filename, wim_version, WIM_VERSION); return WIMLIB_ERR_UNKNOWN_VERSION; } @@ -79,9 +80,9 @@ read_header(int in_fd, struct wim_header *hdr, int open_flags) p = get_u32(p, &chunk_size); if (chunk_size != WIM_CHUNK_SIZE && (hdr->flags & WIM_HDR_FLAG_COMPRESSION)) { - ERROR("Unexpected chunk size of %u! Ask the author to " + ERROR("\"%"TS"\": Unexpected chunk size of %u! Ask the author to " "implement support for other chunk sizes.", - chunk_size); + filename, chunk_size); ERROR("(Or it might just be that the WIM header is invalid.)"); return WIMLIB_ERR_INVALID_CHUNK_SIZE; } @@ -94,16 +95,16 @@ read_header(int in_fd, struct wim_header *hdr, int open_flags) hdr->part_number == 0 || hdr->part_number > hdr->total_parts) { - ERROR("Invalid WIM part number: %hu of %hu", - hdr->part_number, hdr->total_parts); + ERROR("\"%"TS"\": Invalid WIM part number: %hu of %hu", + filename, hdr->part_number, hdr->total_parts); return WIMLIB_ERR_INVALID_PART_NUMBER; } if (!(open_flags & WIMLIB_OPEN_FLAG_SPLIT_OK) && hdr->total_parts != 1) { - ERROR("This WIM is part %u of a %u-part WIM", - hdr->part_number, hdr->total_parts); + ERROR("\"%"TS"\": This WIM is part %u of a %u-part WIM", + filename, hdr->part_number, hdr->total_parts); return WIMLIB_ERR_SPLIT_UNSUPPORTED; } @@ -113,7 +114,8 @@ read_header(int in_fd, struct wim_header *hdr, int open_flags) hdr->part_number, hdr->total_parts, hdr->image_count); if (hdr->image_count >= INT_MAX) { - ERROR("Invalid image count (%u)", hdr->image_count); + ERROR("\"%"TS"\": Invalid image count (%u)", + filename, hdr->image_count); return WIMLIB_ERR_IMAGE_COUNT; } diff --git a/src/wim.c b/src/wim.c index c320b311..9be0f956 100644 --- a/src/wim.c +++ b/src/wim.c @@ -453,7 +453,7 @@ begin_read(WIMStruct *w, const tchar *in_wim_path, int open_flags, return WIMLIB_ERR_OPEN; } - ret = read_header(w->in_fd, &w->hdr, open_flags); + ret = read_header(w->filename, w->in_fd, &w->hdr, open_flags); if (ret) return ret; diff --git a/src/wimlib_internal.h b/src/wimlib_internal.h index 9466a199..82eb42ee 100644 --- a/src/wimlib_internal.h +++ b/src/wimlib_internal.h @@ -493,7 +493,8 @@ dentry_tree_fix_inodes(struct wim_dentry *root, struct list_head *inode_list); /* header.c */ extern int -read_header(int in_fd, struct wim_header *hdr, int split_ok); +read_header(const tchar *filename, int in_fd, struct wim_header *hdr, + int split_ok); extern int write_header(const struct wim_header *hdr, int out_fd); -- 2.43.0