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 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/.
29 #include "wimlib_internal.h"
34 #include "lookup_table.h"
36 #include "buffer_io.h"
37 #include "timestamp.h"
42 #define FUSE_USE_VERSION 26
53 #include <attr/xattr.h>
56 #define MSG_VERSION_TOO_HIGH -1
57 #define MSG_BREAK_LOOP -2
59 /* File descriptor to a file open on the WIM filesystem. */
61 struct wim_inode *f_inode;
62 struct wim_lookup_table_entry *f_lte;
68 struct wimfs_context {
69 /* The WIMStruct for the mounted WIM. */
72 /* Name of the staging directory for a read-write mount. Whenever a new file is
73 * created, it is done so in the staging directory. Furthermore, whenever a
74 * file in the WIM is modified, it is extracted to the staging directory. If
75 * changes are commited when the WIM is unmounted, the file resources are merged
76 * in from the staging directory when writing the new WIM. */
77 char *staging_dir_name;
78 size_t staging_dir_name_len;
80 /* Flags passed to wimlib_mount(). */
83 /* Default flags to use when looking up a WIM dentry (depends on whether
84 * the Windows interface to alternate data streams is being used or
86 int default_lookup_flags;
88 /* Next inode number to be assigned. Note: I didn't bother with a
89 * bitmap of free inode numbers since this isn't even a "real"
90 * filesystem anyway. */
93 /* List of lookup table entries for files in the staging directory */
94 struct list_head staging_list;
96 /* List of inodes in the mounted image */
97 struct hlist_head *image_inode_list;
99 /* Name and message queue descriptors for message queues between the
100 * filesystem daemon process and the unmount process. These are used
101 * when the filesystem is unmounted and the process running
102 * wimlib_unmount_image() (i.e. the `imagex unmount' command) needs to
103 * communicate with the filesystem daemon running fuse_main() (i.e. the
104 * daemon created by the `imagex mount' or `imagex mountrw' commands */
105 char *unmount_to_daemon_mq_name;
106 char *daemon_to_unmount_mq_name;
107 mqd_t unmount_to_daemon_mq;
108 mqd_t daemon_to_unmount_mq;
111 static void init_wimfs_context(struct wimfs_context *ctx)
113 memset(ctx, 0, sizeof(*ctx));
114 ctx->unmount_to_daemon_mq = (mqd_t)-1;
115 ctx->daemon_to_unmount_mq = (mqd_t)-1;
116 INIT_LIST_HEAD(&ctx->staging_list);
119 static inline struct wimfs_context *wimfs_get_context()
121 return (struct wimfs_context*)fuse_get_context()->private_data;
124 static inline WIMStruct *wimfs_get_WIMStruct()
126 return wimfs_get_context()->wim;
129 static inline bool wimfs_ctx_readonly(const struct wimfs_context *ctx)
131 return (ctx->mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) == 0;
134 static inline int get_lookup_flags(const struct wimfs_context *ctx)
136 return ctx->default_lookup_flags;
139 /* Returns nonzero if write permission is requested on the file open flags */
140 static inline int flags_writable(int open_flags)
142 return open_flags & (O_RDWR | O_WRONLY);
146 * Allocate a file descriptor for a stream.
148 * @inode: inode containing the stream we're opening
149 * @stream_id: ID of the stream we're opening
150 * @lte: Lookup table entry for the stream (may be NULL)
151 * @fd_ret: Return the allocated file descriptor if successful.
152 * @readonly: True if this is a read-only mount.
154 * Return 0 iff successful or error code if unsuccessful.
156 static int alloc_wimfs_fd(struct wim_inode *inode,
158 struct wim_lookup_table_entry *lte,
159 struct wimfs_fd **fd_ret,
162 static const u16 fds_per_alloc = 8;
163 static const u16 max_fds = 0xffff;
166 pthread_mutex_lock(&inode->i_mutex);
168 DEBUG("Allocating fd for stream ID %u from inode %lx (open = %u, allocated = %u)",
169 stream_id, inode->i_ino, inode->i_num_opened_fds,
170 inode->i_num_allocated_fds);
172 if (inode->i_num_opened_fds == inode->i_num_allocated_fds) {
173 struct wimfs_fd **fds;
176 if (inode->i_num_allocated_fds == max_fds) {
180 num_new_fds = min(fds_per_alloc,
181 max_fds - inode->i_num_allocated_fds);
183 fds = REALLOC(inode->i_fds,
184 (inode->i_num_allocated_fds + num_new_fds) *
185 sizeof(inode->i_fds[0]));
190 memset(&fds[inode->i_num_allocated_fds], 0,
191 num_new_fds * sizeof(fds[0]));
193 inode->i_num_allocated_fds += num_new_fds;
195 for (u16 i = 0; ; i++) {
196 if (!inode->i_fds[i]) {
197 struct wimfs_fd *fd = CALLOC(1, sizeof(*fd));
206 fd->stream_id = stream_id;
208 inode->i_fds[i] = fd;
209 inode->i_num_opened_fds++;
210 if (lte && !readonly)
211 lte->num_opened_fds++;
212 DEBUG("Allocated fd (idx = %u)", fd->idx);
218 pthread_mutex_unlock(&inode->i_mutex);
222 static void inode_put_fd(struct wim_inode *inode, struct wimfs_fd *fd)
224 wimlib_assert(inode != NULL);
226 pthread_mutex_lock(&inode->i_mutex);
228 wimlib_assert(fd->f_inode == inode);
229 wimlib_assert(inode->i_num_opened_fds != 0);
230 wimlib_assert(fd->idx < inode->i_num_allocated_fds);
231 wimlib_assert(inode->i_fds[fd->idx] == fd);
233 inode->i_fds[fd->idx] = NULL;
235 if (--inode->i_num_opened_fds == 0 && inode->i_nlink == 0) {
236 pthread_mutex_unlock(&inode->i_mutex);
239 pthread_mutex_unlock(&inode->i_mutex);
243 static int lte_put_fd(struct wim_lookup_table_entry *lte, struct wimfs_fd *fd)
245 wimlib_assert(fd->f_lte == lte);
247 if (!lte) /* Empty stream with no lookup table entry */
250 /* Close staging file descriptor if needed. */
252 if (lte->resource_location == RESOURCE_IN_STAGING_FILE
253 && fd->staging_fd != -1)
255 if (close(fd->staging_fd) != 0) {
256 ERROR_WITH_ERRNO("Failed to close staging file");
260 lte_decrement_num_opened_fds(lte);
264 /* Close a file descriptor. */
265 static int close_wimfs_fd(struct wimfs_fd *fd)
268 DEBUG("Closing fd (inode = %lu, opened = %u, allocated = %u)",
269 fd->f_inode->i_ino, fd->f_inode->i_num_opened_fds,
270 fd->f_inode->i_num_allocated_fds);
271 ret = lte_put_fd(fd->f_lte, fd);
275 inode_put_fd(fd->f_inode, fd);
280 * Add a new dentry with a new inode to a WIM image.
282 * @ctx: Context for the mounted WIM image.
283 * @path: Path to create the dentry at.
284 * @dentry_ret: Return the pointer to the dentry if successful.
286 * Returns 0 on success, or negative error number on failure.
288 static int create_dentry(struct wimfs_context *ctx, const char *path,
289 struct wim_dentry **dentry_ret)
291 struct wim_dentry *parent;
292 struct wim_dentry *new;
293 const char *basename;
295 parent = get_parent_dentry(ctx->wim, path);
299 if (!dentry_is_directory(parent))
302 basename = path_basename(path);
303 if (get_dentry_child_with_name(parent, basename))
306 new = new_dentry_with_inode(basename);
310 new->d_inode->i_resolved = 1;
311 new->d_inode->i_ino = ctx->next_ino++;
312 dentry_add_child(parent, new);
313 hlist_add_head(&new->d_inode->i_hlist, ctx->image_inode_list);
318 /* Remove a dentry from a mounted WIM image; i.e. remove an alias for the
319 * corresponding inode.
321 * If there are no remaining references to the inode either through dentries or
322 * open file descriptors, the inode is freed. Otherwise, the inode is not
323 * removed, but the dentry is unlinked and freed.
325 * Either way, all lookup table entries referenced by the inode have their
326 * reference count decremented. If a lookup table entry has no open file
327 * descriptors and no references remaining, it is freed, and the corresponding
328 * staging file is unlinked.
330 static void remove_dentry(struct wim_dentry *dentry,
331 struct wim_lookup_table *lookup_table)
333 struct wim_inode *inode = dentry->d_inode;
334 struct wim_lookup_table_entry *lte;
337 for (i = 0; i <= inode->i_num_ads; i++) {
338 lte = inode_stream_lte_resolved(inode, i);
340 lte_decrement_refcnt(lte, lookup_table);
342 unlink_dentry(dentry);
346 /* Transfers file attributes from a struct wim_inode to a `stat' buffer.
348 * The lookup table entry tells us which stream in the inode we are statting.
349 * For a named data stream, everything returned is the same as the unnamed data
350 * stream except possibly the size and block count. */
351 static int inode_to_stbuf(const struct wim_inode *inode,
352 const struct wim_lookup_table_entry *lte,
355 if (inode_is_symlink(inode))
356 stbuf->st_mode = S_IFLNK | 0777;
357 else if (inode_is_directory(inode))
358 stbuf->st_mode = S_IFDIR | 0755;
360 stbuf->st_mode = S_IFREG | 0755;
362 stbuf->st_ino = (ino_t)inode->i_ino;
363 stbuf->st_nlink = inode->i_nlink;
364 stbuf->st_uid = getuid();
365 stbuf->st_gid = getgid();
368 if (lte->resource_location == RESOURCE_IN_STAGING_FILE) {
369 struct stat native_stat;
370 if (stat(lte->staging_file_name, &native_stat) != 0) {
371 DEBUG("Failed to stat `%s': %m",
372 lte->staging_file_name);
375 stbuf->st_size = native_stat.st_size;
377 stbuf->st_size = wim_resource_size(lte);
383 stbuf->st_atime = wim_timestamp_to_unix(inode->i_last_access_time);
384 stbuf->st_mtime = wim_timestamp_to_unix(inode->i_last_write_time);
385 stbuf->st_ctime = wim_timestamp_to_unix(inode->i_creation_time);
386 stbuf->st_blocks = (stbuf->st_size + 511) / 512;
390 /* Creates a new staging file and returns its file descriptor opened for
393 * @name_ret: A location into which the a pointer to the newly allocated name of
394 * the staging file is stored.
396 * @ctx: Context for the WIM filesystem; this provides the name of the
399 * On success, returns the file descriptor for the staging file, opened for
400 * writing. On failure, returns -1 and sets errno.
402 static int create_staging_file(char **name_ret, struct wimfs_context *ctx)
410 static const size_t STAGING_FILE_NAME_LEN = 20;
412 name_len = ctx->staging_dir_name_len + 1 + STAGING_FILE_NAME_LEN;
413 name = MALLOC(name_len + 1);
421 memcpy(name, ctx->staging_dir_name, ctx->staging_dir_name_len);
422 name[ctx->staging_dir_name_len] = '/';
423 randomize_char_array_with_alnum(name + ctx->staging_dir_name_len + 1,
424 STAGING_FILE_NAME_LEN);
425 name[name_len] = '\0';
428 /* Just in case, verify that the randomly generated name doesn't name an
429 * existing file, and try again if so */
430 } while (stat(name, &stbuf) == 0);
432 if (errno != ENOENT) /* other error?! */
435 /* doesn't exist--- ok */
437 DEBUG("Creating staging file `%s'", name);
439 fd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0600);
451 * Extract a WIM resource to the staging directory.
453 * @inode: Inode that contains the stream we are extracting
455 * @stream_id: Identifier for the stream (it stays constant even if the indices
456 * of the stream entries are changed)
458 * @lte: Pointer to pointer to the lookup table entry for the stream we need to
459 * extract, or NULL if there was no lookup table entry present for the stream
461 * @size: Number of bytes of the stream we want to extract (this supports the
462 * wimfs_truncate() function). It may be more than the actual stream length, in
463 * which case the extra space is filled with zeroes.
465 * @ctx: Context for the WIM filesystem.
467 * Returns 0 on success or a negative error code on failure.
469 static int extract_resource_to_staging_dir(struct wim_inode *inode,
471 struct wim_lookup_table_entry **lte,
473 struct wimfs_context *ctx)
475 char *staging_file_name;
478 struct wim_lookup_table_entry *old_lte, *new_lte;
481 DEBUG("Extracting resource to staging dir: inode %"PRIu64", "
482 "stream id %"PRIu32, inode->i_ino, stream_id);
486 wimlib_assert(old_lte == NULL ||
487 old_lte->resource_location != RESOURCE_IN_STAGING_FILE);
489 /* Create the staging file */
490 fd = create_staging_file(&staging_file_name, ctx);
494 /* Extract the stream to the staging file (possibly truncated) */
496 extract_size = min(wim_resource_size(old_lte), size);
497 ret = extract_wim_resource_to_fd(old_lte, fd, extract_size);
503 /* In the case of truncate() to more than the file length, extend the
504 * file with zeroes by calling ftruncate() on the underlying staging
506 if (ret == 0 && size > extract_size)
507 ret = ftruncate(fd, size);
509 /* Close the staging file descriptor and check for errors. If there's
510 * an error, unlink the staging file. */
511 if (ret != 0 || close(fd) != 0) {
517 goto out_delete_staging_file;
520 /* Now deal with the lookup table entries. We may be able to re-use the
521 * existing entry, but we may have to create a new one instead. */
523 if (old_lte && inode->i_nlink == old_lte->refcnt) {
524 /* The reference count of the existing lookup table entry is the
525 * same as the link count of the inode that contains the stream
526 * we're opening. Therefore, ALL the references to the lookup
527 * table entry correspond to the stream we're trying to extract,
528 * so the lookup table entry can be re-used. */
529 DEBUG("Re-using lookup table entry");
530 lookup_table_unlink(ctx->wim->lookup_table, old_lte);
534 /* There's an existing lookup table entry, but its
535 * reference count is greater than the link count for
536 * the inode containing a stream we're opening.
537 * Therefore, we need to split the lookup table entry.
539 wimlib_assert(old_lte->refcnt > inode->i_nlink);
540 DEBUG("Splitting lookup table entry "
541 "(inode->i_nlink = %u, old_lte->refcnt = %u)",
542 inode->i_nlink, old_lte->refcnt);
545 new_lte = new_lookup_table_entry();
548 goto out_delete_staging_file;
551 /* There may already be open file descriptors to this stream if
552 * it's previously been opened read-only, but just now we're
553 * opening it read-write. Identify those file descriptors and
554 * change their lookup table entry pointers to point to the new
555 * lookup table entry, and open staging file descriptors for
558 * At the same time, we need to count the number of these opened
559 * file descriptors to the new lookup table entry. If there's
560 * an old lookup table entry, this number needs to be subtracted
561 * from the fd's opened to the old entry. */
562 for (u16 i = 0, j = 0; j < inode->i_num_opened_fds; i++) {
563 struct wimfs_fd *fd = inode->i_fds[i];
565 if (fd->stream_id == stream_id) {
566 wimlib_assert(fd->f_lte == old_lte);
567 wimlib_assert(fd->staging_fd == -1);
569 new_lte->num_opened_fds++;
570 fd->staging_fd = open(staging_file_name, O_RDONLY);
571 if (fd->staging_fd == -1) {
573 goto out_revert_fd_changes;
579 DEBUG("%hu fd's were already opened to the file we extracted",
580 new_lte->num_opened_fds);
582 old_lte->num_opened_fds -= new_lte->num_opened_fds;
583 old_lte->refcnt -= inode->i_nlink;
587 new_lte->refcnt = inode->i_nlink;
588 new_lte->resource_location = RESOURCE_IN_STAGING_FILE;
589 new_lte->staging_file_name = staging_file_name;
590 new_lte->lte_inode = inode;
591 random_hash(new_lte->hash);
594 inode->i_lte = new_lte;
596 for (u16 i = 0; i < inode->i_num_ads; i++)
597 if (inode->i_ads_entries[i].stream_id == stream_id)
598 inode->i_ads_entries[i].lte = new_lte;
600 lookup_table_insert(ctx->wim->lookup_table, new_lte);
601 list_add(&new_lte->staging_list, &ctx->staging_list);
604 out_revert_fd_changes:
605 for (u16 i = 0, j = 0; j < new_lte->num_opened_fds; i++) {
606 struct wimfs_fd *fd = inode->i_fds[i];
607 if (fd && fd->stream_id == stream_id && fd->f_lte == new_lte) {
609 if (fd->staging_fd != -1) {
610 close(fd->staging_fd);
616 free_lookup_table_entry(new_lte);
617 out_delete_staging_file:
618 unlink(staging_file_name);
619 FREE(staging_file_name);
624 * Creates a randomly named staging directory and saves its name in the
625 * filesystem context structure.
627 static int make_staging_dir(struct wimfs_context *ctx, const char *user_prefix)
629 static const size_t random_suffix_len = 10;
630 static const char *common_suffix = ".staging";
631 static const size_t common_suffix_len = 8;
633 char *staging_dir_name = NULL;
634 size_t staging_dir_name_len;
636 const char *wim_basename;
637 char *real_user_prefix = NULL;
641 real_user_prefix = realpath(user_prefix, NULL);
642 if (!real_user_prefix) {
643 ERROR_WITH_ERRNO("Could not resolve `%s'",
645 ret = WIMLIB_ERR_NOTDIR;
648 wim_basename = path_basename(ctx->wim->filename);
649 prefix_len = strlen(real_user_prefix) + 1 + strlen(wim_basename);
651 prefix_len = strlen(ctx->wim->filename);
654 staging_dir_name_len = prefix_len + common_suffix_len + random_suffix_len;
656 staging_dir_name = MALLOC(staging_dir_name_len + 1);
657 if (!staging_dir_name) {
658 ret = WIMLIB_ERR_NOMEM;
662 if (real_user_prefix)
663 sprintf(staging_dir_name, "%s/%s", real_user_prefix, wim_basename);
665 strcpy(staging_dir_name, ctx->wim->filename);
667 strcat(staging_dir_name, common_suffix);
669 randomize_char_array_with_alnum(staging_dir_name + prefix_len + common_suffix_len,
672 staging_dir_name[staging_dir_name_len] = '\0';
674 if (mkdir(staging_dir_name, 0700) != 0) {
675 ERROR_WITH_ERRNO("Failed to create temporary directory `%s'",
677 ret = WIMLIB_ERR_MKDIR;
682 FREE(real_user_prefix);
684 ctx->staging_dir_name = staging_dir_name;
685 ctx->staging_dir_name_len = staging_dir_name_len;
687 FREE(staging_dir_name);
692 static int remove_file_or_directory(const char *fpath, const struct stat *sb,
693 int typeflag, struct FTW *ftwbuf)
695 if (remove(fpath) == 0)
698 ERROR_WITH_ERRNO("Cannot remove `%s'", fpath);
699 return WIMLIB_ERR_DELETE_STAGING_DIR;
704 * Deletes the staging directory and all the files contained in it.
706 static int delete_staging_dir(struct wimfs_context *ctx)
709 ret = nftw(ctx->staging_dir_name, remove_file_or_directory,
711 FREE(ctx->staging_dir_name);
712 ctx->staging_dir_name = NULL;
716 static void inode_update_lte_ptr(struct wim_inode *inode,
717 struct wim_lookup_table_entry *old_lte,
718 struct wim_lookup_table_entry *new_lte)
720 if (inode->i_lte == old_lte) {
721 inode->i_lte = new_lte;
723 for (unsigned i = 0; i < inode->i_num_ads; i++) {
724 if (inode->i_ads_entries[i].lte == old_lte) {
725 inode->i_ads_entries[i].lte = new_lte;
732 static int update_lte_of_staging_file(struct wim_lookup_table_entry *lte,
733 struct wim_lookup_table *table)
735 struct wim_lookup_table_entry *duplicate_lte;
737 u8 hash[SHA1_HASH_SIZE];
740 ret = sha1sum(lte->staging_file_name, hash);
743 lookup_table_unlink(table, lte);
744 duplicate_lte = __lookup_resource(table, hash);
746 /* Merge duplicate lookup table entries */
747 duplicate_lte->refcnt += lte->refcnt;
748 inode_update_lte_ptr(lte->lte_inode, lte, duplicate_lte);
749 free_lookup_table_entry(lte);
751 if (stat(lte->staging_file_name, &stbuf) != 0) {
752 ERROR_WITH_ERRNO("Failed to stat `%s'", lte->staging_file_name);
753 return WIMLIB_ERR_STAT;
755 if (stbuf.st_size == 0) {
756 /* Zero-length stream. No lookup table entry needed. */
757 inode_update_lte_ptr(lte->lte_inode, lte, NULL);
758 free_lookup_table_entry(lte);
760 wimlib_assert(<e->file_on_disk == <e->staging_file_name);
761 lte->resource_entry.original_size = stbuf.st_size;
762 lte->resource_entry.size = stbuf.st_size;
763 lte->resource_location = RESOURCE_IN_FILE_ON_DISK;
764 lte->file_on_disk_fp = NULL;
765 copy_hash(lte->hash, hash);
766 lookup_table_insert(table, lte);
772 static int inode_close_fds(struct wim_inode *inode)
774 u16 num_opened_fds = inode->i_num_opened_fds;
775 for (u16 i = 0, j = 0; j < num_opened_fds; i++) {
776 struct wimfs_fd *fd = inode->i_fds[i];
778 wimlib_assert(fd->f_inode == inode);
779 int ret = close_wimfs_fd(fd);
788 /* Overwrites the WIM file, with changes saved. */
789 static int rebuild_wim(struct wimfs_context *ctx, int write_flags,
790 wimlib_progress_func_t progress_func)
793 struct wim_lookup_table_entry *lte, *tmp;
794 WIMStruct *w = ctx->wim;
796 DEBUG("Closing all staging file descriptors.");
797 list_for_each_entry_safe(lte, tmp, &ctx->staging_list, staging_list) {
798 ret = inode_close_fds(lte->lte_inode);
803 DEBUG("Calculating SHA1 checksums for all new staging files.");
804 list_for_each_entry(lte, &ctx->staging_list, staging_list) {
805 ret = update_lte_of_staging_file(lte, w->lookup_table);
810 xml_update_image_info(w, w->current_image);
811 ret = wimlib_overwrite(w, write_flags, 0, progress_func);
813 ERROR("Failed to commit changes to mounted WIM image");
819 /* Simple function that returns the concatenation of 2 strings. */
820 static char *strcat_dup(const char *s1, const char *s2, size_t max_len)
822 size_t len = strlen(s1) + strlen(s2);
825 char *p = MALLOC(len + 1);
828 snprintf(p, len + 1, "%s%s", s1, s2);
832 static int set_message_queue_names(struct wimfs_context *ctx,
833 const char *mount_dir)
835 static const char *u2d_prefix = "/wimlib-unmount-to-daemon-mq";
836 static const char *d2u_prefix = "/wimlib-daemon-to-unmount-mq";
841 dir_path = realpath(mount_dir, NULL);
843 ERROR_WITH_ERRNO("Failed to resolve path \"%s\"", mount_dir);
845 return WIMLIB_ERR_NOMEM;
847 return WIMLIB_ERR_NOTDIR;
857 ctx->unmount_to_daemon_mq_name = strcat_dup(u2d_prefix, dir_path,
859 if (!ctx->unmount_to_daemon_mq_name) {
860 ret = WIMLIB_ERR_NOMEM;
861 goto out_free_dir_path;
863 ctx->daemon_to_unmount_mq_name = strcat_dup(d2u_prefix, dir_path,
865 if (!ctx->daemon_to_unmount_mq_name) {
866 ret = WIMLIB_ERR_NOMEM;
867 goto out_free_unmount_to_daemon_mq_name;
871 goto out_free_dir_path;
872 out_free_unmount_to_daemon_mq_name:
873 FREE(ctx->unmount_to_daemon_mq_name);
874 ctx->unmount_to_daemon_mq_name = NULL;
880 static void free_message_queue_names(struct wimfs_context *ctx)
882 FREE(ctx->unmount_to_daemon_mq_name);
883 FREE(ctx->daemon_to_unmount_mq_name);
884 ctx->unmount_to_daemon_mq_name = NULL;
885 ctx->daemon_to_unmount_mq_name = NULL;
889 * Opens two POSIX message queue: one for sending messages from the unmount
890 * process to the daemon process, and one to go the other way. The names of the
891 * message queues, which must be system-wide unique, are be based on the mount
894 * @daemon specifies whether the calling process is the filesystem daemon or the
897 static int open_message_queues(struct wimfs_context *ctx, bool daemon)
899 int unmount_to_daemon_mq_flags = O_WRONLY | O_CREAT;
900 int daemon_to_unmount_mq_flags = O_RDONLY | O_CREAT;
903 swap(unmount_to_daemon_mq_flags, daemon_to_unmount_mq_flags);
905 DEBUG("Opening message queue \"%s\"", ctx->unmount_to_daemon_mq_name);
906 ctx->unmount_to_daemon_mq = mq_open(ctx->unmount_to_daemon_mq_name,
907 unmount_to_daemon_mq_flags, 0700, NULL);
909 if (ctx->unmount_to_daemon_mq == (mqd_t)-1) {
910 ERROR_WITH_ERRNO("mq_open()");
911 return WIMLIB_ERR_MQUEUE;
914 DEBUG("Opening message queue \"%s\"", ctx->daemon_to_unmount_mq_name);
915 ctx->daemon_to_unmount_mq = mq_open(ctx->daemon_to_unmount_mq_name,
916 daemon_to_unmount_mq_flags, 0700, NULL);
918 if (ctx->daemon_to_unmount_mq == (mqd_t)-1) {
919 ERROR_WITH_ERRNO("mq_open()");
920 mq_close(ctx->unmount_to_daemon_mq);
921 mq_unlink(ctx->unmount_to_daemon_mq_name);
922 ctx->unmount_to_daemon_mq = (mqd_t)-1;
923 return WIMLIB_ERR_MQUEUE;
928 /* Try to determine the maximum message size of a message queue. The return
929 * value is the maximum message size, or a guess of 8192 bytes if it cannot be
931 static long mq_get_msgsize(mqd_t mq)
933 static const char *msgsize_max_file = "/proc/sys/fs/mqueue/msgsize_max";
938 if (mq_getattr(mq, &attr) == 0) {
939 msgsize = attr.mq_msgsize;
941 ERROR_WITH_ERRNO("mq_getattr()");
942 ERROR("Attempting to read %s", msgsize_max_file);
943 fp = fopen(msgsize_max_file, "rb");
945 if (fscanf(fp, "%ld", &msgsize) != 1) {
946 ERROR("Assuming message size of 8192");
951 ERROR_WITH_ERRNO("Failed to open the file `%s'",
953 ERROR("Assuming message size of 8192");
960 static int get_mailbox(mqd_t mq, long needed_msgsize, long *msgsize_ret,
966 msgsize = mq_get_msgsize(mq);
968 if (msgsize < needed_msgsize) {
969 ERROR("Message queue max size must be at least %ld!",
971 return WIMLIB_ERR_MQUEUE;
974 mailbox = MALLOC(msgsize);
976 ERROR("Failed to allocate %ld bytes for mailbox", msgsize);
977 return WIMLIB_ERR_NOMEM;
979 *msgsize_ret = msgsize;
980 *mailbox_ret = mailbox;
984 static void unlink_message_queues(struct wimfs_context *ctx)
986 mq_unlink(ctx->unmount_to_daemon_mq_name);
987 mq_unlink(ctx->daemon_to_unmount_mq_name);
990 /* Closes the message queues, which are allocated in static variables */
991 static void close_message_queues(struct wimfs_context *ctx)
993 DEBUG("Closing message queues");
994 mq_close(ctx->unmount_to_daemon_mq);
995 ctx->unmount_to_daemon_mq = (mqd_t)(-1);
996 mq_close(ctx->daemon_to_unmount_mq);
997 ctx->daemon_to_unmount_mq = (mqd_t)(-1);
998 unlink_message_queues(ctx);
1002 struct unmount_msg_hdr {
1009 struct msg_unmount_request {
1010 struct unmount_msg_hdr hdr;
1012 u8 want_progress_messages;
1015 struct msg_daemon_info {
1016 struct unmount_msg_hdr hdr;
1021 struct msg_unmount_finished {
1022 struct unmount_msg_hdr hdr;
1026 struct msg_write_streams_progress {
1027 struct unmount_msg_hdr hdr;
1028 union wimlib_progress_info info;
1032 MSG_TYPE_UNMOUNT_REQUEST,
1033 MSG_TYPE_DAEMON_INFO,
1034 MSG_TYPE_WRITE_STREAMS_PROGRESS,
1035 MSG_TYPE_UNMOUNT_FINISHED,
1039 struct msg_handler_context_hdr {
1040 int timeout_seconds;
1043 struct unmount_msg_handler_context {
1044 struct msg_handler_context_hdr hdr;
1048 wimlib_progress_func_t progress_func;
1051 struct daemon_msg_handler_context {
1052 struct msg_handler_context_hdr hdr;
1053 struct wimfs_context *wimfs_ctx;
1056 static int send_unmount_request_msg(mqd_t mq, int unmount_flags,
1057 u8 want_progress_messages)
1059 DEBUG("Sending unmount request msg");
1060 struct msg_unmount_request msg = {
1062 .min_version = WIMLIB_MAKEVERSION(1, 2, 1),
1063 .cur_version = WIMLIB_VERSION_CODE,
1064 .msg_type = MSG_TYPE_UNMOUNT_REQUEST,
1065 .msg_size = sizeof(msg),
1067 .unmount_flags = unmount_flags,
1068 .want_progress_messages = want_progress_messages,
1071 if (mq_send(mq, (void*)&msg, sizeof(msg), 1)) {
1072 ERROR_WITH_ERRNO("Failed to communicate with filesystem daemon");
1073 return WIMLIB_ERR_MQUEUE;
1078 static int send_daemon_info_msg(mqd_t mq, pid_t pid, int mount_flags)
1080 DEBUG("Sending daemon info msg (pid = %d, mount_flags=%x)",
1083 struct msg_daemon_info msg = {
1085 .min_version = WIMLIB_MAKEVERSION(1, 2, 1),
1086 .cur_version = WIMLIB_VERSION_CODE,
1087 .msg_type = MSG_TYPE_DAEMON_INFO,
1088 .msg_size = sizeof(msg),
1091 .mount_flags = mount_flags,
1093 if (mq_send(mq, (void*)&msg, sizeof(msg), 1)) {
1094 ERROR_WITH_ERRNO("Failed to send daemon info to unmount process");
1095 return WIMLIB_ERR_MQUEUE;
1100 static void send_unmount_finished_msg(mqd_t mq, int status)
1102 DEBUG("Sending unmount finished msg");
1103 struct msg_unmount_finished msg = {
1105 .min_version = WIMLIB_MAKEVERSION(1, 2, 1),
1106 .cur_version = WIMLIB_VERSION_CODE,
1107 .msg_type = MSG_TYPE_UNMOUNT_FINISHED,
1108 .msg_size = sizeof(msg),
1112 if (mq_send(mq, (void*)&msg, sizeof(msg), 1))
1113 ERROR_WITH_ERRNO("Failed to send status to unmount process");
1116 static int unmount_progress_func(enum wimlib_progress_msg msg,
1117 const union wimlib_progress_info *info)
1119 if (msg == WIMLIB_PROGRESS_MSG_WRITE_STREAMS) {
1120 struct msg_write_streams_progress msg = {
1122 .min_version = WIMLIB_MAKEVERSION(1, 2, 1),
1123 .cur_version = WIMLIB_VERSION_CODE,
1124 .msg_type = MSG_TYPE_WRITE_STREAMS_PROGRESS,
1125 .msg_size = sizeof(msg),
1129 if (mq_send(wimfs_get_context()->daemon_to_unmount_mq,
1130 (void*)&msg, sizeof(msg), 1))
1132 ERROR_WITH_ERRNO("Failed to send progress information "
1133 "to unmount process");
1139 static int msg_unmount_request_handler(const void *_msg, void *_handler_ctx)
1141 const struct msg_unmount_request *msg = _msg;
1142 struct daemon_msg_handler_context *handler_ctx = _handler_ctx;
1143 struct wimfs_context *wimfs_ctx;
1147 wimlib_progress_func_t progress_func;
1149 DEBUG("Handling unmount request msg");
1151 wimfs_ctx = handler_ctx->wimfs_ctx;
1152 if (msg->hdr.msg_size < sizeof(*msg)) {
1153 status = WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1157 unmount_flags = msg->unmount_flags;
1158 if (msg->want_progress_messages)
1159 progress_func = unmount_progress_func;
1161 progress_func = NULL;
1163 ret = send_daemon_info_msg(wimfs_ctx->daemon_to_unmount_mq, getpid(),
1164 wimfs_ctx->mount_flags);
1170 if (wimfs_ctx->mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
1171 if (unmount_flags & WIMLIB_UNMOUNT_FLAG_COMMIT) {
1172 int write_flags = 0;
1173 if (unmount_flags & WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY)
1174 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
1175 if (unmount_flags & WIMLIB_UNMOUNT_FLAG_REBUILD)
1176 write_flags |= WIMLIB_WRITE_FLAG_REBUILD;
1177 if (unmount_flags & WIMLIB_UNMOUNT_FLAG_RECOMPRESS)
1178 write_flags |= WIMLIB_WRITE_FLAG_RECOMPRESS;
1179 status = rebuild_wim(wimfs_ctx, write_flags,
1183 DEBUG("Read-only mount");
1188 if (wimfs_ctx->mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
1189 ret = delete_staging_dir(wimfs_ctx);
1191 ERROR("Failed to delete the staging directory");
1196 send_unmount_finished_msg(wimfs_ctx->daemon_to_unmount_mq, status);
1197 return MSG_BREAK_LOOP;
1200 static int msg_daemon_info_handler(const void *_msg, void *_handler_ctx)
1202 const struct msg_daemon_info *msg = _msg;
1203 struct unmount_msg_handler_context *handler_ctx = _handler_ctx;
1205 DEBUG("Handling daemon info msg");
1206 if (msg->hdr.msg_size < sizeof(*msg))
1207 return WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1208 handler_ctx->daemon_pid = msg->daemon_pid;
1209 handler_ctx->mount_flags = msg->mount_flags;
1210 handler_ctx->hdr.timeout_seconds = 1;
1211 DEBUG("pid of daemon is %d; mount flags were %#x",
1212 handler_ctx->daemon_pid,
1213 handler_ctx->mount_flags);
1217 static int msg_write_streams_progress_handler(const void *_msg,
1220 const struct msg_write_streams_progress *msg = _msg;
1221 struct unmount_msg_handler_context *handler_ctx = _handler_ctx;
1223 if (msg->hdr.msg_size < sizeof(*msg))
1224 return WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1225 if (handler_ctx->progress_func) {
1226 handler_ctx->progress_func(WIMLIB_PROGRESS_MSG_WRITE_STREAMS,
1232 static int msg_unmount_finished_handler(const void *_msg, void *_handler_ctx)
1234 const struct msg_unmount_finished *msg = _msg;
1235 struct unmount_msg_handler_context *handler_ctx = _handler_ctx;
1237 DEBUG("Handling unmount finished message");
1238 if (msg->hdr.msg_size < sizeof(*msg))
1239 return WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1240 handler_ctx->status = msg->status;
1241 DEBUG("status is %d", handler_ctx->status);
1242 return MSG_BREAK_LOOP;
1245 static int unmount_timed_out_cb(void *_handler_ctx)
1247 struct unmount_msg_handler_context *handler_ctx = _handler_ctx;
1249 if (handler_ctx->daemon_pid == 0) {
1252 kill(handler_ctx->daemon_pid, 0);
1253 if (errno == ESRCH) {
1256 DEBUG("Filesystem daemon is still alive... "
1257 "Waiting another %d seconds\n",
1258 handler_ctx->hdr.timeout_seconds);
1263 ERROR("The filesystem daemon has crashed! Changes to the "
1264 "WIM may not have been commited.");
1265 return WIMLIB_ERR_FILESYSTEM_DAEMON_CRASHED;
1268 static int daemon_timed_out_cb(void *_handler_ctx)
1270 ERROR("Timed out waiting for unmount request! "
1271 "Changes to the mounted WIM will not be committed.");
1272 return WIMLIB_ERR_TIMEOUT;
1275 typedef int (*msg_handler_t)(const void *_msg, void *_handler_ctx);
1277 struct msg_handler_callbacks {
1278 int (*timed_out)(void * _handler_ctx);
1279 msg_handler_t msg_handlers[MSG_TYPE_MAX];
1282 static const struct msg_handler_callbacks unmount_msg_handler_callbacks = {
1283 .timed_out = unmount_timed_out_cb,
1285 [MSG_TYPE_DAEMON_INFO] = msg_daemon_info_handler,
1286 [MSG_TYPE_WRITE_STREAMS_PROGRESS] = msg_write_streams_progress_handler,
1287 [MSG_TYPE_UNMOUNT_FINISHED] = msg_unmount_finished_handler,
1291 static const struct msg_handler_callbacks daemon_msg_handler_callbacks = {
1292 .timed_out = daemon_timed_out_cb,
1294 [MSG_TYPE_UNMOUNT_REQUEST] = msg_unmount_request_handler,
1298 static int receive_message(mqd_t mq,
1299 struct msg_handler_context_hdr *handler_ctx,
1300 const msg_handler_t msg_handlers[],
1301 long mailbox_size, void *mailbox)
1304 struct timespec timeout;
1305 ssize_t bytes_received;
1306 struct unmount_msg_hdr *hdr;
1309 gettimeofday(&now, NULL);
1310 timeout.tv_sec = now.tv_sec + handler_ctx->timeout_seconds;
1311 timeout.tv_nsec = now.tv_usec * 1000;
1313 bytes_received = mq_timedreceive(mq, mailbox,
1314 mailbox_size, NULL, &timeout);
1316 if (bytes_received == -1) {
1317 if (errno == ETIMEDOUT) {
1318 ret = WIMLIB_ERR_TIMEOUT;
1320 ERROR_WITH_ERRNO("mq_timedreceive()");
1321 ret = WIMLIB_ERR_MQUEUE;
1323 } else if (bytes_received < sizeof(*hdr) ||
1324 bytes_received != hdr->msg_size) {
1325 ret = WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1326 } else if (WIMLIB_VERSION_CODE < hdr->min_version) {
1327 /*ERROR("Cannot understand the received message. "*/
1328 /*"Please upgrade wimlib to at least v%d.%d.%d",*/
1329 /*WIMLIB_GET_MAJOR_VERSION(hdr->min_version),*/
1330 /*WIMLIB_GET_MINOR_VERSION(hdr->min_version),*/
1331 /*WIMLIB_GET_PATCH_VERSION(hdr->min_version));*/
1332 ret = MSG_VERSION_TOO_HIGH;
1333 } else if (hdr->msg_type >= MSG_TYPE_MAX) {
1334 ret = WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1335 } else if (msg_handlers[hdr->msg_type] == NULL) {
1336 ret = WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE;
1338 ret = msg_handlers[hdr->msg_type](mailbox, handler_ctx);
1343 static int message_loop(mqd_t mq,
1344 const struct msg_handler_callbacks *callbacks,
1345 struct msg_handler_context_hdr *handler_ctx)
1347 static const size_t MAX_MSG_SIZE = 512;
1352 DEBUG("Entering message loop");
1354 ret = get_mailbox(mq, MAX_MSG_SIZE, &msgsize, &mailbox);
1358 ret = receive_message(mq, handler_ctx,
1359 callbacks->msg_handlers,
1361 if (ret == 0 || ret == MSG_VERSION_TOO_HIGH) {
1363 } else if (ret == MSG_BREAK_LOOP) {
1366 } else if (ret == WIMLIB_ERR_TIMEOUT) {
1367 if (callbacks->timed_out)
1368 ret = callbacks->timed_out(handler_ctx);
1374 ERROR_WITH_ERRNO("Error communicating with "
1375 "filesystem daemon");
1380 DEBUG("Exiting message loop");
1384 /* Execute `fusermount -u', which is installed setuid root, to unmount the WIM.
1386 * FUSE does not yet implement synchronous unmounts. This means that fusermount
1387 * -u will return before the filesystem daemon returns from wimfs_destroy().
1388 * This is partly what we want, because we need to send a message from this
1389 * process to the filesystem daemon telling whether --commit was specified or
1390 * not. However, after that, the unmount process must wait for the filesystem
1391 * daemon to finish writing the WIM file.
1393 static int execute_fusermount(const char *dir)
1401 ERROR_WITH_ERRNO("Failed to fork()");
1402 return WIMLIB_ERR_FORK;
1406 execlp("fusermount", "fusermount", "-u", dir, NULL);
1407 ERROR_WITH_ERRNO("Failed to execute `fusermount'");
1408 exit(WIMLIB_ERR_FUSERMOUNT);
1412 ret = waitpid(pid, &status, 0);
1414 ERROR_WITH_ERRNO("Failed to wait for fusermount process to "
1416 return WIMLIB_ERR_FUSERMOUNT;
1419 if (!WIFEXITED(status)) {
1420 ERROR("'fusermount' did not terminate normally!");
1421 return WIMLIB_ERR_FUSERMOUNT;
1424 status = WEXITSTATUS(status);
1429 if (status != WIMLIB_ERR_FUSERMOUNT)
1430 return WIMLIB_ERR_FUSERMOUNT;
1432 /* Try again, but with the `umount' program. This is required on other
1433 * FUSE implementations such as FreeBSD's that do not have a
1434 * `fusermount' program. */
1435 ERROR("Falling back to 'umount'. Note: you may need to be "
1436 "root for this to work");
1439 ERROR_WITH_ERRNO("Failed to fork()");
1440 return WIMLIB_ERR_FORK;
1444 execlp("umount", "umount", dir, NULL);
1445 ERROR_WITH_ERRNO("Failed to execute `umount'");
1446 exit(WIMLIB_ERR_FUSERMOUNT);
1450 ret = waitpid(pid, &status, 0);
1452 ERROR_WITH_ERRNO("Failed to wait for `umount' process to "
1454 return WIMLIB_ERR_FUSERMOUNT;
1457 ERROR("`umount' did not successfully complete");
1458 return WIMLIB_ERR_FUSERMOUNT;
1463 static int wimfs_access(const char *path, int mask)
1465 /* Permissions not implemented */
1469 static int wimfs_chmod(const char *path, mode_t mask)
1471 struct wim_dentry *dentry;
1472 struct wimfs_context *ctx = wimfs_get_context();
1473 struct wim_inode *inode;
1477 ret = lookup_resource(ctx->wim, path,
1478 get_lookup_flags(ctx) | LOOKUP_FLAG_DIRECTORY_OK,
1479 &dentry, NULL, NULL);
1482 inode = dentry->d_inode;
1483 inode_to_stbuf(inode, NULL, &stbuf);
1484 if (mask == stbuf.st_mode)
1490 /* Called when the filesystem is unmounted. */
1491 static void wimfs_destroy(void *p)
1493 struct wimfs_context *wimfs_ctx = wimfs_get_context();
1494 if (open_message_queues(wimfs_ctx, true) == 0) {
1495 struct daemon_msg_handler_context handler_ctx = {
1497 .timeout_seconds = 5,
1499 .wimfs_ctx = wimfs_ctx,
1501 message_loop(wimfs_ctx->unmount_to_daemon_mq,
1502 &daemon_msg_handler_callbacks,
1504 close_message_queues(wimfs_ctx);
1509 static int wimfs_fallocate(const char *path, int mode,
1510 off_t offset, off_t len, struct fuse_file_info *fi)
1512 struct wimfs_fd *fd = (struct wimfs_fd*)(uintptr_t)fi->fh;
1513 wimlib_assert(fd->staging_fd != -1);
1514 return fallocate(fd->staging_fd, mode, offset, len);
1519 static int wimfs_fgetattr(const char *path, struct stat *stbuf,
1520 struct fuse_file_info *fi)
1522 struct wimfs_fd *fd = (struct wimfs_fd*)(uintptr_t)fi->fh;
1523 return inode_to_stbuf(fd->f_inode, fd->f_lte, stbuf);
1526 static int wimfs_ftruncate(const char *path, off_t size,
1527 struct fuse_file_info *fi)
1529 struct wimfs_fd *fd = (struct wimfs_fd*)(uintptr_t)fi->fh;
1530 int ret = ftruncate(fd->staging_fd, size);
1533 if (fd->f_lte && size < fd->f_lte->resource_entry.original_size)
1534 fd->f_lte->resource_entry.original_size = size;
1539 * Fills in a `struct stat' that corresponds to a file or directory in the WIM.
1541 static int wimfs_getattr(const char *path, struct stat *stbuf)
1543 struct wim_dentry *dentry;
1544 struct wim_lookup_table_entry *lte;
1546 struct wimfs_context *ctx = wimfs_get_context();
1548 ret = lookup_resource(ctx->wim, path,
1549 get_lookup_flags(ctx) | LOOKUP_FLAG_DIRECTORY_OK,
1550 &dentry, <e, NULL);
1553 return inode_to_stbuf(dentry->d_inode, lte, stbuf);
1557 /* Read an alternate data stream through the XATTR interface, or get its size */
1558 static int wimfs_getxattr(const char *path, const char *name, char *value,
1562 struct wim_inode *inode;
1563 struct ads_entry *ads_entry;
1565 struct wim_lookup_table_entry *lte;
1566 struct wimfs_context *ctx = wimfs_get_context();
1568 if (!(ctx->mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR))
1571 if (strlen(name) < 5 || memcmp(name, "user.", 5) != 0)
1575 inode = wim_pathname_to_inode(ctx->wim, path);
1579 ads_entry = inode_get_ads_entry(inode, name, NULL);
1583 lte = ads_entry->lte;
1584 res_size = wim_resource_size(lte);
1589 if (res_size > size)
1592 ret = read_full_wim_resource(lte, (u8*)value,
1593 WIMLIB_RESOURCE_FLAG_MULTITHREADED);
1601 /* Create a hard link */
1602 static int wimfs_link(const char *to, const char *from)
1604 struct wim_dentry *from_dentry, *from_dentry_parent;
1605 const char *link_name;
1606 struct wim_inode *inode;
1607 struct wim_lookup_table_entry *lte;
1608 WIMStruct *w = wimfs_get_WIMStruct();
1611 inode = wim_pathname_to_inode(w, to);
1615 if (inode->i_attributes & FILE_ATTRIBUTE_REPARSE_POINT)
1618 if (inode->i_attributes & FILE_ATTRIBUTE_DIRECTORY)
1621 from_dentry_parent = get_parent_dentry(w, from);
1622 if (!from_dentry_parent)
1624 if (!dentry_is_directory(from_dentry_parent))
1627 link_name = path_basename(from);
1628 if (get_dentry_child_with_name(from_dentry_parent, link_name))
1630 from_dentry = new_dentry(link_name);
1634 inode_add_dentry(from_dentry, inode);
1635 from_dentry->d_inode = inode;
1638 for (i = 0; i <= inode->i_num_ads; i++) {
1639 lte = inode_stream_lte_resolved(inode, i);
1643 dentry_add_child(from_dentry_parent, from_dentry);
1648 static int wimfs_listxattr(const char *path, char *list, size_t size)
1651 struct wim_inode *inode;
1652 struct wimfs_context *ctx = wimfs_get_context();
1656 if (!(ctx->mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR))
1659 /* List alternate data streams, or get the list size */
1661 inode = wim_pathname_to_inode(ctx->wim, path);
1667 for (i = 0; i < inode->i_num_ads; i++)
1668 needed_size += inode->i_ads_entries[i].stream_name_utf8_len + 6;
1672 for (i = 0; i < inode->i_num_ads; i++) {
1673 needed_size = inode->i_ads_entries[i].stream_name_utf8_len + 6;
1674 if (needed_size > size)
1676 p += sprintf(p, "user.%s",
1677 inode->i_ads_entries[i].stream_name_utf8) + 1;
1678 size -= needed_size;
1686 /* Create a directory in the WIM.
1687 * @mode is currently ignored. */
1688 static int wimfs_mkdir(const char *path, mode_t mode)
1690 struct wim_dentry *dentry;
1693 ret = create_dentry(wimfs_get_context(), path, &dentry);
1695 dentry->d_inode->i_attributes = FILE_ATTRIBUTE_DIRECTORY;
1699 /* Create a regular file in the WIM.
1700 * @mode is currently ignored. */
1701 static int wimfs_mknod(const char *path, mode_t mode, dev_t rdev)
1703 const char *stream_name;
1704 struct wimfs_context *ctx = wimfs_get_context();
1705 if ((ctx->mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS)
1706 && (stream_name = path_stream_name(path))) {
1707 /* Make an alternate data stream */
1708 struct ads_entry *new_entry;
1709 struct wim_inode *inode;
1711 char *p = (char*)stream_name - 1;
1712 wimlib_assert(*p == ':');
1715 inode = wim_pathname_to_inode(ctx->wim, path);
1718 if (inode->i_attributes &
1719 (FILE_ATTRIBUTE_REPARSE_POINT | FILE_ATTRIBUTE_DIRECTORY))
1721 if (inode_get_ads_entry(inode, stream_name, NULL))
1723 new_entry = inode_add_ads(inode, stream_name);
1728 struct wim_dentry *dentry;
1731 /* Make a normal file (not an alternate data stream) */
1732 ret = create_dentry(ctx, path, &dentry);
1734 dentry->d_inode->i_attributes = FILE_ATTRIBUTE_NORMAL;
1741 static int wimfs_open(const char *path, struct fuse_file_info *fi)
1743 struct wim_dentry *dentry;
1744 struct wim_lookup_table_entry *lte;
1746 struct wimfs_fd *fd;
1747 struct wim_inode *inode;
1750 struct wimfs_context *ctx = wimfs_get_context();
1752 ret = lookup_resource(ctx->wim, path, get_lookup_flags(ctx),
1753 &dentry, <e, &stream_idx);
1757 inode = dentry->d_inode;
1759 if (stream_idx == 0)
1762 stream_id = inode->i_ads_entries[stream_idx - 1].stream_id;
1764 /* The file resource may be in the staging directory (read-write mounts
1765 * only) or in the WIM. If it's in the staging directory, we need to
1766 * open a native file descriptor for the corresponding file. Otherwise,
1767 * we can read the file resource directly from the WIM file if we are
1768 * opening it read-only, but we need to extract the resource to the
1769 * staging directory if we are opening it writable. */
1771 if (flags_writable(fi->flags) &&
1772 (!lte || lte->resource_location != RESOURCE_IN_STAGING_FILE)) {
1773 u64 size = (lte) ? wim_resource_size(lte) : 0;
1774 ret = extract_resource_to_staging_dir(inode, stream_id,
1780 ret = alloc_wimfs_fd(inode, stream_id, lte, &fd,
1781 wimfs_ctx_readonly(ctx));
1785 if (lte && lte->resource_location == RESOURCE_IN_STAGING_FILE) {
1786 fd->staging_fd = open(lte->staging_file_name, fi->flags);
1787 if (fd->staging_fd == -1) {
1788 int errno_save = errno;
1793 fi->fh = (uintptr_t)fd;
1797 /* Opens a directory. */
1798 static int wimfs_opendir(const char *path, struct fuse_file_info *fi)
1800 struct wim_inode *inode;
1802 struct wimfs_fd *fd = NULL;
1803 struct wimfs_context *ctx = wimfs_get_context();
1804 WIMStruct *w = ctx->wim;
1806 inode = wim_pathname_to_inode(w, path);
1809 if (!inode_is_directory(inode))
1811 ret = alloc_wimfs_fd(inode, 0, NULL, &fd, wimfs_ctx_readonly(ctx));
1812 fi->fh = (uintptr_t)fd;
1818 * Read data from a file in the WIM or in the staging directory.
1820 static int wimfs_read(const char *path, char *buf, size_t size,
1821 off_t offset, struct fuse_file_info *fi)
1823 struct wimfs_fd *fd = (struct wimfs_fd*)(uintptr_t)fi->fh;
1829 if (!fd->f_lte) /* Empty stream with no lookup table entry */
1832 if (fd->f_lte->resource_location == RESOURCE_IN_STAGING_FILE) {
1833 /* Read from staging file */
1835 wimlib_assert(fd->f_lte->staging_file_name);
1836 wimlib_assert(fd->staging_fd != -1);
1838 DEBUG("Seek to offset %zu", offset);
1840 if (lseek(fd->staging_fd, offset, SEEK_SET) == -1)
1842 ret = read(fd->staging_fd, buf, size);
1848 u64 res_size = wim_resource_size(fd->f_lte);
1849 if (offset > res_size)
1851 size = min(size, res_size - offset);
1852 if (read_wim_resource(fd->f_lte, (u8*)buf,
1854 WIMLIB_RESOURCE_FLAG_MULTITHREADED) != 0)
1860 struct fill_params {
1862 fuse_fill_dir_t filler;
1865 static int dentry_fuse_fill(struct wim_dentry *dentry, void *arg)
1867 struct fill_params *fill_params = arg;
1868 return fill_params->filler(fill_params->buf, dentry->file_name_utf8,
1872 /* Fills in the entries of the directory specified by @path using the
1873 * FUSE-provided function @filler. */
1874 static int wimfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
1875 off_t offset, struct fuse_file_info *fi)
1877 struct wimfs_fd *fd = (struct wimfs_fd*)(uintptr_t)fi->fh;
1878 struct wim_inode *inode;
1883 inode = fd->f_inode;
1885 struct fill_params fill_params = {
1890 filler(buf, ".", NULL, 0);
1891 filler(buf, "..", NULL, 0);
1893 return for_dentry_in_rbtree(inode->i_children.rb_node,
1894 dentry_fuse_fill, &fill_params);
1898 static int wimfs_readlink(const char *path, char *buf, size_t buf_len)
1900 struct wimfs_context *ctx = wimfs_get_context();
1901 struct wim_inode *inode = wim_pathname_to_inode(ctx->wim, path);
1905 if (!inode_is_symlink(inode))
1908 ret = inode_readlink(inode, buf, buf_len, ctx->wim,
1909 WIMLIB_RESOURCE_FLAG_MULTITHREADED);
1916 static int wimfs_release(const char *path, struct fuse_file_info *fi)
1918 struct wimfs_fd *fd = (struct wimfs_fd*)(uintptr_t)fi->fh;
1919 return close_wimfs_fd(fd);
1922 /* Close a directory */
1923 static int wimfs_releasedir(const char *path, struct fuse_file_info *fi)
1925 struct wimfs_fd *fd = (struct wimfs_fd*)(uintptr_t)fi->fh;
1926 return close_wimfs_fd(fd);
1930 /* Remove an alternate data stream through the XATTR interface */
1931 static int wimfs_removexattr(const char *path, const char *name)
1933 struct wim_inode *inode;
1934 struct ads_entry *ads_entry;
1936 struct wimfs_context *ctx = wimfs_get_context();
1938 if (!(ctx->mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR))
1941 if (strlen(name) < 5 || memcmp(name, "user.", 5) != 0)
1945 inode = wim_pathname_to_inode(ctx->wim, path);
1949 ads_entry = inode_get_ads_entry(inode, name, &ads_idx);
1952 inode_remove_ads(inode, ads_idx, ctx->wim->lookup_table);
1957 /* Renames a file or directory. See rename (3) */
1958 static int wimfs_rename(const char *from, const char *to)
1960 struct wim_dentry *src;
1961 struct wim_dentry *dst;
1962 struct wim_dentry *parent_of_dst;
1963 WIMStruct *w = wimfs_get_WIMStruct();
1966 /* This rename() implementation currently only supports actual files
1967 * (not alternate data streams) */
1969 src = get_dentry(w, from);
1973 dst = get_dentry(w, to);
1976 /* Destination file exists */
1978 if (src == dst) /* Same file */
1981 if (!dentry_is_directory(src)) {
1982 /* Cannot rename non-directory to directory. */
1983 if (dentry_is_directory(dst))
1986 /* Cannot rename directory to a non-directory or a non-empty
1988 if (!dentry_is_directory(dst))
1990 if (inode_has_children(dst->d_inode))
1993 parent_of_dst = dst->parent;
1995 /* Destination does not exist */
1996 parent_of_dst = get_parent_dentry(w, to);
2000 if (!dentry_is_directory(parent_of_dst))
2004 ret = set_dentry_name(src, to);
2008 remove_dentry(dst, w->lookup_table);
2010 dentry_add_child(parent_of_dst, src);
2014 /* Remove a directory */
2015 static int wimfs_rmdir(const char *path)
2017 struct wim_dentry *parent, *dentry;
2018 WIMStruct *w = wimfs_get_WIMStruct();
2020 dentry = get_dentry(w, path);
2024 if (!dentry_is_directory(dentry))
2027 if (dentry_has_children(dentry))
2030 remove_dentry(dentry, w->lookup_table);
2035 /* Write an alternate data stream through the XATTR interface */
2036 static int wimfs_setxattr(const char *path, const char *name,
2037 const char *value, size_t size, int flags)
2039 struct ads_entry *existing_ads_entry;
2040 struct ads_entry *new_ads_entry;
2041 struct wim_lookup_table_entry *existing_lte;
2042 struct wim_lookup_table_entry *lte;
2043 struct wim_inode *inode;
2044 u8 value_hash[SHA1_HASH_SIZE];
2046 struct wimfs_context *ctx = wimfs_get_context();
2048 if (!(ctx->mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR))
2051 if (strlen(name) < 5 || memcmp(name, "user.", 5) != 0)
2055 inode = wim_pathname_to_inode(ctx->wim, path);
2059 existing_ads_entry = inode_get_ads_entry(inode, name, &ads_idx);
2060 if (existing_ads_entry) {
2061 if (flags & XATTR_CREATE)
2063 inode_remove_ads(inode, ads_idx, ctx->wim->lookup_table);
2065 if (flags & XATTR_REPLACE)
2068 new_ads_entry = inode_add_ads(inode, name);
2072 sha1_buffer((const u8*)value, size, value_hash);
2074 existing_lte = __lookup_resource(ctx->wim->lookup_table, value_hash);
2081 lte = new_lookup_table_entry();
2084 value_copy = MALLOC(size);
2089 memcpy(value_copy, value, size);
2090 lte->resource_location = RESOURCE_IN_ATTACHED_BUFFER;
2091 lte->attached_buffer = value_copy;
2092 lte->resource_entry.original_size = size;
2093 lte->resource_entry.size = size;
2094 lte->resource_entry.flags = 0;
2095 copy_hash(lte->hash, value_hash);
2096 lookup_table_insert(ctx->wim->lookup_table, lte);
2098 new_ads_entry->lte = lte;
2103 static int wimfs_symlink(const char *to, const char *from)
2105 struct wimfs_context *ctx = wimfs_get_context();
2106 struct wim_dentry *dentry;
2109 ret = create_dentry(ctx, from, &dentry);
2111 dentry->d_inode->i_attributes = FILE_ATTRIBUTE_REPARSE_POINT;
2112 dentry->d_inode->i_reparse_tag = WIM_IO_REPARSE_TAG_SYMLINK;
2113 if (inode_set_symlink(dentry->d_inode, to,
2114 ctx->wim->lookup_table, NULL))
2116 unlink_dentry(dentry);
2117 free_dentry(dentry);
2125 /* Reduce the size of a file */
2126 static int wimfs_truncate(const char *path, off_t size)
2128 struct wim_dentry *dentry;
2129 struct wim_lookup_table_entry *lte;
2133 struct wim_inode *inode;
2134 struct wimfs_context *ctx = wimfs_get_context();
2136 ret = lookup_resource(ctx->wim, path, get_lookup_flags(ctx),
2137 &dentry, <e, &stream_idx);
2142 if (lte == NULL && size == 0)
2145 inode = dentry->d_inode;
2146 if (stream_idx == 0)
2149 stream_id = inode->i_ads_entries[stream_idx - 1].stream_id;
2151 if (lte->resource_location == RESOURCE_IN_STAGING_FILE) {
2152 ret = truncate(lte->staging_file_name, size);
2156 /* File in WIM. Extract it to the staging directory, but only
2157 * the first @size bytes of it. */
2158 ret = extract_resource_to_staging_dir(inode, stream_id,
2164 /* Unlink a non-directory or alternate data stream */
2165 static int wimfs_unlink(const char *path)
2167 struct wim_dentry *dentry;
2168 struct wim_lookup_table_entry *lte;
2171 struct wimfs_context *ctx = wimfs_get_context();
2173 ret = lookup_resource(ctx->wim, path, get_lookup_flags(ctx),
2174 &dentry, <e, &stream_idx);
2179 if (stream_idx == 0)
2180 remove_dentry(dentry, ctx->wim->lookup_table);
2182 inode_remove_ads(dentry->d_inode, stream_idx - 1,
2183 ctx->wim->lookup_table);
2187 #ifdef HAVE_UTIMENSAT
2189 * Change the timestamp on a file dentry.
2191 * Note that alternate data streams do not have their own timestamps.
2193 static int wimfs_utimens(const char *path, const struct timespec tv[2])
2195 struct wim_dentry *dentry;
2196 struct wim_inode *inode;
2197 WIMStruct *w = wimfs_get_WIMStruct();
2199 dentry = get_dentry(w, path);
2202 inode = dentry->d_inode;
2204 if (tv[0].tv_nsec != UTIME_OMIT) {
2205 if (tv[0].tv_nsec == UTIME_NOW)
2206 inode->i_last_access_time = get_wim_timestamp();
2208 inode->i_last_access_time = timespec_to_wim_timestamp(&tv[0]);
2210 if (tv[1].tv_nsec != UTIME_OMIT) {
2211 if (tv[1].tv_nsec == UTIME_NOW)
2212 inode->i_last_write_time = get_wim_timestamp();
2214 inode->i_last_write_time = timespec_to_wim_timestamp(&tv[1]);
2219 static int wimfs_utime(const char *path, struct utimbuf *times)
2221 struct wim_dentry *dentry;
2222 struct wim_inode *inode;
2223 WIMStruct *w = wimfs_get_WIMStruct();
2225 dentry = get_dentry(w, path);
2228 inode = dentry->d_inode;
2230 inode->i_last_write_time = unix_timestamp_to_wim(times->modtime);
2231 inode->i_last_access_time = unix_timestamp_to_wim(times->actime);
2236 /* Writes to a file in the WIM filesystem.
2237 * It may be an alternate data stream, but here we don't even notice because we
2238 * just get a lookup table entry. */
2239 static int wimfs_write(const char *path, const char *buf, size_t size,
2240 off_t offset, struct fuse_file_info *fi)
2242 struct wimfs_fd *fd = (struct wimfs_fd*)(uintptr_t)fi->fh;
2249 wimlib_assert(fd->f_lte);
2250 wimlib_assert(fd->f_lte->staging_file_name);
2251 wimlib_assert(fd->staging_fd != -1);
2252 wimlib_assert(fd->f_inode);
2254 /* Seek to the requested position */
2255 if (lseek(fd->staging_fd, offset, SEEK_SET) == -1)
2258 /* Write the data. */
2259 ret = write(fd->staging_fd, buf, size);
2263 now = get_wim_timestamp();
2264 fd->f_inode->i_last_write_time = now;
2265 fd->f_inode->i_last_access_time = now;
2269 static struct fuse_operations wimfs_operations = {
2270 .access = wimfs_access,
2271 .chmod = wimfs_chmod,
2272 .destroy = wimfs_destroy,
2274 .fallocate = wimfs_fallocate,
2276 .fgetattr = wimfs_fgetattr,
2277 .ftruncate = wimfs_ftruncate,
2278 .getattr = wimfs_getattr,
2280 .getxattr = wimfs_getxattr,
2284 .listxattr = wimfs_listxattr,
2286 .mkdir = wimfs_mkdir,
2287 .mknod = wimfs_mknod,
2289 .opendir = wimfs_opendir,
2291 .readdir = wimfs_readdir,
2292 .readlink = wimfs_readlink,
2293 .release = wimfs_release,
2294 .releasedir = wimfs_releasedir,
2296 .removexattr = wimfs_removexattr,
2298 .rename = wimfs_rename,
2299 .rmdir = wimfs_rmdir,
2301 .setxattr = wimfs_setxattr,
2303 .symlink = wimfs_symlink,
2304 .truncate = wimfs_truncate,
2305 .unlink = wimfs_unlink,
2306 #ifdef HAVE_UTIMENSAT
2307 .utimens = wimfs_utimens,
2309 .utime = wimfs_utime,
2311 .write = wimfs_write,
2313 /* wimfs keeps file descriptor structures (struct wimfs_fd), so there is
2314 * no need to have the file path provided on operations such as read()
2315 * where only the file descriptor is needed. */
2316 #if FUSE_MAJOR_VERSION > 2 || (FUSE_MAJOR_VERSION == 2 && FUSE_MINOR_VERSION >= 8)
2317 .flag_nullpath_ok = 1,
2319 #if FUSE_MAJOR_VERSION > 2 || (FUSE_MAJOR_VERSION == 2 && FUSE_MINOR_VERSION >= 9)
2321 .flag_utime_omit_ok = 1,
2326 /* Mounts an image from a WIM file. */
2327 WIMLIBAPI int wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
2328 int mount_flags, WIMStruct **additional_swms,
2329 unsigned num_additional_swms,
2330 const char *staging_dir)
2336 struct wim_lookup_table *joined_tab, *wim_tab_save;
2337 struct wim_image_metadata *imd;
2338 struct wimfs_context ctx;
2339 struct hlist_node *cur_node;
2340 struct wim_inode *inode;
2342 DEBUG("Mount: wim = %p, image = %d, dir = %s, flags = %d, ",
2343 wim, image, dir, mount_flags);
2346 return WIMLIB_ERR_INVALID_PARAM;
2348 ret = verify_swm_set(wim, additional_swms, num_additional_swms);
2352 if ((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) && (wim->hdr.total_parts != 1)) {
2353 ERROR("Cannot mount a split WIM read-write");
2354 return WIMLIB_ERR_SPLIT_UNSUPPORTED;
2357 if (num_additional_swms) {
2358 ret = new_joined_lookup_table(wim, additional_swms,
2359 num_additional_swms,
2363 wim_tab_save = wim->lookup_table;
2364 wim->lookup_table = joined_tab;
2367 if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
2368 ret = wim_run_full_verifications(wim);
2373 ret = select_wim_image(wim, image);
2377 DEBUG("Selected image %d", image);
2379 imd = wim_get_current_image_metadata(wim);
2381 if (imd->root_dentry->refcnt != 1) {
2382 ERROR("Cannot mount image that was just exported with "
2383 "wimlib_export_image()");
2384 ret = WIMLIB_ERR_INVALID_PARAM;
2388 if (imd->inode_list.first) /* May be unneeded? */
2389 imd->inode_list.first->pprev = &imd->inode_list.first;
2391 if (imd->modified) {
2392 ERROR("Cannot mount image that was added "
2393 "with wimlib_add_image()");
2394 ret = WIMLIB_ERR_INVALID_PARAM;
2398 if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
2399 ret = lock_wim(wim, wim->fp);
2404 /* Use default stream interface if one was not specified */
2405 if (!(mount_flags & (WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_NONE |
2406 WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR |
2407 WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS)))
2408 mount_flags |= WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR;
2411 DEBUG("Initializing struct wimfs_context");
2412 init_wimfs_context(&ctx);
2414 ctx.mount_flags = mount_flags;
2415 ctx.image_inode_list = &imd->inode_list;
2417 if (mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS)
2418 ctx.default_lookup_flags = LOOKUP_FLAG_ADS_OK;
2420 DEBUG("Unlinking message queues in case they already exist");
2421 ret = set_message_queue_names(&ctx, dir);
2424 unlink_message_queues(&ctx);
2426 DEBUG("Preparing arguments to fuse_main()");
2428 dir_copy = STRDUP(dir);
2430 goto out_free_message_queue_names;
2432 argv[argc++] = "imagex";
2433 argv[argc++] = dir_copy;
2435 /* disable multi-threaded operation for read-write mounts */
2436 if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)
2437 argv[argc++] = "-s";
2439 if (mount_flags & WIMLIB_MOUNT_FLAG_DEBUG)
2440 argv[argc++] = "-d";
2443 * We provide the use_ino option to the FUSE mount because we are going
2444 * to assign inode numbers oursides. */
2445 char optstring[256] =
2449 #if FUSE_MAJOR_VERSION > 2 || (FUSE_MAJOR_VERSION == 2 && FUSE_MINOR_VERSION >= 8)
2453 argv[argc++] = "-o";
2454 argv[argc++] = optstring;
2455 if ((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)) {
2456 /* Read-write mount. Make the staging directory */
2457 ret = make_staging_dir(&ctx, staging_dir);
2459 goto out_free_dir_copy;
2461 /* Read-only mount */
2462 strcat(optstring, ",ro");
2469 DEBUG("FUSE command line (argc = %d): ", argc);
2470 for (i = 0; i < argc; i++) {
2471 fputs(argv[i], stdout);
2479 /* Mark dentry tree as modified if read-write mount. */
2480 if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
2482 imd->has_been_mounted_rw = 1;
2485 /* Resolve the lookup table entries for every inode in the image, and
2486 * assign inode numbers */
2487 DEBUG("Resolving lookup table entries and assigning inode numbers");
2489 hlist_for_each_entry(inode, cur_node, &imd->inode_list, i_hlist) {
2490 inode_resolve_ltes(inode, wim->lookup_table);
2491 inode->i_ino = ctx.next_ino++;
2493 DEBUG("(next_ino = %"PRIu64")", ctx.next_ino);
2495 DEBUG("Calling fuse_main()");
2497 ret = fuse_main(argc, argv, &wimfs_operations, &ctx);
2499 DEBUG("Returned from fuse_main() (ret = %d)", ret);
2502 ret = WIMLIB_ERR_FUSE;
2506 wim->wim_locked = 0;
2507 out_free_message_queue_names:
2508 free_message_queue_names(&ctx);
2510 if (num_additional_swms) {
2511 free_lookup_table(wim->lookup_table);
2512 wim->lookup_table = wim_tab_save;
2518 * Unmounts the WIM file that was previously mounted on @dir by using
2519 * wimlib_mount_image().
2521 WIMLIBAPI int wimlib_unmount_image(const char *dir, int unmount_flags,
2522 wimlib_progress_func_t progress_func)
2525 struct wimfs_context wimfs_ctx;
2527 init_wimfs_context(&wimfs_ctx);
2529 ret = set_message_queue_names(&wimfs_ctx, dir);
2533 ret = open_message_queues(&wimfs_ctx, false);
2535 goto out_free_message_queue_names;
2537 ret = send_unmount_request_msg(wimfs_ctx.unmount_to_daemon_mq,
2539 progress_func != NULL);
2541 goto out_close_message_queues;
2543 ret = execute_fusermount(dir);
2545 goto out_close_message_queues;
2547 struct unmount_msg_handler_context handler_ctx = {
2549 .timeout_seconds = 5,
2552 .progress_func = progress_func,
2555 ret = message_loop(wimfs_ctx.daemon_to_unmount_mq,
2556 &unmount_msg_handler_callbacks,
2559 ret = handler_ctx.status;
2560 out_close_message_queues:
2561 close_message_queues(&wimfs_ctx);
2562 out_free_message_queue_names:
2563 free_message_queue_names(&wimfs_ctx);
2568 #else /* WITH_FUSE */
2571 static inline int mount_unsupported_error()
2573 ERROR("wimlib was compiled with --without-fuse, which disables support "
2574 "for mounting WIMs.");
2575 return WIMLIB_ERR_UNSUPPORTED;
2578 WIMLIBAPI int wimlib_unmount_image(const char *dir, int unmount_flags,
2579 wimlib_progress_func_t progress_func)
2581 return mount_unsupported_error();
2584 WIMLIBAPI int wimlib_mount_image(WIMStruct *wim_p, int image, const char *dir,
2585 int mount_flags, WIMStruct **additional_swms,
2586 unsigned num_additional_swms,
2587 const char *staging_dir)
2589 return mount_unsupported_error();
2592 #endif /* WITH_FUSE */