-static int
-msg_unmount_request_handler(const void *_msg, void *_handler_ctx)
-{
- const struct msg_unmount_request *msg = _msg;
- struct daemon_msg_handler_context *handler_ctx = _handler_ctx;
- struct wimfs_context *wimfs_ctx;
- int status = 0;
- int ret;
- int unmount_flags;
-
- DEBUG("Handling unmount request msg");
-
- wimfs_ctx = handler_ctx->wimfs_ctx;
- if (msg->hdr.msg_size < sizeof(*msg)) {
- status = WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
- goto out;
- }
-
- unmount_flags = msg->unmount_flags;
-
- wimlib_register_progress_function(wimfs_ctx->wim,
- (msg->want_progress_messages ?
- unmount_progress_func : NULL),
- NULL);
-
- ret = send_daemon_info_msg(wimfs_ctx->daemon_to_unmount_mq, getpid(),
- wimfs_ctx->mount_flags);
- if (ret != 0) {
- status = ret;
- goto out;
- }
-
- if (wimfs_ctx->mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
- if (unmount_flags & WIMLIB_UNMOUNT_FLAG_COMMIT) {
-
- if (unmount_flags & WIMLIB_UNMOUNT_FLAG_NEW_IMAGE) {
- ret = renew_current_image(wimfs_ctx);
- if (ret) {
- status = ret;
- goto out;
- }
- } else {
- release_extra_refcnts(wimfs_ctx);
- }
- INIT_LIST_HEAD(&wimfs_ctx->orig_stream_list);
-
- int write_flags = 0;
- if (unmount_flags & WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY)
- write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
- if (unmount_flags & WIMLIB_UNMOUNT_FLAG_REBUILD)
- write_flags |= WIMLIB_WRITE_FLAG_REBUILD;
- if (unmount_flags & WIMLIB_UNMOUNT_FLAG_RECOMPRESS)
- write_flags |= WIMLIB_WRITE_FLAG_RECOMPRESS;
- status = rebuild_wim(wimfs_ctx, write_flags);
- }
- } else {
- DEBUG("Read-only mount");
- status = 0;
- }
-
-out:
- if (wimfs_ctx->mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
- ret = delete_staging_dir(wimfs_ctx);
- if (ret != 0) {
- ERROR("Failed to delete the staging directory");
- if (status == 0)
- status = ret;
- }
- }
- wimfs_ctx->status = status;
- wimfs_ctx->have_status = true;
- return MSG_BREAK_LOOP;
-}
-
-static int
-msg_daemon_info_handler(const void *_msg, void *_handler_ctx)
-{
- const struct msg_daemon_info *msg = _msg;
- struct unmount_msg_handler_context *handler_ctx = _handler_ctx;
-
- DEBUG("Handling daemon info msg");
- if (msg->hdr.msg_size < sizeof(*msg))
- return WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
- handler_ctx->daemon_pid = msg->daemon_pid;
- handler_ctx->mount_flags = msg->mount_flags;
- handler_ctx->hdr.timeout_seconds = 1;
- DEBUG("pid of daemon is %d; mount flags were %#x",
- handler_ctx->daemon_pid,
- handler_ctx->mount_flags);
- return 0;
-}
-
-static int
-msg_write_streams_progress_handler(const void *_msg, void *_handler_ctx)
-{
- const struct msg_write_streams_progress *msg = _msg;
- struct unmount_msg_handler_context *handler_ctx = _handler_ctx;
-
- if (msg->hdr.msg_size < sizeof(*msg))
- return WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
- return call_progress(handler_ctx->progfunc,
- WIMLIB_PROGRESS_MSG_WRITE_STREAMS,
- (union wimlib_progress_info *)&msg->info,
- handler_ctx->progctx);
-}
-
-static int
-msg_unmount_finished_handler(const void *_msg, void *_handler_ctx)
-{
- const struct msg_unmount_finished *msg = _msg;
- struct unmount_msg_handler_context *handler_ctx = _handler_ctx;
-
- DEBUG("Handling unmount finished message");
- if (msg->hdr.msg_size < sizeof(*msg))
- return WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
- handler_ctx->status = msg->status;
- DEBUG("status is %d", handler_ctx->status);
- return MSG_BREAK_LOOP;
-}
-
-static int
-unmount_timed_out_cb(void *_handler_ctx)