]> wimlib.net Git - wimlib/blobdiff - src/mount_image.c
wimlib_mount_image(): Move "argc = 0"
[wimlib] / src / mount_image.c
index df8d523bf64aa38732689d78c5e0193d6f6f39dc..7006c7e4478cb2cce196732b344402e8c567eea8 100644 (file)
@@ -165,7 +165,8 @@ static int alloc_wimfs_fd(struct wim_inode *inode,
 
        pthread_mutex_lock(&inode->i_mutex);
 
-       DEBUG("Allocating fd for stream ID %u from inode %lx (open = %u, allocated = %u)",
+       DEBUG("Allocating fd for stream ID %u from inode %#"PRIx64" "
+             "(open = %u, allocated = %u)",
              stream_id, inode->i_ino, inode->i_num_opened_fds,
              inode->i_num_allocated_fds);
 
@@ -265,7 +266,7 @@ static int lte_put_fd(struct wim_lookup_table_entry *lte, struct wimfs_fd *fd)
 static int close_wimfs_fd(struct wimfs_fd *fd)
 {
        int ret;
-       DEBUG("Closing fd (inode = %lu, opened = %u, allocated = %u)",
+       DEBUG("Closing fd (ino = %#"PRIx64", opened = %u, allocated = %u)",
              fd->f_inode->i_ino, fd->f_inode->i_num_opened_fds,
              fd->f_inode->i_num_allocated_fds);
        ret = lte_put_fd(fd->f_lte, fd);
@@ -801,7 +802,7 @@ static int rebuild_wim(struct wimfs_context *ctx, int write_flags,
        }
 
        DEBUG("Calculating SHA1 checksums for all new staging files.");
-       list_for_each_entry(lte, &ctx->staging_list, staging_list) {
+       list_for_each_entry_safe(lte, tmp, &ctx->staging_list, staging_list) {
                ret = update_lte_of_staging_file(lte, w->lookup_table);
                if (ret != 0)
                        return ret;
@@ -847,12 +848,9 @@ static int set_message_queue_names(struct wimfs_context *ctx,
                        return WIMLIB_ERR_NOTDIR;
        }
 
-       p = dir_path;
-       while (*p) {
+       for (p = dir_path; *p; p++)
                if (*p == '/')
                        *p = 0xff;
-               p++;
-       }
 
        ctx->unmount_to_daemon_mq_name = strcat_dup(u2d_prefix, dir_path,
                                                    NAME_MAX);
@@ -1560,7 +1558,7 @@ static int wimfs_getxattr(const char *path, const char *name, char *value,
 {
        int ret;
        struct wim_inode *inode;
-       struct ads_entry *ads_entry;
+       struct wim_ads_entry *ads_entry;
        size_t res_size;
        struct wim_lookup_table_entry *lte;
        struct wimfs_context *ctx = wimfs_get_context();
@@ -1612,15 +1610,13 @@ static int wimfs_link(const char *to, const char *from)
        if (!inode)
                return -errno;
 
-       if (inode->i_attributes & FILE_ATTRIBUTE_REPARSE_POINT)
-               return -EEXIST;
-
-       if (inode->i_attributes & FILE_ATTRIBUTE_DIRECTORY)
+       if (inode->i_attributes & (FILE_ATTRIBUTE_DIRECTORY |
+                                  FILE_ATTRIBUTE_REPARSE_POINT))
                return -EPERM;
 
        from_dentry_parent = get_parent_dentry(w, from);
        if (!from_dentry_parent)
-               return -ENOENT;
+               return -errno;
        if (!dentry_is_directory(from_dentry_parent))
                return -ENOTDIR;
 
@@ -1705,7 +1701,7 @@ static int wimfs_mknod(const char *path, mode_t mode, dev_t rdev)
        if ((ctx->mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS)
             && (stream_name = path_stream_name(path))) {
                /* Make an alternate data stream */
-               struct ads_entry *new_entry;
+               struct wim_ads_entry *new_entry;
                struct wim_inode *inode;
 
                char *p = (char*)stream_name - 1;
@@ -1778,7 +1774,7 @@ static int wimfs_open(const char *path, struct fuse_file_info *fi)
        }
 
        ret = alloc_wimfs_fd(inode, stream_id, lte, &fd,
-                             wimfs_ctx_readonly(ctx));
+                            wimfs_ctx_readonly(ctx));
        if (ret != 0)
                return ret;
 
@@ -1835,7 +1831,7 @@ static int wimfs_read(const char *path, char *buf, size_t size,
                wimlib_assert(fd->f_lte->staging_file_name);
                wimlib_assert(fd->staging_fd != -1);
 
-               DEBUG("Seek to offset %zu", offset);
+               DEBUG("Seek to offset %"PRIu64, offset);
 
                if (lseek(fd->staging_fd, offset, SEEK_SET) == -1)
                        return -errno;
@@ -1931,7 +1927,7 @@ static int wimfs_releasedir(const char *path, struct fuse_file_info *fi)
 static int wimfs_removexattr(const char *path, const char *name)
 {
        struct wim_inode *inode;
-       struct ads_entry *ads_entry;
+       struct wim_ads_entry *ads_entry;
        u16 ads_idx;
        struct wimfs_context *ctx = wimfs_get_context();
 
@@ -2001,7 +1997,7 @@ static int wimfs_rename(const char *from, const char *to)
                        return -ENOTDIR;
        }
 
-       ret = set_dentry_name(src, to);
+       ret = set_dentry_name(src, path_basename(to));
        if (ret != 0)
                return -ENOMEM;
        if (dst)
@@ -2036,8 +2032,8 @@ static int wimfs_rmdir(const char *path)
 static int wimfs_setxattr(const char *path, const char *name,
                          const char *value, size_t size, int flags)
 {
-       struct ads_entry *existing_ads_entry;
-       struct ads_entry *new_ads_entry;
+       struct wim_ads_entry *existing_ads_entry;
+       struct wim_ads_entry *new_ads_entry;
        struct wim_lookup_table_entry *existing_lte;
        struct wim_lookup_table_entry *lte;
        struct wim_inode *inode;
@@ -2329,7 +2325,7 @@ WIMLIBAPI int wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
                                 unsigned num_additional_swms,
                                 const char *staging_dir)
 {
-       int argc = 0;
+       int argc;
        char *argv[16];
        int ret;
        char *dir_copy;
@@ -2429,6 +2425,7 @@ WIMLIBAPI int wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
        if (!dir_copy)
                goto out_free_message_queue_names;
 
+       argc = 0;
        argv[argc++] = "imagex";
        argv[argc++] = dir_copy;
 
@@ -2441,7 +2438,7 @@ WIMLIBAPI int wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
 
        /*
         * We provide the use_ino option to the FUSE mount because we are going
-        * to assign inode numbers oursides. */
+        * to assign inode numbers ourselves. */
        char optstring[256] =
                "use_ino"
                ",subtype=wimfs"
@@ -2500,6 +2497,12 @@ WIMLIBAPI int wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
 
        if (ret)
                ret = WIMLIB_ERR_FUSE;
+
+       /* Try to delete the staging directory if a deletion wasn't yet
+        * attempted due to an earlier error */
+       if (ctx.staging_dir_name)
+               delete_staging_dir(&ctx);
+
 out_free_dir_copy:
        FREE(dir_copy);
 out_unlock: