From: Eric Biggers Date: Sun, 7 Apr 2013 02:13:06 +0000 (-0500) Subject: resource code fixes/cleanup X-Git-Tag: v1.3.3~82 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=701d2adb1891b0cd4204ff91dca3571d906188b7 resource code fixes/cleanup --- diff --git a/src/mount_image.c b/src/mount_image.c index a2e09b43..a83c6ba2 100644 --- a/src/mount_image.c +++ b/src/mount_image.c @@ -2559,10 +2559,8 @@ wimlib_mount_image(WIMStruct *wim, int image, const char *dir, #endif /* Mark dentry tree as modified if read-write mount. */ - if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) { + if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) imd->modified = 1; - imd->has_been_mounted_rw = 1; - } /* Resolve the lookup table entries for every inode in the image, and * assign inode numbers */ diff --git a/src/resource.c b/src/resource.c index a7a83198..73f860eb 100644 --- a/src/resource.c +++ b/src/resource.c @@ -320,11 +320,11 @@ read_compressed_resource(FILE *fp, * is equal to the uncompressed chunk size. */ if (compressed_chunk_size == uncompressed_chunk_size) { /* Uncompressed chunk */ - if (start_offset != 0) if (fseeko(fp, start_offset, SEEK_CUR)) goto read_error; - if (fread(out_p, 1, partial_chunk_size, fp) != partial_chunk_size) + if (fread(cb ? out_p + start_offset : out_p, + 1, partial_chunk_size, fp) != partial_chunk_size) goto read_error; } else { /* Compressed chunk */ @@ -533,22 +533,18 @@ read_partial_wim_resource(const struct wim_lookup_table_entry *lte, int ret; wimlib_assert(lte->resource_location == RESOURCE_IN_WIM); - wimlib_assert(offset + size <= lte->resource_entry.original_size); wim = lte->wim; - if (flags & WIMLIB_RESOURCE_FLAG_THREADSAFE_READ) { wim_fp = wim_get_fp(wim); if (!wim_fp) { - ret = -1; + ret = WIMLIB_ERR_READ; goto out; } } else { wim_fp = lte->wim->fp; } - wimlib_assert(wim_fp != NULL); - if (lte->resource_entry.flags & WIM_RESHDR_FLAG_COMPRESSED && !(flags & WIMLIB_RESOURCE_FLAG_RAW)) { @@ -593,15 +589,17 @@ read_partial_wim_resource(const struct wim_lookup_table_entry *lte, } goto out_release_fp; read_error: - if (ferror(wim_fp)) { + if (ferror(wim_fp)) ERROR_WITH_ERRNO("Error reading data from WIM"); - } else { + else ERROR("Unexpected EOF in WIM!"); - } ret = WIMLIB_ERR_READ; out_release_fp: - if (flags & WIMLIB_RESOURCE_FLAG_THREADSAFE_READ) - ret |= wim_release_fp(wim, wim_fp); + if (flags & WIMLIB_RESOURCE_FLAG_THREADSAFE_READ) { + int ret2 = wim_release_fp(wim, wim_fp); + if (ret == 0) + ret = ret2; + } out: if (ret) { if (errno == 0) diff --git a/src/wimlib_internal.h b/src/wimlib_internal.h index 0442aaac..e94fab9b 100644 --- a/src/wimlib_internal.h +++ b/src/wimlib_internal.h @@ -268,9 +268,6 @@ struct wim_image_metadata { * different WIM image. */ u8 modified : 1; - /* 1 iff this image has been mounted read-write */ - u8 has_been_mounted_rw : 1; - #ifdef WITH_NTFS_3G struct _ntfs_volume *ntfs_vol; #endif @@ -573,7 +570,6 @@ do_ntfs_umount(struct _ntfs_volume *vol); #define WIMLIB_RESOURCE_FLAG_RAW 0x1 #define WIMLIB_RESOURCE_FLAG_THREADSAFE_READ 0x2 #define WIMLIB_RESOURCE_FLAG_RECOMPRESS 0x4 -//#define WIMLIB_RESOURCE_FLAG_OVERWRITE_INPLACE 0x8 extern int read_resource_prefix(const struct wim_lookup_table_entry *lte,