]> wimlib.net Git - wimlib/blobdiff - src/mount_image.c
Add more comments
[wimlib] / src / mount_image.c
index 4700cb5207a5f38c3726e3582df152d46d7bb128..a2e09b435e43a60a72db289e0839c747315ceeaa 100644 (file)
@@ -99,7 +99,7 @@ struct wimfs_context {
        u64 next_ino;
 
        /* List of inodes in the mounted image */
-       struct hlist_head *image_inode_list;
+       struct list_head *image_inode_list;
 
        /* Name and message queue descriptors for message queues between the
         * filesystem daemon process and the unmount process.  These are used
@@ -346,7 +346,7 @@ create_dentry(struct fuse_context *fuse_ctx, const char *path,
                }
        }
        dentry_add_child(parent, new);
-       hlist_add_head(&new->d_inode->i_hlist, wimfs_ctx->image_inode_list);
+       list_add_tail(&new->d_inode->i_list, wimfs_ctx->image_inode_list);
        if (dentry_ret)
                *dentry_ret = new;
        return 0;
@@ -642,26 +642,13 @@ extract_resource_to_staging_dir(struct wim_inode *inode,
                }
        }
 
-       new_lte->refcnt            = inode->i_nlink;
-       new_lte->resource_location = RESOURCE_IN_STAGING_FILE;
-       new_lte->staging_file_name = staging_file_name;
-       new_lte->lte_inode         = inode;
+       new_lte->refcnt                       = inode->i_nlink;
+       new_lte->resource_location            = RESOURCE_IN_STAGING_FILE;
+       new_lte->staging_file_name            = staging_file_name;
+       new_lte->resource_entry.original_size = size;
 
-       struct wim_lookup_table_entry **my_ptr;
-
-       if (stream_id == 0) {
-               my_ptr = &inode->i_lte;
-       } else {
-               for (u16 i = 0; ; i++) {
-                       wimlib_assert(i < inode->i_num_ads);
-                       if (inode->i_ads_entries[i].stream_id == stream_id) {
-                               my_ptr = &inode->i_ads_entries[i].lte;
-                               break;
-                       }
-               }
-       }
-
-       lookup_table_insert_unhashed(ctx->wim->lookup_table, new_lte, my_ptr);
+       lookup_table_insert_unhashed(ctx->wim->lookup_table, new_lte,
+                                    inode, stream_id);
        *lte = new_lte;
        return 0;
 out_revert_fd_changes:
@@ -807,16 +794,21 @@ rebuild_wim(struct wimfs_context *ctx, int write_flags,
        struct wim_image_metadata *imd = wim_get_current_image_metadata(ctx->wim);
 
        DEBUG("Closing all staging file descriptors.");
-       list_for_each_entry_safe(lte, tmp, &imd->unhashed_streams, staging_list) {
-               ret = inode_close_fds(lte->lte_inode);
+       image_for_each_unhashed_stream_safe(lte, tmp, imd) {
+               ret = inode_close_fds(lte->back_inode);
                if (ret)
                        return ret;
        }
 
        DEBUG("Freeing entries for zero-length streams");
-       list_for_each_entry_safe(lte, tmp, &imd->unhashed_streams, staging_list) {
+       image_for_each_unhashed_stream_safe(lte, tmp, imd) {
+               wimlib_assert(lte->unhashed);
                if (wim_resource_size(lte) == 0) {
-                       *lte->my_ptr = NULL;
+                       print_lookup_table_entry(lte, stderr);
+                       struct wim_lookup_table_entry **back_ptr;
+                       back_ptr = retrieve_lte_pointer(lte);
+                       *back_ptr = NULL;
+                       list_del(&lte->unhashed_list);
                        free_lookup_table_entry(lte);
                }
        }
@@ -1671,9 +1663,7 @@ wimfs_link(const char *to, const char *from)
        struct wim_dentry *from_dentry, *from_dentry_parent;
        const char *link_name;
        struct wim_inode *inode;
-       struct wim_lookup_table_entry *lte;
        WIMStruct *w = wimfs_get_WIMStruct();
-       u16 i;
        int ret;
 
        inode = wim_pathname_to_inode(w, to);
@@ -1698,15 +1688,10 @@ wimfs_link(const char *to, const char *from)
        if (ret)
                return -ENOMEM;
 
-       inode_add_dentry(from_dentry, inode);
-       from_dentry->d_inode = inode;
        inode->i_nlink++;
-
-       for (i = 0; i <= inode->i_num_ads; i++) {
-               lte = inode_stream_lte_resolved(inode, i);
-               if (lte)
-                       lte->refcnt++;
-       }
+       inode_ref_streams(inode);
+       from_dentry->d_inode = inode;
+       inode_add_dentry(from_dentry, inode);
        dentry_add_child(from_dentry_parent, from_dentry);
        return 0;
 }
@@ -1820,6 +1805,7 @@ wimfs_open(const char *path, struct fuse_file_info *fi)
        u16 stream_idx;
        u32 stream_id;
        struct wimfs_context *ctx = wimfs_get_context();
+       struct wim_lookup_table_entry **back_ptr;
 
        ret = lookup_resource(ctx->wim, path, get_lookup_flags(ctx),
                              &dentry, &lte, &stream_idx);
@@ -1828,10 +1814,13 @@ wimfs_open(const char *path, struct fuse_file_info *fi)
 
        inode = dentry->d_inode;
 
-       if (stream_idx == 0)
+       if (stream_idx == 0) {
                stream_id = 0;
-       else
+               back_ptr = &inode->i_lte;
+       } else {
                stream_id = inode->i_ads_entries[stream_idx - 1].stream_id;
+               back_ptr = &inode->i_ads_entries[stream_idx - 1].lte;
+       }
 
        /* The file resource may be in the staging directory (read-write mounts
         * only) or in the WIM.  If it's in the staging directory, we need to
@@ -1847,7 +1836,9 @@ wimfs_open(const char *path, struct fuse_file_info *fi)
                                                      &lte, size, ctx);
                if (ret != 0)
                        return ret;
+               *back_ptr = lte;
        }
+       print_lookup_table_entry(lte, stderr);
 
        ret = alloc_wimfs_fd(inode, stream_id, lte, &fd,
                             wimfs_ctx_readonly(ctx));
@@ -2216,24 +2207,23 @@ wimfs_truncate(const char *path, off_t size)
        if (lte == NULL && size == 0)
                return 0;
 
-       inode = dentry->d_inode;
-       if (stream_idx == 0)
-               stream_id = 0;
-       else
-               stream_id = inode->i_ads_entries[stream_idx - 1].stream_id;
-
        if (lte->resource_location == RESOURCE_IN_STAGING_FILE) {
                ret = truncate(lte->staging_file_name, size);
-               if (ret != 0)
+               if (ret)
                        ret = -errno;
+               else
+                       lte->resource_entry.original_size = size;
        } else {
                /* File in WIM.  Extract it to the staging directory, but only
                 * the first @size bytes of it. */
+               inode = dentry->d_inode;
+               if (stream_idx == 0)
+                       stream_id = 0;
+               else
+                       stream_id = inode->i_ads_entries[stream_idx - 1].stream_id;
                ret = extract_resource_to_staging_dir(inode, stream_id,
                                                      &lte, size, ctx);
        }
-       if (ret == 0)
-               lte->resource_entry.original_size = size;
        return ret;
 }
 
@@ -2336,8 +2326,12 @@ wimfs_write(const char *path, const char *buf, size_t size,
                return -errno;
 
        /* Update file size */
-       if (offset + size > fd->f_lte->resource_entry.original_size)
+       if (offset + size > fd->f_lte->resource_entry.original_size) {
+               DEBUG("Update file size %"PRIu64 " => %"PRIu64"",
+                     fd->f_lte->resource_entry.original_size,
+                     offset + size);
                fd->f_lte->resource_entry.original_size = offset + size;
+       }
 
        /* Update timestamps */
        touch_inode(fd->f_inode);
@@ -2418,7 +2412,6 @@ wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
        struct wim_lookup_table *joined_tab, *wim_tab_save;
        struct wim_image_metadata *imd;
        struct wimfs_context ctx;
-       struct hlist_node *cur_node;
        struct wim_inode *inode;
 
        DEBUG("Mount: wim = %p, image = %d, dir = %s, flags = %d, ",
@@ -2428,7 +2421,7 @@ wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
                return WIMLIB_ERR_INVALID_PARAM;
 
        ret = verify_swm_set(wim, additional_swms, num_additional_swms);
-       if (ret != 0)
+       if (ret)
                return ret;
 
        if ((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) && (wim->hdr.total_parts != 1)) {
@@ -2440,7 +2433,7 @@ wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
                ret = new_joined_lookup_table(wim, additional_swms,
                                              num_additional_swms,
                                              &joined_tab);
-               if (ret != 0)
+               if (ret)
                        return ret;
                wim_tab_save = wim->lookup_table;
                wim->lookup_table = joined_tab;
@@ -2448,12 +2441,16 @@ wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
 
        if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
                ret = wim_run_full_verifications(wim);
-               if (ret != 0)
+               if (ret)
                        goto out;
        }
 
+       ret = wim_checksum_unhashed_streams(wim);
+       if (ret)
+               goto out;
+
        ret = select_wim_image(wim, image);
-       if (ret != 0)
+       if (ret)
                goto out;
 
        DEBUG("Selected image %d", image);
@@ -2476,7 +2473,7 @@ wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
 
        if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
                ret = lock_wim(wim, wim->fp);
-               if (ret != 0)
+               if (ret)
                        goto out;
        }
 
@@ -2486,7 +2483,6 @@ wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
                       WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS)))
                mount_flags |= WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR;
 
-
        DEBUG("Initializing struct wimfs_context");
        init_wimfs_context(&ctx);
        ctx.wim = wim;
@@ -2494,12 +2490,14 @@ wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
        ctx.image_inode_list = &imd->inode_list;
        ctx.default_uid = getuid();
        ctx.default_gid = getgid();
+       wimlib_assert(list_empty(&imd->unhashed_streams));
+       ctx.wim->lookup_table->unhashed_streams = &imd->unhashed_streams;
        if (mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS)
                ctx.default_lookup_flags = LOOKUP_FLAG_ADS_OK;
 
        DEBUG("Unlinking message queues in case they already exist");
        ret = set_message_queue_names(&ctx, dir);
-       if (ret != 0)
+       if (ret)
                goto out_unlock;
        unlink_message_queues(&ctx);
 
@@ -2537,7 +2535,7 @@ wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
        if ((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)) {
                /* Read-write mount.  Make the staging directory */
                ret = make_staging_dir(&ctx, staging_dir);
-               if (ret != 0)
+               if (ret)
                        goto out_free_dir_copy;
        } else {
                /* Read-only mount */
@@ -2570,7 +2568,7 @@ wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
         * assign inode numbers */
        DEBUG("Resolving lookup table entries and assigning inode numbers");
        ctx.next_ino = 1;
-       hlist_for_each_entry(inode, cur_node, &imd->inode_list, i_hlist) {
+       image_for_each_inode(inode, imd) {
                inode_resolve_ltes(inode, wim->lookup_table);
                inode->i_ino = ctx.next_ino++;
        }