4 * This file implements mounting of WIM files using FUSE, which stands for
5 * Filesystem in Userspace. FUSE allows a filesystem to be implemented in a
6 * userspace process by implementing the filesystem primitives--- read(),
7 * write(), readdir(), etc.
11 * Copyright (C) 2012, 2013 Eric Biggers
13 * This file is part of wimlib, a library for working with WIM files.
15 * wimlib is free software; you can redistribute it and/or modify it under the
16 * terms of the GNU General Public License as published by the Free
17 * Software Foundation; either version 3 of the License, or (at your option)
20 * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY
21 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
22 * A PARTICULAR PURPOSE. See the GNU General Public License for more
25 * You should have received a copy of the GNU General Public License
26 * along with wimlib; if not, see http://www.gnu.org/licenses/.
34 #include "wimlib/error.h"
39 # error "FUSE mount not supported on Win32! Please configure --without-fuse"
42 #include "wimlib/encoding.h"
43 #include "wimlib/file_io.h"
44 #include "wimlib/lookup_table.h"
45 #include "wimlib/metadata.h"
46 #include "wimlib/paths.h"
47 #include "wimlib/reparse.h"
48 #include "wimlib/resource.h"
49 #include "wimlib/timestamp.h"
50 #include "wimlib/version.h"
51 #include "wimlib/write.h"
52 #include "wimlib/xml.h"
63 #include <sys/types.h>
68 #define FUSE_USE_VERSION 26
72 #include <attr/xattr.h>
75 #define MSG_VERSION_TOO_HIGH -1
76 #define MSG_BREAK_LOOP -2
78 /* File descriptor to a file open on the WIM filesystem. */
80 struct wim_inode *f_inode;
81 struct wim_lookup_table_entry *f_lte;
82 struct filedes staging_fd;
87 struct wimfs_context {
88 /* The WIMStruct for the mounted WIM. */
91 /* Name of the staging directory for a read-write mount. Whenever a new file is
92 * created, it is done so in the staging directory. Furthermore, whenever a
93 * file in the WIM is modified, it is extracted to the staging directory. If
94 * changes are commited when the WIM is unmounted, the file resources are merged
95 * in from the staging directory when writing the new WIM. */
96 char *staging_dir_name;
97 size_t staging_dir_name_len;
99 /* Flags passed to wimlib_mount(). */
102 /* Default flags to use when looking up a WIM dentry (depends on whether
103 * the Windows interface to alternate data streams is being used or
105 int default_lookup_flags;
107 /* Next inode number to be assigned. Note: I didn't bother with a
108 * bitmap of free inode numbers since this isn't even a "real"
109 * filesystem anyway. */
112 /* List of inodes in the mounted image */
113 struct list_head *image_inode_list;
115 /* Name and message queue descriptors for message queues between the
116 * filesystem daemon process and the unmount process. These are used
117 * when the filesystem is unmounted and the process running
118 * wimlib_unmount_image() needs to communicate with the filesystem
119 * daemon running fuse_main() (i.e. the process created by a call to
120 * wimlib_mount_image(). */
121 char *unmount_to_daemon_mq_name;
122 char *daemon_to_unmount_mq_name;
123 mqd_t unmount_to_daemon_mq;
124 mqd_t daemon_to_unmount_mq;
134 init_wimfs_context(struct wimfs_context *ctx)
136 memset(ctx, 0, sizeof(*ctx));
137 ctx->unmount_to_daemon_mq = (mqd_t)-1;
138 ctx->daemon_to_unmount_mq = (mqd_t)-1;
141 #define WIMFS_CTX(fuse_ctx) ((struct wimfs_context*)(fuse_ctx)->private_data)
143 static inline struct wimfs_context *
144 wimfs_get_context(void)
146 return WIMFS_CTX(fuse_get_context());
149 static inline WIMStruct *
150 wimfs_get_WIMStruct(void)
152 return wimfs_get_context()->wim;
156 wimfs_ctx_readonly(const struct wimfs_context *ctx)
158 return (ctx->mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) == 0;
162 get_lookup_flags(const struct wimfs_context *ctx)
164 return ctx->default_lookup_flags;
167 /* Returns nonzero if write permission is requested on the file open flags */
169 flags_writable(int open_flags)
171 return open_flags & (O_RDWR | O_WRONLY);
175 * Allocate a file descriptor for a stream.
177 * @inode: inode containing the stream we're opening
178 * @stream_id: ID of the stream we're opening
179 * @lte: Lookup table entry for the stream (may be NULL)
180 * @fd_ret: Return the allocated file descriptor if successful.
181 * @readonly: True if this is a read-only mount.
183 * Return 0 iff successful or error code if unsuccessful.
186 alloc_wimfs_fd(struct wim_inode *inode,
188 struct wim_lookup_table_entry *lte,
189 struct wimfs_fd **fd_ret,
192 static const u16 fds_per_alloc = 8;
193 static const u16 max_fds = 0xffff;
196 DEBUG("Allocating fd for stream ID %u from inode %#"PRIx64" "
197 "(open = %u, allocated = %u)",
198 stream_id, inode->i_ino, inode->i_num_opened_fds,
199 inode->i_num_allocated_fds);
201 if (inode->i_num_opened_fds == inode->i_num_allocated_fds) {
202 struct wimfs_fd **fds;
205 if (inode->i_num_allocated_fds == max_fds) {
209 num_new_fds = min(fds_per_alloc,
210 max_fds - inode->i_num_allocated_fds);
212 fds = REALLOC(inode->i_fds,
213 (inode->i_num_allocated_fds + num_new_fds) *
214 sizeof(inode->i_fds[0]));
219 memset(&fds[inode->i_num_allocated_fds], 0,
220 num_new_fds * sizeof(fds[0]));
222 inode->i_num_allocated_fds += num_new_fds;
224 for (u16 i = 0; ; i++) {
225 if (!inode->i_fds[i]) {
226 struct wimfs_fd *fd = CALLOC(1, sizeof(*fd));
233 filedes_invalidate(&fd->staging_fd);
235 fd->stream_id = stream_id;
237 inode->i_fds[i] = fd;
238 inode->i_num_opened_fds++;
239 if (lte && !readonly)
240 lte->num_opened_fds++;
241 DEBUG("Allocated fd (idx = %u)", fd->idx);
251 inode_put_fd(struct wim_inode *inode, struct wimfs_fd *fd)
253 wimlib_assert(inode != NULL);
254 wimlib_assert(fd->f_inode == inode);
255 wimlib_assert(inode->i_num_opened_fds != 0);
256 wimlib_assert(fd->idx < inode->i_num_allocated_fds);
257 wimlib_assert(inode->i_fds[fd->idx] == fd);
259 inode->i_fds[fd->idx] = NULL;
261 if (--inode->i_num_opened_fds == 0) {
264 inode->i_num_allocated_fds = 0;
265 if (inode->i_nlink == 0)
271 lte_put_fd(struct wim_lookup_table_entry *lte, struct wimfs_fd *fd)
273 wimlib_assert(fd->f_lte == lte);
275 if (!lte) /* Empty stream with no lookup table entry */
278 /* Close staging file descriptor if needed. */
280 if (lte->resource_location == RESOURCE_IN_STAGING_FILE
281 && filedes_valid(&fd->staging_fd))
283 if (filedes_close(&fd->staging_fd)) {
284 ERROR_WITH_ERRNO("Failed to close staging file");
288 lte_decrement_num_opened_fds(lte);
292 /* Close a file descriptor. */
294 close_wimfs_fd(struct wimfs_fd *fd)
297 DEBUG("Closing fd (ino = %#"PRIx64", opened = %u, allocated = %u)",
298 fd->f_inode->i_ino, fd->f_inode->i_num_opened_fds,
299 fd->f_inode->i_num_allocated_fds);
300 ret = lte_put_fd(fd->f_lte, fd);
304 inode_put_fd(fd->f_inode, fd);
309 fuse_mask_mode(mode_t mode, struct fuse_context *fuse_ctx)
311 #if FUSE_MAJOR_VERSION > 2 || (FUSE_MAJOR_VERSION == 2 && FUSE_MINOR_VERSION >= 8)
312 mode &= ~fuse_ctx->umask;
318 * Add a new dentry with a new inode to a WIM image.
320 * Returns 0 on success, or negative error number on failure.
323 create_dentry(struct fuse_context *fuse_ctx, const char *path,
324 mode_t mode, int attributes, struct wim_dentry **dentry_ret)
326 struct wim_dentry *parent;
327 struct wim_dentry *new;
328 const char *basename;
329 struct wimfs_context *wimfs_ctx = WIMFS_CTX(fuse_ctx);
332 parent = get_parent_dentry(wimfs_ctx->wim, path);
336 if (!dentry_is_directory(parent))
339 basename = path_basename(path);
340 if (get_dentry_child_with_name(parent, basename))
343 ret = new_dentry_with_inode(basename, &new);
347 new->d_inode->i_resolved = 1;
348 new->d_inode->i_ino = wimfs_ctx->next_ino++;
349 new->d_inode->i_attributes = attributes;
351 if (wimfs_ctx->mount_flags & WIMLIB_MOUNT_FLAG_UNIX_DATA) {
352 if (inode_set_unix_data(new->d_inode,
355 fuse_mask_mode(mode, fuse_ctx),
356 wimfs_ctx->wim->lookup_table,
357 UNIX_DATA_ALL | UNIX_DATA_CREATE))
363 dentry_add_child(parent, new);
364 list_add_tail(&new->d_inode->i_list, wimfs_ctx->image_inode_list);
370 /* Remove a dentry from a mounted WIM image; i.e. remove an alias for the
371 * corresponding inode.
373 * If there are no remaining references to the inode either through dentries or
374 * open file descriptors, the inode is freed. Otherwise, the inode is not
375 * removed, but the dentry is unlinked and freed.
377 * Either way, all lookup table entries referenced by the inode have their
378 * reference count decremented. If a lookup table entry has no open file
379 * descriptors and no references remaining, it is freed, and the corresponding
380 * staging file is unlinked.
383 remove_dentry(struct wim_dentry *dentry,
384 struct wim_lookup_table *lookup_table)
386 struct wim_inode *inode = dentry->d_inode;
387 struct wim_lookup_table_entry *lte;
390 for (i = 0; i <= inode->i_num_ads; i++) {
391 lte = inode_stream_lte_resolved(inode, i);
393 lte_decrement_refcnt(lte, lookup_table);
395 unlink_dentry(dentry);
400 inode_default_unix_mode(const struct wim_inode *inode)
402 if (inode_is_symlink(inode))
403 return S_IFLNK | 0777;
404 else if (inode_is_directory(inode))
405 return S_IFDIR | 0777;
407 return S_IFREG | 0777;
410 /* Transfers file attributes from a struct wim_inode to a `stat' buffer.
412 * The lookup table entry tells us which stream in the inode we are statting.
413 * For a named data stream, everything returned is the same as the unnamed data
414 * stream except possibly the size and block count. */
416 inode_to_stbuf(const struct wim_inode *inode,
417 const struct wim_lookup_table_entry *lte,
420 const struct wimfs_context *ctx = wimfs_get_context();
422 memset(stbuf, 0, sizeof(struct stat));
423 stbuf->st_mode = inode_default_unix_mode(inode);
424 stbuf->st_uid = ctx->default_uid;
425 stbuf->st_gid = ctx->default_gid;
426 if (ctx->mount_flags & WIMLIB_MOUNT_FLAG_UNIX_DATA) {
427 struct wimlib_unix_data unix_data;
428 if (inode_get_unix_data(inode, &unix_data, NULL) == 0) {
429 stbuf->st_uid = unix_data.uid;
430 stbuf->st_gid = unix_data.gid;
431 stbuf->st_mode = unix_data.mode;
434 stbuf->st_ino = (ino_t)inode->i_ino;
435 stbuf->st_nlink = inode->i_nlink;
437 stbuf->st_size = wim_resource_size(lte);
440 #ifdef HAVE_STAT_NANOSECOND_PRECISION
441 stbuf->st_atim = wim_timestamp_to_timespec(inode->i_last_access_time);
442 stbuf->st_mtim = wim_timestamp_to_timespec(inode->i_last_write_time);
443 stbuf->st_ctim = stbuf->st_mtim;
445 stbuf->st_atime = wim_timestamp_to_unix(inode->i_last_access_time);
446 stbuf->st_mtime = wim_timestamp_to_unix(inode->i_last_write_time);
447 stbuf->st_ctime = stbuf->st_mtime;
449 stbuf->st_blocks = (stbuf->st_size + 511) / 512;
454 touch_inode(struct wim_inode *inode)
456 u64 now = get_wim_timestamp();
457 inode->i_last_access_time = now;
458 inode->i_last_write_time = now;
461 /* Creates a new staging file and returns its file descriptor opened for
464 * @name_ret: A location into which the a pointer to the newly allocated name of
465 * the staging file is stored.
467 * @ctx: Context for the WIM filesystem; this provides the name of the
470 * On success, returns the file descriptor for the staging file, opened for
471 * writing. On failure, returns -1 and sets errno.
474 create_staging_file(char **name_ret, struct wimfs_context *ctx)
482 static const size_t STAGING_FILE_NAME_LEN = 20;
484 name_len = ctx->staging_dir_name_len + 1 + STAGING_FILE_NAME_LEN;
485 name = MALLOC(name_len + 1);
493 memcpy(name, ctx->staging_dir_name, ctx->staging_dir_name_len);
494 name[ctx->staging_dir_name_len] = '/';
495 randomize_char_array_with_alnum(name + ctx->staging_dir_name_len + 1,
496 STAGING_FILE_NAME_LEN);
497 name[name_len] = '\0';
500 /* Just in case, verify that the randomly generated name doesn't name an
501 * existing file, and try again if so */
502 } while (stat(name, &stbuf) == 0);
504 if (errno != ENOENT) /* other error?! */
507 /* doesn't exist--- ok */
509 DEBUG("Creating staging file `%s'", name);
511 fd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0600);
523 * Extract a WIM resource to the staging directory.
525 * @inode: Inode that contains the stream we are extracting
527 * @stream_id: Identifier for the stream (it stays constant even if the indices
528 * of the stream entries are changed)
530 * @lte: Pointer to pointer to the lookup table entry for the stream we need to
531 * extract, or NULL if there was no lookup table entry present for the stream
533 * @size: Number of bytes of the stream we want to extract (this supports the
534 * wimfs_truncate() function). It may be more than the actual stream length, in
535 * which case the extra space is filled with zeroes.
537 * @ctx: Context for the WIM filesystem.
539 * Returns 0 on success or a negative error code on failure.
542 extract_resource_to_staging_dir(struct wim_inode *inode,
544 struct wim_lookup_table_entry **lte,
546 struct wimfs_context *ctx)
548 char *staging_file_name;
551 struct wim_lookup_table_entry *old_lte, *new_lte;
554 DEBUG("Extracting resource to staging dir: inode %"PRIu64", "
555 "stream id %"PRIu32, inode->i_ino, stream_id);
559 wimlib_assert(old_lte == NULL ||
560 old_lte->resource_location != RESOURCE_IN_STAGING_FILE);
562 /* Create the staging file */
563 fd = create_staging_file(&staging_file_name, ctx);
567 /* Extract the stream to the staging file (possibly truncated) */
569 struct filedes wimlib_fd;
570 filedes_init(&wimlib_fd, fd);
571 extract_size = min(wim_resource_size(old_lte), size);
572 ret = extract_wim_resource_to_fd(old_lte, &wimlib_fd,
579 /* In the case of truncate() to more than the file length, extend the
580 * file with zeroes by calling ftruncate() on the underlying staging
582 if (ret == 0 && size > extract_size)
583 ret = ftruncate(fd, size);
585 /* Close the staging file descriptor and check for errors. If there's
586 * an error, unlink the staging file. */
587 if (ret != 0 || close(fd) != 0) {
593 goto out_delete_staging_file;
596 /* Now deal with the lookup table entries. We may be able to re-use the
597 * existing entry, but we may have to create a new one instead. */
599 if (old_lte && inode->i_nlink == old_lte->refcnt) {
600 /* The reference count of the existing lookup table entry is the
601 * same as the link count of the inode that contains the stream
602 * we're opening. Therefore, ALL the references to the lookup
603 * table entry correspond to the stream we're trying to extract,
604 * so the lookup table entry can be re-used. */
605 DEBUG("Re-using lookup table entry");
606 lookup_table_unlink(ctx->wim->lookup_table, old_lte);
610 /* There's an existing lookup table entry, but its
611 * reference count is greater than the link count for
612 * the inode containing a stream we're opening.
613 * Therefore, we need to split the lookup table entry.
615 wimlib_assert(old_lte->refcnt > inode->i_nlink);
616 DEBUG("Splitting lookup table entry "
617 "(inode->i_nlink = %u, old_lte->refcnt = %u)",
618 inode->i_nlink, old_lte->refcnt);
621 new_lte = new_lookup_table_entry();
624 goto out_delete_staging_file;
627 /* There may already be open file descriptors to this stream if
628 * it's previously been opened read-only, but just now we're
629 * opening it read-write. Identify those file descriptors and
630 * change their lookup table entry pointers to point to the new
631 * lookup table entry, and open staging file descriptors for
634 * At the same time, we need to count the number of these opened
635 * file descriptors to the new lookup table entry. If there's
636 * an old lookup table entry, this number needs to be subtracted
637 * from the fd's opened to the old entry. */
638 for (u16 i = 0, j = 0; j < inode->i_num_opened_fds; i++) {
639 struct wimfs_fd *fd = inode->i_fds[i];
641 if (fd->stream_id == stream_id) {
644 wimlib_assert(fd->f_lte == old_lte);
645 wimlib_assert(!filedes_valid(&fd->staging_fd));
647 new_lte->num_opened_fds++;
648 raw_fd = open(staging_file_name, O_RDONLY);
651 goto out_revert_fd_changes;
653 filedes_init(&fd->staging_fd, raw_fd);
658 DEBUG("%hu fd's were already opened to the file we extracted",
659 new_lte->num_opened_fds);
661 old_lte->num_opened_fds -= new_lte->num_opened_fds;
662 old_lte->refcnt -= inode->i_nlink;
666 new_lte->refcnt = inode->i_nlink;
667 new_lte->resource_location = RESOURCE_IN_STAGING_FILE;
668 new_lte->staging_file_name = staging_file_name;
669 new_lte->resource_entry.original_size = size;
671 lookup_table_insert_unhashed(ctx->wim->lookup_table, new_lte,
673 *retrieve_lte_pointer(new_lte) = new_lte;
676 out_revert_fd_changes:
677 for (u16 i = 0, j = 0; j < new_lte->num_opened_fds; i++) {
678 struct wimfs_fd *fd = inode->i_fds[i];
679 if (fd && fd->stream_id == stream_id && fd->f_lte == new_lte) {
681 if (filedes_valid(&fd->staging_fd)) {
682 filedes_close(&fd->staging_fd);
683 filedes_invalidate(&fd->staging_fd);
688 free_lookup_table_entry(new_lte);
689 out_delete_staging_file:
690 unlink(staging_file_name);
691 FREE(staging_file_name);
696 * Creates a randomly named staging directory and saves its name in the
697 * filesystem context structure.
700 make_staging_dir(struct wimfs_context *ctx, const char *user_prefix)
702 static const size_t random_suffix_len = 10;
703 static const char *common_suffix = ".staging";
704 static const size_t common_suffix_len = 8;
706 char *staging_dir_name = NULL;
707 size_t staging_dir_name_len;
709 const char *wim_basename;
710 char *real_user_prefix = NULL;
714 real_user_prefix = realpath(user_prefix, NULL);
715 if (!real_user_prefix) {
716 ERROR_WITH_ERRNO("Could not resolve `%s'",
718 ret = WIMLIB_ERR_NOTDIR;
721 wim_basename = path_basename(ctx->wim->filename);
722 prefix_len = strlen(real_user_prefix) + 1 + strlen(wim_basename);
724 prefix_len = strlen(ctx->wim->filename);
727 staging_dir_name_len = prefix_len + common_suffix_len + random_suffix_len;
729 staging_dir_name = MALLOC(staging_dir_name_len + 1);
730 if (!staging_dir_name) {
731 ret = WIMLIB_ERR_NOMEM;
735 if (real_user_prefix)
736 sprintf(staging_dir_name, "%s/%s", real_user_prefix, wim_basename);
738 strcpy(staging_dir_name, ctx->wim->filename);
740 strcat(staging_dir_name, common_suffix);
742 randomize_char_array_with_alnum(staging_dir_name + prefix_len + common_suffix_len,
745 staging_dir_name[staging_dir_name_len] = '\0';
747 if (mkdir(staging_dir_name, 0700) != 0) {
748 ERROR_WITH_ERRNO("Failed to create temporary directory `%s'",
750 ret = WIMLIB_ERR_MKDIR;
755 FREE(real_user_prefix);
757 ctx->staging_dir_name = staging_dir_name;
758 ctx->staging_dir_name_len = staging_dir_name_len;
760 FREE(staging_dir_name);
766 remove_file_or_directory(const char *fpath, const struct stat *sb,
767 int typeflag, struct FTW *ftwbuf)
769 if (remove(fpath) == 0)
772 ERROR_WITH_ERRNO("Cannot remove `%s'", fpath);
773 return WIMLIB_ERR_DELETE_STAGING_DIR;
778 * Deletes the staging directory and all the files contained in it.
781 delete_staging_dir(struct wimfs_context *ctx)
784 ret = nftw(ctx->staging_dir_name, remove_file_or_directory,
786 FREE(ctx->staging_dir_name);
787 ctx->staging_dir_name = NULL;
792 inode_close_fds(struct wim_inode *inode)
794 u16 num_opened_fds = inode->i_num_opened_fds;
795 for (u16 i = 0, j = 0; j < num_opened_fds; i++) {
796 struct wimfs_fd *fd = inode->i_fds[i];
798 wimlib_assert(fd->f_inode == inode);
799 int ret = close_wimfs_fd(fd);
808 /* Overwrites the WIM file, with changes saved. */
810 rebuild_wim(struct wimfs_context *ctx, int write_flags,
811 wimlib_progress_func_t progress_func)
814 struct wim_lookup_table_entry *lte, *tmp;
815 WIMStruct *wim = ctx->wim;
816 struct wim_image_metadata *imd = wim_get_current_image_metadata(ctx->wim);
818 DEBUG("Closing all staging file descriptors.");
819 image_for_each_unhashed_stream_safe(lte, tmp, imd) {
820 ret = inode_close_fds(lte->back_inode);
825 DEBUG("Freeing entries for zero-length streams");
826 image_for_each_unhashed_stream_safe(lte, tmp, imd) {
827 wimlib_assert(lte->unhashed);
828 if (wim_resource_size(lte) == 0) {
829 struct wim_lookup_table_entry **back_ptr;
830 back_ptr = retrieve_lte_pointer(lte);
832 list_del(<e->unhashed_list);
833 free_lookup_table_entry(lte);
837 xml_update_image_info(wim, wim->current_image);
838 ret = wimlib_overwrite(wim, write_flags, 0, progress_func);
840 ERROR("Failed to commit changes to mounted WIM image");
844 /* Simple function that returns the concatenation of 2 strings. */
846 strcat_dup(const char *s1, const char *s2, size_t max_len)
848 size_t len = strlen(s1) + strlen(s2);
851 char *p = MALLOC(len + 1);
854 snprintf(p, len + 1, "%s%s", s1, s2);
859 set_message_queue_names(struct wimfs_context *ctx, const char *mount_dir)
861 static const char *u2d_prefix = "/wimlib-unmount-to-daemon-mq";
862 static const char *d2u_prefix = "/wimlib-daemon-to-unmount-mq";
867 dir_path = realpath(mount_dir, NULL);
869 ERROR_WITH_ERRNO("Failed to resolve path \"%s\"", mount_dir);
871 return WIMLIB_ERR_NOMEM;
873 return WIMLIB_ERR_NOTDIR;
876 for (p = dir_path; *p; p++)
880 ctx->unmount_to_daemon_mq_name = strcat_dup(u2d_prefix, dir_path,
882 if (!ctx->unmount_to_daemon_mq_name) {
883 ret = WIMLIB_ERR_NOMEM;
884 goto out_free_dir_path;
886 ctx->daemon_to_unmount_mq_name = strcat_dup(d2u_prefix, dir_path,
888 if (!ctx->daemon_to_unmount_mq_name) {
889 ret = WIMLIB_ERR_NOMEM;
890 goto out_free_unmount_to_daemon_mq_name;
894 goto out_free_dir_path;
895 out_free_unmount_to_daemon_mq_name:
896 FREE(ctx->unmount_to_daemon_mq_name);
897 ctx->unmount_to_daemon_mq_name = NULL;
904 free_message_queue_names(struct wimfs_context *ctx)
906 FREE(ctx->unmount_to_daemon_mq_name);
907 FREE(ctx->daemon_to_unmount_mq_name);
908 ctx->unmount_to_daemon_mq_name = NULL;
909 ctx->daemon_to_unmount_mq_name = NULL;
913 * Opens two POSIX message queue: one for sending messages from the unmount
914 * process to the daemon process, and one to go the other way. The names of the
915 * message queues, which must be system-wide unique, are be based on the mount
918 * @daemon specifies whether the calling process is the filesystem daemon or the
922 open_message_queues(struct wimfs_context *ctx, bool daemon)
924 int unmount_to_daemon_mq_flags = O_WRONLY | O_CREAT;
925 int daemon_to_unmount_mq_flags = O_RDONLY | O_CREAT;
931 swap(unmount_to_daemon_mq_flags, daemon_to_unmount_mq_flags);
937 orig_umask = umask(0000);
938 DEBUG("Opening message queue \"%s\"", ctx->unmount_to_daemon_mq_name);
939 ctx->unmount_to_daemon_mq = mq_open(ctx->unmount_to_daemon_mq_name,
940 unmount_to_daemon_mq_flags, mode, NULL);
942 if (ctx->unmount_to_daemon_mq == (mqd_t)-1) {
943 ERROR_WITH_ERRNO("mq_open()");
944 ret = WIMLIB_ERR_MQUEUE;
948 DEBUG("Opening message queue \"%s\"", ctx->daemon_to_unmount_mq_name);
949 ctx->daemon_to_unmount_mq = mq_open(ctx->daemon_to_unmount_mq_name,
950 daemon_to_unmount_mq_flags, mode, NULL);
952 if (ctx->daemon_to_unmount_mq == (mqd_t)-1) {
953 ERROR_WITH_ERRNO("mq_open()");
954 mq_close(ctx->unmount_to_daemon_mq);
955 mq_unlink(ctx->unmount_to_daemon_mq_name);
956 ctx->unmount_to_daemon_mq = (mqd_t)-1;
957 ret = WIMLIB_ERR_MQUEUE;
966 /* Try to determine the maximum message size of a message queue. The return
967 * value is the maximum message size, or a guess of 8192 bytes if it cannot be
970 mq_get_msgsize(mqd_t mq)
972 static const char *msgsize_max_file = "/proc/sys/fs/mqueue/msgsize_max";
977 if (mq_getattr(mq, &attr) == 0) {
978 msgsize = attr.mq_msgsize;
980 ERROR_WITH_ERRNO("mq_getattr()");
981 ERROR("Attempting to read %s", msgsize_max_file);
982 fp = fopen(msgsize_max_file, "rb");
984 if (fscanf(fp, "%ld", &msgsize) != 1) {
985 ERROR("Assuming message size of 8192");
990 ERROR_WITH_ERRNO("Failed to open the file `%s'",
992 ERROR("Assuming message size of 8192");
1000 get_mailbox(mqd_t mq, long needed_msgsize, long *msgsize_ret,
1006 msgsize = mq_get_msgsize(mq);
1008 if (msgsize < needed_msgsize) {
1009 ERROR("Message queue max size must be at least %ld!",
1011 return WIMLIB_ERR_MQUEUE;
1014 mailbox = MALLOC(msgsize);
1016 ERROR("Failed to allocate %ld bytes for mailbox", msgsize);
1017 return WIMLIB_ERR_NOMEM;
1019 *msgsize_ret = msgsize;
1020 *mailbox_ret = mailbox;
1025 unlink_message_queues(struct wimfs_context *ctx)
1027 mq_unlink(ctx->unmount_to_daemon_mq_name);
1028 mq_unlink(ctx->daemon_to_unmount_mq_name);
1031 /* Closes the message queues, which are allocated in static variables */
1033 close_message_queues(struct wimfs_context *ctx)
1035 DEBUG("Closing message queues");
1036 mq_close(ctx->unmount_to_daemon_mq);
1037 ctx->unmount_to_daemon_mq = (mqd_t)(-1);
1038 mq_close(ctx->daemon_to_unmount_mq);
1039 ctx->daemon_to_unmount_mq = (mqd_t)(-1);
1040 unlink_message_queues(ctx);
1044 struct unmount_msg_hdr {
1049 } _packed_attribute;
1051 struct msg_unmount_request {
1052 struct unmount_msg_hdr hdr;
1054 u8 want_progress_messages;
1055 } _packed_attribute;
1057 struct msg_daemon_info {
1058 struct unmount_msg_hdr hdr;
1061 } _packed_attribute;
1063 struct msg_unmount_finished {
1064 struct unmount_msg_hdr hdr;
1066 } _packed_attribute;
1068 struct msg_write_streams_progress {
1069 struct unmount_msg_hdr hdr;
1070 union wimlib_progress_info info;
1071 } _packed_attribute;
1074 MSG_TYPE_UNMOUNT_REQUEST,
1075 MSG_TYPE_DAEMON_INFO,
1076 MSG_TYPE_WRITE_STREAMS_PROGRESS,
1077 MSG_TYPE_UNMOUNT_FINISHED,
1081 struct msg_handler_context_hdr {
1082 int timeout_seconds;
1085 struct unmount_msg_handler_context {
1086 struct msg_handler_context_hdr hdr;
1090 wimlib_progress_func_t progress_func;
1093 struct daemon_msg_handler_context {
1094 struct msg_handler_context_hdr hdr;
1095 struct wimfs_context *wimfs_ctx;
1099 send_unmount_request_msg(mqd_t mq, int unmount_flags, u8 want_progress_messages)
1101 DEBUG("Sending unmount request msg");
1102 struct msg_unmount_request msg = {
1104 .min_version = WIMLIB_MAKEVERSION(1, 2, 1),
1105 .cur_version = WIMLIB_VERSION_CODE,
1106 .msg_type = MSG_TYPE_UNMOUNT_REQUEST,
1107 .msg_size = sizeof(msg),
1109 .unmount_flags = unmount_flags,
1110 .want_progress_messages = want_progress_messages,
1113 if (mq_send(mq, (void*)&msg, sizeof(msg), 1)) {
1114 ERROR_WITH_ERRNO("Failed to communicate with filesystem daemon");
1115 return WIMLIB_ERR_MQUEUE;
1121 send_daemon_info_msg(mqd_t mq, pid_t pid, int mount_flags)
1123 DEBUG("Sending daemon info msg (pid = %d, mount_flags=%x)",
1126 struct msg_daemon_info msg = {
1128 .min_version = WIMLIB_MAKEVERSION(1, 2, 1),
1129 .cur_version = WIMLIB_VERSION_CODE,
1130 .msg_type = MSG_TYPE_DAEMON_INFO,
1131 .msg_size = sizeof(msg),
1134 .mount_flags = mount_flags,
1136 if (mq_send(mq, (void*)&msg, sizeof(msg), 1)) {
1137 ERROR_WITH_ERRNO("Failed to send daemon info to unmount process");
1138 return WIMLIB_ERR_MQUEUE;
1144 send_unmount_finished_msg(mqd_t mq, int status)
1146 DEBUG("Sending unmount finished msg");
1147 struct msg_unmount_finished msg = {
1149 .min_version = WIMLIB_MAKEVERSION(1, 2, 1),
1150 .cur_version = WIMLIB_VERSION_CODE,
1151 .msg_type = MSG_TYPE_UNMOUNT_FINISHED,
1152 .msg_size = sizeof(msg),
1156 if (mq_send(mq, (void*)&msg, sizeof(msg), 1))
1157 ERROR_WITH_ERRNO("Failed to send status to unmount process");
1161 unmount_progress_func(enum wimlib_progress_msg msg,
1162 const union wimlib_progress_info *info)
1164 if (msg == WIMLIB_PROGRESS_MSG_WRITE_STREAMS) {
1165 struct msg_write_streams_progress msg = {
1167 .min_version = WIMLIB_MAKEVERSION(1, 2, 1),
1168 .cur_version = WIMLIB_VERSION_CODE,
1169 .msg_type = MSG_TYPE_WRITE_STREAMS_PROGRESS,
1170 .msg_size = sizeof(msg),
1174 if (mq_send(wimfs_get_context()->daemon_to_unmount_mq,
1175 (void*)&msg, sizeof(msg), 1))
1177 ERROR_WITH_ERRNO("Failed to send progress information "
1178 "to unmount process");
1185 msg_unmount_request_handler(const void *_msg, void *_handler_ctx)
1187 const struct msg_unmount_request *msg = _msg;
1188 struct daemon_msg_handler_context *handler_ctx = _handler_ctx;
1189 struct wimfs_context *wimfs_ctx;
1193 wimlib_progress_func_t progress_func;
1195 DEBUG("Handling unmount request msg");
1197 wimfs_ctx = handler_ctx->wimfs_ctx;
1198 if (msg->hdr.msg_size < sizeof(*msg)) {
1199 status = WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1203 unmount_flags = msg->unmount_flags;
1204 if (msg->want_progress_messages)
1205 progress_func = unmount_progress_func;
1207 progress_func = NULL;
1209 ret = send_daemon_info_msg(wimfs_ctx->daemon_to_unmount_mq, getpid(),
1210 wimfs_ctx->mount_flags);
1216 if (wimfs_ctx->mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
1217 if (unmount_flags & WIMLIB_UNMOUNT_FLAG_COMMIT) {
1218 int write_flags = 0;
1219 if (unmount_flags & WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY)
1220 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
1221 if (unmount_flags & WIMLIB_UNMOUNT_FLAG_REBUILD)
1222 write_flags |= WIMLIB_WRITE_FLAG_REBUILD;
1223 if (unmount_flags & WIMLIB_UNMOUNT_FLAG_RECOMPRESS)
1224 write_flags |= WIMLIB_WRITE_FLAG_RECOMPRESS;
1225 status = rebuild_wim(wimfs_ctx, write_flags,
1229 DEBUG("Read-only mount");
1234 if (wimfs_ctx->mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
1235 ret = delete_staging_dir(wimfs_ctx);
1237 ERROR("Failed to delete the staging directory");
1242 wimfs_ctx->status = status;
1243 wimfs_ctx->have_status = true;
1244 return MSG_BREAK_LOOP;
1248 msg_daemon_info_handler(const void *_msg, void *_handler_ctx)
1250 const struct msg_daemon_info *msg = _msg;
1251 struct unmount_msg_handler_context *handler_ctx = _handler_ctx;
1253 DEBUG("Handling daemon info msg");
1254 if (msg->hdr.msg_size < sizeof(*msg))
1255 return WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1256 handler_ctx->daemon_pid = msg->daemon_pid;
1257 handler_ctx->mount_flags = msg->mount_flags;
1258 handler_ctx->hdr.timeout_seconds = 1;
1259 DEBUG("pid of daemon is %d; mount flags were %#x",
1260 handler_ctx->daemon_pid,
1261 handler_ctx->mount_flags);
1266 msg_write_streams_progress_handler(const void *_msg, void *_handler_ctx)
1268 const struct msg_write_streams_progress *msg = _msg;
1269 struct unmount_msg_handler_context *handler_ctx = _handler_ctx;
1271 if (msg->hdr.msg_size < sizeof(*msg))
1272 return WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1273 if (handler_ctx->progress_func) {
1274 handler_ctx->progress_func(WIMLIB_PROGRESS_MSG_WRITE_STREAMS,
1281 msg_unmount_finished_handler(const void *_msg, void *_handler_ctx)
1283 const struct msg_unmount_finished *msg = _msg;
1284 struct unmount_msg_handler_context *handler_ctx = _handler_ctx;
1286 DEBUG("Handling unmount finished message");
1287 if (msg->hdr.msg_size < sizeof(*msg))
1288 return WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1289 handler_ctx->status = msg->status;
1290 DEBUG("status is %d", handler_ctx->status);
1291 return MSG_BREAK_LOOP;
1295 unmount_timed_out_cb(void *_handler_ctx)
1297 struct unmount_msg_handler_context *handler_ctx = _handler_ctx;
1299 if (handler_ctx->daemon_pid == 0) {
1302 kill(handler_ctx->daemon_pid, 0);
1303 if (errno == ESRCH) {
1306 DEBUG("Filesystem daemon is still alive... "
1307 "Waiting another %d seconds\n",
1308 handler_ctx->hdr.timeout_seconds);
1313 ERROR("The filesystem daemon has crashed! Changes to the "
1314 "WIM may not have been commited.");
1315 return WIMLIB_ERR_FILESYSTEM_DAEMON_CRASHED;
1319 daemon_timed_out_cb(void *_handler_ctx)
1321 ERROR("Timed out waiting for unmount request! "
1322 "Changes to the mounted WIM will not be committed.");
1323 return WIMLIB_ERR_TIMEOUT;
1326 typedef int (*msg_handler_t)(const void *_msg, void *_handler_ctx);
1328 struct msg_handler_callbacks {
1329 int (*timed_out)(void * _handler_ctx);
1330 msg_handler_t msg_handlers[MSG_TYPE_MAX];
1333 static const struct msg_handler_callbacks unmount_msg_handler_callbacks = {
1334 .timed_out = unmount_timed_out_cb,
1336 [MSG_TYPE_DAEMON_INFO] = msg_daemon_info_handler,
1337 [MSG_TYPE_WRITE_STREAMS_PROGRESS] = msg_write_streams_progress_handler,
1338 [MSG_TYPE_UNMOUNT_FINISHED] = msg_unmount_finished_handler,
1342 static const struct msg_handler_callbacks daemon_msg_handler_callbacks = {
1343 .timed_out = daemon_timed_out_cb,
1345 [MSG_TYPE_UNMOUNT_REQUEST] = msg_unmount_request_handler,
1350 receive_message(mqd_t mq,
1351 struct msg_handler_context_hdr *handler_ctx,
1352 const msg_handler_t msg_handlers[],
1353 long mailbox_size, void *mailbox)
1356 struct timespec timeout;
1357 ssize_t bytes_received;
1358 struct unmount_msg_hdr *hdr;
1361 gettimeofday(&now, NULL);
1362 timeout.tv_sec = now.tv_sec + handler_ctx->timeout_seconds;
1363 timeout.tv_nsec = now.tv_usec * 1000;
1365 bytes_received = mq_timedreceive(mq, mailbox,
1366 mailbox_size, NULL, &timeout);
1368 if (bytes_received == -1) {
1369 if (errno == ETIMEDOUT) {
1370 ret = WIMLIB_ERR_TIMEOUT;
1372 ERROR_WITH_ERRNO("mq_timedreceive()");
1373 ret = WIMLIB_ERR_MQUEUE;
1375 } else if (bytes_received < sizeof(*hdr) ||
1376 bytes_received != hdr->msg_size) {
1377 ret = WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1378 } else if (WIMLIB_VERSION_CODE < hdr->min_version) {
1379 /*ERROR("Cannot understand the received message. "*/
1380 /*"Please upgrade wimlib to at least v%d.%d.%d",*/
1381 /*WIMLIB_GET_MAJOR_VERSION(hdr->min_version),*/
1382 /*WIMLIB_GET_MINOR_VERSION(hdr->min_version),*/
1383 /*WIMLIB_GET_PATCH_VERSION(hdr->min_version));*/
1384 ret = MSG_VERSION_TOO_HIGH;
1385 } else if (hdr->msg_type >= MSG_TYPE_MAX) {
1386 ret = WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1387 } else if (msg_handlers[hdr->msg_type] == NULL) {
1388 ret = WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1390 ret = msg_handlers[hdr->msg_type](mailbox, handler_ctx);
1396 message_loop(mqd_t mq,
1397 const struct msg_handler_callbacks *callbacks,
1398 struct msg_handler_context_hdr *handler_ctx)
1400 static const size_t MAX_MSG_SIZE = 512;
1405 DEBUG("Entering message loop");
1407 ret = get_mailbox(mq, MAX_MSG_SIZE, &msgsize, &mailbox);
1411 ret = receive_message(mq, handler_ctx,
1412 callbacks->msg_handlers,
1414 if (ret == 0 || ret == MSG_VERSION_TOO_HIGH) {
1416 } else if (ret == MSG_BREAK_LOOP) {
1419 } else if (ret == WIMLIB_ERR_TIMEOUT) {
1420 if (callbacks->timed_out)
1421 ret = callbacks->timed_out(handler_ctx);
1427 ERROR_WITH_ERRNO("Error communicating with "
1428 "filesystem daemon");
1433 DEBUG("Exiting message loop");
1437 /* Execute `fusermount -u', which is installed setuid root, to unmount the WIM.
1439 * FUSE does not yet implement synchronous unmounts. This means that fusermount
1440 * -u will return before the filesystem daemon returns from wimfs_destroy().
1441 * This is partly what we want, because we need to send a message from this
1442 * process to the filesystem daemon telling whether --commit was specified or
1443 * not. However, after that, the unmount process must wait for the filesystem
1444 * daemon to finish writing the WIM file.
1447 execute_fusermount(const char *dir, bool lazy)
1455 ERROR_WITH_ERRNO("Failed to fork()");
1456 return WIMLIB_ERR_FORK;
1462 *argp++ = "fusermount";
1466 *argp++ = (char*)dir;
1468 execvp("fusermount", argv);
1469 ERROR_WITH_ERRNO("Failed to execute `fusermount'");
1470 exit(WIMLIB_ERR_FUSERMOUNT);
1474 ret = waitpid(pid, &status, 0);
1476 ERROR_WITH_ERRNO("Failed to wait for fusermount process to "
1478 return WIMLIB_ERR_FUSERMOUNT;
1481 if (!WIFEXITED(status)) {
1482 ERROR("'fusermount' did not terminate normally!");
1483 return WIMLIB_ERR_FUSERMOUNT;
1486 status = WEXITSTATUS(status);
1491 if (status != WIMLIB_ERR_FUSERMOUNT)
1492 return WIMLIB_ERR_FUSERMOUNT;
1494 /* Try again, but with the `umount' program. This is required on other
1495 * FUSE implementations such as FreeBSD's that do not have a
1496 * `fusermount' program. */
1497 ERROR("Falling back to 'umount'. Note: you may need to be "
1498 "root for this to work");
1501 ERROR_WITH_ERRNO("Failed to fork()");
1502 return WIMLIB_ERR_FORK;
1511 *argp++ = (char*)dir;
1513 execvp("umount", argv);
1514 ERROR_WITH_ERRNO("Failed to execute `umount'");
1515 exit(WIMLIB_ERR_FUSERMOUNT);
1519 ret = waitpid(pid, &status, 0);
1521 ERROR_WITH_ERRNO("Failed to wait for `umount' process to "
1523 return WIMLIB_ERR_FUSERMOUNT;
1526 ERROR("`umount' did not successfully complete");
1527 return WIMLIB_ERR_FUSERMOUNT;
1533 wimfs_chmod(const char *path, mode_t mask)
1535 struct wim_dentry *dentry;
1536 struct wimfs_context *ctx = wimfs_get_context();
1539 if (!(ctx->mount_flags & WIMLIB_MOUNT_FLAG_UNIX_DATA))
1542 ret = wim_pathname_to_stream(ctx->wim, path, LOOKUP_FLAG_DIRECTORY_OK,
1543 &dentry, NULL, NULL);
1547 ret = inode_set_unix_data(dentry->d_inode, ctx->default_uid,
1548 ctx->default_gid, mask,
1549 ctx->wim->lookup_table, UNIX_DATA_MODE);
1550 return ret ? -ENOMEM : 0;
1554 wimfs_chown(const char *path, uid_t uid, gid_t gid)
1556 struct wim_dentry *dentry;
1557 struct wimfs_context *ctx = wimfs_get_context();
1560 if (!(ctx->mount_flags & WIMLIB_MOUNT_FLAG_UNIX_DATA))
1563 ret = wim_pathname_to_stream(ctx->wim, path, LOOKUP_FLAG_DIRECTORY_OK,
1564 &dentry, NULL, NULL);
1568 ret = inode_set_unix_data(dentry->d_inode, uid, gid,
1569 inode_default_unix_mode(dentry->d_inode),
1570 ctx->wim->lookup_table,
1571 UNIX_DATA_UID | UNIX_DATA_GID);
1572 return ret ? -ENOMEM : 0;
1575 /* Called when the filesystem is unmounted. */
1577 wimfs_destroy(void *p)
1579 struct wimfs_context *wimfs_ctx = wimfs_get_context();
1580 if (open_message_queues(wimfs_ctx, true) == 0) {
1581 struct daemon_msg_handler_context handler_ctx = {
1583 .timeout_seconds = 5,
1585 .wimfs_ctx = wimfs_ctx,
1587 message_loop(wimfs_ctx->unmount_to_daemon_mq,
1588 &daemon_msg_handler_callbacks,
1594 wimfs_fgetattr(const char *path, struct stat *stbuf,
1595 struct fuse_file_info *fi)
1597 struct wimfs_fd *fd = (struct wimfs_fd*)(uintptr_t)fi->fh;
1598 return inode_to_stbuf(fd->f_inode, fd->f_lte, stbuf);
1602 wimfs_ftruncate(const char *path, off_t size, struct fuse_file_info *fi)
1604 struct wimfs_fd *fd = (struct wimfs_fd*)(uintptr_t)fi->fh;
1605 int ret = ftruncate(fd->staging_fd.fd, size);
1608 touch_inode(fd->f_inode);
1609 fd->f_lte->resource_entry.original_size = size;
1614 * Fills in a `struct stat' that corresponds to a file or directory in the WIM.
1617 wimfs_getattr(const char *path, struct stat *stbuf)
1619 struct wim_dentry *dentry;
1620 struct wim_lookup_table_entry *lte;
1622 struct wimfs_context *ctx = wimfs_get_context();
1624 ret = wim_pathname_to_stream(ctx->wim, path,
1625 get_lookup_flags(ctx) |
1626 LOOKUP_FLAG_DIRECTORY_OK,
1627 &dentry, <e, NULL);
1630 return inode_to_stbuf(dentry->d_inode, lte, stbuf);
1634 /* Read an alternate data stream through the XATTR interface, or get its size */
1636 wimfs_getxattr(const char *path, const char *name, char *value,
1640 struct wim_inode *inode;
1641 struct wim_ads_entry *ads_entry;
1643 struct wim_lookup_table_entry *lte;
1644 struct wimfs_context *ctx = wimfs_get_context();
1646 if (!(ctx->mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR))
1649 if (strlen(name) <= 5 || memcmp(name, "user.", 5) != 0)
1653 inode = wim_pathname_to_inode(ctx->wim, path);
1657 ads_entry = inode_get_ads_entry(inode, name, NULL);
1661 lte = ads_entry->lte;
1662 res_size = wim_resource_size(lte);
1667 if (res_size > size)
1670 ret = read_full_resource_into_buf(lte, value);
1681 /* Create a hard link */
1683 wimfs_link(const char *to, const char *from)
1685 struct wim_dentry *from_dentry, *from_dentry_parent;
1686 const char *link_name;
1687 struct wim_inode *inode;
1688 WIMStruct *wim = wimfs_get_WIMStruct();
1691 inode = wim_pathname_to_inode(wim, to);
1695 if (inode->i_attributes & (FILE_ATTRIBUTE_DIRECTORY |
1696 FILE_ATTRIBUTE_REPARSE_POINT))
1699 from_dentry_parent = get_parent_dentry(wim, from);
1700 if (!from_dentry_parent)
1702 if (!dentry_is_directory(from_dentry_parent))
1705 link_name = path_basename(from);
1706 if (get_dentry_child_with_name(from_dentry_parent, link_name))
1709 ret = new_dentry(link_name, &from_dentry);
1714 inode_ref_streams(inode);
1715 from_dentry->d_inode = inode;
1716 inode_add_dentry(from_dentry, inode);
1717 dentry_add_child(from_dentry_parent, from_dentry);
1723 wimfs_listxattr(const char *path, char *list, size_t size)
1726 struct wim_inode *inode;
1727 struct wimfs_context *ctx = wimfs_get_context();
1730 bool size_only = (size == 0);
1732 if (!(ctx->mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR))
1735 /* List alternate data streams, or get the list size */
1737 inode = wim_pathname_to_inode(ctx->wim, path);
1742 for (i = 0; i < inode->i_num_ads; i++) {
1744 if (!ads_entry_is_named_stream(&inode->i_ads_entries[i]))
1747 char *stream_name_mbs;
1748 size_t stream_name_mbs_nbytes;
1751 ret = utf16le_to_tstr(inode->i_ads_entries[i].stream_name,
1752 inode->i_ads_entries[i].stream_name_nbytes,
1754 &stream_name_mbs_nbytes);
1758 needed_size = stream_name_mbs_nbytes + 6;
1760 if (needed_size > size) {
1761 FREE(stream_name_mbs);
1764 sprintf(p, "user.%s", stream_name_mbs);
1765 size -= needed_size;
1768 FREE(stream_name_mbs);
1775 /* Create a directory in the WIM image. */
1777 wimfs_mkdir(const char *path, mode_t mode)
1779 return create_dentry(fuse_get_context(), path, mode | S_IFDIR,
1780 FILE_ATTRIBUTE_DIRECTORY, NULL);
1783 /* Create a regular file or alternate data stream in the WIM image. */
1785 wimfs_mknod(const char *path, mode_t mode, dev_t rdev)
1787 const char *stream_name;
1788 struct fuse_context *fuse_ctx = fuse_get_context();
1789 struct wimfs_context *wimfs_ctx = WIMFS_CTX(fuse_ctx);
1794 if ((wimfs_ctx->mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS)
1795 && (stream_name = path_stream_name(path))) {
1796 /* Make an alternate data stream */
1797 struct wim_ads_entry *new_entry;
1798 struct wim_inode *inode;
1800 char *p = (char*)stream_name - 1;
1801 wimlib_assert(*p == ':');
1804 inode = wim_pathname_to_inode(wimfs_ctx->wim, path);
1807 if (inode->i_attributes & FILE_ATTRIBUTE_REPARSE_POINT)
1809 if (inode_get_ads_entry(inode, stream_name, NULL))
1811 new_entry = inode_add_ads(inode, stream_name);
1816 /* Make a normal file (not an alternate data stream) */
1817 return create_dentry(fuse_ctx, path, mode | S_IFREG,
1818 FILE_ATTRIBUTE_NORMAL, NULL);
1824 wimfs_open(const char *path, struct fuse_file_info *fi)
1826 struct wim_dentry *dentry;
1827 struct wim_lookup_table_entry *lte;
1829 struct wimfs_fd *fd;
1830 struct wim_inode *inode;
1833 struct wimfs_context *ctx = wimfs_get_context();
1834 struct wim_lookup_table_entry **back_ptr;
1836 ret = wim_pathname_to_stream(ctx->wim, path, get_lookup_flags(ctx),
1837 &dentry, <e, &stream_idx);
1841 inode = dentry->d_inode;
1843 if (stream_idx == 0) {
1845 back_ptr = &inode->i_lte;
1847 stream_id = inode->i_ads_entries[stream_idx - 1].stream_id;
1848 back_ptr = &inode->i_ads_entries[stream_idx - 1].lte;
1851 /* The file resource may be in the staging directory (read-write mounts
1852 * only) or in the WIM. If it's in the staging directory, we need to
1853 * open a native file descriptor for the corresponding file. Otherwise,
1854 * we can read the file resource directly from the WIM file if we are
1855 * opening it read-only, but we need to extract the resource to the
1856 * staging directory if we are opening it writable. */
1858 if (flags_writable(fi->flags) &&
1859 (!lte || lte->resource_location != RESOURCE_IN_STAGING_FILE)) {
1860 u64 size = (lte) ? wim_resource_size(lte) : 0;
1861 ret = extract_resource_to_staging_dir(inode, stream_id,
1868 ret = alloc_wimfs_fd(inode, stream_id, lte, &fd,
1869 wimfs_ctx_readonly(ctx));
1873 if (lte && lte->resource_location == RESOURCE_IN_STAGING_FILE) {
1876 raw_fd = open(lte->staging_file_name, fi->flags);
1878 int errno_save = errno;
1882 filedes_init(&fd->staging_fd, raw_fd);
1884 fi->fh = (uintptr_t)fd;
1888 /* Opens a directory. */
1890 wimfs_opendir(const char *path, struct fuse_file_info *fi)
1892 struct wim_inode *inode;
1894 struct wimfs_fd *fd = NULL;
1895 struct wimfs_context *ctx = wimfs_get_context();
1896 WIMStruct *wim = ctx->wim;
1898 inode = wim_pathname_to_inode(wim, path);
1901 if (!inode_is_directory(inode))
1903 ret = alloc_wimfs_fd(inode, 0, NULL, &fd, wimfs_ctx_readonly(ctx));
1904 fi->fh = (uintptr_t)fd;
1910 * Read data from a file in the WIM or in the staging directory.
1913 wimfs_read(const char *path, char *buf, size_t size,
1914 off_t offset, struct fuse_file_info *fi)
1916 struct wimfs_fd *fd = (struct wimfs_fd*)(uintptr_t)fi->fh;
1927 res_size = wim_resource_size(fd->f_lte);
1931 if (offset > res_size)
1934 size = min(size, res_size - offset);
1938 switch (fd->f_lte->resource_location) {
1939 case RESOURCE_IN_STAGING_FILE:
1940 ret = raw_pread(&fd->staging_fd, buf, size, offset);
1944 case RESOURCE_IN_WIM:
1945 if (read_partial_wim_resource_into_buf(fd->f_lte, size,
1951 case RESOURCE_IN_ATTACHED_BUFFER:
1952 memcpy(buf, fd->f_lte->attached_buffer + offset, size);
1956 ERROR("Invalid resource location");
1963 struct fill_params {
1965 fuse_fill_dir_t filler;
1969 dentry_fuse_fill(struct wim_dentry *dentry, void *arg)
1971 struct fill_params *fill_params = arg;
1973 char *file_name_mbs;
1974 size_t file_name_mbs_nbytes;
1977 ret = utf16le_to_tstr(dentry->file_name,
1978 dentry->file_name_nbytes,
1980 &file_name_mbs_nbytes);
1984 ret = fill_params->filler(fill_params->buf, file_name_mbs, NULL, 0);
1985 FREE(file_name_mbs);
1989 /* Fills in the entries of the directory specified by @path using the
1990 * FUSE-provided function @filler. */
1992 wimfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
1993 off_t offset, struct fuse_file_info *fi)
1995 struct wimfs_fd *fd = (struct wimfs_fd*)(uintptr_t)fi->fh;
1996 struct wim_inode *inode;
2001 inode = fd->f_inode;
2003 struct fill_params fill_params = {
2008 filler(buf, ".", NULL, 0);
2009 filler(buf, "..", NULL, 0);
2011 return for_dentry_in_rbtree(inode->i_children.rb_node,
2012 dentry_fuse_fill, &fill_params);
2017 wimfs_readlink(const char *path, char *buf, size_t buf_len)
2019 struct wimfs_context *ctx = wimfs_get_context();
2020 struct wim_inode *inode = wim_pathname_to_inode(ctx->wim, path);
2024 if (!inode_is_symlink(inode))
2027 return -ENAMETOOLONG;
2028 ret = wim_inode_readlink(inode, buf, buf_len - 1, NULL);
2030 wimlib_assert(ret <= buf_len - 1);
2033 } else if (ret == -ENAMETOOLONG) {
2034 buf[buf_len - 1] = '\0';
2041 wimfs_release(const char *path, struct fuse_file_info *fi)
2043 struct wimfs_fd *fd = (struct wimfs_fd*)(uintptr_t)fi->fh;
2044 return close_wimfs_fd(fd);
2047 /* Close a directory */
2049 wimfs_releasedir(const char *path, struct fuse_file_info *fi)
2051 struct wimfs_fd *fd = (struct wimfs_fd*)(uintptr_t)fi->fh;
2052 return close_wimfs_fd(fd);
2056 /* Remove an alternate data stream through the XATTR interface */
2058 wimfs_removexattr(const char *path, const char *name)
2060 struct wim_inode *inode;
2061 struct wim_ads_entry *ads_entry;
2063 struct wimfs_context *ctx = wimfs_get_context();
2065 if (!(ctx->mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR))
2068 if (strlen(name) < 5 || memcmp(name, "user.", 5) != 0)
2072 inode = wim_pathname_to_inode(ctx->wim, path);
2076 ads_entry = inode_get_ads_entry(inode, name, &ads_idx);
2079 inode_remove_ads(inode, ads_idx, ctx->wim->lookup_table);
2084 /* Renames a file or directory. See rename (3) */
2086 wimfs_rename(const char *from, const char *to)
2088 return rename_wim_path(wimfs_get_WIMStruct(), from, to);
2091 /* Remove a directory */
2093 wimfs_rmdir(const char *path)
2095 struct wim_dentry *dentry;
2096 WIMStruct *wim = wimfs_get_WIMStruct();
2098 dentry = get_dentry(wim, path);
2102 if (!dentry_is_directory(dentry))
2105 if (dentry_has_children(dentry))
2108 remove_dentry(dentry, wim->lookup_table);
2113 /* Write an alternate data stream through the XATTR interface */
2115 wimfs_setxattr(const char *path, const char *name,
2116 const char *value, size_t size, int flags)
2118 struct wim_ads_entry *existing_ads_entry;
2119 struct wim_inode *inode;
2121 struct wimfs_context *ctx = wimfs_get_context();
2124 if (!(ctx->mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR))
2127 if (strlen(name) <= 5 || memcmp(name, "user.", 5) != 0)
2131 inode = wim_pathname_to_inode(ctx->wim, path);
2135 existing_ads_entry = inode_get_ads_entry(inode, name, &ads_idx);
2136 if (existing_ads_entry) {
2137 if (flags & XATTR_CREATE)
2140 if (flags & XATTR_REPLACE)
2144 ret = inode_add_ads_with_data(inode, name, value,
2145 size, ctx->wim->lookup_table);
2147 if (existing_ads_entry)
2148 inode_remove_ads(inode, ads_idx, ctx->wim->lookup_table);
2157 wimfs_symlink(const char *to, const char *from)
2159 struct fuse_context *fuse_ctx = fuse_get_context();
2160 struct wimfs_context *wimfs_ctx = WIMFS_CTX(fuse_ctx);
2161 struct wim_dentry *dentry;
2164 ret = create_dentry(fuse_ctx, from, S_IFLNK | 0777,
2165 FILE_ATTRIBUTE_REPARSE_POINT, &dentry);
2167 dentry->d_inode->i_reparse_tag = WIM_IO_REPARSE_TAG_SYMLINK;
2168 ret = wim_inode_set_symlink(dentry->d_inode, to,
2169 wimfs_ctx->wim->lookup_table);
2171 remove_dentry(dentry, wimfs_ctx->wim->lookup_table);
2172 if (ret == WIMLIB_ERR_NOMEM)
2182 /* Reduce the size of a file */
2184 wimfs_truncate(const char *path, off_t size)
2186 struct wim_dentry *dentry;
2187 struct wim_lookup_table_entry *lte;
2191 struct wim_inode *inode;
2192 struct wimfs_context *ctx = wimfs_get_context();
2194 ret = wim_pathname_to_stream(ctx->wim, path, get_lookup_flags(ctx),
2195 &dentry, <e, &stream_idx);
2200 if (lte == NULL && size == 0)
2203 if (lte != NULL && lte->resource_location == RESOURCE_IN_STAGING_FILE) {
2204 ret = truncate(lte->staging_file_name, size);
2208 lte->resource_entry.original_size = size;
2210 /* File in WIM. Extract it to the staging directory, but only
2211 * the first @size bytes of it. */
2212 struct wim_lookup_table_entry **back_ptr;
2214 inode = dentry->d_inode;
2215 if (stream_idx == 0) {
2217 back_ptr = &inode->i_lte;
2219 stream_id = inode->i_ads_entries[stream_idx - 1].stream_id;
2220 back_ptr = &inode->i_ads_entries[stream_idx - 1].lte;
2222 ret = extract_resource_to_staging_dir(inode, stream_id,
2229 /* Unlink a non-directory or alternate data stream */
2231 wimfs_unlink(const char *path)
2233 struct wim_dentry *dentry;
2234 struct wim_lookup_table_entry *lte;
2237 struct wimfs_context *ctx = wimfs_get_context();
2239 ret = wim_pathname_to_stream(ctx->wim, path, get_lookup_flags(ctx),
2240 &dentry, <e, &stream_idx);
2245 if (inode_stream_name_nbytes(dentry->d_inode, stream_idx) == 0)
2246 remove_dentry(dentry, ctx->wim->lookup_table);
2248 inode_remove_ads(dentry->d_inode, stream_idx - 1,
2249 ctx->wim->lookup_table);
2253 #ifdef HAVE_UTIMENSAT
2255 * Change the timestamp on a file dentry.
2257 * Note that alternate data streams do not have their own timestamps.
2260 wimfs_utimens(const char *path, const struct timespec tv[2])
2262 struct wim_dentry *dentry;
2263 struct wim_inode *inode;
2264 WIMStruct *wim = wimfs_get_WIMStruct();
2266 dentry = get_dentry(wim, path);
2269 inode = dentry->d_inode;
2271 if (tv[0].tv_nsec != UTIME_OMIT) {
2272 if (tv[0].tv_nsec == UTIME_NOW)
2273 inode->i_last_access_time = get_wim_timestamp();
2275 inode->i_last_access_time = timespec_to_wim_timestamp(tv[0]);
2277 if (tv[1].tv_nsec != UTIME_OMIT) {
2278 if (tv[1].tv_nsec == UTIME_NOW)
2279 inode->i_last_write_time = get_wim_timestamp();
2281 inode->i_last_write_time = timespec_to_wim_timestamp(tv[1]);
2285 #else /* HAVE_UTIMENSAT */
2287 wimfs_utime(const char *path, struct utimbuf *times)
2289 struct wim_dentry *dentry;
2290 struct wim_inode *inode;
2291 WIMStruct *wim = wimfs_get_WIMStruct();
2293 dentry = get_dentry(wim, path);
2296 inode = dentry->d_inode;
2298 inode->i_last_write_time = unix_timestamp_to_wim(times->modtime);
2299 inode->i_last_access_time = unix_timestamp_to_wim(times->actime);
2302 #endif /* !HAVE_UTIMENSAT */
2304 /* Writes to a file in the WIM filesystem.
2305 * It may be an alternate data stream, but here we don't even notice because we
2306 * just get a lookup table entry. */
2308 wimfs_write(const char *path, const char *buf, size_t size,
2309 off_t offset, struct fuse_file_info *fi)
2311 struct wimfs_fd *fd = (struct wimfs_fd*)(uintptr_t)fi->fh;
2317 wimlib_assert(fd->f_lte != NULL);
2318 wimlib_assert(fd->f_lte->staging_file_name != NULL);
2319 wimlib_assert(filedes_valid(&fd->staging_fd));
2320 wimlib_assert(fd->f_inode != NULL);
2322 /* Write the data. */
2323 ret = raw_pwrite(&fd->staging_fd, buf, size, offset);
2327 /* Update file size */
2328 if (offset + size > fd->f_lte->resource_entry.original_size) {
2329 DEBUG("Update file size %"PRIu64 " => %"PRIu64"",
2330 fd->f_lte->resource_entry.original_size,
2332 fd->f_lte->resource_entry.original_size = offset + size;
2335 /* Update timestamps */
2336 touch_inode(fd->f_inode);
2340 static struct fuse_operations wimfs_operations = {
2341 .chmod = wimfs_chmod,
2342 .chown = wimfs_chown,
2343 .destroy = wimfs_destroy,
2344 .fgetattr = wimfs_fgetattr,
2345 .ftruncate = wimfs_ftruncate,
2346 .getattr = wimfs_getattr,
2348 .getxattr = wimfs_getxattr,
2352 .listxattr = wimfs_listxattr,
2354 .mkdir = wimfs_mkdir,
2355 .mknod = wimfs_mknod,
2357 .opendir = wimfs_opendir,
2359 .readdir = wimfs_readdir,
2360 .readlink = wimfs_readlink,
2361 .release = wimfs_release,
2362 .releasedir = wimfs_releasedir,
2364 .removexattr = wimfs_removexattr,
2366 .rename = wimfs_rename,
2367 .rmdir = wimfs_rmdir,
2369 .setxattr = wimfs_setxattr,
2371 .symlink = wimfs_symlink,
2372 .truncate = wimfs_truncate,
2373 .unlink = wimfs_unlink,
2374 #ifdef HAVE_UTIMENSAT
2375 .utimens = wimfs_utimens,
2377 .utime = wimfs_utime,
2379 .write = wimfs_write,
2381 /* wimfs keeps file descriptor structures (struct wimfs_fd), so there is
2382 * no need to have the file path provided on operations such as read()
2383 * where only the file descriptor is needed. */
2384 #if FUSE_MAJOR_VERSION > 2 || (FUSE_MAJOR_VERSION == 2 && FUSE_MINOR_VERSION >= 8)
2385 .flag_nullpath_ok = 1,
2387 #if FUSE_MAJOR_VERSION > 2 || (FUSE_MAJOR_VERSION == 2 && FUSE_MINOR_VERSION >= 9)
2389 .flag_utime_omit_ok = 1,
2394 /* API function documented in wimlib.h */
2396 wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
2397 int mount_flags, const char *staging_dir)
2403 struct wim_image_metadata *imd;
2404 struct wimfs_context ctx;
2405 struct wim_inode *inode;
2407 DEBUG("Mount: wim = %p, image = %d, dir = %s, flags = %d, ",
2408 wim, image, dir, mount_flags);
2411 return WIMLIB_ERR_INVALID_PARAM;
2413 if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
2414 ret = can_delete_from_wim(wim);
2419 ret = select_wim_image(wim, image);
2423 DEBUG("Selected image %d", image);
2425 imd = wim_get_current_image_metadata(wim);
2427 if (imd->refcnt != 1) {
2428 ERROR("Cannot mount image that was just exported with "
2429 "wimlib_export_image()");
2430 return WIMLIB_ERR_INVALID_PARAM;
2433 if (imd->modified) {
2434 ERROR("Cannot mount image that was added "
2435 "with wimlib_add_image()");
2436 return WIMLIB_ERR_INVALID_PARAM;
2439 if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
2440 ret = lock_wim(wim, wim->in_fd.fd);
2445 /* Use default stream interface if one was not specified */
2446 if (!(mount_flags & (WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_NONE |
2447 WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR |
2448 WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS)))
2449 mount_flags |= WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR;
2451 DEBUG("Initializing struct wimfs_context");
2452 init_wimfs_context(&ctx);
2454 ctx.mount_flags = mount_flags;
2455 ctx.image_inode_list = &imd->inode_list;
2456 ctx.default_uid = getuid();
2457 ctx.default_gid = getgid();
2458 wimlib_assert(list_empty(&imd->unhashed_streams));
2459 ctx.wim->lookup_table->unhashed_streams = &imd->unhashed_streams;
2460 if (mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS)
2461 ctx.default_lookup_flags = LOOKUP_FLAG_ADS_OK;
2463 DEBUG("Unlinking message queues in case they already exist");
2464 ret = set_message_queue_names(&ctx, dir);
2467 unlink_message_queues(&ctx);
2469 DEBUG("Preparing arguments to fuse_main()");
2471 dir_copy = STRDUP(dir);
2473 goto out_free_message_queue_names;
2476 argv[argc++] = "wimlib";
2477 argv[argc++] = dir_copy;
2479 /* disable multi-threaded operation */
2480 argv[argc++] = "-s";
2482 if (mount_flags & WIMLIB_MOUNT_FLAG_DEBUG)
2483 argv[argc++] = "-d";
2486 * We provide the use_ino option to the FUSE mount because we are going
2487 * to assign inode numbers ourselves. */
2488 char optstring[256] =
2492 #if FUSE_MAJOR_VERSION > 2 || (FUSE_MAJOR_VERSION == 2 && FUSE_MINOR_VERSION >= 8)
2495 ",default_permissions"
2497 argv[argc++] = "-o";
2498 argv[argc++] = optstring;
2499 if ((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)) {
2500 /* Read-write mount. Make the staging directory */
2501 ret = make_staging_dir(&ctx, staging_dir);
2503 goto out_free_dir_copy;
2505 /* Read-only mount */
2506 strcat(optstring, ",ro");
2508 if (mount_flags & WIMLIB_MOUNT_FLAG_ALLOW_OTHER)
2509 strcat(optstring, ",allow_other");
2515 DEBUG("FUSE command line (argc = %d): ", argc);
2516 for (i = 0; i < argc; i++) {
2517 fputs(argv[i], stdout);
2525 /* Mark dentry tree as modified if read-write mount. */
2526 if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)
2529 /* Resolve the lookup table entries for every inode in the image, and
2530 * assign inode numbers */
2531 DEBUG("Resolving lookup table entries and assigning inode numbers");
2533 image_for_each_inode(inode, imd)
2534 inode->i_ino = ctx.next_ino++;
2535 DEBUG("(next_ino = %"PRIu64")", ctx.next_ino);
2537 DEBUG("Calling fuse_main()");
2539 ret = fuse_main(argc, argv, &wimfs_operations, &ctx);
2541 DEBUG("Returned from fuse_main() (ret = %d)", ret);
2544 ret = WIMLIB_ERR_FUSE;
2546 if (ctx.have_status)
2549 ret = WIMLIB_ERR_TIMEOUT;
2551 if (ctx.daemon_to_unmount_mq != (mqd_t)(-1)) {
2552 send_unmount_finished_msg(ctx.daemon_to_unmount_mq, ret);
2553 close_message_queues(&ctx);
2556 /* Try to delete the staging directory if a deletion wasn't yet
2557 * attempted due to an earlier error */
2558 if (ctx.staging_dir_name)
2559 delete_staging_dir(&ctx);
2563 wim->wim_locked = 0;
2564 out_free_message_queue_names:
2565 free_message_queue_names(&ctx);
2569 /* API function documented in wimlib.h */
2571 wimlib_unmount_image(const char *dir, int unmount_flags,
2572 wimlib_progress_func_t progress_func)
2575 struct wimfs_context wimfs_ctx;
2577 init_wimfs_context(&wimfs_ctx);
2579 ret = set_message_queue_names(&wimfs_ctx, dir);
2583 ret = open_message_queues(&wimfs_ctx, false);
2585 goto out_free_message_queue_names;
2587 ret = send_unmount_request_msg(wimfs_ctx.unmount_to_daemon_mq,
2589 progress_func != NULL);
2591 goto out_close_message_queues;
2593 ret = execute_fusermount(dir, (unmount_flags & WIMLIB_UNMOUNT_FLAG_LAZY) != 0);
2595 goto out_close_message_queues;
2597 struct unmount_msg_handler_context handler_ctx = {
2599 .timeout_seconds = 5,
2602 .progress_func = progress_func,
2605 ret = message_loop(wimfs_ctx.daemon_to_unmount_mq,
2606 &unmount_msg_handler_callbacks,
2609 ret = handler_ctx.status;
2610 out_close_message_queues:
2611 close_message_queues(&wimfs_ctx);
2612 out_free_message_queue_names:
2613 free_message_queue_names(&wimfs_ctx);
2618 #else /* WITH_FUSE */
2622 mount_unsupported_error(void)
2624 #if defined(__WIN32__)
2625 ERROR("Sorry-- Mounting WIM images is not supported on Windows!");
2627 ERROR("wimlib was compiled with --without-fuse, which disables support "
2628 "for mounting WIMs.");
2630 return WIMLIB_ERR_UNSUPPORTED;
2634 wimlib_unmount_image(const tchar *dir, int unmount_flags,
2635 wimlib_progress_func_t progress_func)
2637 return mount_unsupported_error();
2641 wimlib_mount_image(WIMStruct *wim, int image, const tchar *dir,
2642 int mount_flags, const tchar *staging_dir)
2644 return mount_unsupported_error();
2647 #endif /* !WITH_FUSE */