- DEBUG("Calculating SHA1 checksums for all new staging files.");
- list_for_each_entry_safe(lte, tmp, &ctx->staging_list, staging_list) {
- ret = update_lte_of_staging_file(lte, w->lookup_table);
- if (ret != 0)
- return ret;
- }
-
- xml_update_image_info(w, w->current_image);
- ret = wimlib_overwrite(w, write_flags, 0, progress_func);
- if (ret != 0)
- ERROR("Failed to commit changes to mounted WIM image");
- return ret;
-}
-
-
-
-/* Simple function that returns the concatenation of 2 strings. */
-static char *strcat_dup(const char *s1, const char *s2, size_t max_len)
-{
- size_t len = strlen(s1) + strlen(s2);
- if (len > max_len)
- len = max_len;
- char *p = MALLOC(len + 1);
- if (!p)
- return NULL;
- snprintf(p, len + 1, "%s%s", s1, s2);
- return p;
-}
-
-static int set_message_queue_names(struct wimfs_context *ctx,
- const char *mount_dir)
-{
- static const char *u2d_prefix = "/wimlib-unmount-to-daemon-mq";
- static const char *d2u_prefix = "/wimlib-daemon-to-unmount-mq";
- char *dir_path;
- char *p;
- int ret;
-
- dir_path = realpath(mount_dir, NULL);
- if (!dir_path) {
- ERROR_WITH_ERRNO("Failed to resolve path \"%s\"", mount_dir);
- if (errno == ENOMEM)
- return WIMLIB_ERR_NOMEM;
- else
- return WIMLIB_ERR_NOTDIR;
- }
-
- for (p = dir_path; *p; p++)
- if (*p == '/')
- *p = 0xff;
-
- ctx->unmount_to_daemon_mq_name = strcat_dup(u2d_prefix, dir_path,
- NAME_MAX);
- if (!ctx->unmount_to_daemon_mq_name) {
- ret = WIMLIB_ERR_NOMEM;
- goto out_free_dir_path;
- }
- ctx->daemon_to_unmount_mq_name = strcat_dup(d2u_prefix, dir_path,
- NAME_MAX);
- if (!ctx->daemon_to_unmount_mq_name) {
- ret = WIMLIB_ERR_NOMEM;
- goto out_free_unmount_to_daemon_mq_name;
- }
-
- ret = 0;
- goto out_free_dir_path;
-out_free_unmount_to_daemon_mq_name:
- FREE(ctx->unmount_to_daemon_mq_name);
- ctx->unmount_to_daemon_mq_name = NULL;
-out_free_dir_path:
- FREE(dir_path);
- return ret;
-}
-
-static void free_message_queue_names(struct wimfs_context *ctx)
-{
- FREE(ctx->unmount_to_daemon_mq_name);
- FREE(ctx->daemon_to_unmount_mq_name);
- ctx->unmount_to_daemon_mq_name = NULL;
- ctx->daemon_to_unmount_mq_name = NULL;
-}
-
-/*
- * Opens two POSIX message queue: one for sending messages from the unmount
- * process to the daemon process, and one to go the other way. The names of the
- * message queues, which must be system-wide unique, are be based on the mount
- * point.
- *
- * @daemon specifies whether the calling process is the filesystem daemon or the
- * unmount process.
- */
-static int open_message_queues(struct wimfs_context *ctx, bool daemon)
-{
- int unmount_to_daemon_mq_flags = O_WRONLY | O_CREAT;
- int daemon_to_unmount_mq_flags = O_RDONLY | O_CREAT;
- mode_t mode;
- mode_t orig_umask;
- int ret;
-
- if (daemon) {
- swap(unmount_to_daemon_mq_flags, daemon_to_unmount_mq_flags);
- mode = 0600;
- } else {
- mode = 0666;
- }
-
- orig_umask = umask(0000);
- DEBUG("Opening message queue \"%s\"", ctx->unmount_to_daemon_mq_name);
- ctx->unmount_to_daemon_mq = mq_open(ctx->unmount_to_daemon_mq_name,
- unmount_to_daemon_mq_flags, mode, NULL);
-
- if (ctx->unmount_to_daemon_mq == (mqd_t)-1) {
- ERROR_WITH_ERRNO("mq_open()");
- ret = WIMLIB_ERR_MQUEUE;
- goto out;
- }
-
- DEBUG("Opening message queue \"%s\"", ctx->daemon_to_unmount_mq_name);
- ctx->daemon_to_unmount_mq = mq_open(ctx->daemon_to_unmount_mq_name,
- daemon_to_unmount_mq_flags, mode, NULL);
-
- if (ctx->daemon_to_unmount_mq == (mqd_t)-1) {
- ERROR_WITH_ERRNO("mq_open()");
- mq_close(ctx->unmount_to_daemon_mq);
- mq_unlink(ctx->unmount_to_daemon_mq_name);
- ctx->unmount_to_daemon_mq = (mqd_t)-1;
- ret = WIMLIB_ERR_MQUEUE;
- goto out;