]> wimlib.net Git - wimlib/blobdiff - src/write.c
Remove WIMLIB_COMPRESSION_TYPE_INVALID from library
[wimlib] / src / write.c
index 27463d90d059879426f9df0f17121df8e08f4fea..5bca038a61afd909b5d868391ed21ebf37d49a5c 100644 (file)
@@ -451,7 +451,7 @@ begin_chunk_table(struct write_streams_ctx *ctx, u64 res_expected_size)
                reserve_size = expected_num_chunk_entries *
                               get_chunk_entry_size(res_expected_size,
                                                    0 != (ctx->write_resource_flags &
-                                                         WIM_RESHDR_FLAG_PACKED_STREAMS));
+                                                         WRITE_RESOURCE_FLAG_PACK_STREAMS));
                if (ctx->write_resource_flags & WRITE_RESOURCE_FLAG_PACK_STREAMS)
                        reserve_size += sizeof(struct alt_chunk_table_header_disk);
                memset(ctx->chunk_csizes, 0, reserve_size);
@@ -499,7 +499,7 @@ end_chunk_table(struct write_streams_ctx *ctx, u64 res_actual_size,
 
        chunk_entry_size = get_chunk_entry_size(res_actual_size,
                                                0 != (ctx->write_resource_flags &
-                                                     WIM_RESHDR_FLAG_PACKED_STREAMS));
+                                                     WRITE_RESOURCE_FLAG_PACK_STREAMS));
 
        typedef le64 __attribute__((may_alias)) aliased_le64_t;
        typedef le32 __attribute__((may_alias)) aliased_le32_t;
@@ -1261,9 +1261,8 @@ remove_zero_length_streams(struct list_head *stream_list)
  *
  * @out_ctype
  *     Compression format to use to write the output streams, specified as one
- *     of the WIMLIB_COMPRESSION_TYPE_* constants, excepting
- *     WIMLIB_COMPRESSION_TYPE_INVALID but including
- *     WIMLIB_COMPRESSION_TYPE_NONE.
+ *     of the WIMLIB_COMPRESSION_TYPE_* constants.
+ *     WIMLIB_COMPRESSION_TYPE_NONE is allowed.
  *
  * @out_chunk_size
  *     Chunk size to use to write the streams.  It must be a valid chunk size
@@ -2400,28 +2399,30 @@ finish_write(WIMStruct *wim, int image, int write_flags,
 }
 
 #if defined(HAVE_SYS_FILE_H) && defined(HAVE_FLOCK)
+
+/* Set advisory lock on WIM file (if not already done so)  */
 int
-lock_wim(WIMStruct *wim, int fd)
+lock_wim_for_append(WIMStruct *wim)
 {
-       int ret = 0;
-       if (fd != -1 && !wim->wim_locked) {
-               ret = flock(fd, LOCK_EX | LOCK_NB);
-               if (ret != 0) {
-                       if (errno == EWOULDBLOCK) {
-                               ERROR("`%"TS"' is already being modified or has been "
-                                     "mounted read-write\n"
-                                     "        by another process!", wim->filename);
-                               ret = WIMLIB_ERR_ALREADY_LOCKED;
-                       } else {
-                               WARNING_WITH_ERRNO("Failed to lock `%"TS"'",
-                                                  wim->filename);
-                               ret = 0;
-                       }
-               } else {
-                       wim->wim_locked = 1;
-               }
+       if (wim->locked_for_append)
+               return 0;
+       if (!flock(wim->in_fd.fd, LOCK_EX | LOCK_NB)) {
+               wim->locked_for_append = 1;
+               return 0;
+       }
+       if (errno != EWOULDBLOCK)
+               return 0;
+       return WIMLIB_ERR_ALREADY_LOCKED;
+}
+
+/* Remove advisory lock on WIM file (if present)  */
+void
+unlock_wim_for_append(WIMStruct *wim)
+{
+       if (wim->locked_for_append) {
+               flock(wim->in_fd.fd, LOCK_UN);
+               wim->locked_for_append = 0;
        }
-       return ret;
 }
 #endif
 
@@ -3062,7 +3063,7 @@ overwrite_wim_inplace(WIMStruct *wim, int write_flags, unsigned num_threads)
        if (ret)
                goto out_restore_memory_hdr;
 
-       ret = lock_wim(wim, wim->out_fd.fd);
+       ret = lock_wim_for_append(wim);
        if (ret)
                goto out_close_wim;
 
@@ -3098,7 +3099,7 @@ overwrite_wim_inplace(WIMStruct *wim, int write_flags, unsigned num_threads)
        if (ret)
                goto out_truncate;
 
-       wim->wim_locked = 0;
+       unlock_wim_for_append(wim);
        return 0;
 
 out_truncate:
@@ -3112,7 +3113,7 @@ out_truncate:
 out_restore_physical_hdr:
        (void)write_wim_header_flags(hdr_save.flags, &wim->out_fd);
 out_unlock_wim:
-       wim->wim_locked = 0;
+       unlock_wim_for_append(wim);
 out_close_wim:
        (void)close_wim_writable(wim, write_flags);
 out_restore_memory_hdr: