#if defined(HAVE_SYS_FILE_H) && defined(HAVE_FLOCK)
extern int
-lock_wim_for_append(WIMStruct *wim, int fd);
+lock_wim_for_append(WIMStruct *wim);
extern void
-unlock_wim_for_append(WIMStruct *wim, int fd);
+unlock_wim_for_append(WIMStruct *wim);
#else
static inline int
-lock_wim_for_append(WIMStruct *wim, int fd)
+lock_wim_for_append(WIMStruct *wim)
{
return 0;
}
static inline void
-unlock_wim_for_append(WIMStruct *wim, int fd)
+unlock_wim_for_append(WIMStruct *wim)
{
- return 0;
}
#endif
/* Leave the image mounted if commit failed, unless this is a
* forced unmount. The user can retry without commit if they
* want. */
- if (!ret || (unmount_flags & WIMLIB_UNMOUNT_FLAG_FORCE))
+ if (!ret || (unmount_flags & WIMLIB_UNMOUNT_FLAG_FORCE)) {
+ unlock_wim_for_append(wimfs_ctx->wim);
fuse_exit(fuse_ctx->fuse);
+ }
if (mq != (mqd_t)-1)
mq_close(mq);
return ret;
return WIMLIB_ERR_INVALID_PARAM;
}
- ret = lock_wim_for_append(wim, wim->in_fd.fd);
- if (ret)
- return ret;
+ if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
+ ret = lock_wim_for_append(wim);
+ if (ret)
+ return ret;
+ }
/* If the user did not specify an interface for accessing named
* data streams, use the default (extended attributes). */
if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)
delete_staging_dir(&ctx);
out_unlock:
- unlock_wim_for_append(wim, wim->in_fd.fd);
+ unlock_wim_for_append(wim);
return ret;
}
}
#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;
}
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;
}
}
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;
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:
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: