X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fwrite.c;h=aa3585a75b9fa7fd82c59cbed03a26539e3d2dc7;hp=0114618f1658384dc1a99401bc7ba615f35413bd;hb=b9320c921af8d8d2ea3ea80c576ca1e4037af049;hpb=d444f2e5ddee51e7d9d0401cffcf88477c180422 diff --git a/src/write.c b/src/write.c index 0114618f..aa3585a7 100644 --- a/src/write.c +++ b/src/write.c @@ -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; @@ -2400,12 +2400,14 @@ 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_for_append(WIMStruct *wim, int fd) +lock_wim_for_append(WIMStruct *wim) { if (wim->locked_for_append) return 0; - if (!flock(fd, LOCK_EX | LOCK_NB)) { + if (!flock(wim->in_fd.fd, LOCK_EX | LOCK_NB)) { wim->locked_for_append = 1; return 0; } @@ -2413,11 +2415,13 @@ lock_wim_for_append(WIMStruct *wim, int fd) return 0; return WIMLIB_ERR_ALREADY_LOCKED; } + +/* Remove advisory lock on WIM file (if present) */ void -unlock_wim_for_append(WIMStruct *wim, int fd) +unlock_wim_for_append(WIMStruct *wim) { if (wim->locked_for_append) { - flock(fd, LOCK_UN); + flock(wim->in_fd.fd, LOCK_UN); wim->locked_for_append = 0; } } @@ -3060,7 +3064,7 @@ overwrite_wim_inplace(WIMStruct *wim, int write_flags, unsigned num_threads) if (ret) goto out_restore_memory_hdr; - ret = lock_wim_for_append(wim, wim->out_fd.fd); + ret = lock_wim_for_append(wim); if (ret) goto out_close_wim; @@ -3096,8 +3100,7 @@ overwrite_wim_inplace(WIMStruct *wim, int write_flags, unsigned num_threads) if (ret) goto out_truncate; - /* lock was dropped when file descriptor was closed */ - wim->locked_for_append = 0; + unlock_wim_for_append(wim); return 0; out_truncate: @@ -3111,8 +3114,7 @@ out_truncate: out_restore_physical_hdr: (void)write_wim_header_flags(hdr_save.flags, &wim->out_fd); out_unlock_wim: - /* lock is dropped when close_wim_writable() closes the file */ - wim->locked_for_append = 0; + unlock_wim_for_append(wim); out_close_wim: (void)close_wim_writable(wim, write_flags); out_restore_memory_hdr: