Use WIM_HDR_FLAG_WRITE_IN_PROGRESS
authorEric Biggers <ebiggers3@gmail.com>
Wed, 22 May 2013 06:58:47 +0000 (01:58 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Wed, 22 May 2013 06:58:47 +0000 (01:58 -0500)
src/wim.c
src/write.c

index dec3ee9..a745c0a 100644 (file)
--- a/src/wim.c
+++ b/src/wim.c
@@ -468,6 +468,12 @@ begin_read(WIMStruct *w, const tchar *in_wim_path, int open_flags,
        if (ret)
                return ret;
 
+       if (w->hdr.flags & WIM_HDR_FLAG_WRITE_IN_PROGRESS) {
+               WARNING("The WIM_HDR_FLAG_WRITE_IN_PROGRESS is set in the header of \"%"TS"\".\n"
+                       "          It may be being changed by another process, or a process\n"
+                       "          may have crashed while writing the WIM.", in_wim_path);
+       }
+
        if (open_flags & WIMLIB_OPEN_FLAG_WRITE_ACCESS) {
                ret = can_modify_wim(w);
                if (ret)
@@ -476,7 +482,7 @@ begin_read(WIMStruct *w, const tchar *in_wim_path, int open_flags,
 
        if (w->hdr.total_parts != 1 && !(open_flags & WIMLIB_OPEN_FLAG_SPLIT_OK)) {
                ERROR("\"%"TS"\": This WIM is part %u of a %u-part WIM",
-                     w->filename, w->hdr.part_number, w->hdr.total_parts);
+                     in_wim_path, w->hdr.part_number, w->hdr.total_parts);
                return WIMLIB_ERR_SPLIT_UNSUPPORTED;
        }
 
index ba8b697..b1d8708 100644 (file)
@@ -1825,6 +1825,7 @@ finish_write(WIMStruct *w, int image, int write_flags,
                zero_resource_entry(&hdr.integrity);
        }
 
+       hdr.flags &= ~WIM_HDR_FLAG_WRITE_IN_PROGRESS;
        ret = write_header(&hdr, w->out_fd);
        if (ret)
                goto out_close_wim;
@@ -1907,7 +1908,9 @@ begin_write(WIMStruct *w, const tchar *path, int write_flags)
        if (ret)
                return ret;
        /* Write dummy header. It will be overwritten later. */
+       w->hdr.flags |= WIM_HDR_FLAG_WRITE_IN_PROGRESS;
        ret = write_header(&w->hdr, w->out_fd);
+       w->hdr.flags &= ~WIM_HDR_FLAG_WRITE_IN_PROGRESS;
        if (ret)
                return ret;
        if (lseek(w->out_fd, WIM_HEADER_DISK_SIZE, SEEK_SET) == -1) {
@@ -2109,6 +2112,13 @@ overwrite_wim_inplace(WIMStruct *w, int write_flags,
                return ret;
        }
 
+       /* Write header with write in progress flag set. */
+       w->hdr.flags |= WIM_HDR_FLAG_WRITE_IN_PROGRESS;
+       ret = write_header(&w->hdr, w->out_fd);
+       w->hdr.flags &= ~WIM_HDR_FLAG_WRITE_IN_PROGRESS;
+       if (ret)
+               return ret;
+
        if (lseek(w->out_fd, old_wim_end, SEEK_SET) == -1) {
                ERROR_WITH_ERRNO("Can't seek to end of WIM");
                close_wim_writable(w);