+ struct dentry *owner, *user, *tmp;
+
+ owner = container_of(group->dentry_list, struct dentry,
+ link_group_list);
+ owner->ads_entries_status = ADS_ENTRIES_OWNER;
+
+ list_for_each_entry_safe(user, tmp, group->dentry_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;