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/dentry.h"
45 #include "wimlib/inode.h"
46 #include "wimlib/lookup_table.h"
47 #include "wimlib/metadata.h"
48 #include "wimlib/paths.h"
49 #include "wimlib/reparse.h"
50 #include "wimlib/resource.h"
51 #include "wimlib/timestamp.h"
52 #include "wimlib/version.h"
53 #include "wimlib/write.h"
54 #include "wimlib/xml.h"
65 #include <sys/types.h>
70 #define FUSE_USE_VERSION 26
74 #include <attr/xattr.h>
77 #define MSG_VERSION_TOO_HIGH -1
78 #define MSG_BREAK_LOOP -2
80 /* File descriptor to a file open on the WIM filesystem. */
82 struct wim_inode *f_inode;
83 struct wim_lookup_table_entry *f_lte;
84 struct filedes staging_fd;
89 struct wimfs_context {
90 /* The WIMStruct for the mounted WIM. */
93 /* Name of the staging directory for a read-write mount. Whenever a new file is
94 * created, it is done so in the staging directory. Furthermore, whenever a
95 * file in the WIM is modified, it is extracted to the staging directory. If
96 * changes are commited when the WIM is unmounted, the file resources are merged
97 * in from the staging directory when writing the new WIM. */
98 char *staging_dir_name;
99 size_t staging_dir_name_len;
101 /* Flags passed to wimlib_mount(). */
104 /* Default flags to use when looking up a WIM dentry (depends on whether
105 * the Windows interface to alternate data streams is being used or
107 int default_lookup_flags;
109 /* Next inode number to be assigned. Note: I didn't bother with a
110 * bitmap of free inode numbers since this isn't even a "real"
111 * filesystem anyway. */
114 /* List of inodes in the mounted image */
115 struct list_head *image_inode_list;
117 /* Name and message queue descriptors for message queues between the
118 * filesystem daemon process and the unmount process. These are used
119 * when the filesystem is unmounted and the process running
120 * wimlib_unmount_image() needs to communicate with the filesystem
121 * daemon running fuse_main() (i.e. the process created by a call to
122 * wimlib_mount_image(). */
123 char *unmount_to_daemon_mq_name;
124 char *daemon_to_unmount_mq_name;
125 mqd_t unmount_to_daemon_mq;
126 mqd_t daemon_to_unmount_mq;
136 init_wimfs_context(struct wimfs_context *ctx)
138 memset(ctx, 0, sizeof(*ctx));
139 ctx->unmount_to_daemon_mq = (mqd_t)-1;
140 ctx->daemon_to_unmount_mq = (mqd_t)-1;
143 #define WIMFS_CTX(fuse_ctx) ((struct wimfs_context*)(fuse_ctx)->private_data)
145 static inline struct wimfs_context *
146 wimfs_get_context(void)
148 return WIMFS_CTX(fuse_get_context());
151 static inline WIMStruct *
152 wimfs_get_WIMStruct(void)
154 return wimfs_get_context()->wim;
158 get_lookup_flags(const struct wimfs_context *ctx)
160 return ctx->default_lookup_flags;
163 /* Returns nonzero if write permission is requested on the file open flags */
165 flags_writable(int open_flags)
167 return open_flags & (O_RDWR | O_WRONLY);
171 * Allocate a file descriptor for a stream.
173 * @inode: inode containing the stream we're opening
174 * @stream_id: ID of the stream we're opening
175 * @lte: Lookup table entry for the stream (may be NULL)
176 * @fd_ret: Return the allocated file descriptor if successful.
178 * Return 0 iff successful or error code if unsuccessful.
181 alloc_wimfs_fd(struct wim_inode *inode,
183 struct wim_lookup_table_entry *lte,
184 struct wimfs_fd **fd_ret)
186 static const u16 fds_per_alloc = 8;
187 static const u16 max_fds = 0xffff;
190 DEBUG("Allocating fd for stream ID %u from inode %#"PRIx64" "
191 "(open = %u, allocated = %u)",
192 stream_id, inode->i_ino, inode->i_num_opened_fds,
193 inode->i_num_allocated_fds);
195 if (inode->i_num_opened_fds == inode->i_num_allocated_fds) {
196 struct wimfs_fd **fds;
199 if (inode->i_num_allocated_fds == max_fds) {
203 num_new_fds = min(fds_per_alloc,
204 max_fds - inode->i_num_allocated_fds);
206 fds = REALLOC(inode->i_fds,
207 (inode->i_num_allocated_fds + num_new_fds) *
208 sizeof(inode->i_fds[0]));
213 memset(&fds[inode->i_num_allocated_fds], 0,
214 num_new_fds * sizeof(fds[0]));
216 inode->i_num_allocated_fds += num_new_fds;
218 for (u16 i = 0; ; i++) {
219 if (!inode->i_fds[i]) {
220 struct wimfs_fd *fd = CALLOC(1, sizeof(*fd));
227 filedes_invalidate(&fd->staging_fd);
229 fd->stream_id = stream_id;
231 inode->i_fds[i] = fd;
232 inode->i_num_opened_fds++;
234 lte->num_opened_fds++;
235 DEBUG("Allocated fd (idx = %u)", fd->idx);
245 inode_put_fd(struct wim_inode *inode, struct wimfs_fd *fd)
247 wimlib_assert(inode != NULL);
248 wimlib_assert(fd->f_inode == inode);
249 wimlib_assert(inode->i_num_opened_fds != 0);
250 wimlib_assert(fd->idx < inode->i_num_allocated_fds);
251 wimlib_assert(inode->i_fds[fd->idx] == fd);
253 inode->i_fds[fd->idx] = NULL;
255 if (--inode->i_num_opened_fds == 0) {
258 inode->i_num_allocated_fds = 0;
259 if (inode->i_nlink == 0)
265 lte_put_fd(struct wim_lookup_table_entry *lte, struct wimfs_fd *fd)
267 wimlib_assert(fd->f_lte == lte);
269 if (!lte) /* Empty stream with no lookup table entry */
272 /* Close staging file descriptor if needed. */
274 if (lte->resource_location == RESOURCE_IN_STAGING_FILE
275 && filedes_valid(&fd->staging_fd))
277 if (filedes_close(&fd->staging_fd)) {
278 ERROR_WITH_ERRNO("Failed to close staging file");
282 lte_decrement_num_opened_fds(lte);
286 /* Close a file descriptor. */
288 close_wimfs_fd(struct wimfs_fd *fd)
291 DEBUG("Closing fd (ino = %#"PRIx64", opened = %u, allocated = %u)",
292 fd->f_inode->i_ino, fd->f_inode->i_num_opened_fds,
293 fd->f_inode->i_num_allocated_fds);
294 ret = lte_put_fd(fd->f_lte, fd);
298 inode_put_fd(fd->f_inode, fd);
303 fuse_mask_mode(mode_t mode, struct fuse_context *fuse_ctx)
305 #if FUSE_MAJOR_VERSION > 2 || (FUSE_MAJOR_VERSION == 2 && FUSE_MINOR_VERSION >= 8)
306 mode &= ~fuse_ctx->umask;
312 * Add a new dentry with a new inode to a WIM image.
314 * Returns 0 on success, or negative error number on failure.
317 create_dentry(struct fuse_context *fuse_ctx, const char *path,
318 mode_t mode, int attributes, struct wim_dentry **dentry_ret)
320 struct wim_dentry *parent;
321 struct wim_dentry *new;
322 const char *basename;
323 struct wimfs_context *wimfs_ctx = WIMFS_CTX(fuse_ctx);
326 parent = get_parent_dentry(wimfs_ctx->wim, path, WIMLIB_CASE_SENSITIVE);
330 if (!dentry_is_directory(parent))
333 basename = path_basename(path);
334 if (get_dentry_child_with_name(parent, basename, WIMLIB_CASE_SENSITIVE))
337 ret = new_dentry_with_inode(basename, &new);
341 new->d_inode->i_resolved = 1;
342 new->d_inode->i_ino = wimfs_ctx->next_ino++;
343 new->d_inode->i_attributes = attributes;
345 if (wimfs_ctx->mount_flags & WIMLIB_MOUNT_FLAG_UNIX_DATA) {
346 if (inode_set_unix_data(new->d_inode,
349 fuse_mask_mode(mode, fuse_ctx),
350 wimfs_ctx->wim->lookup_table,
351 UNIX_DATA_ALL | UNIX_DATA_CREATE))
357 dentry_add_child(parent, new);
358 list_add_tail(&new->d_inode->i_list, wimfs_ctx->image_inode_list);
364 static struct wim_inode *
365 wim_pathname_to_inode(WIMStruct *wim, const tchar *path)
367 struct wim_dentry *dentry;
368 dentry = get_dentry(wim, path, WIMLIB_CASE_SENSITIVE);
370 return dentry->d_inode;
375 /* Remove a dentry from a mounted WIM image; i.e. remove an alias for the
376 * corresponding inode.
378 * If there are no remaining references to the inode either through dentries or
379 * open file descriptors, the inode is freed. Otherwise, the inode is not
380 * removed, but the dentry is unlinked and freed.
382 * Either way, all lookup table entries referenced by the inode have their
383 * reference count decremented. If a lookup table entry has no open file
384 * descriptors and no references remaining, it is freed, and the corresponding
385 * staging file is unlinked.
388 remove_dentry(struct wim_dentry *dentry,
389 struct wim_lookup_table *lookup_table)
391 struct wim_inode *inode = dentry->d_inode;
392 struct wim_lookup_table_entry *lte;
395 for (i = 0; i <= inode->i_num_ads; i++) {
396 lte = inode_stream_lte_resolved(inode, i);
398 lte_decrement_refcnt(lte, lookup_table);
400 unlink_dentry(dentry);
405 inode_default_unix_mode(const struct wim_inode *inode)
407 if (inode_is_symlink(inode))
408 return S_IFLNK | 0777;
409 else if (inode_is_directory(inode))
410 return S_IFDIR | 0777;
412 return S_IFREG | 0777;
415 /* Transfers file attributes from a struct wim_inode to a `stat' buffer.
417 * The lookup table entry tells us which stream in the inode we are statting.
418 * For a named data stream, everything returned is the same as the unnamed data
419 * stream except possibly the size and block count. */
421 inode_to_stbuf(const struct wim_inode *inode,
422 const struct wim_lookup_table_entry *lte,
425 const struct wimfs_context *ctx = wimfs_get_context();
427 memset(stbuf, 0, sizeof(struct stat));
428 stbuf->st_mode = inode_default_unix_mode(inode);
429 stbuf->st_uid = ctx->default_uid;
430 stbuf->st_gid = ctx->default_gid;
431 if (ctx->mount_flags & WIMLIB_MOUNT_FLAG_UNIX_DATA) {
432 struct wimlib_unix_data unix_data;
433 if (inode_get_unix_data(inode, &unix_data, NULL) == 0) {
434 stbuf->st_uid = unix_data.uid;
435 stbuf->st_gid = unix_data.gid;
436 stbuf->st_mode = unix_data.mode;
439 stbuf->st_ino = (ino_t)inode->i_ino;
440 stbuf->st_nlink = inode->i_nlink;
442 stbuf->st_size = lte->size;
445 #ifdef HAVE_STAT_NANOSECOND_PRECISION
446 stbuf->st_atim = wim_timestamp_to_timespec(inode->i_last_access_time);
447 stbuf->st_mtim = wim_timestamp_to_timespec(inode->i_last_write_time);
448 stbuf->st_ctim = stbuf->st_mtim;
450 stbuf->st_atime = wim_timestamp_to_unix(inode->i_last_access_time);
451 stbuf->st_mtime = wim_timestamp_to_unix(inode->i_last_write_time);
452 stbuf->st_ctime = stbuf->st_mtime;
454 stbuf->st_blocks = (stbuf->st_size + 511) / 512;
459 touch_inode(struct wim_inode *inode)
461 u64 now = get_wim_timestamp();
462 inode->i_last_access_time = now;
463 inode->i_last_write_time = now;
466 /* Creates a new staging file and returns its file descriptor opened for
469 * @name_ret: A location into which the a pointer to the newly allocated name of
470 * the staging file is stored.
472 * @ctx: Context for the WIM filesystem; this provides the name of the
475 * On success, returns the file descriptor for the staging file, opened for
476 * writing. On failure, returns -1 and sets errno.
479 create_staging_file(char **name_ret, struct wimfs_context *ctx)
487 static const size_t STAGING_FILE_NAME_LEN = 20;
489 name_len = ctx->staging_dir_name_len + 1 + STAGING_FILE_NAME_LEN;
490 name = MALLOC(name_len + 1);
498 memcpy(name, ctx->staging_dir_name, ctx->staging_dir_name_len);
499 name[ctx->staging_dir_name_len] = '/';
500 randomize_char_array_with_alnum(name + ctx->staging_dir_name_len + 1,
501 STAGING_FILE_NAME_LEN);
502 name[name_len] = '\0';
505 /* Just in case, verify that the randomly generated name doesn't name an
506 * existing file, and try again if so */
507 } while (stat(name, &stbuf) == 0);
509 if (errno != ENOENT) /* other error?! */
512 /* doesn't exist--- ok */
514 DEBUG("Creating staging file `%s'", name);
516 fd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0600);
528 * Extract a WIM resource to the staging directory.
530 * @inode: Inode that contains the stream we are extracting
532 * @stream_id: Identifier for the stream (it stays constant even if the indices
533 * of the stream entries are changed)
535 * @lte: Pointer to pointer to the lookup table entry for the stream we need to
536 * extract, or NULL if there was no lookup table entry present for the stream
538 * @size: Number of bytes of the stream we want to extract (this supports the
539 * wimfs_truncate() function). It may be more than the actual stream length, in
540 * which case the extra space is filled with zeroes.
542 * @ctx: Context for the WIM filesystem.
544 * Returns 0 on success or a negative error code on failure.
547 extract_resource_to_staging_dir(struct wim_inode *inode,
549 struct wim_lookup_table_entry **lte,
551 struct wimfs_context *ctx)
553 char *staging_file_name;
556 struct wim_lookup_table_entry *old_lte, *new_lte;
559 DEBUG("Extracting resource to staging dir: inode %"PRIu64", "
560 "stream id %"PRIu32, inode->i_ino, stream_id);
564 wimlib_assert(old_lte == NULL ||
565 old_lte->resource_location != RESOURCE_IN_STAGING_FILE);
567 /* Create the staging file */
568 fd = create_staging_file(&staging_file_name, ctx);
572 /* Extract the stream to the staging file (possibly truncated) */
574 struct filedes wimlib_fd;
575 filedes_init(&wimlib_fd, fd);
576 extract_size = min(old_lte->size, size);
577 ret = extract_stream_to_fd(old_lte, &wimlib_fd, extract_size);
583 /* In the case of truncate() to more than the file length, extend the
584 * file with zeroes by calling ftruncate() on the underlying staging
586 if (ret == 0 && size > extract_size)
587 ret = ftruncate(fd, size);
589 /* Close the staging file descriptor and check for errors. If there's
590 * an error, unlink the staging file. */
591 if (ret != 0 || close(fd) != 0) {
597 goto out_delete_staging_file;
600 /* Now deal with the lookup table entries. We may be able to re-use the
601 * existing entry, but we may have to create a new one instead. */
603 if (old_lte && inode->i_nlink == old_lte->refcnt) {
604 /* The reference count of the existing lookup table entry is the
605 * same as the link count of the inode that contains the stream
606 * we're opening. Therefore, ALL the references to the lookup
607 * table entry correspond to the stream we're trying to extract,
608 * so the lookup table entry can be re-used. */
609 DEBUG("Re-using lookup table entry");
610 lookup_table_unlink(ctx->wim->lookup_table, old_lte);
614 /* There's an existing lookup table entry, but its
615 * reference count is greater than the link count for
616 * the inode containing a stream we're opening.
617 * Therefore, we need to split the lookup table entry.
619 wimlib_assert(old_lte->refcnt > inode->i_nlink);
620 DEBUG("Splitting lookup table entry "
621 "(inode->i_nlink = %u, old_lte->refcnt = %u)",
622 inode->i_nlink, old_lte->refcnt);
625 new_lte = new_lookup_table_entry();
628 goto out_delete_staging_file;
631 /* There may already be open file descriptors to this stream if
632 * it's previously been opened read-only, but just now we're
633 * opening it read-write. Identify those file descriptors and
634 * change their lookup table entry pointers to point to the new
635 * lookup table entry, and open staging file descriptors for
638 * At the same time, we need to count the number of these opened
639 * file descriptors to the new lookup table entry. If there's
640 * an old lookup table entry, this number needs to be subtracted
641 * from the fd's opened to the old entry. */
642 for (u16 i = 0, j = 0; j < inode->i_num_opened_fds; i++) {
643 struct wimfs_fd *fd = inode->i_fds[i];
645 if (fd->stream_id == stream_id) {
648 wimlib_assert(fd->f_lte == old_lte);
649 wimlib_assert(!filedes_valid(&fd->staging_fd));
651 new_lte->num_opened_fds++;
652 raw_fd = open(staging_file_name, O_RDONLY);
655 goto out_revert_fd_changes;
657 filedes_init(&fd->staging_fd, raw_fd);
662 DEBUG("%hu fd's were already opened to the file we extracted",
663 new_lte->num_opened_fds);
665 old_lte->num_opened_fds -= new_lte->num_opened_fds;
666 old_lte->refcnt -= inode->i_nlink;
670 new_lte->refcnt = inode->i_nlink;
671 new_lte->resource_location = RESOURCE_IN_STAGING_FILE;
672 new_lte->staging_file_name = staging_file_name;
673 new_lte->size = size;
675 add_unhashed_stream(new_lte, inode, stream_id,
676 &wim_get_current_image_metadata(ctx->wim)->unhashed_streams);
677 *retrieve_lte_pointer(new_lte) = new_lte;
680 out_revert_fd_changes:
681 for (u16 i = 0, j = 0; j < new_lte->num_opened_fds; i++) {
682 struct wimfs_fd *fd = inode->i_fds[i];
683 if (fd && fd->stream_id == stream_id && fd->f_lte == new_lte) {
685 if (filedes_valid(&fd->staging_fd)) {
686 filedes_close(&fd->staging_fd);
687 filedes_invalidate(&fd->staging_fd);
692 free_lookup_table_entry(new_lte);
693 out_delete_staging_file:
694 unlink(staging_file_name);
695 FREE(staging_file_name);
700 * Creates a randomly named staging directory and saves its name in the
701 * filesystem context structure.
704 make_staging_dir(struct wimfs_context *ctx, const char *user_prefix)
706 static const size_t random_suffix_len = 10;
707 static const char *common_suffix = ".staging";
708 static const size_t common_suffix_len = 8;
710 char *staging_dir_name = NULL;
711 size_t staging_dir_name_len;
713 const char *wim_basename;
714 char *real_user_prefix = NULL;
718 real_user_prefix = realpath(user_prefix, NULL);
719 if (!real_user_prefix) {
720 ERROR_WITH_ERRNO("Could not resolve `%s'",
722 ret = WIMLIB_ERR_NOTDIR;
725 wim_basename = path_basename(ctx->wim->filename);
726 prefix_len = strlen(real_user_prefix) + 1 + strlen(wim_basename);
728 prefix_len = strlen(ctx->wim->filename);
731 staging_dir_name_len = prefix_len + common_suffix_len + random_suffix_len;
733 staging_dir_name = MALLOC(staging_dir_name_len + 1);
734 if (!staging_dir_name) {
735 ret = WIMLIB_ERR_NOMEM;
739 if (real_user_prefix)
740 sprintf(staging_dir_name, "%s/%s", real_user_prefix, wim_basename);
742 strcpy(staging_dir_name, ctx->wim->filename);
744 strcat(staging_dir_name, common_suffix);
746 randomize_char_array_with_alnum(staging_dir_name + prefix_len + common_suffix_len,
749 staging_dir_name[staging_dir_name_len] = '\0';
751 if (mkdir(staging_dir_name, 0700) != 0) {
752 ERROR_WITH_ERRNO("Failed to create temporary directory `%s'",
754 ret = WIMLIB_ERR_MKDIR;
759 FREE(real_user_prefix);
761 ctx->staging_dir_name = staging_dir_name;
762 ctx->staging_dir_name_len = staging_dir_name_len;
764 FREE(staging_dir_name);
770 remove_file_or_directory(const char *fpath, const struct stat *sb,
771 int typeflag, struct FTW *ftwbuf)
773 if (remove(fpath) == 0)
776 ERROR_WITH_ERRNO("Cannot remove `%s'", fpath);
777 return WIMLIB_ERR_DELETE_STAGING_DIR;
782 * Deletes the staging directory and all the files contained in it.
785 delete_staging_dir(struct wimfs_context *ctx)
788 ret = nftw(ctx->staging_dir_name, remove_file_or_directory,
790 FREE(ctx->staging_dir_name);
791 ctx->staging_dir_name = NULL;
796 inode_close_fds(struct wim_inode *inode)
798 u16 num_opened_fds = inode->i_num_opened_fds;
799 for (u16 i = 0, j = 0; j < num_opened_fds; i++) {
800 struct wimfs_fd *fd = inode->i_fds[i];
802 wimlib_assert(fd->f_inode == inode);
803 int ret = close_wimfs_fd(fd);
812 /* Overwrites the WIM file, with changes saved. */
814 rebuild_wim(struct wimfs_context *ctx, int write_flags,
815 wimlib_progress_func_t progress_func)
818 struct wim_lookup_table_entry *lte, *tmp;
819 WIMStruct *wim = ctx->wim;
820 struct wim_image_metadata *imd = wim_get_current_image_metadata(ctx->wim);
822 DEBUG("Closing all staging file descriptors.");
823 image_for_each_unhashed_stream_safe(lte, tmp, imd) {
824 ret = inode_close_fds(lte->back_inode);
829 DEBUG("Freeing entries for zero-length streams");
830 image_for_each_unhashed_stream_safe(lte, tmp, imd) {
831 wimlib_assert(lte->unhashed);
832 if (lte->size == 0) {
833 struct wim_lookup_table_entry **back_ptr;
834 back_ptr = retrieve_lte_pointer(lte);
836 list_del(<e->unhashed_list);
837 free_lookup_table_entry(lte);
841 xml_update_image_info(wim, wim->current_image);
842 ret = wimlib_overwrite(wim, write_flags, 0, progress_func);
844 ERROR("Failed to commit changes to mounted WIM image");
848 /* Simple function that returns the concatenation of 2 strings. */
850 strcat_dup(const char *s1, const char *s2, size_t max_len)
852 size_t len = strlen(s1) + strlen(s2);
855 char *p = MALLOC(len + 1);
858 snprintf(p, len + 1, "%s%s", s1, s2);
863 set_message_queue_names(struct wimfs_context *ctx, const char *mount_dir)
865 static const char *u2d_prefix = "/wimlib-unmount-to-daemon-mq";
866 static const char *d2u_prefix = "/wimlib-daemon-to-unmount-mq";
871 dir_path = realpath(mount_dir, NULL);
873 ERROR_WITH_ERRNO("Failed to resolve path \"%s\"", mount_dir);
875 return WIMLIB_ERR_NOMEM;
877 return WIMLIB_ERR_NOTDIR;
880 for (p = dir_path; *p; p++)
884 ctx->unmount_to_daemon_mq_name = strcat_dup(u2d_prefix, dir_path,
886 if (!ctx->unmount_to_daemon_mq_name) {
887 ret = WIMLIB_ERR_NOMEM;
888 goto out_free_dir_path;
890 ctx->daemon_to_unmount_mq_name = strcat_dup(d2u_prefix, dir_path,
892 if (!ctx->daemon_to_unmount_mq_name) {
893 ret = WIMLIB_ERR_NOMEM;
894 goto out_free_unmount_to_daemon_mq_name;
898 goto out_free_dir_path;
899 out_free_unmount_to_daemon_mq_name:
900 FREE(ctx->unmount_to_daemon_mq_name);
901 ctx->unmount_to_daemon_mq_name = NULL;
908 free_message_queue_names(struct wimfs_context *ctx)
910 FREE(ctx->unmount_to_daemon_mq_name);
911 FREE(ctx->daemon_to_unmount_mq_name);
912 ctx->unmount_to_daemon_mq_name = NULL;
913 ctx->daemon_to_unmount_mq_name = NULL;
917 * Opens two POSIX message queue: one for sending messages from the unmount
918 * process to the daemon process, and one to go the other way. The names of the
919 * message queues, which must be system-wide unique, are be based on the mount
922 * @daemon specifies whether the calling process is the filesystem daemon or the
926 open_message_queues(struct wimfs_context *ctx, bool daemon)
928 int unmount_to_daemon_mq_flags = O_WRONLY | O_CREAT;
929 int daemon_to_unmount_mq_flags = O_RDONLY | O_CREAT;
935 swap(unmount_to_daemon_mq_flags, daemon_to_unmount_mq_flags);
941 orig_umask = umask(0000);
942 DEBUG("Opening message queue \"%s\"", ctx->unmount_to_daemon_mq_name);
943 ctx->unmount_to_daemon_mq = mq_open(ctx->unmount_to_daemon_mq_name,
944 unmount_to_daemon_mq_flags, mode, NULL);
946 if (ctx->unmount_to_daemon_mq == (mqd_t)-1) {
947 ERROR_WITH_ERRNO("mq_open()");
948 ret = WIMLIB_ERR_MQUEUE;
952 DEBUG("Opening message queue \"%s\"", ctx->daemon_to_unmount_mq_name);
953 ctx->daemon_to_unmount_mq = mq_open(ctx->daemon_to_unmount_mq_name,
954 daemon_to_unmount_mq_flags, mode, NULL);
956 if (ctx->daemon_to_unmount_mq == (mqd_t)-1) {
957 ERROR_WITH_ERRNO("mq_open()");
958 mq_close(ctx->unmount_to_daemon_mq);
959 mq_unlink(ctx->unmount_to_daemon_mq_name);
960 ctx->unmount_to_daemon_mq = (mqd_t)-1;
961 ret = WIMLIB_ERR_MQUEUE;
970 /* Try to determine the maximum message size of a message queue. The return
971 * value is the maximum message size, or a guess of 8192 bytes if it cannot be
974 mq_get_msgsize(mqd_t mq)
976 static const char *msgsize_max_file = "/proc/sys/fs/mqueue/msgsize_max";
981 if (mq_getattr(mq, &attr) == 0) {
982 msgsize = attr.mq_msgsize;
984 ERROR_WITH_ERRNO("mq_getattr()");
985 ERROR("Attempting to read %s", msgsize_max_file);
986 fp = fopen(msgsize_max_file, "rb");
988 if (fscanf(fp, "%ld", &msgsize) != 1) {
989 ERROR("Assuming message size of 8192");
994 ERROR_WITH_ERRNO("Failed to open the file `%s'",
996 ERROR("Assuming message size of 8192");
1004 get_mailbox(mqd_t mq, long needed_msgsize, long *msgsize_ret,
1010 msgsize = mq_get_msgsize(mq);
1012 if (msgsize < needed_msgsize) {
1013 ERROR("Message queue max size must be at least %ld!",
1015 return WIMLIB_ERR_MQUEUE;
1018 mailbox = MALLOC(msgsize);
1020 ERROR("Failed to allocate %ld bytes for mailbox", msgsize);
1021 return WIMLIB_ERR_NOMEM;
1023 *msgsize_ret = msgsize;
1024 *mailbox_ret = mailbox;
1029 unlink_message_queues(struct wimfs_context *ctx)
1031 mq_unlink(ctx->unmount_to_daemon_mq_name);
1032 mq_unlink(ctx->daemon_to_unmount_mq_name);
1035 /* Closes the message queues, which are allocated in static variables */
1037 close_message_queues(struct wimfs_context *ctx)
1039 DEBUG("Closing message queues");
1040 mq_close(ctx->unmount_to_daemon_mq);
1041 ctx->unmount_to_daemon_mq = (mqd_t)(-1);
1042 mq_close(ctx->daemon_to_unmount_mq);
1043 ctx->daemon_to_unmount_mq = (mqd_t)(-1);
1044 unlink_message_queues(ctx);
1048 struct unmount_msg_hdr {
1053 } _packed_attribute;
1055 struct msg_unmount_request {
1056 struct unmount_msg_hdr hdr;
1058 u8 want_progress_messages;
1059 } _packed_attribute;
1061 struct msg_daemon_info {
1062 struct unmount_msg_hdr hdr;
1065 } _packed_attribute;
1067 struct msg_unmount_finished {
1068 struct unmount_msg_hdr hdr;
1070 } _packed_attribute;
1072 struct msg_write_streams_progress {
1073 struct unmount_msg_hdr hdr;
1074 union wimlib_progress_info info;
1075 } _packed_attribute;
1078 MSG_TYPE_UNMOUNT_REQUEST,
1079 MSG_TYPE_DAEMON_INFO,
1080 MSG_TYPE_WRITE_STREAMS_PROGRESS,
1081 MSG_TYPE_UNMOUNT_FINISHED,
1085 struct msg_handler_context_hdr {
1086 int timeout_seconds;
1089 struct unmount_msg_handler_context {
1090 struct msg_handler_context_hdr hdr;
1094 wimlib_progress_func_t progress_func;
1097 struct daemon_msg_handler_context {
1098 struct msg_handler_context_hdr hdr;
1099 struct wimfs_context *wimfs_ctx;
1103 send_unmount_request_msg(mqd_t mq, int unmount_flags, u8 want_progress_messages)
1105 DEBUG("Sending unmount request msg");
1106 struct msg_unmount_request msg = {
1108 .min_version = WIMLIB_MAKEVERSION(1, 2, 1),
1109 .cur_version = WIMLIB_VERSION_CODE,
1110 .msg_type = MSG_TYPE_UNMOUNT_REQUEST,
1111 .msg_size = sizeof(msg),
1113 .unmount_flags = unmount_flags,
1114 .want_progress_messages = want_progress_messages,
1117 if (mq_send(mq, (void*)&msg, sizeof(msg), 1)) {
1118 ERROR_WITH_ERRNO("Failed to communicate with filesystem daemon");
1119 return WIMLIB_ERR_MQUEUE;
1125 send_daemon_info_msg(mqd_t mq, pid_t pid, int mount_flags)
1127 DEBUG("Sending daemon info msg (pid = %d, mount_flags=%x)",
1130 struct msg_daemon_info msg = {
1132 .min_version = WIMLIB_MAKEVERSION(1, 2, 1),
1133 .cur_version = WIMLIB_VERSION_CODE,
1134 .msg_type = MSG_TYPE_DAEMON_INFO,
1135 .msg_size = sizeof(msg),
1138 .mount_flags = mount_flags,
1140 if (mq_send(mq, (void*)&msg, sizeof(msg), 1)) {
1141 ERROR_WITH_ERRNO("Failed to send daemon info to unmount process");
1142 return WIMLIB_ERR_MQUEUE;
1148 send_unmount_finished_msg(mqd_t mq, int status)
1150 DEBUG("Sending unmount finished msg");
1151 struct msg_unmount_finished msg = {
1153 .min_version = WIMLIB_MAKEVERSION(1, 2, 1),
1154 .cur_version = WIMLIB_VERSION_CODE,
1155 .msg_type = MSG_TYPE_UNMOUNT_FINISHED,
1156 .msg_size = sizeof(msg),
1160 if (mq_send(mq, (void*)&msg, sizeof(msg), 1))
1161 ERROR_WITH_ERRNO("Failed to send status to unmount process");
1165 unmount_progress_func(enum wimlib_progress_msg msg,
1166 const union wimlib_progress_info *info)
1168 if (msg == WIMLIB_PROGRESS_MSG_WRITE_STREAMS) {
1169 struct msg_write_streams_progress msg = {
1171 .min_version = WIMLIB_MAKEVERSION(1, 2, 1),
1172 .cur_version = WIMLIB_VERSION_CODE,
1173 .msg_type = MSG_TYPE_WRITE_STREAMS_PROGRESS,
1174 .msg_size = sizeof(msg),
1178 if (mq_send(wimfs_get_context()->daemon_to_unmount_mq,
1179 (void*)&msg, sizeof(msg), 1))
1181 ERROR_WITH_ERRNO("Failed to send progress information "
1182 "to unmount process");
1189 msg_unmount_request_handler(const void *_msg, void *_handler_ctx)
1191 const struct msg_unmount_request *msg = _msg;
1192 struct daemon_msg_handler_context *handler_ctx = _handler_ctx;
1193 struct wimfs_context *wimfs_ctx;
1197 wimlib_progress_func_t progress_func;
1199 DEBUG("Handling unmount request msg");
1201 wimfs_ctx = handler_ctx->wimfs_ctx;
1202 if (msg->hdr.msg_size < sizeof(*msg)) {
1203 status = WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1207 unmount_flags = msg->unmount_flags;
1208 if (msg->want_progress_messages)
1209 progress_func = unmount_progress_func;
1211 progress_func = NULL;
1213 ret = send_daemon_info_msg(wimfs_ctx->daemon_to_unmount_mq, getpid(),
1214 wimfs_ctx->mount_flags);
1220 if (wimfs_ctx->mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
1221 if (unmount_flags & WIMLIB_UNMOUNT_FLAG_COMMIT) {
1222 int write_flags = 0;
1223 if (unmount_flags & WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY)
1224 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
1225 if (unmount_flags & WIMLIB_UNMOUNT_FLAG_REBUILD)
1226 write_flags |= WIMLIB_WRITE_FLAG_REBUILD;
1227 if (unmount_flags & WIMLIB_UNMOUNT_FLAG_RECOMPRESS)
1228 write_flags |= WIMLIB_WRITE_FLAG_RECOMPRESS;
1229 status = rebuild_wim(wimfs_ctx, write_flags,
1233 DEBUG("Read-only mount");
1238 if (wimfs_ctx->mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
1239 ret = delete_staging_dir(wimfs_ctx);
1241 ERROR("Failed to delete the staging directory");
1246 wimfs_ctx->status = status;
1247 wimfs_ctx->have_status = true;
1248 return MSG_BREAK_LOOP;
1252 msg_daemon_info_handler(const void *_msg, void *_handler_ctx)
1254 const struct msg_daemon_info *msg = _msg;
1255 struct unmount_msg_handler_context *handler_ctx = _handler_ctx;
1257 DEBUG("Handling daemon info msg");
1258 if (msg->hdr.msg_size < sizeof(*msg))
1259 return WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1260 handler_ctx->daemon_pid = msg->daemon_pid;
1261 handler_ctx->mount_flags = msg->mount_flags;
1262 handler_ctx->hdr.timeout_seconds = 1;
1263 DEBUG("pid of daemon is %d; mount flags were %#x",
1264 handler_ctx->daemon_pid,
1265 handler_ctx->mount_flags);
1270 msg_write_streams_progress_handler(const void *_msg, void *_handler_ctx)
1272 const struct msg_write_streams_progress *msg = _msg;
1273 struct unmount_msg_handler_context *handler_ctx = _handler_ctx;
1275 if (msg->hdr.msg_size < sizeof(*msg))
1276 return WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1277 if (handler_ctx->progress_func) {
1278 handler_ctx->progress_func(WIMLIB_PROGRESS_MSG_WRITE_STREAMS,
1285 msg_unmount_finished_handler(const void *_msg, void *_handler_ctx)
1287 const struct msg_unmount_finished *msg = _msg;
1288 struct unmount_msg_handler_context *handler_ctx = _handler_ctx;
1290 DEBUG("Handling unmount finished message");
1291 if (msg->hdr.msg_size < sizeof(*msg))
1292 return WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1293 handler_ctx->status = msg->status;
1294 DEBUG("status is %d", handler_ctx->status);
1295 return MSG_BREAK_LOOP;
1299 unmount_timed_out_cb(void *_handler_ctx)
1301 const struct unmount_msg_handler_context *handler_ctx = _handler_ctx;
1303 if (handler_ctx->daemon_pid == 0 ||
1304 (kill(handler_ctx->daemon_pid, 0) != 0 && errno == ESRCH))
1306 ERROR("The filesystem daemon has crashed! Changes to the "
1307 "WIM may not have been commited.");
1308 return WIMLIB_ERR_FILESYSTEM_DAEMON_CRASHED;
1311 DEBUG("Filesystem daemon is still alive... "
1312 "Waiting another %d seconds", handler_ctx->hdr.timeout_seconds);
1317 daemon_timed_out_cb(void *_handler_ctx)
1319 ERROR("Timed out waiting for unmount request! "
1320 "Changes to the mounted WIM will not be committed.");
1321 return WIMLIB_ERR_TIMEOUT;
1324 typedef int (*msg_handler_t)(const void *_msg, void *_handler_ctx);
1326 struct msg_handler_callbacks {
1327 int (*timed_out)(void * _handler_ctx);
1328 msg_handler_t msg_handlers[MSG_TYPE_MAX];
1331 static const struct msg_handler_callbacks unmount_msg_handler_callbacks = {
1332 .timed_out = unmount_timed_out_cb,
1334 [MSG_TYPE_DAEMON_INFO] = msg_daemon_info_handler,
1335 [MSG_TYPE_WRITE_STREAMS_PROGRESS] = msg_write_streams_progress_handler,
1336 [MSG_TYPE_UNMOUNT_FINISHED] = msg_unmount_finished_handler,
1340 static const struct msg_handler_callbacks daemon_msg_handler_callbacks = {
1341 .timed_out = daemon_timed_out_cb,
1343 [MSG_TYPE_UNMOUNT_REQUEST] = msg_unmount_request_handler,
1348 receive_message(mqd_t mq,
1349 struct msg_handler_context_hdr *handler_ctx,
1350 const msg_handler_t msg_handlers[],
1351 long mailbox_size, void *mailbox)
1354 struct timespec timeout;
1355 ssize_t bytes_received;
1356 struct unmount_msg_hdr *hdr;
1359 gettimeofday(&now, NULL);
1360 timeout.tv_sec = now.tv_sec + handler_ctx->timeout_seconds;
1361 timeout.tv_nsec = now.tv_usec * 1000;
1363 bytes_received = mq_timedreceive(mq, mailbox,
1364 mailbox_size, NULL, &timeout);
1366 if (bytes_received == -1) {
1367 if (errno == ETIMEDOUT) {
1368 ret = WIMLIB_ERR_TIMEOUT;
1370 ERROR_WITH_ERRNO("mq_timedreceive()");
1371 ret = WIMLIB_ERR_MQUEUE;
1373 } else if (bytes_received < sizeof(*hdr) ||
1374 bytes_received != hdr->msg_size) {
1375 ret = WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1376 } else if (WIMLIB_VERSION_CODE < hdr->min_version) {
1377 /*ERROR("Cannot understand the received message. "*/
1378 /*"Please upgrade wimlib to at least v%d.%d.%d",*/
1379 /*WIMLIB_GET_MAJOR_VERSION(hdr->min_version),*/
1380 /*WIMLIB_GET_MINOR_VERSION(hdr->min_version),*/
1381 /*WIMLIB_GET_PATCH_VERSION(hdr->min_version));*/
1382 ret = MSG_VERSION_TOO_HIGH;
1383 } else if (hdr->msg_type >= MSG_TYPE_MAX) {
1384 ret = WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1385 } else if (msg_handlers[hdr->msg_type] == NULL) {
1386 ret = WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1388 ret = msg_handlers[hdr->msg_type](mailbox, handler_ctx);
1394 message_loop(mqd_t mq,
1395 const struct msg_handler_callbacks *callbacks,
1396 struct msg_handler_context_hdr *handler_ctx)
1398 static const size_t MAX_MSG_SIZE = 512;
1403 DEBUG("Entering message loop");
1405 ret = get_mailbox(mq, MAX_MSG_SIZE, &msgsize, &mailbox);
1409 ret = receive_message(mq, handler_ctx,
1410 callbacks->msg_handlers,
1412 if (ret == 0 || ret == MSG_VERSION_TOO_HIGH) {
1414 } else if (ret == MSG_BREAK_LOOP) {
1417 } else if (ret == WIMLIB_ERR_TIMEOUT) {
1418 if (callbacks->timed_out)
1419 ret = callbacks->timed_out(handler_ctx);
1425 ERROR_WITH_ERRNO("Error communicating with "
1426 "filesystem daemon");
1431 DEBUG("Exiting message loop");
1435 /* Execute `fusermount -u', which is installed setuid root, to unmount the WIM.
1437 * FUSE does not yet implement synchronous unmounts. This means that fusermount
1438 * -u will return before the filesystem daemon returns from wimfs_destroy().
1439 * This is partly what we want, because we need to send a message from this
1440 * process to the filesystem daemon telling whether --commit was specified or
1441 * not. However, after that, the unmount process must wait for the filesystem
1442 * daemon to finish writing the WIM file.
1445 execute_fusermount(const char *dir, bool lazy)
1453 ERROR_WITH_ERRNO("Failed to fork()");
1454 return WIMLIB_ERR_FORK;
1460 *argp++ = "fusermount";
1464 *argp++ = (char*)dir;
1466 execvp("fusermount", argv);
1467 ERROR_WITH_ERRNO("Failed to execute `fusermount'");
1468 exit(WIMLIB_ERR_FUSERMOUNT);
1472 ret = waitpid(pid, &status, 0);
1474 ERROR_WITH_ERRNO("Failed to wait for fusermount process to "
1476 return WIMLIB_ERR_FUSERMOUNT;
1479 if (!WIFEXITED(status)) {
1480 ERROR("'fusermount' did not terminate normally!");
1481 return WIMLIB_ERR_FUSERMOUNT;
1484 status = WEXITSTATUS(status);
1489 if (status != WIMLIB_ERR_FUSERMOUNT)
1490 return WIMLIB_ERR_FUSERMOUNT;
1492 /* Try again, but with the `umount' program. This is required on other
1493 * FUSE implementations such as FreeBSD's that do not have a
1494 * `fusermount' program. */
1495 ERROR("Falling back to 'umount'. Note: you may need to be "
1496 "root for this to work");
1499 ERROR_WITH_ERRNO("Failed to fork()");
1500 return WIMLIB_ERR_FORK;
1509 *argp++ = (char*)dir;
1511 execvp("umount", argv);
1512 ERROR_WITH_ERRNO("Failed to execute `umount'");
1513 exit(WIMLIB_ERR_FUSERMOUNT);
1517 ret = waitpid(pid, &status, 0);
1519 ERROR_WITH_ERRNO("Failed to wait for `umount' process to "
1521 return WIMLIB_ERR_FUSERMOUNT;
1524 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
1525 ERROR("`umount' did not successfully complete");
1526 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->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 stream_size = lte->size;
1667 if (stream_size > size)
1670 ret = read_full_stream_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, WIMLIB_CASE_SENSITIVE);
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,
1707 WIMLIB_CASE_SENSITIVE))
1710 ret = new_dentry(link_name, &from_dentry);
1715 inode_ref_streams(inode);
1716 from_dentry->d_inode = inode;
1717 inode_add_dentry(from_dentry, inode);
1718 dentry_add_child(from_dentry_parent, from_dentry);
1724 wimfs_listxattr(const char *path, char *list, size_t size)
1727 struct wim_inode *inode;
1728 struct wimfs_context *ctx = wimfs_get_context();
1731 bool size_only = (size == 0);
1733 if (!(ctx->mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR))
1736 /* List alternate data streams, or get the list size */
1738 inode = wim_pathname_to_inode(ctx->wim, path);
1743 for (i = 0; i < inode->i_num_ads; i++) {
1745 if (!ads_entry_is_named_stream(&inode->i_ads_entries[i]))
1748 char *stream_name_mbs;
1749 size_t stream_name_mbs_nbytes;
1752 ret = utf16le_to_tstr(inode->i_ads_entries[i].stream_name,
1753 inode->i_ads_entries[i].stream_name_nbytes,
1755 &stream_name_mbs_nbytes);
1759 needed_size = stream_name_mbs_nbytes + 6;
1761 if (needed_size > size) {
1762 FREE(stream_name_mbs);
1765 sprintf(p, "user.%s", stream_name_mbs);
1766 size -= needed_size;
1769 FREE(stream_name_mbs);
1776 /* Create a directory in the WIM image. */
1778 wimfs_mkdir(const char *path, mode_t mode)
1780 return create_dentry(fuse_get_context(), path, mode | S_IFDIR,
1781 FILE_ATTRIBUTE_DIRECTORY, NULL);
1784 /* Create a regular file or alternate data stream in the WIM image. */
1786 wimfs_mknod(const char *path, mode_t mode, dev_t rdev)
1788 const char *stream_name;
1789 struct fuse_context *fuse_ctx = fuse_get_context();
1790 struct wimfs_context *wimfs_ctx = WIMFS_CTX(fuse_ctx);
1795 if ((wimfs_ctx->mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS)
1796 && (stream_name = path_stream_name(path))) {
1797 /* Make an alternate data stream */
1798 struct wim_ads_entry *new_entry;
1799 struct wim_inode *inode;
1801 char *p = (char*)stream_name - 1;
1802 wimlib_assert(*p == ':');
1805 inode = wim_pathname_to_inode(wimfs_ctx->wim, path);
1808 if (inode->i_attributes & FILE_ATTRIBUTE_REPARSE_POINT)
1810 if (inode_get_ads_entry(inode, stream_name, NULL))
1812 new_entry = inode_add_ads(inode, stream_name);
1817 /* Make a normal file (not an alternate data stream) */
1818 return create_dentry(fuse_ctx, path, mode | S_IFREG,
1819 FILE_ATTRIBUTE_NORMAL, NULL);
1825 wimfs_open(const char *path, struct fuse_file_info *fi)
1827 struct wim_dentry *dentry;
1828 struct wim_lookup_table_entry *lte;
1830 struct wimfs_fd *fd;
1831 struct wim_inode *inode;
1834 struct wimfs_context *ctx = wimfs_get_context();
1835 struct wim_lookup_table_entry **back_ptr;
1837 ret = wim_pathname_to_stream(ctx->wim, path, get_lookup_flags(ctx),
1838 &dentry, <e, &stream_idx);
1842 inode = dentry->d_inode;
1844 if (stream_idx == 0) {
1846 back_ptr = &inode->i_lte;
1848 stream_id = inode->i_ads_entries[stream_idx - 1].stream_id;
1849 back_ptr = &inode->i_ads_entries[stream_idx - 1].lte;
1852 /* The file resource may be in the staging directory (read-write mounts
1853 * only) or in the WIM. If it's in the staging directory, we need to
1854 * open a native file descriptor for the corresponding file. Otherwise,
1855 * we can read the file resource directly from the WIM file if we are
1856 * opening it read-only, but we need to extract the resource to the
1857 * staging directory if we are opening it writable. */
1859 if (flags_writable(fi->flags) &&
1860 (!lte || lte->resource_location != RESOURCE_IN_STAGING_FILE)) {
1861 u64 size = (lte) ? lte->size : 0;
1862 ret = extract_resource_to_staging_dir(inode, stream_id,
1869 ret = alloc_wimfs_fd(inode, stream_id, lte, &fd);
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);
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 stream_size = fd->f_lte->size;
1931 if (offset > stream_size)
1934 size = min(size, stream_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_stream_into_buf(fd->f_lte, size,
1947 ret = errno ? -errno : -EIO;
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))
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,
2089 WIMLIB_CASE_SENSITIVE);
2092 /* Remove a directory */
2094 wimfs_rmdir(const char *path)
2096 struct wim_dentry *dentry;
2097 WIMStruct *wim = wimfs_get_WIMStruct();
2099 dentry = get_dentry(wim, path, WIMLIB_CASE_SENSITIVE);
2103 if (!dentry_is_directory(dentry))
2106 if (dentry_has_children(dentry))
2109 remove_dentry(dentry, wim->lookup_table);
2114 /* Write an alternate data stream through the XATTR interface */
2116 wimfs_setxattr(const char *path, const char *name,
2117 const char *value, size_t size, int flags)
2119 struct wim_ads_entry *existing_ads_entry;
2120 struct wim_inode *inode;
2122 struct wimfs_context *ctx = wimfs_get_context();
2125 if (!(ctx->mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR))
2128 if (strlen(name) <= 5 || memcmp(name, "user.", 5) != 0)
2132 inode = wim_pathname_to_inode(ctx->wim, path);
2136 existing_ads_entry = inode_get_ads_entry(inode, name, &ads_idx);
2137 if (existing_ads_entry) {
2138 if (flags & XATTR_CREATE)
2141 if (flags & XATTR_REPLACE)
2145 ret = inode_add_ads_with_data(inode, name, value,
2146 size, ctx->wim->lookup_table);
2148 if (existing_ads_entry)
2149 inode_remove_ads(inode, ads_idx, ctx->wim->lookup_table);
2158 wimfs_symlink(const char *to, const char *from)
2160 struct fuse_context *fuse_ctx = fuse_get_context();
2161 struct wimfs_context *wimfs_ctx = WIMFS_CTX(fuse_ctx);
2162 struct wim_dentry *dentry;
2165 ret = create_dentry(fuse_ctx, from, S_IFLNK | 0777,
2166 FILE_ATTRIBUTE_REPARSE_POINT, &dentry);
2168 dentry->d_inode->i_reparse_tag = WIM_IO_REPARSE_TAG_SYMLINK;
2169 ret = wim_inode_set_symlink(dentry->d_inode, to,
2170 wimfs_ctx->wim->lookup_table);
2172 remove_dentry(dentry, wimfs_ctx->wim->lookup_table);
2173 if (ret == WIMLIB_ERR_NOMEM)
2183 /* Reduce the size of a file */
2185 wimfs_truncate(const char *path, off_t size)
2187 struct wim_dentry *dentry;
2188 struct wim_lookup_table_entry *lte;
2192 struct wim_inode *inode;
2193 struct wimfs_context *ctx = wimfs_get_context();
2195 ret = wim_pathname_to_stream(ctx->wim, path, get_lookup_flags(ctx),
2196 &dentry, <e, &stream_idx);
2201 if (lte == NULL && size == 0)
2204 if (lte != NULL && lte->resource_location == RESOURCE_IN_STAGING_FILE) {
2205 ret = truncate(lte->staging_file_name, size);
2211 /* File in WIM. Extract it to the staging directory, but only
2212 * the first @size bytes of it. */
2213 struct wim_lookup_table_entry **back_ptr;
2215 inode = dentry->d_inode;
2216 if (stream_idx == 0) {
2218 back_ptr = &inode->i_lte;
2220 stream_id = inode->i_ads_entries[stream_idx - 1].stream_id;
2221 back_ptr = &inode->i_ads_entries[stream_idx - 1].lte;
2223 ret = extract_resource_to_staging_dir(inode, stream_id,
2230 /* Unlink a non-directory or alternate data stream */
2232 wimfs_unlink(const char *path)
2234 struct wim_dentry *dentry;
2235 struct wim_lookup_table_entry *lte;
2238 struct wimfs_context *ctx = wimfs_get_context();
2240 ret = wim_pathname_to_stream(ctx->wim, path, get_lookup_flags(ctx),
2241 &dentry, <e, &stream_idx);
2246 if (inode_stream_name_nbytes(dentry->d_inode, stream_idx) == 0)
2247 remove_dentry(dentry, ctx->wim->lookup_table);
2249 inode_remove_ads(dentry->d_inode, stream_idx - 1,
2250 ctx->wim->lookup_table);
2254 #ifdef HAVE_UTIMENSAT
2256 * Change the timestamp on a file dentry.
2258 * Note that alternate data streams do not have their own timestamps.
2261 wimfs_utimens(const char *path, const struct timespec tv[2])
2263 struct wim_dentry *dentry;
2264 struct wim_inode *inode;
2265 WIMStruct *wim = wimfs_get_WIMStruct();
2267 dentry = get_dentry(wim, path, WIMLIB_CASE_SENSITIVE);
2270 inode = dentry->d_inode;
2272 if (tv[0].tv_nsec != UTIME_OMIT) {
2273 if (tv[0].tv_nsec == UTIME_NOW)
2274 inode->i_last_access_time = get_wim_timestamp();
2276 inode->i_last_access_time = timespec_to_wim_timestamp(tv[0]);
2278 if (tv[1].tv_nsec != UTIME_OMIT) {
2279 if (tv[1].tv_nsec == UTIME_NOW)
2280 inode->i_last_write_time = get_wim_timestamp();
2282 inode->i_last_write_time = timespec_to_wim_timestamp(tv[1]);
2286 #else /* HAVE_UTIMENSAT */
2288 wimfs_utime(const char *path, struct utimbuf *times)
2290 struct wim_dentry *dentry;
2291 struct wim_inode *inode;
2292 WIMStruct *wim = wimfs_get_WIMStruct();
2294 dentry = get_dentry(wim, path, WIMLIB_CASE_SENSITIVE);
2297 inode = dentry->d_inode;
2299 inode->i_last_write_time = unix_timestamp_to_wim(times->modtime);
2300 inode->i_last_access_time = unix_timestamp_to_wim(times->actime);
2303 #endif /* !HAVE_UTIMENSAT */
2305 /* Writes to a file in the WIM filesystem.
2306 * It may be an alternate data stream, but here we don't even notice because we
2307 * just get a lookup table entry. */
2309 wimfs_write(const char *path, const char *buf, size_t size,
2310 off_t offset, struct fuse_file_info *fi)
2312 struct wimfs_fd *fd = (struct wimfs_fd*)(uintptr_t)fi->fh;
2318 wimlib_assert(fd->f_lte != NULL);
2319 wimlib_assert(fd->f_lte->staging_file_name != NULL);
2320 wimlib_assert(filedes_valid(&fd->staging_fd));
2321 wimlib_assert(fd->f_inode != NULL);
2323 /* Write the data. */
2324 ret = raw_pwrite(&fd->staging_fd, buf, size, offset);
2328 /* Update file size */
2329 if (offset + size > fd->f_lte->size) {
2330 DEBUG("Update file size %"PRIu64 " => %"PRIu64"",
2331 fd->f_lte->size, offset + size);
2332 fd->f_lte->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->modified) {
2428 /* wimfs_read() only supports a limited number of stream
2429 * locations, not including RESOURCE_IN_FILE_ON_DISK,
2430 * RESOURCE_IN_NTFS_VOLUME, etc. that might appear if files were
2431 * added to the WIM image. */
2432 ERROR("Cannot mount an image with newly added files!");
2433 return WIMLIB_ERR_INVALID_PARAM;
2436 if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
2437 ret = lock_wim(wim, wim->in_fd.fd);
2442 /* Use default stream interface if one was not specified */
2443 if (!(mount_flags & (WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_NONE |
2444 WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR |
2445 WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS)))
2446 mount_flags |= WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR;
2448 DEBUG("Initializing struct wimfs_context");
2449 init_wimfs_context(&ctx);
2451 ctx.mount_flags = mount_flags;
2452 ctx.image_inode_list = &imd->inode_list;
2453 ctx.default_uid = getuid();
2454 ctx.default_gid = getgid();
2455 wimlib_assert(list_empty(&imd->unhashed_streams));
2456 if (mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS)
2457 ctx.default_lookup_flags = LOOKUP_FLAG_ADS_OK;
2459 DEBUG("Unlinking message queues in case they already exist");
2460 ret = set_message_queue_names(&ctx, dir);
2463 unlink_message_queues(&ctx);
2465 DEBUG("Preparing arguments to fuse_main()");
2467 dir_copy = STRDUP(dir);
2469 goto out_free_message_queue_names;
2472 argv[argc++] = "wimlib";
2473 argv[argc++] = dir_copy;
2475 /* disable multi-threaded operation */
2476 argv[argc++] = "-s";
2478 if (mount_flags & WIMLIB_MOUNT_FLAG_DEBUG)
2479 argv[argc++] = "-d";
2482 * We provide the use_ino option to the FUSE mount because we are going
2483 * to assign inode numbers ourselves. */
2484 char optstring[256] =
2488 #if FUSE_MAJOR_VERSION > 2 || (FUSE_MAJOR_VERSION == 2 && FUSE_MINOR_VERSION >= 8)
2491 ",default_permissions"
2493 argv[argc++] = "-o";
2494 argv[argc++] = optstring;
2495 if ((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)) {
2496 /* Read-write mount. Make the staging directory */
2497 ret = make_staging_dir(&ctx, staging_dir);
2499 goto out_free_dir_copy;
2501 /* Read-only mount */
2502 strcat(optstring, ",ro");
2504 if (mount_flags & WIMLIB_MOUNT_FLAG_ALLOW_OTHER)
2505 strcat(optstring, ",allow_other");
2511 DEBUG("FUSE command line (argc = %d): ", argc);
2512 for (i = 0; i < argc; i++) {
2513 fputs(argv[i], stdout);
2521 /* Mark dentry tree as modified if read-write mount. */
2522 if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)
2525 /* Resolve the lookup table entries for every inode in the image, and
2526 * assign inode numbers */
2527 DEBUG("Resolving lookup table entries and assigning inode numbers");
2529 image_for_each_inode(inode, imd)
2530 inode->i_ino = ctx.next_ino++;
2531 DEBUG("(next_ino = %"PRIu64")", ctx.next_ino);
2533 DEBUG("Calling fuse_main()");
2535 ret = fuse_main(argc, argv, &wimfs_operations, &ctx);
2537 DEBUG("Returned from fuse_main() (ret = %d)", ret);
2540 ret = WIMLIB_ERR_FUSE;
2542 if (ctx.have_status)
2545 ret = WIMLIB_ERR_TIMEOUT;
2547 if (ctx.daemon_to_unmount_mq != (mqd_t)(-1)) {
2548 send_unmount_finished_msg(ctx.daemon_to_unmount_mq, ret);
2549 close_message_queues(&ctx);
2552 /* Try to delete the staging directory if a deletion wasn't yet
2553 * attempted due to an earlier error */
2554 if (ctx.staging_dir_name)
2555 delete_staging_dir(&ctx);
2559 wim->wim_locked = 0;
2560 out_free_message_queue_names:
2561 free_message_queue_names(&ctx);
2565 /* API function documented in wimlib.h */
2567 wimlib_unmount_image(const char *dir, int unmount_flags,
2568 wimlib_progress_func_t progress_func)
2571 struct wimfs_context wimfs_ctx;
2573 init_wimfs_context(&wimfs_ctx);
2575 ret = set_message_queue_names(&wimfs_ctx, dir);
2579 ret = open_message_queues(&wimfs_ctx, false);
2581 goto out_free_message_queue_names;
2583 ret = send_unmount_request_msg(wimfs_ctx.unmount_to_daemon_mq,
2585 progress_func != NULL);
2587 goto out_close_message_queues;
2589 ret = execute_fusermount(dir, (unmount_flags & WIMLIB_UNMOUNT_FLAG_LAZY) != 0);
2591 goto out_close_message_queues;
2593 struct unmount_msg_handler_context handler_ctx = {
2595 .timeout_seconds = 5,
2598 .progress_func = progress_func,
2601 ret = message_loop(wimfs_ctx.daemon_to_unmount_mq,
2602 &unmount_msg_handler_callbacks,
2605 ret = handler_ctx.status;
2606 out_close_message_queues:
2607 close_message_queues(&wimfs_ctx);
2608 out_free_message_queue_names:
2609 free_message_queue_names(&wimfs_ctx);
2614 #else /* WITH_FUSE */
2618 mount_unsupported_error(void)
2620 #if defined(__WIN32__)
2621 ERROR("Sorry-- Mounting WIM images is not supported on Windows!");
2623 ERROR("wimlib was compiled with --without-fuse, which disables support "
2624 "for mounting WIMs.");
2626 return WIMLIB_ERR_UNSUPPORTED;
2630 wimlib_unmount_image(const tchar *dir, int unmount_flags,
2631 wimlib_progress_func_t progress_func)
2633 return mount_unsupported_error();
2637 wimlib_mount_image(WIMStruct *wim, int image, const tchar *dir,
2638 int mount_flags, const tchar *staging_dir)
2640 return mount_unsupported_error();
2643 #endif /* !WITH_FUSE */