- ntfs_loc->ntfs_vol_p = ntfs_vol_p;
- ntfs_loc->path_utf8 = MALLOC(path_len + 1);
- if (!ntfs_loc->path_utf8)
- goto out_free_ntfs_loc;
- memcpy(ntfs_loc->path_utf8, path, path_len + 1);
- ntfs_loc->stream_name_utf16 = MALLOC(actx->attr->name_length * 2);
- if (!ntfs_loc->stream_name_utf16)
- goto out_free_ntfs_loc;
- memcpy(ntfs_loc->stream_name_utf16,
- attr_record_name(actx->attr),
- actx->attr->name_length * 2);
-
- ntfs_loc->stream_name_utf16_num_chars = actx->attr->name_length;
- ntfs_loc->is_reparse_point = (type == AT_REPARSE_POINT);
- lte = new_lookup_table_entry();
- if (!lte)
- goto out_free_ntfs_loc;
- lte->ntfs_loc = ntfs_loc;
- lte->resource_location = RESOURCE_IN_NTFS_VOLUME;
- lte->resource_entry.original_size = actx->attr->data_size;
- lte->resource_entry.size = actx->attr->data_size;
- copy_hash(lte->hash, attr_hash);
- lookup_table_insert(lookup_table, lte);
+ }
+ /* Checksum the stream. */
+ ret = ntfs_attr_sha1sum(ni, actx->attr, attr_hash,
+ type == AT_REPARSE_POINT, &reparse_tag);
+ if (ret != 0)
+ goto out_put_actx;
+
+ /* Make a lookup table entry for the stream, or use an existing
+ * one if there's already an identical stream. */
+ lte = __lookup_resource(lookup_table, attr_hash);
+ ret = WIMLIB_ERR_NOMEM;
+ if (lte) {
+ lte->refcnt++;
+ } else {
+ ntfs_loc = CALLOC(1, sizeof(*ntfs_loc));
+ if (!ntfs_loc)
+ goto out_put_actx;
+ ntfs_loc->ntfs_vol_p = ntfs_vol_p;
+ ntfs_loc->path_utf8 = MALLOC(path_len + 1);
+ if (!ntfs_loc->path_utf8)
+ goto out_free_ntfs_loc;
+ memcpy(ntfs_loc->path_utf8, path, path_len + 1);
+ if (name_length) {
+ ntfs_loc->stream_name_utf16 = MALLOC(name_length * 2);
+ if (!ntfs_loc->stream_name_utf16)
+ goto out_free_ntfs_loc;
+ memcpy(ntfs_loc->stream_name_utf16,
+ attr_record_name(actx->attr),
+ actx->attr->name_length * 2);
+ ntfs_loc->stream_name_utf16_num_chars = name_length;
+ }
+
+ lte = new_lookup_table_entry();
+ if (!lte)
+ goto out_free_ntfs_loc;
+ lte->ntfs_loc = ntfs_loc;
+ lte->resource_location = RESOURCE_IN_NTFS_VOLUME;
+ if (type == AT_REPARSE_POINT) {
+ dentry->d_inode->reparse_tag = reparse_tag;
+ ntfs_loc->is_reparse_point = true;
+ lte->resource_entry.original_size = data_size - 8;
+ lte->resource_entry.size = data_size - 8;
+ } else {
+ ntfs_loc->is_reparse_point = false;
+ lte->resource_entry.original_size = data_size;
+ lte->resource_entry.size = data_size;
+ }
+ ntfs_loc = NULL;
+ DEBUG("Add resource for `%s' (size = %zu)",
+ dentry->file_name_utf8,
+ lte->resource_entry.original_size);
+ copy_hash(lte->hash, attr_hash);
+ lookup_table_insert(lookup_table, lte);
+ }