-static bool dentries_have_same_ads(const struct dentry *d1,
- const struct dentry *d2)
-{
- /* Verify stream names and hashes are the same */
- for (u16 i = 0; i < d1->num_ads; i++) {
- if (strcmp(d1->ads_entries[i].stream_name_utf8,
- d2->ads_entries[i].stream_name_utf8) != 0)
- return false;
- if (memcmp(d1->ads_entries[i].hash,
- d2->ads_entries[i].hash,
- WIM_HASH_SIZE) != 0)
- return false;
- }
- return true;
-}
-
-/* Share the alternate stream entries between hard-linked dentries. */
-int share_dentry_ads(struct dentry *master, struct dentry *slave)
-{
- const char *mismatch_type;
- wimlib_assert(master->num_ads == 0 ||
- master->ads_entries != slave->ads_entries);
- if (master->attributes != slave->attributes) {
- mismatch_type = "attributes";
- goto mismatch;
- }
- if (master->attributes & FILE_ATTRIBUTE_DIRECTORY) {
- WARNING("`%s' is hard-linked to `%s', which is a directory ",
- slave->full_path_utf8, master->full_path_utf8);
- return WIMLIB_ERR_INVALID_DENTRY;
- }
- if (master->security_id != slave->security_id) {
- mismatch_type = "security ID";
- goto mismatch;
- }
- if (memcmp(master->hash, slave->hash, WIM_HASH_SIZE) != 0) {
- mismatch_type = "main file resource";
- goto mismatch;
- }
- if (!dentries_have_same_ads(master, slave)) {
- mismatch_type = "Alternate Stream Entries";
- goto mismatch;
- }
- dentry_free_ads_entries(slave);
- slave->ads_entries = master->ads_entries;
- slave->link_group_master_status = GROUP_SLAVE;
- return 0;
-mismatch:
- WARNING("Dentries `%s' and `%s' in the same hard-link group but "
- "do not share the same %s",
- master->full_path_utf8, slave->full_path_utf8,
- mismatch_type);
- return WIMLIB_ERR_INVALID_DENTRY;
-}