resource code fixes/cleanup
authorEric Biggers <ebiggers3@gmail.com>
Sun, 7 Apr 2013 02:13:06 +0000 (21:13 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sun, 7 Apr 2013 02:13:06 +0000 (21:13 -0500)
src/mount_image.c
src/resource.c
src/wimlib_internal.h

index a2e09b4..a83c6ba 100644 (file)
@@ -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 */
index a7a8319..73f860e 100644 (file)
@@ -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)
index 0442aaa..e94fab9 100644 (file)
@@ -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,