]> wimlib.net Git - wimlib/blobdiff - src/mount.c
Hard link disambiguation
[wimlib] / src / mount.c
index ac4aeb376c750d9ed94387711aca35e0a54e9aeb..9385b5298975f41bf6b60d797cd92ac36a7338b7 100644 (file)
@@ -221,7 +221,7 @@ int dentry_to_stbuf(const struct dentry *dentry, struct stat *stbuf)
        stbuf->st_gid   = getgid();
 
        /* Use the size of the unnamed (default) file stream. */
-       lte = dentry_first_lte_resolved(dentry);
+       lte = dentry_unnamed_lte_resolved(dentry);
        if (lte) {
                if (lte->resource_location == RESOURCE_IN_STAGING_FILE) {
                        wimlib_assert(lte->staging_file_name);
@@ -988,7 +988,9 @@ static int wimfs_getattr(const char *path, struct stat *stbuf)
        struct dentry *dentry;
        int ret;
 
-       ret = lookup_resource(w, path, get_lookup_flags(), &dentry, NULL, NULL);
+       ret = lookup_resource(w, path,
+                             get_lookup_flags() | LOOKUP_FLAG_DIRECTORY_OK,
+                             &dentry, NULL, NULL);
        if (ret != 0)
                return ret;
        return dentry_to_stbuf(dentry, stbuf);
@@ -1007,7 +1009,7 @@ static int wimfs_getxattr(const char *path, const char *name, char *value,
        if (!(mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR))
                return -ENOTSUP;
 
-       if (memcmp(name, "user.", 5) != 0)
+       if (strlen(name) < 5 || memcmp(name, "user.", 5) != 0)
                return -ENOATTR;
        name += 5;
 
@@ -1412,7 +1414,7 @@ static int wimfs_removexattr(const char *path, const char *name)
        if (!(mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR))
                return -ENOTSUP;
 
-       if (memcmp(name, "user.", 5) != 0)
+       if (strlen(name) < 5 || memcmp(name, "user.", 5) != 0)
                return -ENOATTR;
        name += 5;
 
@@ -1529,6 +1531,10 @@ static int wimfs_setxattr(const char *path, const char *name,
        if (!(mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR))
                return -ENOTSUP;
 
+       if (strlen(name) < 5 || memcmp(name, "user.", 5) != 0)
+               return -ENOATTR;
+       name += 5;
+
        dentry = get_dentry(w, path);
        if (!dentry)
                return -ENOENT;
@@ -1562,6 +1568,7 @@ static int wimfs_setxattr(const char *path, const char *name,
                        FREE(lte);
                        return -ENOMEM;
                }
+               memcpy(value_copy, value, size);
                lte->resource_location            = RESOURCE_IN_ATTACHED_BUFFER;
                lte->attached_buffer              = value_copy;
                lte->resource_entry.original_size = size;
@@ -1768,12 +1775,34 @@ static int check_lte_refcnt(struct lookup_table_entry *lte, void *ignore)
                lte_group_size++;
        if (lte_group_size > lte->refcnt) {
 #ifdef ENABLE_ERROR_MESSAGES
-               ERROR("The following lookup table entry has a reference count "
+               struct dentry *example_dentry;
+               struct list_head *next;
+               struct stream_list_head *head;
+               WARNING("The following lookup table entry has a reference count "
                      "of %u, but", lte->refcnt);
-               ERROR("We found %u references to it", lte_group_size);
+               WARNING("We found %u references to it", lte_group_size);
+               next = lte->lte_group_list.next;
+               head = container_of(next, struct stream_list_head, list);
+               if (head->type == STREAM_TYPE_NORMAL) {
+                       example_dentry = container_of(head, struct dentry,
+                                                     lte_group_list);
+                       WARNING("(One dentry referencing it is at `%s')",
+                               example_dentry->full_path_utf8);
+               }
                print_lookup_table_entry(lte);
 #endif
+               /* Guess what!  install.wim for Windows 8 contains a stream with
+                * 2 dentries referencing it, but the lookup table entry has
+                * reference count of 1.  So we will need to handle this case
+                * and not just make it be an error...  I'm just setting the
+                * reference count to the number of references we found. */
+
+               #if 1
+               lte->refcnt = lte_group_size;
+               WARNING("Fixing reference count");
+               #else
                return WIMLIB_ERR_INVALID_DENTRY;
+               #endif
        }
        return 0;
 }
@@ -1800,7 +1829,7 @@ WIMLIBAPI int wimlib_mount(WIMStruct *wim, int image, const char *dir,
 
        DEBUG("Selected image %d", image);
 
-       next_link_group_id = assign_link_groups(wim->image_metadata[image - 1].lgt);
+       next_link_group_id = assign_link_group_ids(wim->image_metadata[image - 1].lgt);
 
        /* Resolve all the lookup table entries of the dentry tree */
        for_dentry_in_tree(wim_root_dentry(wim), dentry_resolve_ltes,