]> wimlib.net Git - wimlib/blobdiff - src/mount_image.c
Ugly hack
[wimlib] / src / mount_image.c
index b3ae030da0a4c0c875beeb6304a71925ed46d98f..090a828026e95e197180cf96bd8f4513125a9208 100644 (file)
@@ -291,7 +291,7 @@ static int create_dentry(struct wimfs_context *ctx, const char *path,
 
        new = new_dentry_with_inode(basename);
        if (!new)
-               return -ENOMEM;
+               return -errno;
 
        new->d_inode->resolved = 1;
        new->d_inode->ino = ctx->next_ino++;
@@ -1389,46 +1389,53 @@ static int execute_fusermount(const char *dir)
        }
 
        /* Parent */
-       ret = wait(&status);
+       ret = waitpid(pid, &status, 0);
        if (ret == -1) {
                ERROR_WITH_ERRNO("Failed to wait for fusermount process to "
                                 "terminate");
                return WIMLIB_ERR_FUSERMOUNT;
        }
 
-       if (status != 0) {
-               if (status == WIMLIB_ERR_FUSERMOUNT)
-                       ERROR("Could not find the `fusermount' program");
-               else
-                       ERROR("fusermount exited with status %d", status);
+       if (!WIFEXITED(status)) {
+               ERROR("'fusermount' did not terminate normally!");
+               return WIMLIB_ERR_FUSERMOUNT;
+       }
 
-               /* Try again, but with the `umount' program.  This is required
-                * on other FUSE implementations such as FreeBSD's that do not
-                * have a `fusermount' program. */
+       status = WEXITSTATUS(status);
 
-               pid = fork();
-               if (pid == -1) {
-                       ERROR_WITH_ERRNO("Failed to fork()");
-                       return WIMLIB_ERR_FORK;
-               }
-               if (pid == 0) {
-                       /* Child */
-                       execlp("umount", "umount", dir, NULL);
-                       ERROR_WITH_ERRNO("Failed to execute `umount'");
-                       exit(WIMLIB_ERR_FUSERMOUNT);
-               }
+       if (status == 0)
+               return 0;
 
-               /* Parent */
-               ret = wait(&status);
-               if (ret == -1) {
-                       ERROR_WITH_ERRNO("Failed to wait for `umount' process to "
-                                        "terminate");
-                       return WIMLIB_ERR_FUSERMOUNT;
-               }
-               if (status != 0) {
-                       ERROR("`umount' exited with failure status");
-                       return WIMLIB_ERR_FUSERMOUNT;
-               }
+       if (status != WIMLIB_ERR_FUSERMOUNT)
+               return WIMLIB_ERR_FUSERMOUNT;
+
+       /* Try again, but with the `umount' program.  This is required on other
+        * FUSE implementations such as FreeBSD's that do not have a
+        * `fusermount' program. */
+       ERROR("Falling back to 'umount'.  Note: you may need to be "
+             "root for this to work");
+       pid = fork();
+       if (pid == -1) {
+               ERROR_WITH_ERRNO("Failed to fork()");
+               return WIMLIB_ERR_FORK;
+       }
+       if (pid == 0) {
+               /* Child */
+               execlp("umount", "umount", dir, NULL);
+               ERROR_WITH_ERRNO("Failed to execute `umount'");
+               exit(WIMLIB_ERR_FUSERMOUNT);
+       }
+
+       /* Parent */
+       ret = waitpid(pid, &status, 0);
+       if (ret == -1) {
+               ERROR_WITH_ERRNO("Failed to wait for `umount' process to "
+                                "terminate");
+               return WIMLIB_ERR_FUSERMOUNT;
+       }
+       if (status != 0) {
+               ERROR("`umount' did not successfully complete");
+               return WIMLIB_ERR_FUSERMOUNT;
        }
        return 0;
 }
@@ -1602,7 +1609,7 @@ static int wimfs_link(const char *to, const char *from)
                return -EEXIST;
        from_dentry = new_dentry(link_name);
        if (!from_dentry)
-               return -ENOMEM;
+               return -errno;
 
        inode_add_dentry(from_dentry, inode);
        from_dentry->d_inode = inode;
@@ -2363,6 +2370,9 @@ WIMLIBAPI int wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
                goto out;
        }
 
+       if (imd->inode_list.first)
+               imd->inode_list.first->pprev = &imd->inode_list.first;
+
        if (imd->modified) {
                ERROR("Cannot mount image that was added "
                      "with wimlib_add_image()");