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 calculate_sha1sum_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];
782 ret = sha1sum(lte->staging_file_name, hash);
786 lookup_table_unlink(table, lte);
787 copy_hash(lte->hash, hash);
789 duplicate_lte = __lookup_resource(table, hash);
792 /* Merge duplicate lookup table entries */
794 lte_list_change_lte_ptr(lte, duplicate_lte);
795 duplicate_lte->refcnt += lte->refcnt;
796 list_splice(&duplicate_lte->lte_group_list,
797 <e->lte_group_list);
799 free_lookup_table_entry(lte);
801 lookup_table_insert(table, lte);
807 /* Overwrites the WIM file, with changes saved. */
808 static int rebuild_wim(WIMStruct *w, bool check_integrity)
811 struct lookup_table_entry *lte, *tmp;
813 /* Close all the staging file descriptors. */
814 DEBUG("Closing all staging file descriptors.");
815 list_for_each_entry(lte, &staging_list, staging_list) {
816 ret = close_lte_fds(lte);
821 /* Calculate SHA1 checksums for all staging files, and merge unnecessary
822 * lookup table entries. */
823 DEBUG("Calculating SHA1 checksums for all new staging files.");
824 list_for_each_entry_safe(lte, tmp, &staging_list, staging_list) {
825 ret = calculate_sha1sum_of_staging_file(lte, w->lookup_table);
832 xml_update_image_info(w, w->current_image);
834 ret = wimlib_overwrite(w, check_integrity);
836 ERROR("Failed to commit changes");
842 /* Called when the filesystem is unmounted. */
843 static void wimfs_destroy(void *p)
845 /* For read-write mounts, the `imagex unmount' command, which is
846 * running in a separate process and is executing the
847 * wimlib_unmount() function, will send this process a byte
848 * through a message queue that indicates whether the --commit
849 * option was specified or not. */
852 struct timespec timeout;
854 ssize_t bytes_received;
857 char check_integrity;
860 ret = open_message_queues(true);
864 msgsize = mq_get_msgsize(unmount_to_daemon_mq);
869 /* Wait at most 3 seconds before giving up and discarding changes. */
870 gettimeofday(&now, NULL);
871 timeout.tv_sec = now.tv_sec + 3;
872 timeout.tv_nsec = now.tv_usec * 1000;
873 DEBUG("Waiting for message telling us whether to commit or not, and "
874 "whether to include integrity checks.");
876 bytes_received = mq_timedreceive(unmount_to_daemon_mq, msg,
877 msgsize, NULL, &timeout);
879 check_integrity = msg[1];
880 if (bytes_received == -1) {
881 if (errno == ETIMEDOUT) {
884 ERROR_WITH_ERRNO("mq_timedreceive()");
886 ERROR("Not committing.");
888 DEBUG("Received message: [%d %d]", msg[0], msg[1]);
892 if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
894 status = chdir(working_directory);
896 ERROR_WITH_ERRNO("chdir()");
897 status = WIMLIB_ERR_NOTDIR;
900 status = rebuild_wim(w, (check_integrity != 0));
902 ret = delete_staging_dir();
904 ERROR_WITH_ERRNO("Failed to delete the staging "
910 DEBUG("Read-only mount");
913 DEBUG("Sending status %u", status);
914 ret = mq_send(daemon_to_unmount_mq, &status, 1, 1);
916 ERROR_WITH_ERRNO("Failed to send status to unmount process");
917 close_message_queues();
920 static int wimfs_fallocate(const char *path, int mode,
921 off_t offset, off_t len, struct fuse_file_info *fi)
923 struct wimlib_fd *fd = (struct wimlib_fd*)fi->fh;
924 wimlib_assert(fd->staging_fd != -1);
925 return fallocate(fd->staging_fd, mode, offset, len);
928 static int wimfs_fgetattr(const char *path, struct stat *stbuf,
929 struct fuse_file_info *fi)
931 struct wimlib_fd *fd = (struct wimlib_fd*)fi->fh;
932 return dentry_to_stbuf(fd->dentry, stbuf);
935 static int wimfs_ftruncate(const char *path, off_t size,
936 struct fuse_file_info *fi)
938 struct wimlib_fd *fd = (struct wimlib_fd*)fi->fh;
939 int ret = ftruncate(fd->staging_fd, size);
942 fd->lte->resource_entry.original_size = size;
947 * Fills in a `struct stat' that corresponds to a file or directory in the WIM.
949 static int wimfs_getattr(const char *path, struct stat *stbuf)
951 struct dentry *dentry = get_dentry(w, path);
954 return dentry_to_stbuf(dentry, stbuf);
957 static int wimfs_getxattr(const char *path, const char *name, char *value,
964 /* Create a hard link */
965 static int wimfs_link(const char *to, const char *from)
967 struct dentry *to_dentry, *from_dentry, *from_dentry_parent;
968 const char *link_name;
970 to_dentry = get_dentry(w, to);
973 if (!dentry_is_regular_file(to_dentry))
976 from_dentry_parent = get_parent_dentry(w, from);
977 if (!from_dentry_parent)
979 if (!dentry_is_directory(from_dentry_parent))
982 link_name = path_basename(from);
983 if (get_dentry_child_with_name(from_dentry_parent, link_name))
985 from_dentry = clone_dentry(to_dentry);
988 if (change_dentry_name(from_dentry, link_name) != 0) {
993 /* Add the new dentry to the dentry list for the link group */
994 list_add(&from_dentry->link_group_list, &to_dentry->link_group_list);
996 /* Increment reference counts for the unnamed file stream and all
997 * alternate data streams. */
998 if (from_dentry->lte) {
999 list_add(&from_dentry->lte_group_list.list,
1000 &to_dentry->lte_group_list.list);
1001 from_dentry->lte->refcnt++;
1003 for (u16 i = 0; i < from_dentry->num_ads; i++) {
1004 struct ads_entry *ads_entry = &from_dentry->ads_entries[i];
1006 ads_entry->lte->refcnt++;
1009 /* The ADS entries are owned by another dentry. */
1010 from_dentry->ads_entries_status = ADS_ENTRIES_USER;
1012 link_dentry(from_dentry, from_dentry_parent);
1016 static int wimfs_listxattr(const char *path, char *list, size_t size)
1023 * Create a directory in the WIM.
1024 * @mode is currently ignored.
1026 static int wimfs_mkdir(const char *path, mode_t mode)
1028 struct dentry *parent;
1029 struct dentry *newdir;
1030 const char *basename;
1032 parent = get_parent_dentry(w, path);
1036 if (!dentry_is_directory(parent))
1039 basename = path_basename(path);
1040 if (get_dentry_child_with_name(parent, basename))
1043 newdir = new_dentry(basename);
1044 newdir->attributes |= FILE_ATTRIBUTE_DIRECTORY;
1045 newdir->resolved = true;
1046 newdir->hard_link = next_link_group_id++;
1047 link_dentry(newdir, parent);
1052 /* Creates a regular file. */
1053 static int wimfs_mknod(const char *path, mode_t mode, dev_t rdev)
1055 const char *stream_name;
1056 if ((mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS)
1057 && (stream_name = path_stream_name(path))) {
1058 /* Make an alternate data stream */
1059 struct ads_entry *new_entry;
1060 struct dentry *dentry;
1062 dentry = get_dentry(w, path);
1063 if (!dentry || !dentry_is_regular_file(dentry))
1065 if (dentry_get_ads_entry(dentry, stream_name))
1067 new_entry = dentry_add_ads(dentry, stream_name);
1071 struct dentry *dentry, *parent;
1072 const char *basename;
1074 /* Make a normal file (not an alternate data stream) */
1076 /* Make sure that the parent of @path exists and is a directory, and
1077 * that the dentry named by @path does not already exist. */
1078 parent = get_parent_dentry(w, path);
1081 if (!dentry_is_directory(parent))
1084 basename = path_basename(path);
1085 if (get_dentry_child_with_name(parent, path))
1088 dentry = new_dentry(basename);
1091 dentry->resolved = true;
1092 dentry->hard_link = next_link_group_id++;
1093 dentry->lte_group_list.type = STREAM_TYPE_NORMAL;
1094 INIT_LIST_HEAD(&dentry->lte_group_list.list);
1095 link_dentry(dentry, parent);
1102 static int wimfs_open(const char *path, struct fuse_file_info *fi)
1104 struct dentry *dentry;
1105 struct lookup_table_entry *lte;
1108 struct wimlib_fd *fd;
1109 unsigned stream_idx;
1111 ret = lookup_resource(w, path, get_lookup_flags(), &dentry, <e,
1117 /* Empty file with no lookup-table entry. This is fine if it's
1118 * a read-only filesystem. Otherwise we need to create a lookup
1119 * table entry so that we can keep track of the file descriptors
1120 * (this is important in case someone opens the file for
1122 if (!(mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)) {
1127 ret = extract_resource_to_staging_dir(dentry, stream_idx,
1133 ret = alloc_wimlib_fd(lte, &fd);
1137 fd->dentry = dentry;
1139 /* The file resource may be in the staging directory (read-write
1140 * mounts only) or in the WIM. If it's in the staging
1141 * directory, we need to open a native file descriptor for the
1142 * corresponding file. Otherwise, we can read the file resource
1143 * directly from the WIM file if we are opening it read-only,
1144 * but we need to extract the resource to the staging directory
1145 * if we are opening it writable. */
1146 if (flags_writable(fi->flags) && !lte->staging_file_name) {
1147 ret = extract_resource_to_staging_dir(dentry, stream_idx, <e,
1148 lte->resource_entry.original_size);
1152 if (lte->staging_file_name) {
1153 fd->staging_fd = open(lte->staging_file_name, fi->flags);
1154 if (fd->staging_fd == -1) {
1155 close_wimlib_fd(fd);
1159 fi->fh = (uint64_t)fd;
1163 /* Opens a directory. */
1164 static int wimfs_opendir(const char *path, struct fuse_file_info *fi)
1166 struct dentry *dentry;
1168 dentry = get_dentry(w, path);
1171 if (!dentry_is_directory(dentry))
1173 dentry->num_times_opened++;
1174 fi->fh = (uint64_t)dentry;
1180 * Read data from a file in the WIM or in the staging directory.
1182 static int wimfs_read(const char *path, char *buf, size_t size,
1183 off_t offset, struct fuse_file_info *fi)
1185 struct wimlib_fd *fd = (struct wimlib_fd*)fi->fh;
1188 /* Empty file with no lookup table entry on read-only mounted
1190 wimlib_assert(!(mount_flags & WIMLIB_MOUNT_FLAG_READWRITE));
1194 wimlib_assert(fd->lte);
1196 if (fd->lte->staging_file_name) {
1197 /* Read from staging file */
1199 wimlib_assert(fd->staging_fd != -1);
1202 DEBUG("Seek to offset %zu", offset);
1204 if (lseek(fd->staging_fd, offset, SEEK_SET) == -1)
1206 ret = read(fd->staging_fd, buf, size);
1213 struct resource_entry *res_entry;
1216 res_entry = &fd->lte->resource_entry;
1218 ctype = wim_resource_compression_type(w, res_entry);
1220 if (offset > res_entry->original_size)
1223 size = min(size, res_entry->original_size - offset);
1225 if (read_resource(w->fp, res_entry->size,
1226 res_entry->original_size,
1227 res_entry->offset, ctype, size,
1234 /* Fills in the entries of the directory specified by @path using the
1235 * FUSE-provided function @filler. */
1236 static int wimfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
1237 off_t offset, struct fuse_file_info *fi)
1239 struct dentry *parent, *child;
1241 parent = (struct dentry*)fi->fh;
1242 wimlib_assert(parent);
1243 child = parent->children;
1245 filler(buf, ".", NULL, 0);
1246 filler(buf, "..", NULL, 0);
1252 if (filler(buf, child->file_name_utf8, NULL, 0))
1254 child = child->next;
1255 } while (child != parent->children);
1260 static int wimfs_readlink(const char *path, char *buf, size_t buf_len)
1262 struct dentry *dentry = get_dentry(w, path);
1266 if (!dentry_is_symlink(dentry))
1269 ret = dentry_readlink(dentry, buf, buf_len, w);
1276 static int wimfs_release(const char *path, struct fuse_file_info *fi)
1279 struct wimlib_fd *fd = (struct wimlib_fd*)fi->fh;
1282 /* Empty file with no lookup table entry on read-only mounted
1284 wimlib_assert(!(mount_flags & WIMLIB_MOUNT_FLAG_READWRITE));
1288 if (flags_writable(fi->flags) && fd->dentry) {
1289 u64 now = get_wim_timestamp();
1290 fd->dentry->last_access_time = now;
1291 fd->dentry->last_write_time = now;
1294 return close_wimlib_fd(fd);
1297 static int wimfs_releasedir(const char *path, struct fuse_file_info *fi)
1299 struct dentry *dentry = (struct dentry *)fi->fh;
1301 wimlib_assert(dentry);
1302 wimlib_assert(dentry->num_times_opened);
1303 if (--dentry->num_times_opened == 0)
1304 free_dentry(dentry);
1308 static int wimfs_removexattr(const char *path, const char *name)
1314 /* Renames a file or directory. See rename (3) */
1315 static int wimfs_rename(const char *from, const char *to)
1319 struct dentry *parent_of_dst;
1320 char *file_name_utf16 = NULL, *file_name_utf8 = NULL;
1321 u16 file_name_utf16_len, file_name_utf8_len;
1324 /* This rename() implementation currently only supports actual files
1325 * (not alternate data streams) */
1327 src = get_dentry(w, from);
1331 dst = get_dentry(w, to);
1334 ret = get_names(&file_name_utf16, &file_name_utf8,
1335 &file_name_utf16_len, &file_name_utf8_len,
1341 /* Destination file exists */
1343 if (src == dst) /* Same file */
1346 if (!dentry_is_directory(src)) {
1347 /* Cannot rename non-directory to directory. */
1348 if (dentry_is_directory(dst))
1351 /* Cannot rename directory to a non-directory or a non-empty
1353 if (!dentry_is_directory(dst))
1355 if (dst->children != NULL)
1358 parent_of_dst = dst->parent;
1359 remove_dentry(dst, w->lookup_table);
1361 /* Destination does not exist */
1362 parent_of_dst = get_parent_dentry(w, to);
1366 if (!dentry_is_directory(parent_of_dst))
1370 FREE(src->file_name);
1371 FREE(src->file_name_utf8);
1372 src->file_name = file_name_utf16;
1373 src->file_name_utf8 = file_name_utf8;
1374 src->file_name_len = file_name_utf16_len;
1375 src->file_name_utf8_len = file_name_utf8_len;
1378 link_dentry(src, parent_of_dst);
1382 /* Remove a directory */
1383 static int wimfs_rmdir(const char *path)
1385 struct dentry *dentry;
1387 dentry = get_dentry(w, path);
1391 if (!dentry_is_empty_directory(dentry))
1394 unlink_dentry(dentry);
1395 if (dentry->num_times_opened == 0)
1396 free_dentry(dentry);
1400 static int wimfs_setxattr(const char *path, const char *name,
1401 const char *value, size_t size, int flags)
1407 static int wimfs_symlink(const char *to, const char *from)
1409 struct dentry *dentry_parent, *dentry;
1410 const char *link_name;
1411 struct lookup_table_entry *lte;
1413 dentry_parent = get_parent_dentry(w, from);
1416 if (!dentry_is_directory(dentry_parent))
1419 link_name = path_basename(from);
1421 if (get_dentry_child_with_name(dentry_parent, link_name))
1423 dentry = new_dentry(link_name);
1427 dentry->attributes = FILE_ATTRIBUTE_REPARSE_POINT;
1428 dentry->reparse_tag = WIM_IO_REPARSE_TAG_SYMLINK;
1429 dentry->hard_link = next_link_group_id++;
1431 if (dentry_set_symlink(dentry, to, w->lookup_table, <e) != 0)
1432 goto out_free_dentry;
1436 dentry->ads_entries[1].lte_group_list.type = STREAM_TYPE_ADS;
1437 list_add(&dentry->ads_entries[1].lte_group_list.list,
1438 <e->lte_group_list);
1439 wimlib_assert(dentry->resolved);
1441 link_dentry(dentry, dentry_parent);
1444 free_dentry(dentry);
1449 /* Reduce the size of a file */
1450 static int wimfs_truncate(const char *path, off_t size)
1452 struct dentry *dentry;
1453 struct lookup_table_entry *lte;
1455 unsigned stream_idx;
1457 ret = lookup_resource(w, path, get_lookup_flags(), &dentry,
1463 if (!lte) /* Already a zero-length file */
1466 if (lte->staging_file_name) {
1467 ret = truncate(lte->staging_file_name, size);
1470 lte->resource_entry.original_size = size;
1472 /* File in WIM. Extract it to the staging directory, but only
1473 * the first @size bytes of it. */
1474 ret = extract_resource_to_staging_dir(dentry, stream_idx,
1477 dentry_update_all_timestamps(dentry);
1481 /* Remove a regular file */
1482 static int wimfs_unlink(const char *path)
1484 struct dentry *dentry;
1485 struct lookup_table_entry *lte;
1488 unsigned stream_idx;
1490 ret = lookup_resource(w, path, get_lookup_flags(), &dentry,
1496 if (stream_idx == 0) {
1497 /* We are removing the full dentry including all alternate data
1499 remove_dentry(dentry, w->lookup_table);
1501 /* We are removing an alternate data stream. */
1502 struct ads_entry *ads_entry;
1504 ads_entry = &dentry->ads_entries[stream_idx - 1];
1505 lte = lte_decrement_refcnt(lte, w->lookup_table);
1507 list_del(&ads_entry->lte_group_list.list);
1508 dentry_remove_ads(dentry, ads_entry);
1510 /* Beware: The lookup table entry(s) may still be referenced by users
1511 * that have opened the corresponding streams. They are freed later in
1512 * wimfs_release() when the last file user has closed the stream. */
1517 * Change the timestamp on a file dentry.
1519 * Note that alternate data streams do not have their own timestamps.
1521 static int wimfs_utimens(const char *path, const struct timespec tv[2])
1523 struct dentry *dentry = get_dentry(w, path);
1526 if (tv[0].tv_nsec != UTIME_OMIT) {
1527 if (tv[0].tv_nsec == UTIME_NOW)
1528 dentry->last_access_time = get_wim_timestamp();
1530 dentry->last_access_time = timespec_to_wim_timestamp(&tv[0]);
1532 if (tv[1].tv_nsec != UTIME_OMIT) {
1533 if (tv[1].tv_nsec == UTIME_NOW)
1534 dentry->last_write_time = get_wim_timestamp();
1536 dentry->last_write_time = timespec_to_wim_timestamp(&tv[1]);
1541 /* Writes to a file in the WIM filesystem.
1542 * It may be an alternate data stream, but here we don't even notice because we
1543 * just get a lookup table entry. */
1544 static int wimfs_write(const char *path, const char *buf, size_t size,
1545 off_t offset, struct fuse_file_info *fi)
1547 struct wimlib_fd *fd = (struct wimlib_fd*)fi->fh;
1551 wimlib_assert(fd->lte);
1552 wimlib_assert(fd->lte->staging_file_name);
1553 wimlib_assert(fd->staging_fd != -1);
1555 /* Seek to the requested position */
1556 if (lseek(fd->staging_fd, offset, SEEK_SET) == -1)
1559 /* Write the data. */
1560 ret = write(fd->staging_fd, buf, size);
1567 static struct fuse_operations wimfs_operations = {
1568 .access = wimfs_access,
1569 .destroy = wimfs_destroy,
1570 .fallocate = wimfs_fallocate,
1571 .fgetattr = wimfs_fgetattr,
1572 .ftruncate = wimfs_ftruncate,
1573 .getattr = wimfs_getattr,
1574 .getxattr = wimfs_getxattr,
1576 .listxattr = wimfs_listxattr,
1577 .mkdir = wimfs_mkdir,
1578 .mknod = wimfs_mknod,
1580 .opendir = wimfs_opendir,
1582 .readdir = wimfs_readdir,
1583 .readlink = wimfs_readlink,
1584 .release = wimfs_release,
1585 .releasedir = wimfs_releasedir,
1586 .removexattr = wimfs_removexattr,
1587 .rename = wimfs_rename,
1588 .rmdir = wimfs_rmdir,
1589 .setxattr = wimfs_setxattr,
1590 .symlink = wimfs_symlink,
1591 .truncate = wimfs_truncate,
1592 .unlink = wimfs_unlink,
1593 .utimens = wimfs_utimens,
1594 .write = wimfs_write,
1598 static int check_lte_refcnt(struct lookup_table_entry *lte, void *ignore)
1600 size_t lte_group_size = 0;
1601 struct list_head *cur;
1602 list_for_each(cur, <e->lte_group_list)
1604 if (lte_group_size > lte->refcnt) {
1605 #ifdef ENABLE_ERROR_MESSAGES
1606 ERROR("The following lookup table entry has a reference count "
1607 "of %u, but", lte->refcnt);
1608 ERROR("We found %u references to it", lte_group_size);
1609 print_lookup_table_entry(lte);
1611 return WIMLIB_ERR_INVALID_DENTRY;
1616 /* Mounts a WIM file. */
1617 WIMLIBAPI int wimlib_mount(WIMStruct *wim, int image, const char *dir,
1625 DEBUG("Mount: wim = %p, image = %d, dir = %s, flags = %d, ",
1626 wim, image, dir, flags);
1629 return WIMLIB_ERR_INVALID_PARAM;
1631 ret = wimlib_select_image(wim, image);
1636 DEBUG("Selected image %d", image);
1638 next_link_group_id = assign_link_groups(wim->image_metadata[image - 1].lgt);
1640 /* Resolve all the lookup table entries of the dentry tree */
1641 for_dentry_in_tree(wim_root_dentry(wim), dentry_resolve_ltes,
1644 ret = for_lookup_table_entry(wim->lookup_table, check_lte_refcnt, NULL);
1648 if (flags & WIMLIB_MOUNT_FLAG_READWRITE)
1649 wim_get_current_image_metadata(wim)->modified = true;
1651 if (!(flags & (WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_NONE |
1652 WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR |
1653 WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS)))
1654 flags |= WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR;
1657 working_directory = getcwd(NULL, 0);
1658 if (!working_directory) {
1659 ERROR_WITH_ERRNO("Could not determine current directory");
1660 return WIMLIB_ERR_NOTDIR;
1665 return WIMLIB_ERR_NOMEM;
1667 argv[argc++] = "mount";
1669 argv[argc++] = "-s"; /* disable multi-threaded operation */
1671 if (flags & WIMLIB_MOUNT_FLAG_DEBUG)
1672 argv[argc++] = "-d";
1675 * We provide the use_ino option because we are going to assign inode
1676 * numbers oursides. We've already numbered the hard link groups with
1677 * unique numbers with the assign_link_groups() function, and the static
1678 * variable next_link_group_id is set to the next available link group
1679 * ID that we will assign to new dentries.
1681 char optstring[256] = "use_ino";
1682 argv[argc++] = "-o";
1683 argv[argc++] = optstring;
1684 if ((flags & WIMLIB_MOUNT_FLAG_READWRITE)) {
1685 /* Read-write mount. Make the staging directory */
1687 if (!staging_dir_name) {
1689 return WIMLIB_ERR_MKDIR;
1692 /* Read-only mount */
1693 strcat(optstring, ",ro");
1700 DEBUG("FUSE command line (argc = %d): ", argc);
1701 for (i = 0; i < argc; i++) {
1702 fputs(argv[i], stdout);
1710 /* Set static variables. */
1712 mount_flags = flags;
1714 ret = fuse_main(argc, argv, &wimfs_operations, NULL);
1716 return (ret == 0) ? 0 : WIMLIB_ERR_FUSE;
1721 * Unmounts the WIM file that was previously mounted on @dir by using
1724 WIMLIBAPI int wimlib_unmount(const char *dir, int flags)
1731 struct timespec timeout;
1735 /* Execute `fusermount -u', which is installed setuid root, to unmount
1738 * FUSE does not yet implement synchronous unmounts. This means that
1739 * fusermount -u will return before the filesystem daemon returns from
1740 * wimfs_destroy(). This is partly what we want, because we need to
1741 * send a message from this process to the filesystem daemon telling
1742 * whether --commit was specified or not. However, after that, the
1743 * unmount process must wait for the filesystem daemon to finish writing
1750 ERROR_WITH_ERRNO("Failed to fork()");
1751 return WIMLIB_ERR_FORK;
1754 execlp("fusermount", "fusermount", "-u", dir, NULL);
1755 ERROR_WITH_ERRNO("Failed to execute `fusermount'");
1756 return WIMLIB_ERR_FUSERMOUNT;
1759 ret = waitpid(pid, &status, 0);
1761 ERROR_WITH_ERRNO("Failed to wait for fusermount process to "
1763 return WIMLIB_ERR_FUSERMOUNT;
1767 ERROR("fusermount exited with status %d", status);
1768 return WIMLIB_ERR_FUSERMOUNT;
1771 /* Open message queues between the unmount process and the
1772 * filesystem daemon. */
1773 ret = open_message_queues(false);
1777 /* Send a message to the filesystem saying whether to commit or
1779 msg[0] = (flags & WIMLIB_UNMOUNT_FLAG_COMMIT) ? 1 : 0;
1780 msg[1] = (flags & WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY) ? 1 : 0;
1782 DEBUG("Sending message: %s, %s",
1783 (msg[0] == 0) ? "don't commit" : "commit",
1784 (msg[1] == 0) ? "don't check" : "check");
1785 ret = mq_send(unmount_to_daemon_mq, msg, 2, 1);
1787 ERROR("Failed to notify filesystem daemon whether we want to "
1788 "commit changes or not");
1789 close_message_queues();
1790 return WIMLIB_ERR_MQUEUE;
1793 /* Wait for a message from the filesytem daemon indicating whether the
1794 * filesystem was unmounted successfully (0) or an error occurred (1).
1795 * This may take a long time if a big WIM file needs to be rewritten. */
1797 /* Wait at most 600??? seconds before giving up and returning false.
1798 * Either it's a really big WIM file, or (more likely) the
1799 * filesystem daemon has crashed or failed for some reason.
1801 * XXX come up with some method to determine if the filesystem
1802 * daemon has really crashed or not.
1804 * XXX Idea: have mount daemon write its PID into the WIM file header?
1807 gettimeofday(&now, NULL);
1808 timeout.tv_sec = now.tv_sec + 600;
1809 timeout.tv_nsec = now.tv_usec * 1000;
1811 msgsize = mq_get_msgsize(daemon_to_unmount_mq);
1812 char mailbox[msgsize];
1815 DEBUG("Waiting for message telling us whether the unmount was "
1816 "successful or not.");
1817 ret = mq_timedreceive(daemon_to_unmount_mq, mailbox, msgsize,
1820 close_message_queues();
1822 if (errno_save == ETIMEDOUT) {
1823 ERROR("Timed out- probably the filesystem daemon "
1824 "crashed and the WIM was not written "
1826 return WIMLIB_ERR_TIMEOUT;
1828 ERROR("mq_receive(): %s", strerror(errno_save));
1829 return WIMLIB_ERR_MQUEUE;
1833 DEBUG("Received message: %s",
1834 (mailbox[0] == 0) ? "Unmount OK" : "Unmount Failed");
1835 if (mailbox[0] != 0)
1836 ERROR("Unmount failed");
1840 #else /* WITH_FUSE */
1843 static inline int mount_unsupported_error()
1845 ERROR("WIMLIB was compiled with --without-fuse, which disables support "
1846 "for mounting WIMs.");
1847 return WIMLIB_ERR_UNSUPPORTED;
1850 WIMLIBAPI int wimlib_unmount(const char *dir, int flags)
1852 return mount_unsupported_error();
1855 WIMLIBAPI int wimlib_mount(WIMStruct *wim_p, int image, const char *dir,
1858 return mount_unsupported_error();
1861 #endif /* WITH_FUSE */