+static int
+begin_unmount(const char *dir, int unmount_flags, int *mount_flags_ret,
+ wimlib_progress_func_t progfunc, void *progctx)
+{
+ int mount_flags;
+ int mounted_image;
+ int wim_filename_len;
+ union wimlib_progress_info progress;
+
+ if (getxattr(dir, "wimfs.mount_flags",
+ &mount_flags, sizeof(int)) != sizeof(int))
+ return WIMLIB_ERR_NOT_A_MOUNTPOINT;
+
+ *mount_flags_ret = mount_flags;
+
+ if (!progfunc)
+ return 0;
+
+ if (getxattr(dir, "wimfs.mounted_image",
+ &mounted_image, sizeof(int)) != sizeof(int))
+ return WIMLIB_ERR_NOT_A_MOUNTPOINT;
+
+ wim_filename_len = getxattr(dir, "wimfs.wim_filename", NULL, 0);
+ if (wim_filename_len < 0)
+ return WIMLIB_ERR_NOT_A_MOUNTPOINT;
+
+ char wim_filename[wim_filename_len + 1];
+ if (getxattr(dir, "wimfs.wim_filename",
+ wim_filename, wim_filename_len) != wim_filename_len)
+ return WIMLIB_ERR_NOT_A_MOUNTPOINT;
+ wim_filename[wim_filename_len] = '\0';
+
+ progress.unmount.mountpoint = dir;
+ progress.unmount.mounted_wim = wim_filename;
+ progress.unmount.mounted_image = mounted_image;
+ progress.unmount.mount_flags = mount_flags;
+ progress.unmount.unmount_flags = unmount_flags;
+
+ return call_progress(progfunc, WIMLIB_PROGRESS_MSG_UNMOUNT_BEGIN,
+ &progress, progctx);
+}
+
+/* API function documented in wimlib.h */
+WIMLIBAPI int
+wimlib_unmount_image_with_progress(const char *dir, int unmount_flags,
+ wimlib_progress_func_t progfunc, void *progctx)