]> wimlib.net Git - wimlib/blobdiff - src/mount.c
Make lookup table use hlist
[wimlib] / src / mount.c
index 68909618596997c14b5c10cb0277b48e25c7d809..25b6bcd5c15548ff0465422d07e7f7ebcdc197c5 100644 (file)
@@ -1039,6 +1039,7 @@ static int wimfs_mkdir(const char *path, mode_t mode)
        newdir = new_dentry(basename);
        newdir->attributes |= FILE_ATTRIBUTE_DIRECTORY;
        newdir->resolved = true;
+       newdir->hard_link = next_link_group_id++;
        link_dentry(newdir, parent);
        return 0;
 }
@@ -1421,10 +1422,13 @@ static int wimfs_symlink(const char *to, const char *from)
 
        dentry->attributes = FILE_ATTRIBUTE_REPARSE_POINT;
        dentry->reparse_tag = WIM_IO_REPARSE_TAG_SYMLINK;
+       dentry->hard_link = next_link_group_id++;
 
        if (dentry_set_symlink(dentry, to, w->lookup_table, &lte) != 0)
                goto out_free_dentry;
 
+       wimlib_assert(lte);
+
        dentry->ads_entries[1].lte_group_list.type = STREAM_TYPE_ADS;
        list_add(&dentry->ads_entries[1].lte_group_list.list,
                 &lte->lte_group_list);
@@ -1580,6 +1584,24 @@ static struct fuse_operations wimfs_operations = {
 };
 
 
+static int check_lte_refcnt(struct lookup_table_entry *lte, void *ignore)
+{
+       size_t lte_group_size = 0;
+       struct list_head *cur;
+       list_for_each(cur, &lte->lte_group_list)
+               lte_group_size++;
+       if (lte_group_size > lte->refcnt) {
+#ifdef ENABLE_ERROR_MESSAGES
+               ERROR("The following lookup table entry has a reference count "
+                     "of %u, but", lte->refcnt);
+               ERROR("We found %u references to it", lte_group_size);
+               print_lookup_table_entry(lte, NULL);
+#endif
+               return WIMLIB_ERR_INVALID_DENTRY;
+       }
+       return 0;
+}
+
 /* Mounts a WIM file. */
 WIMLIBAPI int wimlib_mount(WIMStruct *wim, int image, const char *dir, 
                           int flags)
@@ -1608,6 +1630,10 @@ WIMLIBAPI int wimlib_mount(WIMStruct *wim, int image, const char *dir,
        for_dentry_in_tree(wim_root_dentry(wim), dentry_resolve_ltes,
                           wim->lookup_table);
 
+       ret = for_lookup_table_entry(wim->lookup_table, check_lte_refcnt, NULL);
+       if (ret != 0)
+               return ret;
+
        if (flags & WIMLIB_MOUNT_FLAG_READWRITE)
                wim_get_current_image_metadata(wim)->modified = true;
 
@@ -1762,7 +1788,10 @@ WIMLIBAPI int wimlib_unmount(const char *dir, int flags)
         * filesystem daemon has crashed or failed for some reason.
         *
         * XXX come up with some method to determine if the filesystem
-        * daemon has really crashed or not. */
+        * daemon has really crashed or not. 
+        *
+        * XXX Idea: have mount daemon write its PID into the WIM file header?
+        * */
 
        gettimeofday(&now, NULL);
        timeout.tv_sec = now.tv_sec + 600;