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 Lesser General Public License as published by the Free
17 * Software Foundation; either version 2.1 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 Lesser General Public License for more
25 * You should have received a copy of the GNU Lesser General Public License
26 * along with wimlib; if not, see http://www.gnu.org/licenses/.
29 #include "wimlib_internal.h"
33 #include "lookup_table.h"
36 #include "timestamp.h"
40 #define FUSE_USE_VERSION 26
52 struct lookup_table_entry *lte;
53 struct dentry *dentry;
56 /* The WIMStruct for the mounted WIM. */
59 /* Working directory when `imagex mount' is run. */
60 static const char *working_directory;
62 /* Name of the staging directory for a read-write mount. Whenever a new file is
63 * created, it is done so in the staging directory. Furthermore, whenever a
64 * file in the WIM is modified, it is extracted to the staging directory. If
65 * changes are commited when the WIM is unmounted, the file resources are merged
66 * in from the staging directory when writing the new WIM. */
67 static char *staging_dir_name;
68 static size_t staging_dir_name_len;
70 /* Flags passed to wimlib_mount(). */
71 static int mount_flags;
73 /* Name of the directory on which the WIM file is mounted. */
74 static const char *mount_dir;
76 /* Next hard link group ID to be assigned. These are also used as the inode
78 static u64 next_link_group_id;
80 /* List of lookup table entries in the staging directory */
81 static LIST_HEAD(staging_list);
83 static inline int get_lookup_flags()
85 if (mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS)
86 return LOOKUP_FLAG_ADS_OK;
91 /* Returns nonzero if write permission is requested on the file open flags */
92 static inline int flags_writable(int open_flags)
94 return open_flags & (O_RDWR | O_WRONLY);
98 * Allocate a file descriptor for a lookup table entry
100 static int alloc_wimlib_fd(struct lookup_table_entry *lte,
101 struct wimlib_fd **fd_ret)
103 static const u16 fds_per_alloc = 8;
104 static const u16 max_fds = 0xffff;
106 if (lte->num_opened_fds == lte->num_allocated_fds) {
107 struct wimlib_fd **fds;
110 if (lte->num_allocated_fds == max_fds)
112 num_new_fds = min(fds_per_alloc, max_fds - lte->num_allocated_fds);
114 fds = REALLOC(lte->fds, (lte->num_allocated_fds + num_new_fds) *
115 sizeof(lte->fds[0]));
118 memset(&fds[lte->num_allocated_fds], 0,
119 num_new_fds * sizeof(fds[0]));
121 lte->num_allocated_fds += num_new_fds;
123 for (u16 i = 0; ; i++) {
125 struct wimlib_fd *fd = CALLOC(1, sizeof(*fd));
132 lte->num_opened_fds++;
139 static int close_wimlib_fd(struct wimlib_fd *fd)
141 struct lookup_table_entry *lte = fd->lte;
144 wimlib_assert(lte->num_opened_fds);
146 if (lte->staging_file_name) {
147 wimlib_assert(fd->staging_fd != -1);
148 if (close(fd->staging_fd) != 0)
151 if (--lte->num_opened_fds == 0 && lte->refcnt == 0) {
152 if (lte->staging_file_name)
153 unlink(lte->staging_file_name);
154 free_lookup_table_entry(lte);
156 wimlib_assert(lte->fds[fd->idx] == fd);
157 lte->fds[fd->idx] = NULL;
162 /* Remove a dentry and all its alternate file streams */
163 static void remove_dentry(struct dentry *dentry,
164 struct lookup_table *lookup_table)
166 wimlib_assert(dentry);
167 wimlib_assert(dentry->resolved);
169 struct lookup_table_entry *lte = dentry->lte;
172 lte = lte_decrement_refcnt(lte, lookup_table);
173 if (lte && lte->num_opened_fds)
174 for (u16 i = 0; i < lte->num_allocated_fds; i++)
175 if (lte->fds[i] && lte->fds[i]->dentry == dentry)
176 lte->fds[i]->dentry = NULL;
177 if (i == dentry->num_ads)
179 lte = dentry->ads_entries[i].lte;
183 unlink_dentry(dentry);
187 /* Transfers file attributes from a struct dentry to a `stat' buffer. */
188 int dentry_to_stbuf(const struct dentry *dentry, struct stat *stbuf)
190 struct lookup_table_entry *lte;
192 if (dentry_is_symlink(dentry))
193 stbuf->st_mode = S_IFLNK | 0777;
194 else if (dentry_is_directory(dentry))
195 stbuf->st_mode = S_IFDIR | 0755;
197 stbuf->st_mode = S_IFREG | 0644;
199 stbuf->st_ino = (ino_t)dentry->hard_link;
201 stbuf->st_nlink = dentry_link_group_size(dentry);
202 stbuf->st_uid = getuid();
203 stbuf->st_gid = getgid();
205 /* Use the size of the unnamed (default) file stream. */
206 lte = dentry_first_lte_resolved(dentry);
208 if (lte->staging_file_name) {
209 struct stat native_stat;
210 if (stat(lte->staging_file_name, &native_stat) != 0) {
211 DEBUG("Failed to stat `%s': %m",
212 lte->staging_file_name);
215 stbuf->st_size = native_stat.st_size;
217 stbuf->st_size = lte->resource_entry.original_size;
223 stbuf->st_atime = wim_timestamp_to_unix(dentry->last_access_time);
224 stbuf->st_mtime = wim_timestamp_to_unix(dentry->last_write_time);
225 stbuf->st_ctime = wim_timestamp_to_unix(dentry->creation_time);
226 stbuf->st_blocks = (stbuf->st_size + 511) / 512;
230 /* Creates a new staging file and returns its file descriptor opened for
233 * @name_ret: A location into which the a pointer to the newly allocated name of
234 * the staging file is stored.
235 * @return: The file descriptor for the new file. Returns -1 and sets errno on
236 * error, for any reason possible from the creat() function.
238 static int create_staging_file(char **name_ret, int open_flags)
246 name_len = staging_dir_name_len + 1 + SHA1_HASH_SIZE;
247 name = MALLOC(name_len + 1);
255 memcpy(name, staging_dir_name, staging_dir_name_len);
256 name[staging_dir_name_len] = '/';
257 randomize_char_array_with_alnum(name + staging_dir_name_len + 1,
259 name[name_len] = '\0';
262 /* Just in case, verify that the randomly generated name doesn't name an
263 * existing file, and try again if so */
264 } while (stat(name, &stbuf) == 0);
270 /* doesn't exist--- ok */
272 DEBUG("Creating staging file `%s'", name);
274 fd = open(name, open_flags | O_CREAT | O_TRUNC, 0600);
286 * Removes open file descriptors from a lookup table entry @old_lte where the
287 * file descriptors have opened the corresponding file resource in the context
288 * of the hard link group @link_group; these file descriptors are extracted and
289 * placed in a new lookup table entry, which is returned.
291 static struct lookup_table_entry *
292 lte_extract_fds(struct lookup_table_entry *old_lte, u64 link_group)
295 u16 num_transferred_fds;
296 struct lookup_table_entry *new_lte;
298 new_lte = new_lookup_table_entry();
302 num_transferred_fds = 0;
303 for (u16 i = 0; i < old_lte->num_allocated_fds; i++)
304 if (old_lte->fds[i] && old_lte->fds[i]->dentry &&
305 old_lte->fds[i]->dentry->hard_link == link_group)
306 num_transferred_fds++;
307 DEBUG("Transferring %u file descriptors",
308 num_transferred_fds);
309 new_lte->fds = MALLOC(num_transferred_fds * sizeof(new_lte->fds[0]));
314 for (u16 i = 0, j = 0; ; i++) {
315 if (old_lte->fds[i] && old_lte->fds[i]->dentry &&
316 old_lte->fds[i]->dentry->hard_link == link_group) {
317 struct wimlib_fd *fd = old_lte->fds[i];
318 old_lte->fds[i] = NULL;
321 new_lte->fds[j] = fd;
322 if (++j == num_transferred_fds)
326 DEBUG("old_lte: %u fds open; new_lte: %u fds open",
327 old_lte->num_opened_fds, new_lte->num_opened_fds);
328 old_lte->num_opened_fds -= num_transferred_fds;
329 new_lte->num_opened_fds = num_transferred_fds;
330 new_lte->num_allocated_fds = num_transferred_fds;
335 * Transfers an alternate data stream entry to a new lookup table entry
337 static void lte_transfer_ads_entry(struct lookup_table_entry *new_lte,
338 struct ads_entry *ads_entry)
340 list_del(&ads_entry->lte_group_list.list);
341 list_add(&ads_entry->lte_group_list.list, &new_lte->lte_group_list);
342 ads_entry->lte = new_lte;
346 * Transfers a dentry to a new lookup table entry
348 static void lte_transfer_dentry(struct lookup_table_entry *new_lte,
349 struct dentry *dentry)
351 wimlib_assert(dentry->lte_group_list.list.next);
352 wimlib_assert(new_lte->lte_group_list.next);
353 list_del(&dentry->lte_group_list.list);
354 list_add(&dentry->lte_group_list.list, &new_lte->lte_group_list);
355 dentry->lte = new_lte;
358 static void lte_transfer_stream_entries(struct lookup_table_entry *new_lte,
359 struct dentry *dentry,
362 INIT_LIST_HEAD(&new_lte->lte_group_list);
363 if (stream_idx == 0) {
364 struct list_head *pos = &dentry->link_group_list;
367 d = container_of(pos, struct dentry, link_group_list);
368 wimlib_assert(d->hard_link == dentry->hard_link);
369 lte_transfer_dentry(new_lte, d);
371 } while (pos != &dentry->link_group_list);
373 struct ads_entry *ads_entry;
374 wimlib_assert(stream_idx <= dentry->num_ads);
375 ads_entry = &dentry->ads_entries[stream_idx - 1];
376 lte_transfer_ads_entry(new_lte, ads_entry);
381 * Extract a WIM resource to the staging directory.
383 * @dentry, @stream_idx: The stream on whose behalf we are modifying the lookup
384 * table entry (these may be more streams than this that reference the lookup
387 * @lte: Pointer to pointer to the lookup table entry for the stream we need to
388 * extract, or NULL if there was no lookup table entry present for the stream
390 * @size: Number of bytes of the stream we want to extract (this supports the
391 * wimfs_truncate() function).
393 static int extract_resource_to_staging_dir(struct dentry *dentry,
395 struct lookup_table_entry **lte,
398 char *staging_file_name;
401 struct lookup_table_entry *old_lte, *new_lte;
402 size_t link_group_size;
406 * - Create a staging file for the WIM resource
407 * - Extract the resource to it
408 * - Create a new lte for the file resource
409 * - Transfer fds from the old lte to the new lte, but only if they share the
410 * same hard link group as this dentry. If there is no old lte, then this
411 * step does not need to be done
412 * - Transfer stream entries from the old lte's list to the new lte's list. If
413 * there is no old lte, we instead transfer entries for the hard link group.
415 * Note: *lte is permitted to be NULL, in which case there is no old
416 * lookup table entry.
419 DEBUG("Extracting resource `%s' to staging directory", dentry->full_path_utf8);
422 fd = create_staging_file(&staging_file_name, O_WRONLY);
427 ret = extract_resource_to_fd(w, &old_lte->resource_entry, fd,
431 if (ret != 0 || close(fd) != 0) {
437 goto out_delete_staging_file;
440 link_group_size = dentry_link_group_size(dentry);
443 if (link_group_size == old_lte->refcnt) {
444 /* This hard link group is the only user of the lookup
445 * table entry, so we can re-use it. */
446 DEBUG("Re-using lookup table entry");
447 lookup_table_unlink(w->lookup_table, old_lte);
450 DEBUG("Splitting lookup table entry "
451 "(link_group_size = %u, lte refcnt = %u)",
452 link_group_size, old_lte->refcnt);
453 /* Split a hard link group away from the "lookup table
454 * entry" hard link group (i.e. we had two hard link
455 * groups that were identical, but now we are changing
459 * The ADS really complicate things here and not
460 * everything is going to work correctly yet. For
461 * example it could be the same that a file contains two
462 * file streams that are identical and therefore share
463 * the same lookup table entry despite the fact that the
464 * streams themselves are not hardlinked.
466 wimlib_assert(old_lte->refcnt > link_group_size);
468 new_lte = lte_extract_fds(old_lte, dentry->hard_link);
471 goto out_delete_staging_file;
474 lte_transfer_stream_entries(new_lte, dentry, stream_idx);
475 old_lte->refcnt -= link_group_size;
478 /* No old_lte was supplied, so the resource had no lookup table
479 * entry before (it must be an empty resource) */
480 new_lte = new_lookup_table_entry();
483 goto out_delete_staging_file;
485 lte_transfer_stream_entries(new_lte, dentry, stream_idx);
487 new_lte->resource_entry.original_size = size;
488 new_lte->refcnt = link_group_size;
489 random_hash(new_lte->hash);
490 new_lte->staging_file_name = staging_file_name;
492 lookup_table_insert(w->lookup_table, new_lte);
493 list_add(&new_lte->staging_list, &staging_list);
496 out_delete_staging_file:
497 unlink(staging_file_name);
498 FREE(staging_file_name);
503 * Creates a randomly named staging directory and returns its name into the
504 * static variable staging_dir_name.
506 * If the staging directory cannot be created, staging_dir_name is set to NULL.
508 static void make_staging_dir()
510 /* XXX Give the user an option of where to stage files */
512 static char prefix[] = "wimlib-staging-";
513 static const size_t prefix_len = 15;
514 static const size_t suffix_len = 10;
516 size_t pwd_len = strlen(working_directory);
518 staging_dir_name_len = pwd_len + 1 + prefix_len + suffix_len;
520 staging_dir_name = MALLOC(staging_dir_name_len + 1);
521 if (!staging_dir_name) {
522 ERROR("Out of memory");
526 memcpy(staging_dir_name, working_directory, pwd_len);
527 staging_dir_name[pwd_len] = '/';
528 memcpy(staging_dir_name + pwd_len + 1, prefix, prefix_len);
529 randomize_char_array_with_alnum(staging_dir_name + pwd_len + 1 + prefix_len,
531 staging_dir_name[staging_dir_name_len] = '\0';
533 if (mkdir(staging_dir_name, 0700) != 0) {
534 ERROR_WITH_ERRNO("Failed to create temporary directory `%s'",
536 FREE(staging_dir_name);
537 staging_dir_name = NULL;
541 static int remove_file_or_directory(const char *fpath, const struct stat *sb,
542 int typeflag, struct FTW *ftwbuf)
544 if (remove(fpath) == 0)
547 return WIMLIB_ERR_DELETE_STAGING_DIR;
552 * Deletes the staging directory and all the files contained in it.
554 static inline int delete_staging_dir()
558 ret = nftw(staging_dir_name, remove_file_or_directory,10, FTW_DEPTH);
559 staging_dir_name = NULL;
563 /* Name and message queue descriptors for message queues between the filesystem
564 * daemon process and the unmount process. These are used when the filesystem
565 * is unmounted and the process running wimlib_mount() (i.e. the `imagex
566 * unmount' command) needs to communicate with the filesystem daemon running
567 * fuse_main() (i.e. that spawned by the `imagex mount' or `imagex mountrw'
569 static char *unmount_to_daemon_mq_name;
570 static char *daemon_to_unmount_mq_name;
571 static int unmount_to_daemon_mq;
572 static int daemon_to_unmount_mq;
574 /* Simple function that returns the concatenation of 4 strings. */
575 static char *strcat_dup(const char *s1, const char *s2, const char *s3,
578 size_t len = strlen(s1) + strlen(s2) + strlen(s3) + strlen(s4) + 1;
579 char *p = MALLOC(len);
590 /* Removes trailing forward slashes in a string. */
591 static void remove_trailing_slashes(char *s)
593 long len = strlen(s);
594 for (long i = len - 1; i >= 1; i--) {
602 /* Changes forward slashes to underscores in a string. */
603 static void s_slashes_underscores_g(char *s)
613 * Opens two POSIX message queue: one for sending messages from the unmount
614 * process to the daemon process, and one to go the other way. The names of the
615 * message queues, which must be system-wide unique, are be based on the mount
616 * point. (There of course is still a possibility of a collision if one were to
617 * unmount two identically named directories simultaneously...)
619 * @daemon specifies whether the calling process is the filesystem daemon or the
622 static int open_message_queues(bool daemon)
624 static const char *slash = "/";
625 static const char *prefix = "wimlib-";
626 static const char *u2d_suffix = "unmount-to-daemon-mq";
627 static const char *d2u_suffix = "daemon-to-unmount-mq";
629 const char *mount_dir_basename = path_basename(mount_dir);
633 unmount_to_daemon_mq_name = strcat_dup(slash, mount_dir_basename,
635 if (!unmount_to_daemon_mq_name) {
636 ERROR("Out of memory");
637 return WIMLIB_ERR_NOMEM;
639 daemon_to_unmount_mq_name = strcat_dup(slash, mount_dir_basename,
641 if (!daemon_to_unmount_mq_name) {
642 ERROR("Out of memory");
643 ret = WIMLIB_ERR_NOMEM;
647 remove_trailing_slashes(unmount_to_daemon_mq_name);
648 remove_trailing_slashes(daemon_to_unmount_mq_name);
649 s_slashes_underscores_g(unmount_to_daemon_mq_name + 1);
650 s_slashes_underscores_g(daemon_to_unmount_mq_name + 1);
653 flags = O_RDONLY | O_CREAT;
655 flags = O_WRONLY | O_CREAT;
657 unmount_to_daemon_mq = mq_open(unmount_to_daemon_mq_name, flags,
660 if (unmount_to_daemon_mq == -1) {
661 ERROR_WITH_ERRNO("mq_open()");
662 ret = WIMLIB_ERR_MQUEUE;
667 flags = O_WRONLY | O_CREAT;
669 flags = O_RDONLY | O_CREAT;
671 daemon_to_unmount_mq = mq_open(daemon_to_unmount_mq_name, flags,
674 if (daemon_to_unmount_mq == -1) {
675 ERROR_WITH_ERRNO("mq_open()");
676 ret = WIMLIB_ERR_MQUEUE;
681 mq_close(unmount_to_daemon_mq);
682 mq_unlink(unmount_to_daemon_mq_name);
684 FREE(daemon_to_unmount_mq_name);
686 FREE(unmount_to_daemon_mq_name);
690 static int mq_get_msgsize(mqd_t mq)
692 static const char *msgsize_max_file = "/proc/sys/fs/mqueue/msgsize_max";
697 if (mq_getattr(unmount_to_daemon_mq, &attr) == 0) {
698 msgsize = attr.mq_msgsize;
700 ERROR_WITH_ERRNO("mq_getattr()");
701 ERROR("Attempting to read %s", msgsize_max_file);
702 fp = fopen(msgsize_max_file, "rb");
704 if (fscanf(fp, "%d", &msgsize) != 1) {
705 ERROR("Assuming message size of 8192");
710 ERROR_WITH_ERRNO("Failed to open the file `%s'",
712 ERROR("Assuming message size of 8192");
719 /* Closes the message queues, which are allocated in static variables */
720 static void close_message_queues()
722 mq_close(unmount_to_daemon_mq);
723 mq_close(daemon_to_unmount_mq);
724 mq_unlink(unmount_to_daemon_mq_name);
725 mq_unlink(daemon_to_unmount_mq_name);
728 static int wimfs_access(const char *path, int mask)
730 /* XXX Permissions not implemented */
734 /* Closes the staging file descriptor associated with the lookup table entry, if
736 static int close_lte_fds(struct lookup_table_entry *lte)
738 for (u16 i = 0, j = 0; j < lte->num_opened_fds; i++) {
739 if (lte->fds[i] && lte->fds[i]->staging_fd != -1) {
740 if (close(lte->fds[i]->staging_fd) != 0) {
741 ERROR_WITH_ERRNO("Failed close file `%s'",
742 lte->staging_file_name);
743 return WIMLIB_ERR_WRITE;
751 static void lte_list_change_lte_ptr(struct lookup_table_entry *lte,
752 struct lookup_table_entry *newptr)
754 struct list_head *pos;
755 struct stream_list_head *head;
756 list_for_each(pos, <e->lte_group_list) {
757 head = container_of(pos, struct stream_list_head, list);
758 if (head->type == STREAM_TYPE_ADS) {
759 struct ads_entry *ads_entry;
760 ads_entry = container_of(head, struct ads_entry, lte_group_list);
762 ads_entry->lte = newptr;
764 wimlib_assert(head->type == STREAM_TYPE_NORMAL);
766 struct dentry *dentry;
767 dentry = container_of(head, struct dentry, lte_group_list);
769 dentry->lte = newptr;
775 static int update_lte_of_staging_file(struct lookup_table_entry *lte,
776 struct lookup_table *table)
778 struct lookup_table_entry *duplicate_lte;
780 u8 hash[SHA1_HASH_SIZE];
783 wimlib_assert(lte->staging_file_name);
785 ret = sha1sum(lte->staging_file_name, hash);
790 lookup_table_unlink(table, lte);
792 duplicate_lte = __lookup_resource(table, hash);
795 /* Merge duplicate lookup table entries */
797 lte_list_change_lte_ptr(lte, duplicate_lte);
798 duplicate_lte->refcnt += lte->refcnt;
799 list_splice(<e->lte_group_list,
800 &duplicate_lte->lte_group_list);
802 free_lookup_table_entry(lte);
804 if (stat(lte->staging_file_name, &stbuf) != 0) {
805 ERROR_WITH_ERRNO("Failed to stat `%s'", lte->staging_file_name);
806 return WIMLIB_ERR_STAT;
808 copy_hash(lte->hash, hash);
809 lte->resource_entry.original_size = stbuf.st_size;
810 lookup_table_insert(table, lte);
816 /* Overwrites the WIM file, with changes saved. */
817 static int rebuild_wim(WIMStruct *w, bool check_integrity)
820 struct lookup_table_entry *lte, *tmp;
822 /* Close all the staging file descriptors. */
823 DEBUG("Closing all staging file descriptors.");
824 list_for_each_entry(lte, &staging_list, staging_list) {
825 ret = close_lte_fds(lte);
830 /* Calculate SHA1 checksums for all staging files, and merge unnecessary
831 * lookup table entries. */
832 DEBUG("Calculating SHA1 checksums for all new staging files.");
833 list_for_each_entry_safe(lte, tmp, &staging_list, staging_list) {
834 ret = update_lte_of_staging_file(lte, w->lookup_table);
841 xml_update_image_info(w, w->current_image);
843 ret = wimlib_overwrite(w, check_integrity);
845 ERROR("Failed to commit changes");
851 /* Called when the filesystem is unmounted. */
852 static void wimfs_destroy(void *p)
854 /* For read-write mounts, the `imagex unmount' command, which is
855 * running in a separate process and is executing the
856 * wimlib_unmount() function, will send this process a byte
857 * through a message queue that indicates whether the --commit
858 * option was specified or not. */
861 struct timespec timeout;
863 ssize_t bytes_received;
866 char check_integrity;
869 ret = open_message_queues(true);
873 msgsize = mq_get_msgsize(unmount_to_daemon_mq);
878 /* Wait at most 3 seconds before giving up and discarding changes. */
879 gettimeofday(&now, NULL);
880 timeout.tv_sec = now.tv_sec + 3;
881 timeout.tv_nsec = now.tv_usec * 1000;
882 DEBUG("Waiting for message telling us whether to commit or not, and "
883 "whether to include integrity checks.");
885 bytes_received = mq_timedreceive(unmount_to_daemon_mq, msg,
886 msgsize, NULL, &timeout);
888 check_integrity = msg[1];
889 if (bytes_received == -1) {
890 if (errno == ETIMEDOUT) {
893 ERROR_WITH_ERRNO("mq_timedreceive()");
895 ERROR("Not committing.");
897 DEBUG("Received message: [%d %d]", msg[0], msg[1]);
901 if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
903 status = chdir(working_directory);
905 ERROR_WITH_ERRNO("chdir()");
906 status = WIMLIB_ERR_NOTDIR;
909 status = rebuild_wim(w, (check_integrity != 0));
911 ret = delete_staging_dir();
913 ERROR_WITH_ERRNO("Failed to delete the staging "
919 DEBUG("Read-only mount");
922 DEBUG("Sending status %u", status);
923 ret = mq_send(daemon_to_unmount_mq, &status, 1, 1);
925 ERROR_WITH_ERRNO("Failed to send status to unmount process");
926 close_message_queues();
929 static int wimfs_fallocate(const char *path, int mode,
930 off_t offset, off_t len, struct fuse_file_info *fi)
932 struct wimlib_fd *fd = (struct wimlib_fd*)fi->fh;
933 wimlib_assert(fd->staging_fd != -1);
934 return fallocate(fd->staging_fd, mode, offset, len);
937 static int wimfs_fgetattr(const char *path, struct stat *stbuf,
938 struct fuse_file_info *fi)
940 struct wimlib_fd *fd = (struct wimlib_fd*)fi->fh;
941 return dentry_to_stbuf(fd->dentry, stbuf);
944 static int wimfs_ftruncate(const char *path, off_t size,
945 struct fuse_file_info *fi)
947 struct wimlib_fd *fd = (struct wimlib_fd*)fi->fh;
948 int ret = ftruncate(fd->staging_fd, size);
951 fd->lte->resource_entry.original_size = size;
956 * Fills in a `struct stat' that corresponds to a file or directory in the WIM.
958 static int wimfs_getattr(const char *path, struct stat *stbuf)
960 struct dentry *dentry = get_dentry(w, path);
963 return dentry_to_stbuf(dentry, stbuf);
966 static int wimfs_getxattr(const char *path, const char *name, char *value,
973 /* Create a hard link */
974 static int wimfs_link(const char *to, const char *from)
976 struct dentry *to_dentry, *from_dentry, *from_dentry_parent;
977 const char *link_name;
979 to_dentry = get_dentry(w, to);
982 if (!dentry_is_regular_file(to_dentry))
985 from_dentry_parent = get_parent_dentry(w, from);
986 if (!from_dentry_parent)
988 if (!dentry_is_directory(from_dentry_parent))
991 link_name = path_basename(from);
992 if (get_dentry_child_with_name(from_dentry_parent, link_name))
994 from_dentry = clone_dentry(to_dentry);
997 if (change_dentry_name(from_dentry, link_name) != 0) {
1002 /* Add the new dentry to the dentry list for the link group */
1003 list_add(&from_dentry->link_group_list, &to_dentry->link_group_list);
1005 /* Increment reference counts for the unnamed file stream and all
1006 * alternate data streams. */
1007 if (from_dentry->lte) {
1008 list_add(&from_dentry->lte_group_list.list,
1009 &to_dentry->lte_group_list.list);
1010 from_dentry->lte->refcnt++;
1012 for (u16 i = 0; i < from_dentry->num_ads; i++) {
1013 struct ads_entry *ads_entry = &from_dentry->ads_entries[i];
1015 ads_entry->lte->refcnt++;
1018 /* The ADS entries are owned by another dentry. */
1019 from_dentry->ads_entries_status = ADS_ENTRIES_USER;
1021 link_dentry(from_dentry, from_dentry_parent);
1025 static int wimfs_listxattr(const char *path, char *list, size_t size)
1032 * Create a directory in the WIM.
1033 * @mode is currently ignored.
1035 static int wimfs_mkdir(const char *path, mode_t mode)
1037 struct dentry *parent;
1038 struct dentry *newdir;
1039 const char *basename;
1041 parent = get_parent_dentry(w, path);
1045 if (!dentry_is_directory(parent))
1048 basename = path_basename(path);
1049 if (get_dentry_child_with_name(parent, basename))
1052 newdir = new_dentry(basename);
1053 newdir->attributes |= FILE_ATTRIBUTE_DIRECTORY;
1054 newdir->resolved = true;
1055 newdir->hard_link = next_link_group_id++;
1056 link_dentry(newdir, parent);
1061 /* Creates a regular file. */
1062 static int wimfs_mknod(const char *path, mode_t mode, dev_t rdev)
1064 const char *stream_name;
1065 if ((mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS)
1066 && (stream_name = path_stream_name(path))) {
1067 /* Make an alternate data stream */
1068 struct ads_entry *new_entry;
1069 struct dentry *dentry;
1071 dentry = get_dentry(w, path);
1072 if (!dentry || !dentry_is_regular_file(dentry))
1074 if (dentry_get_ads_entry(dentry, stream_name))
1076 new_entry = dentry_add_ads(dentry, stream_name);
1080 struct dentry *dentry, *parent;
1081 const char *basename;
1083 /* Make a normal file (not an alternate data stream) */
1085 /* Make sure that the parent of @path exists and is a directory, and
1086 * that the dentry named by @path does not already exist. */
1087 parent = get_parent_dentry(w, path);
1090 if (!dentry_is_directory(parent))
1093 basename = path_basename(path);
1094 if (get_dentry_child_with_name(parent, path))
1097 dentry = new_dentry(basename);
1100 dentry->resolved = true;
1101 dentry->hard_link = next_link_group_id++;
1102 dentry->lte_group_list.type = STREAM_TYPE_NORMAL;
1103 INIT_LIST_HEAD(&dentry->lte_group_list.list);
1104 link_dentry(dentry, parent);
1111 static int wimfs_open(const char *path, struct fuse_file_info *fi)
1113 struct dentry *dentry;
1114 struct lookup_table_entry *lte;
1117 struct wimlib_fd *fd;
1118 unsigned stream_idx;
1120 ret = lookup_resource(w, path, get_lookup_flags(), &dentry, <e,
1126 /* Empty file with no lookup-table entry. This is fine if it's
1127 * a read-only filesystem. Otherwise we need to create a lookup
1128 * table entry so that we can keep track of the file descriptors
1129 * (this is important in case someone opens the file for
1131 if (!(mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)) {
1136 ret = extract_resource_to_staging_dir(dentry, stream_idx,
1142 ret = alloc_wimlib_fd(lte, &fd);
1146 fd->dentry = dentry;
1148 /* The file resource may be in the staging directory (read-write
1149 * mounts only) or in the WIM. If it's in the staging
1150 * directory, we need to open a native file descriptor for the
1151 * corresponding file. Otherwise, we can read the file resource
1152 * directly from the WIM file if we are opening it read-only,
1153 * but we need to extract the resource to the staging directory
1154 * if we are opening it writable. */
1155 if (flags_writable(fi->flags) && !lte->staging_file_name) {
1156 ret = extract_resource_to_staging_dir(dentry, stream_idx, <e,
1157 lte->resource_entry.original_size);
1161 if (lte->staging_file_name) {
1162 fd->staging_fd = open(lte->staging_file_name, fi->flags);
1163 if (fd->staging_fd == -1) {
1164 close_wimlib_fd(fd);
1168 fi->fh = (uint64_t)fd;
1172 /* Opens a directory. */
1173 static int wimfs_opendir(const char *path, struct fuse_file_info *fi)
1175 struct dentry *dentry;
1177 dentry = get_dentry(w, path);
1180 if (!dentry_is_directory(dentry))
1182 dentry->num_times_opened++;
1183 fi->fh = (uint64_t)dentry;
1189 * Read data from a file in the WIM or in the staging directory.
1191 static int wimfs_read(const char *path, char *buf, size_t size,
1192 off_t offset, struct fuse_file_info *fi)
1194 struct wimlib_fd *fd = (struct wimlib_fd*)fi->fh;
1197 /* Empty file with no lookup table entry on read-only mounted
1199 wimlib_assert(!(mount_flags & WIMLIB_MOUNT_FLAG_READWRITE));
1203 wimlib_assert(fd->lte);
1205 if (fd->lte->staging_file_name) {
1206 /* Read from staging file */
1208 wimlib_assert(fd->staging_fd != -1);
1211 DEBUG("Seek to offset %zu", offset);
1213 if (lseek(fd->staging_fd, offset, SEEK_SET) == -1)
1215 ret = read(fd->staging_fd, buf, size);
1222 struct resource_entry *res_entry;
1225 res_entry = &fd->lte->resource_entry;
1227 ctype = wim_resource_compression_type(w, res_entry);
1229 if (offset > res_entry->original_size)
1232 size = min(size, res_entry->original_size - offset);
1234 if (read_resource(w->fp, res_entry->size,
1235 res_entry->original_size,
1236 res_entry->offset, ctype, size,
1243 /* Fills in the entries of the directory specified by @path using the
1244 * FUSE-provided function @filler. */
1245 static int wimfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
1246 off_t offset, struct fuse_file_info *fi)
1248 struct dentry *parent, *child;
1250 parent = (struct dentry*)fi->fh;
1251 wimlib_assert(parent);
1252 child = parent->children;
1254 filler(buf, ".", NULL, 0);
1255 filler(buf, "..", NULL, 0);
1261 if (filler(buf, child->file_name_utf8, NULL, 0))
1263 child = child->next;
1264 } while (child != parent->children);
1269 static int wimfs_readlink(const char *path, char *buf, size_t buf_len)
1271 struct dentry *dentry = get_dentry(w, path);
1275 if (!dentry_is_symlink(dentry))
1278 ret = dentry_readlink(dentry, buf, buf_len, w);
1285 static int wimfs_release(const char *path, struct fuse_file_info *fi)
1288 struct wimlib_fd *fd = (struct wimlib_fd*)fi->fh;
1291 /* Empty file with no lookup table entry on read-only mounted
1293 wimlib_assert(!(mount_flags & WIMLIB_MOUNT_FLAG_READWRITE));
1297 if (flags_writable(fi->flags) && fd->dentry) {
1298 u64 now = get_wim_timestamp();
1299 fd->dentry->last_access_time = now;
1300 fd->dentry->last_write_time = now;
1303 return close_wimlib_fd(fd);
1306 static int wimfs_releasedir(const char *path, struct fuse_file_info *fi)
1308 struct dentry *dentry = (struct dentry *)fi->fh;
1310 wimlib_assert(dentry);
1311 wimlib_assert(dentry->num_times_opened);
1312 if (--dentry->num_times_opened == 0)
1313 free_dentry(dentry);
1317 static int wimfs_removexattr(const char *path, const char *name)
1323 /* Renames a file or directory. See rename (3) */
1324 static int wimfs_rename(const char *from, const char *to)
1328 struct dentry *parent_of_dst;
1329 char *file_name_utf16 = NULL, *file_name_utf8 = NULL;
1330 u16 file_name_utf16_len, file_name_utf8_len;
1333 /* This rename() implementation currently only supports actual files
1334 * (not alternate data streams) */
1336 src = get_dentry(w, from);
1340 dst = get_dentry(w, to);
1343 ret = get_names(&file_name_utf16, &file_name_utf8,
1344 &file_name_utf16_len, &file_name_utf8_len,
1350 /* Destination file exists */
1352 if (src == dst) /* Same file */
1355 if (!dentry_is_directory(src)) {
1356 /* Cannot rename non-directory to directory. */
1357 if (dentry_is_directory(dst))
1360 /* Cannot rename directory to a non-directory or a non-empty
1362 if (!dentry_is_directory(dst))
1364 if (dst->children != NULL)
1367 parent_of_dst = dst->parent;
1368 remove_dentry(dst, w->lookup_table);
1370 /* Destination does not exist */
1371 parent_of_dst = get_parent_dentry(w, to);
1375 if (!dentry_is_directory(parent_of_dst))
1379 FREE(src->file_name);
1380 FREE(src->file_name_utf8);
1381 src->file_name = file_name_utf16;
1382 src->file_name_utf8 = file_name_utf8;
1383 src->file_name_len = file_name_utf16_len;
1384 src->file_name_utf8_len = file_name_utf8_len;
1387 link_dentry(src, parent_of_dst);
1391 /* Remove a directory */
1392 static int wimfs_rmdir(const char *path)
1394 struct dentry *dentry;
1396 dentry = get_dentry(w, path);
1400 if (!dentry_is_empty_directory(dentry))
1403 unlink_dentry(dentry);
1404 if (dentry->num_times_opened == 0)
1405 free_dentry(dentry);
1409 static int wimfs_setxattr(const char *path, const char *name,
1410 const char *value, size_t size, int flags)
1416 static int wimfs_symlink(const char *to, const char *from)
1418 struct dentry *dentry_parent, *dentry;
1419 const char *link_name;
1420 struct lookup_table_entry *lte;
1422 dentry_parent = get_parent_dentry(w, from);
1425 if (!dentry_is_directory(dentry_parent))
1428 link_name = path_basename(from);
1430 if (get_dentry_child_with_name(dentry_parent, link_name))
1432 dentry = new_dentry(link_name);
1436 dentry->attributes = FILE_ATTRIBUTE_REPARSE_POINT;
1437 dentry->reparse_tag = WIM_IO_REPARSE_TAG_SYMLINK;
1438 dentry->hard_link = next_link_group_id++;
1440 if (dentry_set_symlink(dentry, to, w->lookup_table, <e) != 0)
1441 goto out_free_dentry;
1445 dentry->ads_entries[1].lte_group_list.type = STREAM_TYPE_ADS;
1446 list_add(&dentry->ads_entries[1].lte_group_list.list,
1447 <e->lte_group_list);
1448 wimlib_assert(dentry->resolved);
1450 link_dentry(dentry, dentry_parent);
1453 free_dentry(dentry);
1458 /* Reduce the size of a file */
1459 static int wimfs_truncate(const char *path, off_t size)
1461 struct dentry *dentry;
1462 struct lookup_table_entry *lte;
1464 unsigned stream_idx;
1466 ret = lookup_resource(w, path, get_lookup_flags(), &dentry,
1472 if (!lte) /* Already a zero-length file */
1475 if (lte->staging_file_name) {
1476 ret = truncate(lte->staging_file_name, size);
1479 lte->resource_entry.original_size = size;
1481 /* File in WIM. Extract it to the staging directory, but only
1482 * the first @size bytes of it. */
1483 ret = extract_resource_to_staging_dir(dentry, stream_idx,
1486 dentry_update_all_timestamps(dentry);
1490 /* Remove a regular file */
1491 static int wimfs_unlink(const char *path)
1493 struct dentry *dentry;
1494 struct lookup_table_entry *lte;
1497 unsigned stream_idx;
1499 ret = lookup_resource(w, path, get_lookup_flags(), &dentry,
1505 if (stream_idx == 0) {
1506 /* We are removing the full dentry including all alternate data
1508 remove_dentry(dentry, w->lookup_table);
1510 /* We are removing an alternate data stream. */
1511 struct ads_entry *ads_entry;
1513 ads_entry = &dentry->ads_entries[stream_idx - 1];
1514 lte = lte_decrement_refcnt(lte, w->lookup_table);
1516 list_del(&ads_entry->lte_group_list.list);
1517 dentry_remove_ads(dentry, ads_entry);
1519 /* Beware: The lookup table entry(s) may still be referenced by users
1520 * that have opened the corresponding streams. They are freed later in
1521 * wimfs_release() when the last file user has closed the stream. */
1526 * Change the timestamp on a file dentry.
1528 * Note that alternate data streams do not have their own timestamps.
1530 static int wimfs_utimens(const char *path, const struct timespec tv[2])
1532 struct dentry *dentry = get_dentry(w, path);
1535 if (tv[0].tv_nsec != UTIME_OMIT) {
1536 if (tv[0].tv_nsec == UTIME_NOW)
1537 dentry->last_access_time = get_wim_timestamp();
1539 dentry->last_access_time = timespec_to_wim_timestamp(&tv[0]);
1541 if (tv[1].tv_nsec != UTIME_OMIT) {
1542 if (tv[1].tv_nsec == UTIME_NOW)
1543 dentry->last_write_time = get_wim_timestamp();
1545 dentry->last_write_time = timespec_to_wim_timestamp(&tv[1]);
1550 /* Writes to a file in the WIM filesystem.
1551 * It may be an alternate data stream, but here we don't even notice because we
1552 * just get a lookup table entry. */
1553 static int wimfs_write(const char *path, const char *buf, size_t size,
1554 off_t offset, struct fuse_file_info *fi)
1556 struct wimlib_fd *fd = (struct wimlib_fd*)fi->fh;
1560 wimlib_assert(fd->lte);
1561 wimlib_assert(fd->lte->staging_file_name);
1562 wimlib_assert(fd->staging_fd != -1);
1564 /* Seek to the requested position */
1565 if (lseek(fd->staging_fd, offset, SEEK_SET) == -1)
1568 /* Write the data. */
1569 ret = write(fd->staging_fd, buf, size);
1576 static struct fuse_operations wimfs_operations = {
1577 .access = wimfs_access,
1578 .destroy = wimfs_destroy,
1579 .fallocate = wimfs_fallocate,
1580 .fgetattr = wimfs_fgetattr,
1581 .ftruncate = wimfs_ftruncate,
1582 .getattr = wimfs_getattr,
1583 .getxattr = wimfs_getxattr,
1585 .listxattr = wimfs_listxattr,
1586 .mkdir = wimfs_mkdir,
1587 .mknod = wimfs_mknod,
1589 .opendir = wimfs_opendir,
1591 .readdir = wimfs_readdir,
1592 .readlink = wimfs_readlink,
1593 .release = wimfs_release,
1594 .releasedir = wimfs_releasedir,
1595 .removexattr = wimfs_removexattr,
1596 .rename = wimfs_rename,
1597 .rmdir = wimfs_rmdir,
1598 .setxattr = wimfs_setxattr,
1599 .symlink = wimfs_symlink,
1600 .truncate = wimfs_truncate,
1601 .unlink = wimfs_unlink,
1602 .utimens = wimfs_utimens,
1603 .write = wimfs_write,
1607 static int check_lte_refcnt(struct lookup_table_entry *lte, void *ignore)
1609 size_t lte_group_size = 0;
1610 struct list_head *cur;
1611 list_for_each(cur, <e->lte_group_list)
1613 if (lte_group_size > lte->refcnt) {
1614 #ifdef ENABLE_ERROR_MESSAGES
1615 ERROR("The following lookup table entry has a reference count "
1616 "of %u, but", lte->refcnt);
1617 ERROR("We found %u references to it", lte_group_size);
1618 print_lookup_table_entry(lte);
1620 return WIMLIB_ERR_INVALID_DENTRY;
1625 /* Mounts a WIM file. */
1626 WIMLIBAPI int wimlib_mount(WIMStruct *wim, int image, const char *dir,
1634 DEBUG("Mount: wim = %p, image = %d, dir = %s, flags = %d, ",
1635 wim, image, dir, flags);
1638 return WIMLIB_ERR_INVALID_PARAM;
1640 ret = wimlib_select_image(wim, image);
1645 DEBUG("Selected image %d", image);
1647 next_link_group_id = assign_link_groups(wim->image_metadata[image - 1].lgt);
1649 /* Resolve all the lookup table entries of the dentry tree */
1650 for_dentry_in_tree(wim_root_dentry(wim), dentry_resolve_ltes,
1653 ret = for_lookup_table_entry(wim->lookup_table, check_lte_refcnt, NULL);
1657 if (flags & WIMLIB_MOUNT_FLAG_READWRITE)
1658 wim_get_current_image_metadata(wim)->modified = true;
1660 if (!(flags & (WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_NONE |
1661 WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR |
1662 WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS)))
1663 flags |= WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR;
1666 working_directory = getcwd(NULL, 0);
1667 if (!working_directory) {
1668 ERROR_WITH_ERRNO("Could not determine current directory");
1669 return WIMLIB_ERR_NOTDIR;
1674 return WIMLIB_ERR_NOMEM;
1676 argv[argc++] = "imagex";
1678 argv[argc++] = "-s"; /* disable multi-threaded operation */
1680 if (flags & WIMLIB_MOUNT_FLAG_DEBUG)
1681 argv[argc++] = "-d";
1684 * We provide the use_ino option because we are going to assign inode
1685 * numbers oursides. We've already numbered the hard link groups with
1686 * unique numbers with the assign_link_groups() function, and the static
1687 * variable next_link_group_id is set to the next available link group
1688 * ID that we will assign to new dentries.
1690 char optstring[256] = "use_ino";
1691 argv[argc++] = "-o";
1692 argv[argc++] = optstring;
1693 if ((flags & WIMLIB_MOUNT_FLAG_READWRITE)) {
1694 /* Read-write mount. Make the staging directory */
1696 if (!staging_dir_name) {
1698 return WIMLIB_ERR_MKDIR;
1701 /* Read-only mount */
1702 strcat(optstring, ",ro");
1709 DEBUG("FUSE command line (argc = %d): ", argc);
1710 for (i = 0; i < argc; i++) {
1711 fputs(argv[i], stdout);
1719 /* Set static variables. */
1721 mount_flags = flags;
1723 ret = fuse_main(argc, argv, &wimfs_operations, NULL);
1725 return (ret == 0) ? 0 : WIMLIB_ERR_FUSE;
1730 * Unmounts the WIM file that was previously mounted on @dir by using
1733 WIMLIBAPI int wimlib_unmount(const char *dir, int flags)
1740 struct timespec timeout;
1744 /* Execute `fusermount -u', which is installed setuid root, to unmount
1747 * FUSE does not yet implement synchronous unmounts. This means that
1748 * fusermount -u will return before the filesystem daemon returns from
1749 * wimfs_destroy(). This is partly what we want, because we need to
1750 * send a message from this process to the filesystem daemon telling
1751 * whether --commit was specified or not. However, after that, the
1752 * unmount process must wait for the filesystem daemon to finish writing
1759 ERROR_WITH_ERRNO("Failed to fork()");
1760 return WIMLIB_ERR_FORK;
1763 execlp("fusermount", "fusermount", "-u", dir, NULL);
1764 ERROR_WITH_ERRNO("Failed to execute `fusermount'");
1765 return WIMLIB_ERR_FUSERMOUNT;
1768 ret = waitpid(pid, &status, 0);
1770 ERROR_WITH_ERRNO("Failed to wait for fusermount process to "
1772 return WIMLIB_ERR_FUSERMOUNT;
1776 ERROR("fusermount exited with status %d", status);
1777 return WIMLIB_ERR_FUSERMOUNT;
1780 /* Open message queues between the unmount process and the
1781 * filesystem daemon. */
1782 ret = open_message_queues(false);
1786 /* Send a message to the filesystem saying whether to commit or
1788 msg[0] = (flags & WIMLIB_UNMOUNT_FLAG_COMMIT) ? 1 : 0;
1789 msg[1] = (flags & WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY) ? 1 : 0;
1791 DEBUG("Sending message: %s, %s",
1792 (msg[0] == 0) ? "don't commit" : "commit",
1793 (msg[1] == 0) ? "don't check" : "check");
1794 ret = mq_send(unmount_to_daemon_mq, msg, 2, 1);
1796 ERROR("Failed to notify filesystem daemon whether we want to "
1797 "commit changes or not");
1798 close_message_queues();
1799 return WIMLIB_ERR_MQUEUE;
1802 /* Wait for a message from the filesytem daemon indicating whether the
1803 * filesystem was unmounted successfully (0) or an error occurred (1).
1804 * This may take a long time if a big WIM file needs to be rewritten. */
1806 /* Wait at most 600??? seconds before giving up and returning false.
1807 * Either it's a really big WIM file, or (more likely) the
1808 * filesystem daemon has crashed or failed for some reason.
1810 * XXX come up with some method to determine if the filesystem
1811 * daemon has really crashed or not.
1813 * XXX Idea: have mount daemon write its PID into the WIM file header?
1816 gettimeofday(&now, NULL);
1817 timeout.tv_sec = now.tv_sec + 600;
1818 timeout.tv_nsec = now.tv_usec * 1000;
1820 msgsize = mq_get_msgsize(daemon_to_unmount_mq);
1821 char mailbox[msgsize];
1824 DEBUG("Waiting for message telling us whether the unmount was "
1825 "successful or not.");
1826 ret = mq_timedreceive(daemon_to_unmount_mq, mailbox, msgsize,
1829 close_message_queues();
1831 if (errno_save == ETIMEDOUT) {
1832 ERROR("Timed out- probably the filesystem daemon "
1833 "crashed and the WIM was not written "
1835 return WIMLIB_ERR_TIMEOUT;
1837 ERROR("mq_receive(): %s", strerror(errno_save));
1838 return WIMLIB_ERR_MQUEUE;
1842 DEBUG("Received message: %s",
1843 (mailbox[0] == 0) ? "Unmount OK" : "Unmount Failed");
1844 if (mailbox[0] != 0)
1845 ERROR("Unmount failed");
1849 #else /* WITH_FUSE */
1852 static inline int mount_unsupported_error()
1854 ERROR("WIMLIB was compiled with --without-fuse, which disables support "
1855 "for mounting WIMs.");
1856 return WIMLIB_ERR_UNSUPPORTED;
1859 WIMLIBAPI int wimlib_unmount(const char *dir, int flags)
1861 return mount_unsupported_error();
1864 WIMLIBAPI int wimlib_mount(WIMStruct *wim_p, int image, const char *dir,
1867 return mount_unsupported_error();
1870 #endif /* WITH_FUSE */