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, WIMLIB_CASE_SENSITIVE);
336 if (!dentry_is_directory(parent))
339 basename = path_basename(path);
340 if (get_dentry_child_with_name(parent, basename, WIMLIB_CASE_SENSITIVE))
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 static struct wim_inode *
371 wim_pathname_to_inode(WIMStruct *wim, const tchar *path)
373 struct wim_dentry *dentry;
374 dentry = get_dentry(wim, path, WIMLIB_CASE_SENSITIVE);
376 return dentry->d_inode;
381 /* Remove a dentry from a mounted WIM image; i.e. remove an alias for the
382 * corresponding inode.
384 * If there are no remaining references to the inode either through dentries or
385 * open file descriptors, the inode is freed. Otherwise, the inode is not
386 * removed, but the dentry is unlinked and freed.
388 * Either way, all lookup table entries referenced by the inode have their
389 * reference count decremented. If a lookup table entry has no open file
390 * descriptors and no references remaining, it is freed, and the corresponding
391 * staging file is unlinked.
394 remove_dentry(struct wim_dentry *dentry,
395 struct wim_lookup_table *lookup_table)
397 struct wim_inode *inode = dentry->d_inode;
398 struct wim_lookup_table_entry *lte;
401 for (i = 0; i <= inode->i_num_ads; i++) {
402 lte = inode_stream_lte_resolved(inode, i);
404 lte_decrement_refcnt(lte, lookup_table);
406 unlink_dentry(dentry);
411 inode_default_unix_mode(const struct wim_inode *inode)
413 if (inode_is_symlink(inode))
414 return S_IFLNK | 0777;
415 else if (inode_is_directory(inode))
416 return S_IFDIR | 0777;
418 return S_IFREG | 0777;
421 /* Transfers file attributes from a struct wim_inode to a `stat' buffer.
423 * The lookup table entry tells us which stream in the inode we are statting.
424 * For a named data stream, everything returned is the same as the unnamed data
425 * stream except possibly the size and block count. */
427 inode_to_stbuf(const struct wim_inode *inode,
428 const struct wim_lookup_table_entry *lte,
431 const struct wimfs_context *ctx = wimfs_get_context();
433 memset(stbuf, 0, sizeof(struct stat));
434 stbuf->st_mode = inode_default_unix_mode(inode);
435 stbuf->st_uid = ctx->default_uid;
436 stbuf->st_gid = ctx->default_gid;
437 if (ctx->mount_flags & WIMLIB_MOUNT_FLAG_UNIX_DATA) {
438 struct wimlib_unix_data unix_data;
439 if (inode_get_unix_data(inode, &unix_data, NULL) == 0) {
440 stbuf->st_uid = unix_data.uid;
441 stbuf->st_gid = unix_data.gid;
442 stbuf->st_mode = unix_data.mode;
445 stbuf->st_ino = (ino_t)inode->i_ino;
446 stbuf->st_nlink = inode->i_nlink;
448 stbuf->st_size = lte->size;
451 #ifdef HAVE_STAT_NANOSECOND_PRECISION
452 stbuf->st_atim = wim_timestamp_to_timespec(inode->i_last_access_time);
453 stbuf->st_mtim = wim_timestamp_to_timespec(inode->i_last_write_time);
454 stbuf->st_ctim = stbuf->st_mtim;
456 stbuf->st_atime = wim_timestamp_to_unix(inode->i_last_access_time);
457 stbuf->st_mtime = wim_timestamp_to_unix(inode->i_last_write_time);
458 stbuf->st_ctime = stbuf->st_mtime;
460 stbuf->st_blocks = (stbuf->st_size + 511) / 512;
465 touch_inode(struct wim_inode *inode)
467 u64 now = get_wim_timestamp();
468 inode->i_last_access_time = now;
469 inode->i_last_write_time = now;
472 /* Creates a new staging file and returns its file descriptor opened for
475 * @name_ret: A location into which the a pointer to the newly allocated name of
476 * the staging file is stored.
478 * @ctx: Context for the WIM filesystem; this provides the name of the
481 * On success, returns the file descriptor for the staging file, opened for
482 * writing. On failure, returns -1 and sets errno.
485 create_staging_file(char **name_ret, struct wimfs_context *ctx)
493 static const size_t STAGING_FILE_NAME_LEN = 20;
495 name_len = ctx->staging_dir_name_len + 1 + STAGING_FILE_NAME_LEN;
496 name = MALLOC(name_len + 1);
504 memcpy(name, ctx->staging_dir_name, ctx->staging_dir_name_len);
505 name[ctx->staging_dir_name_len] = '/';
506 randomize_char_array_with_alnum(name + ctx->staging_dir_name_len + 1,
507 STAGING_FILE_NAME_LEN);
508 name[name_len] = '\0';
511 /* Just in case, verify that the randomly generated name doesn't name an
512 * existing file, and try again if so */
513 } while (stat(name, &stbuf) == 0);
515 if (errno != ENOENT) /* other error?! */
518 /* doesn't exist--- ok */
520 DEBUG("Creating staging file `%s'", name);
522 fd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0600);
534 * Extract a WIM resource to the staging directory.
536 * @inode: Inode that contains the stream we are extracting
538 * @stream_id: Identifier for the stream (it stays constant even if the indices
539 * of the stream entries are changed)
541 * @lte: Pointer to pointer to the lookup table entry for the stream we need to
542 * extract, or NULL if there was no lookup table entry present for the stream
544 * @size: Number of bytes of the stream we want to extract (this supports the
545 * wimfs_truncate() function). It may be more than the actual stream length, in
546 * which case the extra space is filled with zeroes.
548 * @ctx: Context for the WIM filesystem.
550 * Returns 0 on success or a negative error code on failure.
553 extract_resource_to_staging_dir(struct wim_inode *inode,
555 struct wim_lookup_table_entry **lte,
557 struct wimfs_context *ctx)
559 char *staging_file_name;
562 struct wim_lookup_table_entry *old_lte, *new_lte;
565 DEBUG("Extracting resource to staging dir: inode %"PRIu64", "
566 "stream id %"PRIu32, inode->i_ino, stream_id);
570 wimlib_assert(old_lte == NULL ||
571 old_lte->resource_location != RESOURCE_IN_STAGING_FILE);
573 /* Create the staging file */
574 fd = create_staging_file(&staging_file_name, ctx);
578 /* Extract the stream to the staging file (possibly truncated) */
580 struct filedes wimlib_fd;
581 filedes_init(&wimlib_fd, fd);
582 extract_size = min(old_lte->size, size);
583 ret = extract_stream_to_fd(old_lte, &wimlib_fd, extract_size);
589 /* In the case of truncate() to more than the file length, extend the
590 * file with zeroes by calling ftruncate() on the underlying staging
592 if (ret == 0 && size > extract_size)
593 ret = ftruncate(fd, size);
595 /* Close the staging file descriptor and check for errors. If there's
596 * an error, unlink the staging file. */
597 if (ret != 0 || close(fd) != 0) {
603 goto out_delete_staging_file;
606 /* Now deal with the lookup table entries. We may be able to re-use the
607 * existing entry, but we may have to create a new one instead. */
609 if (old_lte && inode->i_nlink == old_lte->refcnt) {
610 /* The reference count of the existing lookup table entry is the
611 * same as the link count of the inode that contains the stream
612 * we're opening. Therefore, ALL the references to the lookup
613 * table entry correspond to the stream we're trying to extract,
614 * so the lookup table entry can be re-used. */
615 DEBUG("Re-using lookup table entry");
616 lookup_table_unlink(ctx->wim->lookup_table, old_lte);
620 /* There's an existing lookup table entry, but its
621 * reference count is greater than the link count for
622 * the inode containing a stream we're opening.
623 * Therefore, we need to split the lookup table entry.
625 wimlib_assert(old_lte->refcnt > inode->i_nlink);
626 DEBUG("Splitting lookup table entry "
627 "(inode->i_nlink = %u, old_lte->refcnt = %u)",
628 inode->i_nlink, old_lte->refcnt);
631 new_lte = new_lookup_table_entry();
634 goto out_delete_staging_file;
637 /* There may already be open file descriptors to this stream if
638 * it's previously been opened read-only, but just now we're
639 * opening it read-write. Identify those file descriptors and
640 * change their lookup table entry pointers to point to the new
641 * lookup table entry, and open staging file descriptors for
644 * At the same time, we need to count the number of these opened
645 * file descriptors to the new lookup table entry. If there's
646 * an old lookup table entry, this number needs to be subtracted
647 * from the fd's opened to the old entry. */
648 for (u16 i = 0, j = 0; j < inode->i_num_opened_fds; i++) {
649 struct wimfs_fd *fd = inode->i_fds[i];
651 if (fd->stream_id == stream_id) {
654 wimlib_assert(fd->f_lte == old_lte);
655 wimlib_assert(!filedes_valid(&fd->staging_fd));
657 new_lte->num_opened_fds++;
658 raw_fd = open(staging_file_name, O_RDONLY);
661 goto out_revert_fd_changes;
663 filedes_init(&fd->staging_fd, raw_fd);
668 DEBUG("%hu fd's were already opened to the file we extracted",
669 new_lte->num_opened_fds);
671 old_lte->num_opened_fds -= new_lte->num_opened_fds;
672 old_lte->refcnt -= inode->i_nlink;
676 new_lte->refcnt = inode->i_nlink;
677 new_lte->resource_location = RESOURCE_IN_STAGING_FILE;
678 new_lte->staging_file_name = staging_file_name;
679 new_lte->size = size;
681 lookup_table_insert_unhashed(ctx->wim->lookup_table, new_lte,
683 *retrieve_lte_pointer(new_lte) = new_lte;
686 out_revert_fd_changes:
687 for (u16 i = 0, j = 0; j < new_lte->num_opened_fds; i++) {
688 struct wimfs_fd *fd = inode->i_fds[i];
689 if (fd && fd->stream_id == stream_id && fd->f_lte == new_lte) {
691 if (filedes_valid(&fd->staging_fd)) {
692 filedes_close(&fd->staging_fd);
693 filedes_invalidate(&fd->staging_fd);
698 free_lookup_table_entry(new_lte);
699 out_delete_staging_file:
700 unlink(staging_file_name);
701 FREE(staging_file_name);
706 * Creates a randomly named staging directory and saves its name in the
707 * filesystem context structure.
710 make_staging_dir(struct wimfs_context *ctx, const char *user_prefix)
712 static const size_t random_suffix_len = 10;
713 static const char *common_suffix = ".staging";
714 static const size_t common_suffix_len = 8;
716 char *staging_dir_name = NULL;
717 size_t staging_dir_name_len;
719 const char *wim_basename;
720 char *real_user_prefix = NULL;
724 real_user_prefix = realpath(user_prefix, NULL);
725 if (!real_user_prefix) {
726 ERROR_WITH_ERRNO("Could not resolve `%s'",
728 ret = WIMLIB_ERR_NOTDIR;
731 wim_basename = path_basename(ctx->wim->filename);
732 prefix_len = strlen(real_user_prefix) + 1 + strlen(wim_basename);
734 prefix_len = strlen(ctx->wim->filename);
737 staging_dir_name_len = prefix_len + common_suffix_len + random_suffix_len;
739 staging_dir_name = MALLOC(staging_dir_name_len + 1);
740 if (!staging_dir_name) {
741 ret = WIMLIB_ERR_NOMEM;
745 if (real_user_prefix)
746 sprintf(staging_dir_name, "%s/%s", real_user_prefix, wim_basename);
748 strcpy(staging_dir_name, ctx->wim->filename);
750 strcat(staging_dir_name, common_suffix);
752 randomize_char_array_with_alnum(staging_dir_name + prefix_len + common_suffix_len,
755 staging_dir_name[staging_dir_name_len] = '\0';
757 if (mkdir(staging_dir_name, 0700) != 0) {
758 ERROR_WITH_ERRNO("Failed to create temporary directory `%s'",
760 ret = WIMLIB_ERR_MKDIR;
765 FREE(real_user_prefix);
767 ctx->staging_dir_name = staging_dir_name;
768 ctx->staging_dir_name_len = staging_dir_name_len;
770 FREE(staging_dir_name);
776 remove_file_or_directory(const char *fpath, const struct stat *sb,
777 int typeflag, struct FTW *ftwbuf)
779 if (remove(fpath) == 0)
782 ERROR_WITH_ERRNO("Cannot remove `%s'", fpath);
783 return WIMLIB_ERR_DELETE_STAGING_DIR;
788 * Deletes the staging directory and all the files contained in it.
791 delete_staging_dir(struct wimfs_context *ctx)
794 ret = nftw(ctx->staging_dir_name, remove_file_or_directory,
796 FREE(ctx->staging_dir_name);
797 ctx->staging_dir_name = NULL;
802 inode_close_fds(struct wim_inode *inode)
804 u16 num_opened_fds = inode->i_num_opened_fds;
805 for (u16 i = 0, j = 0; j < num_opened_fds; i++) {
806 struct wimfs_fd *fd = inode->i_fds[i];
808 wimlib_assert(fd->f_inode == inode);
809 int ret = close_wimfs_fd(fd);
818 /* Overwrites the WIM file, with changes saved. */
820 rebuild_wim(struct wimfs_context *ctx, int write_flags,
821 wimlib_progress_func_t progress_func)
824 struct wim_lookup_table_entry *lte, *tmp;
825 WIMStruct *wim = ctx->wim;
826 struct wim_image_metadata *imd = wim_get_current_image_metadata(ctx->wim);
828 DEBUG("Closing all staging file descriptors.");
829 image_for_each_unhashed_stream_safe(lte, tmp, imd) {
830 ret = inode_close_fds(lte->back_inode);
835 DEBUG("Freeing entries for zero-length streams");
836 image_for_each_unhashed_stream_safe(lte, tmp, imd) {
837 wimlib_assert(lte->unhashed);
838 if (lte->size == 0) {
839 struct wim_lookup_table_entry **back_ptr;
840 back_ptr = retrieve_lte_pointer(lte);
842 list_del(<e->unhashed_list);
843 free_lookup_table_entry(lte);
847 xml_update_image_info(wim, wim->current_image);
848 ret = wimlib_overwrite(wim, write_flags, 0, progress_func);
850 ERROR("Failed to commit changes to mounted WIM image");
854 /* Simple function that returns the concatenation of 2 strings. */
856 strcat_dup(const char *s1, const char *s2, size_t max_len)
858 size_t len = strlen(s1) + strlen(s2);
861 char *p = MALLOC(len + 1);
864 snprintf(p, len + 1, "%s%s", s1, s2);
869 set_message_queue_names(struct wimfs_context *ctx, const char *mount_dir)
871 static const char *u2d_prefix = "/wimlib-unmount-to-daemon-mq";
872 static const char *d2u_prefix = "/wimlib-daemon-to-unmount-mq";
877 dir_path = realpath(mount_dir, NULL);
879 ERROR_WITH_ERRNO("Failed to resolve path \"%s\"", mount_dir);
881 return WIMLIB_ERR_NOMEM;
883 return WIMLIB_ERR_NOTDIR;
886 for (p = dir_path; *p; p++)
890 ctx->unmount_to_daemon_mq_name = strcat_dup(u2d_prefix, dir_path,
892 if (!ctx->unmount_to_daemon_mq_name) {
893 ret = WIMLIB_ERR_NOMEM;
894 goto out_free_dir_path;
896 ctx->daemon_to_unmount_mq_name = strcat_dup(d2u_prefix, dir_path,
898 if (!ctx->daemon_to_unmount_mq_name) {
899 ret = WIMLIB_ERR_NOMEM;
900 goto out_free_unmount_to_daemon_mq_name;
904 goto out_free_dir_path;
905 out_free_unmount_to_daemon_mq_name:
906 FREE(ctx->unmount_to_daemon_mq_name);
907 ctx->unmount_to_daemon_mq_name = NULL;
914 free_message_queue_names(struct wimfs_context *ctx)
916 FREE(ctx->unmount_to_daemon_mq_name);
917 FREE(ctx->daemon_to_unmount_mq_name);
918 ctx->unmount_to_daemon_mq_name = NULL;
919 ctx->daemon_to_unmount_mq_name = NULL;
923 * Opens two POSIX message queue: one for sending messages from the unmount
924 * process to the daemon process, and one to go the other way. The names of the
925 * message queues, which must be system-wide unique, are be based on the mount
928 * @daemon specifies whether the calling process is the filesystem daemon or the
932 open_message_queues(struct wimfs_context *ctx, bool daemon)
934 int unmount_to_daemon_mq_flags = O_WRONLY | O_CREAT;
935 int daemon_to_unmount_mq_flags = O_RDONLY | O_CREAT;
941 swap(unmount_to_daemon_mq_flags, daemon_to_unmount_mq_flags);
947 orig_umask = umask(0000);
948 DEBUG("Opening message queue \"%s\"", ctx->unmount_to_daemon_mq_name);
949 ctx->unmount_to_daemon_mq = mq_open(ctx->unmount_to_daemon_mq_name,
950 unmount_to_daemon_mq_flags, mode, NULL);
952 if (ctx->unmount_to_daemon_mq == (mqd_t)-1) {
953 ERROR_WITH_ERRNO("mq_open()");
954 ret = WIMLIB_ERR_MQUEUE;
958 DEBUG("Opening message queue \"%s\"", ctx->daemon_to_unmount_mq_name);
959 ctx->daemon_to_unmount_mq = mq_open(ctx->daemon_to_unmount_mq_name,
960 daemon_to_unmount_mq_flags, mode, NULL);
962 if (ctx->daemon_to_unmount_mq == (mqd_t)-1) {
963 ERROR_WITH_ERRNO("mq_open()");
964 mq_close(ctx->unmount_to_daemon_mq);
965 mq_unlink(ctx->unmount_to_daemon_mq_name);
966 ctx->unmount_to_daemon_mq = (mqd_t)-1;
967 ret = WIMLIB_ERR_MQUEUE;
976 /* Try to determine the maximum message size of a message queue. The return
977 * value is the maximum message size, or a guess of 8192 bytes if it cannot be
980 mq_get_msgsize(mqd_t mq)
982 static const char *msgsize_max_file = "/proc/sys/fs/mqueue/msgsize_max";
987 if (mq_getattr(mq, &attr) == 0) {
988 msgsize = attr.mq_msgsize;
990 ERROR_WITH_ERRNO("mq_getattr()");
991 ERROR("Attempting to read %s", msgsize_max_file);
992 fp = fopen(msgsize_max_file, "rb");
994 if (fscanf(fp, "%ld", &msgsize) != 1) {
995 ERROR("Assuming message size of 8192");
1000 ERROR_WITH_ERRNO("Failed to open the file `%s'",
1002 ERROR("Assuming message size of 8192");
1010 get_mailbox(mqd_t mq, long needed_msgsize, long *msgsize_ret,
1016 msgsize = mq_get_msgsize(mq);
1018 if (msgsize < needed_msgsize) {
1019 ERROR("Message queue max size must be at least %ld!",
1021 return WIMLIB_ERR_MQUEUE;
1024 mailbox = MALLOC(msgsize);
1026 ERROR("Failed to allocate %ld bytes for mailbox", msgsize);
1027 return WIMLIB_ERR_NOMEM;
1029 *msgsize_ret = msgsize;
1030 *mailbox_ret = mailbox;
1035 unlink_message_queues(struct wimfs_context *ctx)
1037 mq_unlink(ctx->unmount_to_daemon_mq_name);
1038 mq_unlink(ctx->daemon_to_unmount_mq_name);
1041 /* Closes the message queues, which are allocated in static variables */
1043 close_message_queues(struct wimfs_context *ctx)
1045 DEBUG("Closing message queues");
1046 mq_close(ctx->unmount_to_daemon_mq);
1047 ctx->unmount_to_daemon_mq = (mqd_t)(-1);
1048 mq_close(ctx->daemon_to_unmount_mq);
1049 ctx->daemon_to_unmount_mq = (mqd_t)(-1);
1050 unlink_message_queues(ctx);
1054 struct unmount_msg_hdr {
1059 } _packed_attribute;
1061 struct msg_unmount_request {
1062 struct unmount_msg_hdr hdr;
1064 u8 want_progress_messages;
1065 } _packed_attribute;
1067 struct msg_daemon_info {
1068 struct unmount_msg_hdr hdr;
1071 } _packed_attribute;
1073 struct msg_unmount_finished {
1074 struct unmount_msg_hdr hdr;
1076 } _packed_attribute;
1078 struct msg_write_streams_progress {
1079 struct unmount_msg_hdr hdr;
1080 union wimlib_progress_info info;
1081 } _packed_attribute;
1084 MSG_TYPE_UNMOUNT_REQUEST,
1085 MSG_TYPE_DAEMON_INFO,
1086 MSG_TYPE_WRITE_STREAMS_PROGRESS,
1087 MSG_TYPE_UNMOUNT_FINISHED,
1091 struct msg_handler_context_hdr {
1092 int timeout_seconds;
1095 struct unmount_msg_handler_context {
1096 struct msg_handler_context_hdr hdr;
1100 wimlib_progress_func_t progress_func;
1103 struct daemon_msg_handler_context {
1104 struct msg_handler_context_hdr hdr;
1105 struct wimfs_context *wimfs_ctx;
1109 send_unmount_request_msg(mqd_t mq, int unmount_flags, u8 want_progress_messages)
1111 DEBUG("Sending unmount request msg");
1112 struct msg_unmount_request msg = {
1114 .min_version = WIMLIB_MAKEVERSION(1, 2, 1),
1115 .cur_version = WIMLIB_VERSION_CODE,
1116 .msg_type = MSG_TYPE_UNMOUNT_REQUEST,
1117 .msg_size = sizeof(msg),
1119 .unmount_flags = unmount_flags,
1120 .want_progress_messages = want_progress_messages,
1123 if (mq_send(mq, (void*)&msg, sizeof(msg), 1)) {
1124 ERROR_WITH_ERRNO("Failed to communicate with filesystem daemon");
1125 return WIMLIB_ERR_MQUEUE;
1131 send_daemon_info_msg(mqd_t mq, pid_t pid, int mount_flags)
1133 DEBUG("Sending daemon info msg (pid = %d, mount_flags=%x)",
1136 struct msg_daemon_info msg = {
1138 .min_version = WIMLIB_MAKEVERSION(1, 2, 1),
1139 .cur_version = WIMLIB_VERSION_CODE,
1140 .msg_type = MSG_TYPE_DAEMON_INFO,
1141 .msg_size = sizeof(msg),
1144 .mount_flags = mount_flags,
1146 if (mq_send(mq, (void*)&msg, sizeof(msg), 1)) {
1147 ERROR_WITH_ERRNO("Failed to send daemon info to unmount process");
1148 return WIMLIB_ERR_MQUEUE;
1154 send_unmount_finished_msg(mqd_t mq, int status)
1156 DEBUG("Sending unmount finished msg");
1157 struct msg_unmount_finished msg = {
1159 .min_version = WIMLIB_MAKEVERSION(1, 2, 1),
1160 .cur_version = WIMLIB_VERSION_CODE,
1161 .msg_type = MSG_TYPE_UNMOUNT_FINISHED,
1162 .msg_size = sizeof(msg),
1166 if (mq_send(mq, (void*)&msg, sizeof(msg), 1))
1167 ERROR_WITH_ERRNO("Failed to send status to unmount process");
1171 unmount_progress_func(enum wimlib_progress_msg msg,
1172 const union wimlib_progress_info *info)
1174 if (msg == WIMLIB_PROGRESS_MSG_WRITE_STREAMS) {
1175 struct msg_write_streams_progress msg = {
1177 .min_version = WIMLIB_MAKEVERSION(1, 2, 1),
1178 .cur_version = WIMLIB_VERSION_CODE,
1179 .msg_type = MSG_TYPE_WRITE_STREAMS_PROGRESS,
1180 .msg_size = sizeof(msg),
1184 if (mq_send(wimfs_get_context()->daemon_to_unmount_mq,
1185 (void*)&msg, sizeof(msg), 1))
1187 ERROR_WITH_ERRNO("Failed to send progress information "
1188 "to unmount process");
1195 msg_unmount_request_handler(const void *_msg, void *_handler_ctx)
1197 const struct msg_unmount_request *msg = _msg;
1198 struct daemon_msg_handler_context *handler_ctx = _handler_ctx;
1199 struct wimfs_context *wimfs_ctx;
1203 wimlib_progress_func_t progress_func;
1205 DEBUG("Handling unmount request msg");
1207 wimfs_ctx = handler_ctx->wimfs_ctx;
1208 if (msg->hdr.msg_size < sizeof(*msg)) {
1209 status = WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1213 unmount_flags = msg->unmount_flags;
1214 if (msg->want_progress_messages)
1215 progress_func = unmount_progress_func;
1217 progress_func = NULL;
1219 ret = send_daemon_info_msg(wimfs_ctx->daemon_to_unmount_mq, getpid(),
1220 wimfs_ctx->mount_flags);
1226 if (wimfs_ctx->mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
1227 if (unmount_flags & WIMLIB_UNMOUNT_FLAG_COMMIT) {
1228 int write_flags = 0;
1229 if (unmount_flags & WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY)
1230 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
1231 if (unmount_flags & WIMLIB_UNMOUNT_FLAG_REBUILD)
1232 write_flags |= WIMLIB_WRITE_FLAG_REBUILD;
1233 if (unmount_flags & WIMLIB_UNMOUNT_FLAG_RECOMPRESS)
1234 write_flags |= WIMLIB_WRITE_FLAG_RECOMPRESS;
1235 status = rebuild_wim(wimfs_ctx, write_flags,
1239 DEBUG("Read-only mount");
1244 if (wimfs_ctx->mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
1245 ret = delete_staging_dir(wimfs_ctx);
1247 ERROR("Failed to delete the staging directory");
1252 wimfs_ctx->status = status;
1253 wimfs_ctx->have_status = true;
1254 return MSG_BREAK_LOOP;
1258 msg_daemon_info_handler(const void *_msg, void *_handler_ctx)
1260 const struct msg_daemon_info *msg = _msg;
1261 struct unmount_msg_handler_context *handler_ctx = _handler_ctx;
1263 DEBUG("Handling daemon info msg");
1264 if (msg->hdr.msg_size < sizeof(*msg))
1265 return WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1266 handler_ctx->daemon_pid = msg->daemon_pid;
1267 handler_ctx->mount_flags = msg->mount_flags;
1268 handler_ctx->hdr.timeout_seconds = 1;
1269 DEBUG("pid of daemon is %d; mount flags were %#x",
1270 handler_ctx->daemon_pid,
1271 handler_ctx->mount_flags);
1276 msg_write_streams_progress_handler(const void *_msg, void *_handler_ctx)
1278 const struct msg_write_streams_progress *msg = _msg;
1279 struct unmount_msg_handler_context *handler_ctx = _handler_ctx;
1281 if (msg->hdr.msg_size < sizeof(*msg))
1282 return WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1283 if (handler_ctx->progress_func) {
1284 handler_ctx->progress_func(WIMLIB_PROGRESS_MSG_WRITE_STREAMS,
1291 msg_unmount_finished_handler(const void *_msg, void *_handler_ctx)
1293 const struct msg_unmount_finished *msg = _msg;
1294 struct unmount_msg_handler_context *handler_ctx = _handler_ctx;
1296 DEBUG("Handling unmount finished message");
1297 if (msg->hdr.msg_size < sizeof(*msg))
1298 return WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1299 handler_ctx->status = msg->status;
1300 DEBUG("status is %d", handler_ctx->status);
1301 return MSG_BREAK_LOOP;
1305 unmount_timed_out_cb(void *_handler_ctx)
1307 struct unmount_msg_handler_context *handler_ctx = _handler_ctx;
1309 if (handler_ctx->daemon_pid == 0) {
1312 kill(handler_ctx->daemon_pid, 0);
1313 if (errno == ESRCH) {
1316 DEBUG("Filesystem daemon is still alive... "
1317 "Waiting another %d seconds\n",
1318 handler_ctx->hdr.timeout_seconds);
1323 ERROR("The filesystem daemon has crashed! Changes to the "
1324 "WIM may not have been commited.");
1325 return WIMLIB_ERR_FILESYSTEM_DAEMON_CRASHED;
1329 daemon_timed_out_cb(void *_handler_ctx)
1331 ERROR("Timed out waiting for unmount request! "
1332 "Changes to the mounted WIM will not be committed.");
1333 return WIMLIB_ERR_TIMEOUT;
1336 typedef int (*msg_handler_t)(const void *_msg, void *_handler_ctx);
1338 struct msg_handler_callbacks {
1339 int (*timed_out)(void * _handler_ctx);
1340 msg_handler_t msg_handlers[MSG_TYPE_MAX];
1343 static const struct msg_handler_callbacks unmount_msg_handler_callbacks = {
1344 .timed_out = unmount_timed_out_cb,
1346 [MSG_TYPE_DAEMON_INFO] = msg_daemon_info_handler,
1347 [MSG_TYPE_WRITE_STREAMS_PROGRESS] = msg_write_streams_progress_handler,
1348 [MSG_TYPE_UNMOUNT_FINISHED] = msg_unmount_finished_handler,
1352 static const struct msg_handler_callbacks daemon_msg_handler_callbacks = {
1353 .timed_out = daemon_timed_out_cb,
1355 [MSG_TYPE_UNMOUNT_REQUEST] = msg_unmount_request_handler,
1360 receive_message(mqd_t mq,
1361 struct msg_handler_context_hdr *handler_ctx,
1362 const msg_handler_t msg_handlers[],
1363 long mailbox_size, void *mailbox)
1366 struct timespec timeout;
1367 ssize_t bytes_received;
1368 struct unmount_msg_hdr *hdr;
1371 gettimeofday(&now, NULL);
1372 timeout.tv_sec = now.tv_sec + handler_ctx->timeout_seconds;
1373 timeout.tv_nsec = now.tv_usec * 1000;
1375 bytes_received = mq_timedreceive(mq, mailbox,
1376 mailbox_size, NULL, &timeout);
1378 if (bytes_received == -1) {
1379 if (errno == ETIMEDOUT) {
1380 ret = WIMLIB_ERR_TIMEOUT;
1382 ERROR_WITH_ERRNO("mq_timedreceive()");
1383 ret = WIMLIB_ERR_MQUEUE;
1385 } else if (bytes_received < sizeof(*hdr) ||
1386 bytes_received != hdr->msg_size) {
1387 ret = WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1388 } else if (WIMLIB_VERSION_CODE < hdr->min_version) {
1389 /*ERROR("Cannot understand the received message. "*/
1390 /*"Please upgrade wimlib to at least v%d.%d.%d",*/
1391 /*WIMLIB_GET_MAJOR_VERSION(hdr->min_version),*/
1392 /*WIMLIB_GET_MINOR_VERSION(hdr->min_version),*/
1393 /*WIMLIB_GET_PATCH_VERSION(hdr->min_version));*/
1394 ret = MSG_VERSION_TOO_HIGH;
1395 } else if (hdr->msg_type >= MSG_TYPE_MAX) {
1396 ret = WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1397 } else if (msg_handlers[hdr->msg_type] == NULL) {
1398 ret = WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1400 ret = msg_handlers[hdr->msg_type](mailbox, handler_ctx);
1406 message_loop(mqd_t mq,
1407 const struct msg_handler_callbacks *callbacks,
1408 struct msg_handler_context_hdr *handler_ctx)
1410 static const size_t MAX_MSG_SIZE = 512;
1415 DEBUG("Entering message loop");
1417 ret = get_mailbox(mq, MAX_MSG_SIZE, &msgsize, &mailbox);
1421 ret = receive_message(mq, handler_ctx,
1422 callbacks->msg_handlers,
1424 if (ret == 0 || ret == MSG_VERSION_TOO_HIGH) {
1426 } else if (ret == MSG_BREAK_LOOP) {
1429 } else if (ret == WIMLIB_ERR_TIMEOUT) {
1430 if (callbacks->timed_out)
1431 ret = callbacks->timed_out(handler_ctx);
1437 ERROR_WITH_ERRNO("Error communicating with "
1438 "filesystem daemon");
1443 DEBUG("Exiting message loop");
1447 /* Execute `fusermount -u', which is installed setuid root, to unmount the WIM.
1449 * FUSE does not yet implement synchronous unmounts. This means that fusermount
1450 * -u will return before the filesystem daemon returns from wimfs_destroy().
1451 * This is partly what we want, because we need to send a message from this
1452 * process to the filesystem daemon telling whether --commit was specified or
1453 * not. However, after that, the unmount process must wait for the filesystem
1454 * daemon to finish writing the WIM file.
1457 execute_fusermount(const char *dir, bool lazy)
1465 ERROR_WITH_ERRNO("Failed to fork()");
1466 return WIMLIB_ERR_FORK;
1472 *argp++ = "fusermount";
1476 *argp++ = (char*)dir;
1478 execvp("fusermount", argv);
1479 ERROR_WITH_ERRNO("Failed to execute `fusermount'");
1480 exit(WIMLIB_ERR_FUSERMOUNT);
1484 ret = waitpid(pid, &status, 0);
1486 ERROR_WITH_ERRNO("Failed to wait for fusermount process to "
1488 return WIMLIB_ERR_FUSERMOUNT;
1491 if (!WIFEXITED(status)) {
1492 ERROR("'fusermount' did not terminate normally!");
1493 return WIMLIB_ERR_FUSERMOUNT;
1496 status = WEXITSTATUS(status);
1501 if (status != WIMLIB_ERR_FUSERMOUNT)
1502 return WIMLIB_ERR_FUSERMOUNT;
1504 /* Try again, but with the `umount' program. This is required on other
1505 * FUSE implementations such as FreeBSD's that do not have a
1506 * `fusermount' program. */
1507 ERROR("Falling back to 'umount'. Note: you may need to be "
1508 "root for this to work");
1511 ERROR_WITH_ERRNO("Failed to fork()");
1512 return WIMLIB_ERR_FORK;
1521 *argp++ = (char*)dir;
1523 execvp("umount", argv);
1524 ERROR_WITH_ERRNO("Failed to execute `umount'");
1525 exit(WIMLIB_ERR_FUSERMOUNT);
1529 ret = waitpid(pid, &status, 0);
1531 ERROR_WITH_ERRNO("Failed to wait for `umount' process to "
1533 return WIMLIB_ERR_FUSERMOUNT;
1536 ERROR("`umount' did not successfully complete");
1537 return WIMLIB_ERR_FUSERMOUNT;
1543 wimfs_chmod(const char *path, mode_t mask)
1545 struct wim_dentry *dentry;
1546 struct wimfs_context *ctx = wimfs_get_context();
1549 if (!(ctx->mount_flags & WIMLIB_MOUNT_FLAG_UNIX_DATA))
1552 ret = wim_pathname_to_stream(ctx->wim, path, LOOKUP_FLAG_DIRECTORY_OK,
1553 &dentry, NULL, NULL);
1557 ret = inode_set_unix_data(dentry->d_inode, ctx->default_uid,
1558 ctx->default_gid, mask,
1559 ctx->wim->lookup_table, UNIX_DATA_MODE);
1560 return ret ? -ENOMEM : 0;
1564 wimfs_chown(const char *path, uid_t uid, gid_t gid)
1566 struct wim_dentry *dentry;
1567 struct wimfs_context *ctx = wimfs_get_context();
1570 if (!(ctx->mount_flags & WIMLIB_MOUNT_FLAG_UNIX_DATA))
1573 ret = wim_pathname_to_stream(ctx->wim, path, LOOKUP_FLAG_DIRECTORY_OK,
1574 &dentry, NULL, NULL);
1578 ret = inode_set_unix_data(dentry->d_inode, uid, gid,
1579 inode_default_unix_mode(dentry->d_inode),
1580 ctx->wim->lookup_table,
1581 UNIX_DATA_UID | UNIX_DATA_GID);
1582 return ret ? -ENOMEM : 0;
1585 /* Called when the filesystem is unmounted. */
1587 wimfs_destroy(void *p)
1589 struct wimfs_context *wimfs_ctx = wimfs_get_context();
1590 if (open_message_queues(wimfs_ctx, true) == 0) {
1591 struct daemon_msg_handler_context handler_ctx = {
1593 .timeout_seconds = 5,
1595 .wimfs_ctx = wimfs_ctx,
1597 message_loop(wimfs_ctx->unmount_to_daemon_mq,
1598 &daemon_msg_handler_callbacks,
1604 wimfs_fgetattr(const char *path, struct stat *stbuf,
1605 struct fuse_file_info *fi)
1607 struct wimfs_fd *fd = (struct wimfs_fd*)(uintptr_t)fi->fh;
1608 return inode_to_stbuf(fd->f_inode, fd->f_lte, stbuf);
1612 wimfs_ftruncate(const char *path, off_t size, struct fuse_file_info *fi)
1614 struct wimfs_fd *fd = (struct wimfs_fd*)(uintptr_t)fi->fh;
1615 int ret = ftruncate(fd->staging_fd.fd, size);
1618 touch_inode(fd->f_inode);
1619 fd->f_lte->size = size;
1624 * Fills in a `struct stat' that corresponds to a file or directory in the WIM.
1627 wimfs_getattr(const char *path, struct stat *stbuf)
1629 struct wim_dentry *dentry;
1630 struct wim_lookup_table_entry *lte;
1632 struct wimfs_context *ctx = wimfs_get_context();
1634 ret = wim_pathname_to_stream(ctx->wim, path,
1635 get_lookup_flags(ctx) |
1636 LOOKUP_FLAG_DIRECTORY_OK,
1637 &dentry, <e, NULL);
1640 return inode_to_stbuf(dentry->d_inode, lte, stbuf);
1644 /* Read an alternate data stream through the XATTR interface, or get its size */
1646 wimfs_getxattr(const char *path, const char *name, char *value,
1650 struct wim_inode *inode;
1651 struct wim_ads_entry *ads_entry;
1653 struct wim_lookup_table_entry *lte;
1654 struct wimfs_context *ctx = wimfs_get_context();
1656 if (!(ctx->mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR))
1659 if (strlen(name) <= 5 || memcmp(name, "user.", 5) != 0)
1663 inode = wim_pathname_to_inode(ctx->wim, path);
1667 ads_entry = inode_get_ads_entry(inode, name, NULL);
1671 lte = ads_entry->lte;
1672 stream_size = lte->size;
1677 if (stream_size > size)
1680 ret = read_full_stream_into_buf(lte, value);
1691 /* Create a hard link */
1693 wimfs_link(const char *to, const char *from)
1695 struct wim_dentry *from_dentry, *from_dentry_parent;
1696 const char *link_name;
1697 struct wim_inode *inode;
1698 WIMStruct *wim = wimfs_get_WIMStruct();
1701 inode = wim_pathname_to_inode(wim, to);
1705 if (inode->i_attributes & (FILE_ATTRIBUTE_DIRECTORY |
1706 FILE_ATTRIBUTE_REPARSE_POINT))
1709 from_dentry_parent = get_parent_dentry(wim, from, WIMLIB_CASE_SENSITIVE);
1710 if (!from_dentry_parent)
1712 if (!dentry_is_directory(from_dentry_parent))
1715 link_name = path_basename(from);
1716 if (get_dentry_child_with_name(from_dentry_parent, link_name,
1717 WIMLIB_CASE_SENSITIVE))
1720 ret = new_dentry(link_name, &from_dentry);
1725 inode_ref_streams(inode);
1726 from_dentry->d_inode = inode;
1727 inode_add_dentry(from_dentry, inode);
1728 dentry_add_child(from_dentry_parent, from_dentry);
1734 wimfs_listxattr(const char *path, char *list, size_t size)
1737 struct wim_inode *inode;
1738 struct wimfs_context *ctx = wimfs_get_context();
1741 bool size_only = (size == 0);
1743 if (!(ctx->mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR))
1746 /* List alternate data streams, or get the list size */
1748 inode = wim_pathname_to_inode(ctx->wim, path);
1753 for (i = 0; i < inode->i_num_ads; i++) {
1755 if (!ads_entry_is_named_stream(&inode->i_ads_entries[i]))
1758 char *stream_name_mbs;
1759 size_t stream_name_mbs_nbytes;
1762 ret = utf16le_to_tstr(inode->i_ads_entries[i].stream_name,
1763 inode->i_ads_entries[i].stream_name_nbytes,
1765 &stream_name_mbs_nbytes);
1769 needed_size = stream_name_mbs_nbytes + 6;
1771 if (needed_size > size) {
1772 FREE(stream_name_mbs);
1775 sprintf(p, "user.%s", stream_name_mbs);
1776 size -= needed_size;
1779 FREE(stream_name_mbs);
1786 /* Create a directory in the WIM image. */
1788 wimfs_mkdir(const char *path, mode_t mode)
1790 return create_dentry(fuse_get_context(), path, mode | S_IFDIR,
1791 FILE_ATTRIBUTE_DIRECTORY, NULL);
1794 /* Create a regular file or alternate data stream in the WIM image. */
1796 wimfs_mknod(const char *path, mode_t mode, dev_t rdev)
1798 const char *stream_name;
1799 struct fuse_context *fuse_ctx = fuse_get_context();
1800 struct wimfs_context *wimfs_ctx = WIMFS_CTX(fuse_ctx);
1805 if ((wimfs_ctx->mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS)
1806 && (stream_name = path_stream_name(path))) {
1807 /* Make an alternate data stream */
1808 struct wim_ads_entry *new_entry;
1809 struct wim_inode *inode;
1811 char *p = (char*)stream_name - 1;
1812 wimlib_assert(*p == ':');
1815 inode = wim_pathname_to_inode(wimfs_ctx->wim, path);
1818 if (inode->i_attributes & FILE_ATTRIBUTE_REPARSE_POINT)
1820 if (inode_get_ads_entry(inode, stream_name, NULL))
1822 new_entry = inode_add_ads(inode, stream_name);
1827 /* Make a normal file (not an alternate data stream) */
1828 return create_dentry(fuse_ctx, path, mode | S_IFREG,
1829 FILE_ATTRIBUTE_NORMAL, NULL);
1835 wimfs_open(const char *path, struct fuse_file_info *fi)
1837 struct wim_dentry *dentry;
1838 struct wim_lookup_table_entry *lte;
1840 struct wimfs_fd *fd;
1841 struct wim_inode *inode;
1844 struct wimfs_context *ctx = wimfs_get_context();
1845 struct wim_lookup_table_entry **back_ptr;
1847 ret = wim_pathname_to_stream(ctx->wim, path, get_lookup_flags(ctx),
1848 &dentry, <e, &stream_idx);
1852 inode = dentry->d_inode;
1854 if (stream_idx == 0) {
1856 back_ptr = &inode->i_lte;
1858 stream_id = inode->i_ads_entries[stream_idx - 1].stream_id;
1859 back_ptr = &inode->i_ads_entries[stream_idx - 1].lte;
1862 /* The file resource may be in the staging directory (read-write mounts
1863 * only) or in the WIM. If it's in the staging directory, we need to
1864 * open a native file descriptor for the corresponding file. Otherwise,
1865 * we can read the file resource directly from the WIM file if we are
1866 * opening it read-only, but we need to extract the resource to the
1867 * staging directory if we are opening it writable. */
1869 if (flags_writable(fi->flags) &&
1870 (!lte || lte->resource_location != RESOURCE_IN_STAGING_FILE)) {
1871 u64 size = (lte) ? lte->size : 0;
1872 ret = extract_resource_to_staging_dir(inode, stream_id,
1879 ret = alloc_wimfs_fd(inode, stream_id, lte, &fd,
1880 wimfs_ctx_readonly(ctx));
1884 if (lte && lte->resource_location == RESOURCE_IN_STAGING_FILE) {
1887 raw_fd = open(lte->staging_file_name, fi->flags);
1889 int errno_save = errno;
1893 filedes_init(&fd->staging_fd, raw_fd);
1895 fi->fh = (uintptr_t)fd;
1899 /* Opens a directory. */
1901 wimfs_opendir(const char *path, struct fuse_file_info *fi)
1903 struct wim_inode *inode;
1905 struct wimfs_fd *fd = NULL;
1906 struct wimfs_context *ctx = wimfs_get_context();
1907 WIMStruct *wim = ctx->wim;
1909 inode = wim_pathname_to_inode(wim, path);
1912 if (!inode_is_directory(inode))
1914 ret = alloc_wimfs_fd(inode, 0, NULL, &fd, wimfs_ctx_readonly(ctx));
1915 fi->fh = (uintptr_t)fd;
1921 * Read data from a file in the WIM or in the staging directory.
1924 wimfs_read(const char *path, char *buf, size_t size,
1925 off_t offset, struct fuse_file_info *fi)
1927 struct wimfs_fd *fd = (struct wimfs_fd*)(uintptr_t)fi->fh;
1938 stream_size = fd->f_lte->size;
1942 if (offset > stream_size)
1945 size = min(size, stream_size - offset);
1949 switch (fd->f_lte->resource_location) {
1950 case RESOURCE_IN_STAGING_FILE:
1951 ret = raw_pread(&fd->staging_fd, buf, size, offset);
1955 case RESOURCE_IN_WIM:
1956 if (read_partial_wim_stream_into_buf(fd->f_lte, size,
1958 ret = errno ? -errno : -EIO;
1962 case RESOURCE_IN_ATTACHED_BUFFER:
1963 memcpy(buf, fd->f_lte->attached_buffer + offset, size);
1967 ERROR("Invalid resource location");
1974 struct fill_params {
1976 fuse_fill_dir_t filler;
1980 dentry_fuse_fill(struct wim_dentry *dentry, void *arg)
1982 struct fill_params *fill_params = arg;
1984 char *file_name_mbs;
1985 size_t file_name_mbs_nbytes;
1988 ret = utf16le_to_tstr(dentry->file_name,
1989 dentry->file_name_nbytes,
1991 &file_name_mbs_nbytes);
1995 ret = fill_params->filler(fill_params->buf, file_name_mbs, NULL, 0);
1996 FREE(file_name_mbs);
2000 /* Fills in the entries of the directory specified by @path using the
2001 * FUSE-provided function @filler. */
2003 wimfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
2004 off_t offset, struct fuse_file_info *fi)
2006 struct wimfs_fd *fd = (struct wimfs_fd*)(uintptr_t)fi->fh;
2007 struct wim_inode *inode;
2012 inode = fd->f_inode;
2014 struct fill_params fill_params = {
2019 filler(buf, ".", NULL, 0);
2020 filler(buf, "..", NULL, 0);
2022 return for_dentry_in_rbtree(inode->i_children.rb_node,
2023 dentry_fuse_fill, &fill_params);
2028 wimfs_readlink(const char *path, char *buf, size_t buf_len)
2030 struct wimfs_context *ctx = wimfs_get_context();
2031 struct wim_inode *inode = wim_pathname_to_inode(ctx->wim, path);
2035 if (!inode_is_symlink(inode))
2038 return -ENAMETOOLONG;
2039 ret = wim_inode_readlink(inode, buf, buf_len - 1, NULL);
2041 wimlib_assert(ret <= buf_len - 1);
2044 } else if (ret == -ENAMETOOLONG) {
2045 buf[buf_len - 1] = '\0';
2052 wimfs_release(const char *path, struct fuse_file_info *fi)
2054 struct wimfs_fd *fd = (struct wimfs_fd*)(uintptr_t)fi->fh;
2055 return close_wimfs_fd(fd);
2058 /* Close a directory */
2060 wimfs_releasedir(const char *path, struct fuse_file_info *fi)
2062 struct wimfs_fd *fd = (struct wimfs_fd*)(uintptr_t)fi->fh;
2063 return close_wimfs_fd(fd);
2067 /* Remove an alternate data stream through the XATTR interface */
2069 wimfs_removexattr(const char *path, const char *name)
2071 struct wim_inode *inode;
2072 struct wim_ads_entry *ads_entry;
2074 struct wimfs_context *ctx = wimfs_get_context();
2076 if (!(ctx->mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR))
2079 if (strlen(name) < 5 || memcmp(name, "user.", 5) != 0)
2083 inode = wim_pathname_to_inode(ctx->wim, path);
2087 ads_entry = inode_get_ads_entry(inode, name, &ads_idx);
2090 inode_remove_ads(inode, ads_idx, ctx->wim->lookup_table);
2095 /* Renames a file or directory. See rename (3) */
2097 wimfs_rename(const char *from, const char *to)
2099 return rename_wim_path(wimfs_get_WIMStruct(), from, to,
2100 WIMLIB_CASE_SENSITIVE);
2103 /* Remove a directory */
2105 wimfs_rmdir(const char *path)
2107 struct wim_dentry *dentry;
2108 WIMStruct *wim = wimfs_get_WIMStruct();
2110 dentry = get_dentry(wim, path, WIMLIB_CASE_SENSITIVE);
2114 if (!dentry_is_directory(dentry))
2117 if (dentry_has_children(dentry))
2120 remove_dentry(dentry, wim->lookup_table);
2125 /* Write an alternate data stream through the XATTR interface */
2127 wimfs_setxattr(const char *path, const char *name,
2128 const char *value, size_t size, int flags)
2130 struct wim_ads_entry *existing_ads_entry;
2131 struct wim_inode *inode;
2133 struct wimfs_context *ctx = wimfs_get_context();
2136 if (!(ctx->mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR))
2139 if (strlen(name) <= 5 || memcmp(name, "user.", 5) != 0)
2143 inode = wim_pathname_to_inode(ctx->wim, path);
2147 existing_ads_entry = inode_get_ads_entry(inode, name, &ads_idx);
2148 if (existing_ads_entry) {
2149 if (flags & XATTR_CREATE)
2152 if (flags & XATTR_REPLACE)
2156 ret = inode_add_ads_with_data(inode, name, value,
2157 size, ctx->wim->lookup_table);
2159 if (existing_ads_entry)
2160 inode_remove_ads(inode, ads_idx, ctx->wim->lookup_table);
2169 wimfs_symlink(const char *to, const char *from)
2171 struct fuse_context *fuse_ctx = fuse_get_context();
2172 struct wimfs_context *wimfs_ctx = WIMFS_CTX(fuse_ctx);
2173 struct wim_dentry *dentry;
2176 ret = create_dentry(fuse_ctx, from, S_IFLNK | 0777,
2177 FILE_ATTRIBUTE_REPARSE_POINT, &dentry);
2179 dentry->d_inode->i_reparse_tag = WIM_IO_REPARSE_TAG_SYMLINK;
2180 ret = wim_inode_set_symlink(dentry->d_inode, to,
2181 wimfs_ctx->wim->lookup_table);
2183 remove_dentry(dentry, wimfs_ctx->wim->lookup_table);
2184 if (ret == WIMLIB_ERR_NOMEM)
2194 /* Reduce the size of a file */
2196 wimfs_truncate(const char *path, off_t size)
2198 struct wim_dentry *dentry;
2199 struct wim_lookup_table_entry *lte;
2203 struct wim_inode *inode;
2204 struct wimfs_context *ctx = wimfs_get_context();
2206 ret = wim_pathname_to_stream(ctx->wim, path, get_lookup_flags(ctx),
2207 &dentry, <e, &stream_idx);
2212 if (lte == NULL && size == 0)
2215 if (lte != NULL && lte->resource_location == RESOURCE_IN_STAGING_FILE) {
2216 ret = truncate(lte->staging_file_name, size);
2222 /* File in WIM. Extract it to the staging directory, but only
2223 * the first @size bytes of it. */
2224 struct wim_lookup_table_entry **back_ptr;
2226 inode = dentry->d_inode;
2227 if (stream_idx == 0) {
2229 back_ptr = &inode->i_lte;
2231 stream_id = inode->i_ads_entries[stream_idx - 1].stream_id;
2232 back_ptr = &inode->i_ads_entries[stream_idx - 1].lte;
2234 ret = extract_resource_to_staging_dir(inode, stream_id,
2241 /* Unlink a non-directory or alternate data stream */
2243 wimfs_unlink(const char *path)
2245 struct wim_dentry *dentry;
2246 struct wim_lookup_table_entry *lte;
2249 struct wimfs_context *ctx = wimfs_get_context();
2251 ret = wim_pathname_to_stream(ctx->wim, path, get_lookup_flags(ctx),
2252 &dentry, <e, &stream_idx);
2257 if (inode_stream_name_nbytes(dentry->d_inode, stream_idx) == 0)
2258 remove_dentry(dentry, ctx->wim->lookup_table);
2260 inode_remove_ads(dentry->d_inode, stream_idx - 1,
2261 ctx->wim->lookup_table);
2265 #ifdef HAVE_UTIMENSAT
2267 * Change the timestamp on a file dentry.
2269 * Note that alternate data streams do not have their own timestamps.
2272 wimfs_utimens(const char *path, const struct timespec tv[2])
2274 struct wim_dentry *dentry;
2275 struct wim_inode *inode;
2276 WIMStruct *wim = wimfs_get_WIMStruct();
2278 dentry = get_dentry(wim, path, WIMLIB_CASE_SENSITIVE);
2281 inode = dentry->d_inode;
2283 if (tv[0].tv_nsec != UTIME_OMIT) {
2284 if (tv[0].tv_nsec == UTIME_NOW)
2285 inode->i_last_access_time = get_wim_timestamp();
2287 inode->i_last_access_time = timespec_to_wim_timestamp(tv[0]);
2289 if (tv[1].tv_nsec != UTIME_OMIT) {
2290 if (tv[1].tv_nsec == UTIME_NOW)
2291 inode->i_last_write_time = get_wim_timestamp();
2293 inode->i_last_write_time = timespec_to_wim_timestamp(tv[1]);
2297 #else /* HAVE_UTIMENSAT */
2299 wimfs_utime(const char *path, struct utimbuf *times)
2301 struct wim_dentry *dentry;
2302 struct wim_inode *inode;
2303 WIMStruct *wim = wimfs_get_WIMStruct();
2305 dentry = get_dentry(wim, path, WIMLIB_CASE_SENSITIVE);
2308 inode = dentry->d_inode;
2310 inode->i_last_write_time = unix_timestamp_to_wim(times->modtime);
2311 inode->i_last_access_time = unix_timestamp_to_wim(times->actime);
2314 #endif /* !HAVE_UTIMENSAT */
2316 /* Writes to a file in the WIM filesystem.
2317 * It may be an alternate data stream, but here we don't even notice because we
2318 * just get a lookup table entry. */
2320 wimfs_write(const char *path, const char *buf, size_t size,
2321 off_t offset, struct fuse_file_info *fi)
2323 struct wimfs_fd *fd = (struct wimfs_fd*)(uintptr_t)fi->fh;
2329 wimlib_assert(fd->f_lte != NULL);
2330 wimlib_assert(fd->f_lte->staging_file_name != NULL);
2331 wimlib_assert(filedes_valid(&fd->staging_fd));
2332 wimlib_assert(fd->f_inode != NULL);
2334 /* Write the data. */
2335 ret = raw_pwrite(&fd->staging_fd, buf, size, offset);
2339 /* Update file size */
2340 if (offset + size > fd->f_lte->size) {
2341 DEBUG("Update file size %"PRIu64 " => %"PRIu64"",
2342 fd->f_lte->size, offset + size);
2343 fd->f_lte->size = offset + size;
2346 /* Update timestamps */
2347 touch_inode(fd->f_inode);
2351 static struct fuse_operations wimfs_operations = {
2352 .chmod = wimfs_chmod,
2353 .chown = wimfs_chown,
2354 .destroy = wimfs_destroy,
2355 .fgetattr = wimfs_fgetattr,
2356 .ftruncate = wimfs_ftruncate,
2357 .getattr = wimfs_getattr,
2359 .getxattr = wimfs_getxattr,
2363 .listxattr = wimfs_listxattr,
2365 .mkdir = wimfs_mkdir,
2366 .mknod = wimfs_mknod,
2368 .opendir = wimfs_opendir,
2370 .readdir = wimfs_readdir,
2371 .readlink = wimfs_readlink,
2372 .release = wimfs_release,
2373 .releasedir = wimfs_releasedir,
2375 .removexattr = wimfs_removexattr,
2377 .rename = wimfs_rename,
2378 .rmdir = wimfs_rmdir,
2380 .setxattr = wimfs_setxattr,
2382 .symlink = wimfs_symlink,
2383 .truncate = wimfs_truncate,
2384 .unlink = wimfs_unlink,
2385 #ifdef HAVE_UTIMENSAT
2386 .utimens = wimfs_utimens,
2388 .utime = wimfs_utime,
2390 .write = wimfs_write,
2392 /* wimfs keeps file descriptor structures (struct wimfs_fd), so there is
2393 * no need to have the file path provided on operations such as read()
2394 * where only the file descriptor is needed. */
2395 #if FUSE_MAJOR_VERSION > 2 || (FUSE_MAJOR_VERSION == 2 && FUSE_MINOR_VERSION >= 8)
2396 .flag_nullpath_ok = 1,
2398 #if FUSE_MAJOR_VERSION > 2 || (FUSE_MAJOR_VERSION == 2 && FUSE_MINOR_VERSION >= 9)
2400 .flag_utime_omit_ok = 1,
2405 /* API function documented in wimlib.h */
2407 wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
2408 int mount_flags, const char *staging_dir)
2414 struct wim_image_metadata *imd;
2415 struct wimfs_context ctx;
2416 struct wim_inode *inode;
2418 DEBUG("Mount: wim = %p, image = %d, dir = %s, flags = %d, ",
2419 wim, image, dir, mount_flags);
2422 return WIMLIB_ERR_INVALID_PARAM;
2424 if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
2425 ret = can_delete_from_wim(wim);
2430 ret = select_wim_image(wim, image);
2434 DEBUG("Selected image %d", image);
2436 imd = wim_get_current_image_metadata(wim);
2438 if (imd->refcnt != 1) {
2439 ERROR("Cannot mount image that was just exported with "
2440 "wimlib_export_image()");
2441 return WIMLIB_ERR_INVALID_PARAM;
2444 if (imd->modified) {
2445 ERROR("Cannot mount image that was added "
2446 "with wimlib_add_image()");
2447 return WIMLIB_ERR_INVALID_PARAM;
2450 if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
2451 ret = lock_wim(wim, wim->in_fd.fd);
2456 /* Use default stream interface if one was not specified */
2457 if (!(mount_flags & (WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_NONE |
2458 WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR |
2459 WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS)))
2460 mount_flags |= WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR;
2462 DEBUG("Initializing struct wimfs_context");
2463 init_wimfs_context(&ctx);
2465 ctx.mount_flags = mount_flags;
2466 ctx.image_inode_list = &imd->inode_list;
2467 ctx.default_uid = getuid();
2468 ctx.default_gid = getgid();
2469 wimlib_assert(list_empty(&imd->unhashed_streams));
2470 ctx.wim->lookup_table->unhashed_streams = &imd->unhashed_streams;
2471 if (mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS)
2472 ctx.default_lookup_flags = LOOKUP_FLAG_ADS_OK;
2474 DEBUG("Unlinking message queues in case they already exist");
2475 ret = set_message_queue_names(&ctx, dir);
2478 unlink_message_queues(&ctx);
2480 DEBUG("Preparing arguments to fuse_main()");
2482 dir_copy = STRDUP(dir);
2484 goto out_free_message_queue_names;
2487 argv[argc++] = "wimlib";
2488 argv[argc++] = dir_copy;
2490 /* disable multi-threaded operation */
2491 argv[argc++] = "-s";
2493 if (mount_flags & WIMLIB_MOUNT_FLAG_DEBUG)
2494 argv[argc++] = "-d";
2497 * We provide the use_ino option to the FUSE mount because we are going
2498 * to assign inode numbers ourselves. */
2499 char optstring[256] =
2503 #if FUSE_MAJOR_VERSION > 2 || (FUSE_MAJOR_VERSION == 2 && FUSE_MINOR_VERSION >= 8)
2506 ",default_permissions"
2508 argv[argc++] = "-o";
2509 argv[argc++] = optstring;
2510 if ((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)) {
2511 /* Read-write mount. Make the staging directory */
2512 ret = make_staging_dir(&ctx, staging_dir);
2514 goto out_free_dir_copy;
2516 /* Read-only mount */
2517 strcat(optstring, ",ro");
2519 if (mount_flags & WIMLIB_MOUNT_FLAG_ALLOW_OTHER)
2520 strcat(optstring, ",allow_other");
2526 DEBUG("FUSE command line (argc = %d): ", argc);
2527 for (i = 0; i < argc; i++) {
2528 fputs(argv[i], stdout);
2536 /* Mark dentry tree as modified if read-write mount. */
2537 if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)
2540 /* Resolve the lookup table entries for every inode in the image, and
2541 * assign inode numbers */
2542 DEBUG("Resolving lookup table entries and assigning inode numbers");
2544 image_for_each_inode(inode, imd)
2545 inode->i_ino = ctx.next_ino++;
2546 DEBUG("(next_ino = %"PRIu64")", ctx.next_ino);
2548 DEBUG("Calling fuse_main()");
2550 ret = fuse_main(argc, argv, &wimfs_operations, &ctx);
2552 DEBUG("Returned from fuse_main() (ret = %d)", ret);
2555 ret = WIMLIB_ERR_FUSE;
2557 if (ctx.have_status)
2560 ret = WIMLIB_ERR_TIMEOUT;
2562 if (ctx.daemon_to_unmount_mq != (mqd_t)(-1)) {
2563 send_unmount_finished_msg(ctx.daemon_to_unmount_mq, ret);
2564 close_message_queues(&ctx);
2567 /* Try to delete the staging directory if a deletion wasn't yet
2568 * attempted due to an earlier error */
2569 if (ctx.staging_dir_name)
2570 delete_staging_dir(&ctx);
2574 wim->wim_locked = 0;
2575 out_free_message_queue_names:
2576 free_message_queue_names(&ctx);
2580 /* API function documented in wimlib.h */
2582 wimlib_unmount_image(const char *dir, int unmount_flags,
2583 wimlib_progress_func_t progress_func)
2586 struct wimfs_context wimfs_ctx;
2588 init_wimfs_context(&wimfs_ctx);
2590 ret = set_message_queue_names(&wimfs_ctx, dir);
2594 ret = open_message_queues(&wimfs_ctx, false);
2596 goto out_free_message_queue_names;
2598 ret = send_unmount_request_msg(wimfs_ctx.unmount_to_daemon_mq,
2600 progress_func != NULL);
2602 goto out_close_message_queues;
2604 ret = execute_fusermount(dir, (unmount_flags & WIMLIB_UNMOUNT_FLAG_LAZY) != 0);
2606 goto out_close_message_queues;
2608 struct unmount_msg_handler_context handler_ctx = {
2610 .timeout_seconds = 5,
2613 .progress_func = progress_func,
2616 ret = message_loop(wimfs_ctx.daemon_to_unmount_mq,
2617 &unmount_msg_handler_callbacks,
2620 ret = handler_ctx.status;
2621 out_close_message_queues:
2622 close_message_queues(&wimfs_ctx);
2623 out_free_message_queue_names:
2624 free_message_queue_names(&wimfs_ctx);
2629 #else /* WITH_FUSE */
2633 mount_unsupported_error(void)
2635 #if defined(__WIN32__)
2636 ERROR("Sorry-- Mounting WIM images is not supported on Windows!");
2638 ERROR("wimlib was compiled with --without-fuse, which disables support "
2639 "for mounting WIMs.");
2641 return WIMLIB_ERR_UNSUPPORTED;
2645 wimlib_unmount_image(const tchar *dir, int unmount_flags,
2646 wimlib_progress_func_t progress_func)
2648 return mount_unsupported_error();
2652 wimlib_mount_image(WIMStruct *wim, int image, const tchar *dir,
2653 int mount_flags, const tchar *staging_dir)
2655 return mount_unsupported_error();
2658 #endif /* !WITH_FUSE */