X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fdentry.c;h=1abe6ba75b69d18c9190537d16c4bf0ec9331343;hb=3bb3e3c3806a121686cec80c56f2718c714915ef;hp=b2bddf2293f14f20e24280f0bb66de823d6e352a;hpb=69a6de2b04308332d9e5e8bc61f34e4b9460c12f;p=wimlib diff --git a/src/dentry.c b/src/dentry.c index b2bddf22..1abe6ba7 100644 --- a/src/dentry.c +++ b/src/dentry.c @@ -37,6 +37,7 @@ #include "wimlib/error.h" #include "wimlib/lookup_table.h" #include "wimlib/metadata.h" +#include "wimlib/paths.h" #include "wimlib/resource.h" #include "wimlib/security.h" #include "wimlib/sha1.h" @@ -141,7 +142,9 @@ struct wim_dentry_on_disk { * As a further special case, if this field is all zeroes but there is * an alternate data stream entry with no name and a nonzero SHA-1 * message digest field, then that hash must be used instead of this - * one. (wimlib does not use this quirk on WIM images it creates.) + * one. In fact, when named data streams are present, some versions of + * Windows PE contain a bug where they only look in the alternate data + * stream entries for the unnamed data stream, not here. */ u8 unnamed_stream_hash[SHA1_HASH_SIZE]; @@ -254,7 +257,7 @@ get_utf16le_name(const tchar *name, utf16lechar **name_utf16le_ret, #if TCHAR_IS_UTF16LE name_utf16le_nbytes = tstrlen(name) * sizeof(utf16lechar); name_utf16le = MALLOC(name_utf16le_nbytes + sizeof(utf16lechar)); - if (!name_utf16le) + if (name_utf16le == NULL) return WIMLIB_ERR_NOMEM; memcpy(name_utf16le, name, name_utf16le_nbytes + sizeof(utf16lechar)); ret = 0; @@ -433,6 +436,24 @@ for_dentry_tree_in_rbtree(struct rb_node *node, return 0; } +/* + * Iterate over all children of @dentry, calling the function @visitor, passing + * it a child dentry and the extra argument @arg. + * + * Note: this function iterates over ALL child dentries, even those with the + * same case-insensitive name. + * + * Note: this function clobbers the tmp_list field of the child dentries. */ +int +for_dentry_child(const struct wim_dentry *dentry, + int (*visitor)(struct wim_dentry *, void *), + void *arg) +{ + return for_dentry_in_rbtree(dentry->d_inode->i_children.rb_node, + visitor, + arg); +} + /* Calls a function on all directory entries in a WIM dentry tree. Logically, * this is a pre-order traversal (the function is called on a parent dentry * before its children), but sibling dentries will be visited in order as well. @@ -443,7 +464,7 @@ for_dentry_in_tree(struct wim_dentry *root, { int ret; - if (!root) + if (root == NULL) return 0; ret = (*visitor)(root, arg); if (ret) @@ -461,7 +482,7 @@ for_dentry_in_tree_depth(struct wim_dentry *root, { int ret; - if (!root) + if (root == NULL) return 0; ret = for_dentry_tree_in_rbtree_depth(root->d_inode->i_children.rb_node, visitor, arg); @@ -485,7 +506,7 @@ calculate_dentry_full_path(struct wim_dentry *dentry) if (dentry_is_root(dentry)) { static const tchar _root_path[] = {WIM_PATH_SEPARATOR, T('\0')}; full_path = TSTRDUP(_root_path); - if (!full_path) + if (full_path == NULL) return WIMLIB_ERR_NOMEM; full_path_nbytes = 1 * sizeof(tchar); } else { @@ -499,7 +520,7 @@ calculate_dentry_full_path(struct wim_dentry *dentry) parent_full_path = T(""); parent_full_path_nbytes = 0; } else { - if (!parent->_full_path) { + if (parent->_full_path == NULL) { ret = calculate_dentry_full_path(parent); if (ret) return ret; @@ -525,7 +546,7 @@ calculate_dentry_full_path(struct wim_dentry *dentry) full_path_nbytes = parent_full_path_nbytes + sizeof(tchar) + filename_nbytes; full_path = MALLOC(full_path_nbytes + sizeof(tchar)); - if (!full_path) + if (full_path == NULL) return WIMLIB_ERR_NOMEM; memcpy(full_path, parent_full_path, parent_full_path_nbytes); full_path[parent_full_path_nbytes / sizeof(tchar)] = WIM_PATH_SEPARATOR; @@ -614,141 +635,132 @@ calculate_subdir_offsets(struct wim_dentry *dentry, u64 *subdir_offset_p) } } -/* Case-sensitive UTF-16LE dentry or stream name comparison. Used on both UNIX - * (always) and Windows (sometimes) */ -static int -compare_utf16le_names_case_sensitive(const utf16lechar *name1, size_t nbytes1, - const utf16lechar *name2, size_t nbytes2) -{ - /* Return the result if the strings differ up to their minimum length. - * Note that we cannot use strcmp() or strncmp() here, as the strings - * are in UTF-16LE format. */ - int result = memcmp(name1, name2, min(nbytes1, nbytes2)); - if (result) - return result; - - /* The strings are the same up to their minimum length, so return a - * result based on their lengths. */ - if (nbytes1 < nbytes2) - return -1; - else if (nbytes1 > nbytes2) - return 1; - else - return 0; -} - -#ifdef __WIN32__ -/* Windoze: Case-insensitive UTF-16LE dentry or stream name comparison */ -static int -compare_utf16le_names_case_insensitive(const utf16lechar *name1, size_t nbytes1, - const utf16lechar *name2, size_t nbytes2) -{ - /* Return the result if the strings differ up to their minimum length. - * */ - int result = _wcsnicmp((const wchar_t*)name1, (const wchar_t*)name2, - min(nbytes1 / 2, nbytes2 / 2)); - if (result) - return result; - - /* The strings are the same up to their minimum length, so return a - * result based on their lengths. */ - if (nbytes1 < nbytes2) - return -1; - else if (nbytes1 > nbytes2) - return 1; - else - return 0; -} -#endif /* __WIN32__ */ - -#ifdef __WIN32__ -# define compare_utf16le_names compare_utf16le_names_case_insensitive -#else -# define compare_utf16le_names compare_utf16le_names_case_sensitive -#endif - - -#ifdef __WIN32__ static int dentry_compare_names_case_insensitive(const struct wim_dentry *d1, const struct wim_dentry *d2) { - return compare_utf16le_names_case_insensitive(d1->file_name, - d1->file_name_nbytes, - d2->file_name, - d2->file_name_nbytes); + return cmp_utf16le_strings(d1->file_name, + d1->file_name_nbytes / 2, + d2->file_name, + d2->file_name_nbytes / 2, + true); } -#endif /* __WIN32__ */ static int dentry_compare_names_case_sensitive(const struct wim_dentry *d1, const struct wim_dentry *d2) { - return compare_utf16le_names_case_sensitive(d1->file_name, - d1->file_name_nbytes, - d2->file_name, - d2->file_name_nbytes); + return cmp_utf16le_strings(d1->file_name, + d1->file_name_nbytes / 2, + d2->file_name, + d2->file_name_nbytes / 2, + false); } -#ifdef __WIN32__ -# define dentry_compare_names dentry_compare_names_case_insensitive -#else -# define dentry_compare_names dentry_compare_names_case_sensitive -#endif - /* Return %true iff the alternate data stream entry @entry has the UTF-16LE * stream name @name that has length @name_nbytes bytes. */ static inline bool ads_entry_has_name(const struct wim_ads_entry *entry, - const utf16lechar *name, size_t name_nbytes) + const utf16lechar *name, size_t name_nbytes, + bool ignore_case) { - return !compare_utf16le_names(name, name_nbytes, - entry->stream_name, - entry->stream_name_nbytes); + return 0 == cmp_utf16le_strings(name, + name_nbytes / 2, + entry->stream_name, + entry->stream_name_nbytes / 2, + ignore_case); } +/* Default case sensitivity behavior for searches with + * WIMLIB_CASE_PLATFORM_DEFAULT specified. This can be modified by + * wimlib_global_init(). */ +bool default_ignore_case = +#ifdef __WIN32__ + true +#else + false +#endif +; + +static bool +will_ignore_case(CASE_SENSITIVITY_TYPE case_type) +{ + if (case_type == WIMLIB_CASE_SENSITIVE) + return false; + if (case_type == WIMLIB_CASE_INSENSITIVE) + return true; + + return default_ignore_case; +} + + /* Given a UTF-16LE filename and a directory, look up the dentry for the file. * Return it if found, otherwise NULL. This is case-sensitive on UNIX and * case-insensitive on Windows. */ struct wim_dentry * get_dentry_child_with_utf16le_name(const struct wim_dentry *dentry, const utf16lechar *name, - size_t name_nbytes) + size_t name_nbytes, + CASE_SENSITIVITY_TYPE case_ctype) { struct rb_node *node; -#ifdef __WIN32__ - node = dentry->d_inode->i_children_case_insensitive.rb_node; -#else - node = dentry->d_inode->i_children.rb_node; -#endif + bool ignore_case = will_ignore_case(case_ctype); + + if (ignore_case) + node = dentry->d_inode->i_children_case_insensitive.rb_node; + else + node = dentry->d_inode->i_children.rb_node; struct wim_dentry *child; while (node) { - #ifdef __WIN32__ - child = rb_entry(node, struct wim_dentry, rb_node_case_insensitive); - #else - child = rbnode_dentry(node); - #endif - int result = compare_utf16le_names(name, name_nbytes, - child->file_name, - child->file_name_nbytes); - if (result < 0) + if (ignore_case) + child = rb_entry(node, struct wim_dentry, rb_node_case_insensitive); + else + child = rb_entry(node, struct wim_dentry, rb_node); + + int result = cmp_utf16le_strings(name, + name_nbytes / 2, + child->file_name, + child->file_name_nbytes / 2, + ignore_case); + if (result < 0) { node = node->rb_left; - else if (result > 0) + } else if (result > 0) { node = node->rb_right; - else { - #ifdef __WIN32__ - if (!list_empty(&child->case_insensitive_conflict_list)) - { - WARNING("Result of case-insensitive lookup is ambiguous " - "(returning \"%ls\" instead of \"%ls\")", - child->file_name, - container_of(child->case_insensitive_conflict_list.next, - struct wim_dentry, - case_insensitive_conflict_list)->file_name); - } - #endif + } else if (!ignore_case || + list_empty(&child->case_insensitive_conflict_list)) { + return child; + } else { + /* Multiple dentries have the same case-insensitive + * name, and a case-insensitive lookup is being + * performed. Choose the dentry with the same + * case-sensitive name, if one exists; otherwise print a + * warning and choose one arbitrarily. */ + struct wim_dentry *alt = child; + size_t num_alts = 0; + + do { + num_alts++; + if (0 == cmp_utf16le_strings(name, + name_nbytes / 2, + alt->file_name, + alt->file_name_nbytes / 2, + false)) + return alt; + alt = list_entry(alt->case_insensitive_conflict_list.next, + struct wim_dentry, + case_insensitive_conflict_list); + } while (alt != child); + + WARNING("Result of case-insensitive lookup is ambiguous\n" + " (returning \"%"TS"\" of %zu " + "possible files, including \"%"TS"\")", + dentry_full_path(child), + num_alts, + dentry_full_path(list_entry(child->case_insensitive_conflict_list.next, + struct wim_dentry, + case_insensitive_conflict_list))); return child; } } @@ -758,11 +770,13 @@ get_dentry_child_with_utf16le_name(const struct wim_dentry *dentry, /* Returns the child of @dentry that has the file name @name. Returns NULL if * no child has the name. */ struct wim_dentry * -get_dentry_child_with_name(const struct wim_dentry *dentry, const tchar *name) +get_dentry_child_with_name(const struct wim_dentry *dentry, const tchar *name, + CASE_SENSITIVITY_TYPE case_type) { #if TCHAR_IS_UTF16LE return get_dentry_child_with_utf16le_name(dentry, name, - tstrlen(name) * sizeof(tchar)); + tstrlen(name) * sizeof(tchar), + case_type); #else utf16lechar *utf16le_name; size_t utf16le_name_nbytes; @@ -776,7 +790,8 @@ get_dentry_child_with_name(const struct wim_dentry *dentry, const tchar *name) } else { child = get_dentry_child_with_utf16le_name(dentry, utf16le_name, - utf16le_name_nbytes); + utf16le_name_nbytes, + case_type); FREE(utf16le_name); } return child; @@ -784,13 +799,14 @@ get_dentry_child_with_name(const struct wim_dentry *dentry, const tchar *name) } static struct wim_dentry * -get_dentry_utf16le(WIMStruct *wim, const utf16lechar *path) +get_dentry_utf16le(WIMStruct *wim, const utf16lechar *path, + CASE_SENSITIVITY_TYPE case_type) { struct wim_dentry *cur_dentry, *parent_dentry; const utf16lechar *p, *pp; cur_dentry = parent_dentry = wim_root_dentry(wim); - if (!cur_dentry) { + if (cur_dentry == NULL) { errno = ENOENT; return NULL; } @@ -806,7 +822,8 @@ get_dentry_utf16le(WIMStruct *wim, const utf16lechar *path) pp++; cur_dentry = get_dentry_child_with_utf16le_name(parent_dentry, p, - (void*)pp - (void*)p); + (u8*)pp - (u8*)p, + case_type); if (cur_dentry == NULL) break; p = pp; @@ -824,14 +841,12 @@ get_dentry_utf16le(WIMStruct *wim, const utf16lechar *path) /* * Returns the dentry in the currently selected WIM image named by @path * starting from the root of the WIM image, or NULL if there is no such dentry. - * - * On Windows, the search is done case-insensitively. */ struct wim_dentry * -get_dentry(WIMStruct *wim, const tchar *path) +get_dentry(WIMStruct *wim, const tchar *path, CASE_SENSITIVITY_TYPE case_type) { #if TCHAR_IS_UTF16LE - return get_dentry_utf16le(wim, path); + return get_dentry_utf16le(wim, path, case_type); #else utf16lechar *path_utf16le; size_t path_utf16le_nbytes; @@ -842,23 +857,12 @@ get_dentry(WIMStruct *wim, const tchar *path) &path_utf16le, &path_utf16le_nbytes); if (ret) return NULL; - dentry = get_dentry_utf16le(wim, path_utf16le); + dentry = get_dentry_utf16le(wim, path_utf16le, case_type); FREE(path_utf16le); return dentry; #endif } -struct wim_inode * -wim_pathname_to_inode(WIMStruct *wim, const tchar *path) -{ - struct wim_dentry *dentry; - dentry = get_dentry(wim, path); - if (dentry) - return dentry->d_inode; - else - return NULL; -} - /* Takes in a path of length @len in @buf, and transforms it into a string for * the path of its parent directory. */ static void @@ -877,14 +881,15 @@ to_parent_name(tchar *buf, size_t len) /* Returns the dentry that corresponds to the parent directory of @path, or NULL * if the dentry is not found. */ struct wim_dentry * -get_parent_dentry(WIMStruct *wim, const tchar *path) +get_parent_dentry(WIMStruct *wim, const tchar *path, + CASE_SENSITIVITY_TYPE case_type) { size_t path_len = tstrlen(path); tchar buf[path_len + 1]; tmemcpy(buf, path, path_len + 1); to_parent_name(buf, path_len); - return get_dentry(wim, buf); + return get_dentry(wim, buf, case_type); } /* Prints the full path of a dentry. */ @@ -1045,7 +1050,7 @@ new_dentry(const tchar *name, struct wim_dentry **dentry_ret) int ret; dentry = MALLOC(sizeof(struct wim_dentry)); - if (!dentry) + if (dentry == NULL) return WIMLIB_ERR_NOMEM; dentry_common_init(dentry); @@ -1077,7 +1082,7 @@ _new_dentry_with_inode(const tchar *name, struct wim_dentry **dentry_ret, dentry->d_inode = new_timeless_inode(); else dentry->d_inode = new_inode(); - if (!dentry->d_inode) { + if (dentry->d_inode == NULL) { free_dentry(dentry); return WIMLIB_ERR_NOMEM; } @@ -1139,7 +1144,7 @@ init_ads_entry(struct wim_ads_entry *ads_entry, const void *name, if (is_utf16le) { utf16lechar *p = MALLOC(name_nbytes + sizeof(utf16lechar)); - if (!p) + if (p == NULL) return WIMLIB_ERR_NOMEM; memcpy(p, name, name_nbytes); p[name_nbytes / 2] = cpu_to_le16(0); @@ -1250,8 +1255,6 @@ free_dentry_tree(struct wim_dentry *root, struct wim_lookup_table *lookup_table) for_dentry_in_tree_depth(root, do_free_dentry, lookup_table); } -#ifdef __WIN32__ - /* Insert a dentry into the case insensitive index for a directory. * * This is a red-black tree, but when multiple dentries share the same @@ -1287,7 +1290,6 @@ dentry_add_child_case_insensitive(struct wim_dentry *parent, rb_insert_color(&child->rb_node_case_insensitive, root); return NULL; } -#endif /* * Links a dentry into the directory tree. @@ -1331,7 +1333,7 @@ dentry_add_child(struct wim_dentry * restrict parent, rb_link_node(&child->rb_node, rb_parent, new); rb_insert_color(&child->rb_node, root); -#ifdef __WIN32__ + /* Case insensitive child dentry index */ { struct wim_dentry *existing; existing = dentry_add_child_case_insensitive(parent, child); @@ -1343,7 +1345,6 @@ dentry_add_child(struct wim_dentry * restrict parent, INIT_LIST_HEAD(&child->case_insensitive_conflict_list); } } -#endif return NULL; } @@ -1356,7 +1357,7 @@ unlink_dentry(struct wim_dentry *dentry) if (parent == dentry) return; rb_erase(&dentry->rb_node, &parent->d_inode->i_children); -#ifdef __WIN32__ + if (dentry->rb_node_case_insensitive.__rb_parent_color) { /* This dentry was in the case-insensitive red-black tree. */ rb_erase(&dentry->rb_node_case_insensitive, @@ -1375,7 +1376,76 @@ unlink_dentry(struct wim_dentry *dentry) } } list_del(&dentry->case_insensitive_conflict_list); -#endif +} + +static int +free_dentry_full_path(struct wim_dentry *dentry, void *_ignore) +{ + FREE(dentry->_full_path); + dentry->_full_path = NULL; + return 0; +} + +/* Rename a file or directory in the WIM. */ +int +rename_wim_path(WIMStruct *wim, const tchar *from, const tchar *to, + CASE_SENSITIVITY_TYPE case_type) +{ + struct wim_dentry *src; + struct wim_dentry *dst; + struct wim_dentry *parent_of_dst; + int ret; + + /* This rename() implementation currently only supports actual files + * (not alternate data streams) */ + + src = get_dentry(wim, from, case_type); + if (!src) + return -errno; + + dst = get_dentry(wim, to, case_type); + + if (dst) { + /* Destination file exists */ + + if (src == dst) /* Same file */ + return 0; + + if (!dentry_is_directory(src)) { + /* Cannot rename non-directory to directory. */ + if (dentry_is_directory(dst)) + return -EISDIR; + } else { + /* Cannot rename directory to a non-directory or a non-empty + * directory */ + if (!dentry_is_directory(dst)) + return -ENOTDIR; + if (dentry_has_children(dst)) + return -ENOTEMPTY; + } + parent_of_dst = dst->parent; + } else { + /* Destination does not exist */ + parent_of_dst = get_parent_dentry(wim, to, case_type); + if (!parent_of_dst) + return -errno; + + if (!dentry_is_directory(parent_of_dst)) + return -ENOTDIR; + } + + ret = set_dentry_name(src, path_basename(to)); + if (ret) + return -ENOMEM; + if (dst) { + unlink_dentry(dst); + free_dentry_tree(dst, wim->lookup_table); + } + unlink_dentry(src); + dentry_add_child(parent_of_dst, src); + if (src->_full_path) + for_dentry_in_tree(src, free_dentry_full_path, NULL); + return 0; } /* @@ -1423,7 +1493,8 @@ inode_get_ads_entry(struct wim_inode *inode, const tchar *stream_name, do { if (ads_entry_has_name(&inode->i_ads_entries[i], stream_name_utf16le, - stream_name_utf16le_nbytes)) + stream_name_utf16le_nbytes, + false)) { if (idx_ret) *idx_ret = i; @@ -1455,7 +1526,7 @@ do_inode_add_ads(struct wim_inode *inode, const void *stream_name, num_ads = inode->i_num_ads + 1; ads_entries = REALLOC(inode->i_ads_entries, num_ads * sizeof(inode->i_ads_entries[0])); - if (!ads_entries) { + if (ads_entries == NULL) { ERROR("Failed to allocate memory for new alternate data stream"); return NULL; } @@ -1503,22 +1574,22 @@ add_stream_from_data_buffer(const void *buffer, size_t size, sha1_buffer(buffer, size, hash); existing_lte = lookup_resource(lookup_table, hash); if (existing_lte) { - wimlib_assert(wim_resource_size(existing_lte) == size); + wimlib_assert(existing_lte->size == size); lte = existing_lte; lte->refcnt++; } else { void *buffer_copy; lte = new_lookup_table_entry(); - if (!lte) + if (lte == NULL) return NULL; buffer_copy = memdup(buffer, size); - if (!buffer_copy) { + if (buffer_copy == NULL) { free_lookup_table_entry(lte); return NULL; } - lte->resource_location = RESOURCE_IN_ATTACHED_BUFFER; - lte->attached_buffer = buffer_copy; - lte->resource_entry.original_size = size; + lte->resource_location = RESOURCE_IN_ATTACHED_BUFFER; + lte->attached_buffer = buffer_copy; + lte->size = size; copy_hash(lte->hash, hash); lookup_table_insert(lookup_table, lte); } @@ -1535,12 +1606,12 @@ inode_add_ads_with_data(struct wim_inode *inode, const tchar *name, wimlib_assert(inode->i_resolved); new_ads_entry = inode_add_ads(inode, name); - if (!new_ads_entry) + if (new_ads_entry == NULL) return WIMLIB_ERR_NOMEM; new_ads_entry->lte = add_stream_from_data_buffer(value, size, lookup_table); - if (!new_ads_entry->lte) { + if (new_ads_entry->lte == NULL) { inode_remove_ads(inode, new_ads_entry - inode->i_ads_entries, lookup_table); return WIMLIB_ERR_NOMEM; @@ -1564,7 +1635,7 @@ inode_set_unnamed_stream(struct wim_inode *inode, const void *data, size_t len, struct wim_lookup_table *lookup_table) { inode->i_lte = add_stream_from_data_buffer(data, len, lookup_table); - if (!inode->i_lte) + if (inode->i_lte == NULL) return WIMLIB_ERR_NOMEM; inode->i_resolved = 1; return 0; @@ -1621,21 +1692,21 @@ inode_get_unix_data(const struct wim_inode *inode, ads_entry = inode_get_ads_entry((struct wim_inode*)inode, WIMLIB_UNIX_DATA_TAG, NULL); - if (!ads_entry) + if (ads_entry == NULL) return NO_UNIX_DATA; if (stream_idx_ret) *stream_idx_ret = ads_entry - inode->i_ads_entries; lte = ads_entry->lte; - if (!lte) + if (lte == NULL) return NO_UNIX_DATA; - size = wim_resource_size(lte); + size = lte->size; if (size != sizeof(struct wimlib_unix_data)) return BAD_UNIX_DATA; - ret = read_full_resource_into_buf(lte, unix_data); + ret = read_full_stream_into_buf(lte, unix_data); if (ret) return ret; @@ -1714,7 +1785,7 @@ read_ads_entries(const u8 * restrict p, struct wim_inode * restrict inode, * data stream entries. */ num_ads = inode->i_num_ads; ads_entries = CALLOC(num_ads, sizeof(inode->i_ads_entries[0])); - if (!ads_entries) + if (ads_entries == NULL) goto out_of_memory; /* Read the entries into our newly allocated buffer. */ @@ -1769,7 +1840,7 @@ read_ads_entries(const u8 * restrict p, struct wim_inode * restrict inode, goto out_invalid; cur_entry->stream_name = MALLOC(cur_entry->stream_name_nbytes + 2); - if (!cur_entry->stream_name) + if (cur_entry->stream_name == NULL) goto out_of_memory; memcpy(cur_entry->stream_name, @@ -1908,7 +1979,7 @@ read_dentry(const u8 * restrict metadata_resource, u64 metadata_resource_len, /* Allocate a `struct wim_inode' for this `struct wim_dentry'. */ inode = new_timeless_inode(); - if (!inode) + if (inode == NULL) return WIMLIB_ERR_NOMEM; /* Read more fields; some into the dentry, and some into the inode. */ @@ -1976,7 +2047,7 @@ read_dentry(const u8 * restrict metadata_resource, u64 metadata_resource_len, * is no null terminator following it. */ if (file_name_nbytes) { file_name = MALLOC(file_name_nbytes + 2); - if (!file_name) { + if (file_name == NULL) { ERROR("Failed to allocate %d bytes for dentry file name", file_name_nbytes + 2); ret = WIMLIB_ERR_NOMEM; @@ -1994,7 +2065,7 @@ read_dentry(const u8 * restrict metadata_resource, u64 metadata_resource_len, * filename, there is no null terminator following it. */ if (short_name_nbytes) { short_name = MALLOC(short_name_nbytes + 2); - if (!short_name) { + if (short_name == NULL) { ERROR("Failed to allocate %d bytes for dentry short name", short_name_nbytes + 2); ret = WIMLIB_ERR_NOMEM; @@ -2131,7 +2202,7 @@ read_dentry_tree(const u8 * restrict metadata_resource, /* Not end of directory. Allocate this child permanently and * link it to the parent and previous child. */ child = memdup(&cur_child, sizeof(struct wim_dentry)); - if (!child) { + if (child == NULL) { ERROR("Failed to allocate new dentry!"); ret = WIMLIB_ERR_NOMEM; break; @@ -2523,7 +2594,7 @@ do_iterate_dir_tree(WIMStruct *wim, wdentry = CALLOC(1, sizeof(struct wimlib_dir_entry) + (1 + dentry->d_inode->i_num_ads) * sizeof(struct wimlib_stream_entry)); - if (!wdentry) + if (wdentry == NULL) goto out; ret = init_wimlib_dentry(wdentry, dentry, wim, flags); @@ -2567,8 +2638,8 @@ image_do_iterate_dir_tree(WIMStruct *wim) struct image_iterate_dir_tree_ctx *ctx = wim->private; struct wim_dentry *dentry; - dentry = get_dentry(wim, ctx->path); - if (!dentry) + dentry = get_dentry(wim, ctx->path, WIMLIB_CASE_PLATFORM_DEFAULT); + if (dentry == NULL) return WIMLIB_ERR_PATH_DOES_NOT_EXIST; return do_iterate_dir_tree(wim, dentry, ctx->flags, ctx->cb, ctx->user_ctx); } @@ -2626,7 +2697,7 @@ inode_metadata_consistent(const struct wim_inode *inode, /* Compare stream sizes. */ if (lte && template_lte) { - if (wim_resource_size(lte) != wim_resource_size(template_lte)) + if (lte->size != template_lte->size) return false; /* If hash happens to be available, compare with template. */ @@ -2634,9 +2705,9 @@ inode_metadata_consistent(const struct wim_inode *inode, !hashes_equal(lte->hash, template_lte->hash)) return false; - } else if (lte && wim_resource_size(lte)) { + } else if (lte && lte->size) { return false; - } else if (template_lte && wim_resource_size(template_lte)) { + } else if (template_lte && template_lte->size) { return false; } } @@ -2673,7 +2744,7 @@ inode_copy_checksums(struct wim_inode *inode, /* Only take action if both entries exist, the entry for @inode * has no checksum calculated, but the entry for @template_inode * does. */ - if (!lte || !template_lte || + if (lte == NULL || template_lte == NULL || !lte->unhashed || template_lte->unhashed) continue; @@ -2735,8 +2806,9 @@ dentry_reference_template(struct wim_dentry *dentry, void *_args) if (ret) return ret; - template_dentry = get_dentry(template_wim, dentry->_full_path); - if (!template_dentry) { + template_dentry = get_dentry(template_wim, dentry->_full_path, + WIMLIB_CASE_SENSITIVE); + if (template_dentry == NULL) { DEBUG("\"%"TS"\": newly added file", dentry->_full_path); return 0; }