X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fdentry.c;h=6a7593887caeb2c042d8ae1ca93e5b3f5ae3eefa;hb=fad3fab0e85346f6c1d5111d84d5ecfb6bc99249;hp=302409f9fe56034a1c29c191ebc1995af7fbab6b;hpb=43a26b833482fc019c7aeee95656b8f2f3077db7;p=wimlib diff --git a/src/dentry.c b/src/dentry.c index 302409f9..6a759388 100644 --- a/src/dentry.c +++ b/src/dentry.c @@ -1299,9 +1299,7 @@ setup_inode_streams(const u8 *p, const u8 *end, struct wim_inode *inode, inode->i_num_streams = 1 + num_extra_streams; - if (likely(inode->i_num_streams <= ARRAY_LEN(inode->i_embedded_streams))) { - inode->i_streams = inode->i_embedded_streams; - } else { + if (unlikely(inode->i_num_streams > ARRAY_LEN(inode->i_embedded_streams))) { inode->i_streams = CALLOC(inode->i_num_streams, sizeof(inode->i_streams[0])); if (!inode->i_streams) @@ -1821,8 +1819,7 @@ write_dentry(const struct wim_dentry * restrict dentry, u8 * restrict p) const struct wim_inode_stream *efs_strm; const u8 *efs_hash; - efs_strm = inode_get_stream(inode, STREAM_TYPE_EFSRPC_RAW_DATA, - NO_STREAM_NAME); + efs_strm = inode_get_unnamed_stream(inode, STREAM_TYPE_EFSRPC_RAW_DATA); efs_hash = efs_strm ? stream_hash(efs_strm) : zero_hash; copy_hash(disk_dentry->default_hash, efs_hash); disk_dentry->num_extra_streams = cpu_to_le16(0); @@ -1838,7 +1835,6 @@ write_dentry(const struct wim_dentry * restrict dentry, u8 * restrict p) */ bool have_named_data_stream = false; bool have_reparse_point_stream = false; - u16 num_extra_streams = 0; const u8 *unnamed_data_stream_hash = zero_hash; const u8 *reparse_point_hash; for (unsigned i = 0; i < inode->i_num_streams; i++) { @@ -1854,7 +1850,9 @@ write_dentry(const struct wim_dentry * restrict dentry, u8 * restrict p) } } - if (have_reparse_point_stream || have_named_data_stream) { + if (unlikely(have_reparse_point_stream || have_named_data_stream)) { + + unsigned num_extra_streams = 0; copy_hash(disk_dentry->default_hash, zero_hash); @@ -1867,19 +1865,22 @@ write_dentry(const struct wim_dentry * restrict dentry, u8 * restrict p) p = write_extra_stream_entry(p, NO_STREAM_NAME, unnamed_data_stream_hash); num_extra_streams++; - } else { - copy_hash(disk_dentry->default_hash, unnamed_data_stream_hash); - } - for (unsigned i = 0; i < inode->i_num_streams; i++) { - const struct wim_inode_stream *strm = &inode->i_streams[i]; - if (stream_is_named_data_stream(strm)) { - p = write_extra_stream_entry(p, strm->stream_name, - stream_hash(strm)); - num_extra_streams++; + for (unsigned i = 0; i < inode->i_num_streams; i++) { + const struct wim_inode_stream *strm = &inode->i_streams[i]; + if (stream_is_named_data_stream(strm)) { + p = write_extra_stream_entry(p, strm->stream_name, + stream_hash(strm)); + num_extra_streams++; + } } + wimlib_assert(num_extra_streams <= 0xFFFF); + + disk_dentry->num_extra_streams = cpu_to_le16(num_extra_streams); + } else { + copy_hash(disk_dentry->default_hash, unnamed_data_stream_hash); + disk_dentry->num_extra_streams = cpu_to_le16(0); } - disk_dentry->num_extra_streams = cpu_to_le16(num_extra_streams); } return p;