-
-static int link_group_free_duplicate_data(struct link_group *group,
- struct link_group **bad_links)
-{
- struct dentry *owner, *user, *tmp;
-
- /* Find a dentry with non-zero hash to use as a possible link group
- * owner (see comments above the share_dentry_ads() function */
- owner = container_of(group->dentry_list, struct dentry,
- link_group_list);
- do {
- /* imagex.exe may move the un-named data stream from the dentry
- * itself to the first alternate data stream, if there are
- * other alternate data streams */
- if (!is_zero_hash(owner->hash) ||
- (owner->num_ads && !is_zero_hash(owner->ads_entries[0].hash)))
- goto found_owner;
- owner = container_of(owner->link_group_list.next,
- struct dentry,
- link_group_list);
- } while (&owner->link_group_list != group->dentry_list);
-
- ERROR("Could not find owner of data streams in hard link group");
- return WIMLIB_ERR_INVALID_DENTRY;
-found_owner:
- owner->ads_entries_status = ADS_ENTRIES_OWNER;
- list_for_each_entry_safe(user, tmp, &owner->link_group_list,
- link_group_list)
- {
- /* I would like it to be an error if two dentries are in the
- * same hard link group but have irreconcilable differences such
- * as different file permissions, but unfortunately some of M$'s
- * WIMs contain many instances of this error. This problem is
- * worked around here by splitting each offending dentry off
- * into its own hard link group. */
- if (share_dentry_ads(owner, user) != 0) {
- struct link_group *single;
- single = MALLOC(sizeof(struct link_group));
- if (!single)
- return WIMLIB_ERR_NOMEM;
- list_del(&user->link_group_list);
- INIT_LIST_HEAD(&user->link_group_list);
- single->link_group_id = 0;
- single->next = *bad_links;
- single->dentry_list = &user->link_group_list;
- *bad_links = single;
- user->ads_entries_status = ADS_ENTRIES_OWNER;
- }
- }
- return 0;
-}
-
-/*
- * Goes through each link group and shares the ads_entries (Alternate Data
- * Stream entries) field of each dentry between members of a hard link group.
- *
- * In the process, the dentries in each link group are checked for consistency.
- * If they contain data features that indicate they cannot really be in the same
- * hard link group, this should be an error, but in reality this case needs to
- * be handled, so we split the dentries into different hard link groups.
- *
- * One of the dentries in the group is arbitrarily assigned the role of "owner"
- * (ADS_ENTRIES_OWNER), while the others are "users" (ADS_ENTRIES_USER).
- */
-int link_groups_free_duplicate_data(struct link_group_table *table)
-{
- for (u64 i = 0; i < table->capacity; i++) {
- struct link_group *group = table->array[i];
- while (group) {
- int ret;
- ret = link_group_free_duplicate_data(group,
- &table->singles);
- if (ret != 0)
- return ret;
- group = group->next;
- }
- }
- return 0;
-}