static struct dentry *get_dentry_relative_path(struct dentry *cur_dir,
const char *path)
{
- struct dentry *child;
+ struct dentry *child, *children;
size_t base_len;
const char *new_path;
if (*path == '\0')
return cur_dir;
- child = cur_dir->d_inode->children;
- if (child) {
+ children = cur_dir->d_inode->children;
+ if (children) {
new_path = path_next_part(path, &base_len);
+ child = children;
do {
if (dentry_has_name(child, path, base_len))
return get_dentry_relative_path(child, new_path);
child = child->next;
- } while (child != cur_dir->d_inode->children);
+ } while (child != children);
}
return NULL;
}
{
struct dentry *dentry;
dentry = get_dentry(w, path);
- if (!dentry)
- return NULL;
- else
+ if (dentry)
return dentry->d_inode;
+ else
+ return NULL;
}
/* Returns the dentry that corresponds to the parent directory of @path, or NULL
*/
void free_dentry(struct dentry *dentry)
{
- wimlib_assert(dentry);
- struct inode *inode;
-
+ wimlib_assert(dentry != NULL);
FREE(dentry->file_name);
FREE(dentry->file_name_utf8);
FREE(dentry->short_name);
void put_dentry(struct dentry *dentry)
{
- wimlib_assert(dentry);
- wimlib_assert(dentry->refcnt);
+ wimlib_assert(dentry != NULL);
+ wimlib_assert(dentry->refcnt != 0);
if (--dentry->refcnt == 0)
free_dentry(dentry);
WARNING("The following lookup table entry "
"has a reference count of %u, but",
lte->refcnt);
- WARNING("We found %zu references to it",
+ WARNING("We found %u references to it",
lte->real_refcnt);
WARNING("(One dentry referencing it is at `%s')",
first_dentry->full_path_utf8);
/* Run some miscellaneous verifications on a WIM dentry */
int verify_dentry(struct dentry *dentry, void *wim)
{
- const WIMStruct *w = wim;
- const struct inode *inode = dentry->d_inode;
int ret;
if (!dentry->d_inode->verified) {
- ret = verify_inode(dentry->d_inode, w);
+ ret = verify_inode(dentry->d_inode, wim);
if (ret != 0)
return ret;
}
"short_name_len = %hu, file_name_len = %hu)",
calculated_size, dentry->length,
short_name_len, file_name_len);
- return WIMLIB_ERR_INVALID_DENTRY;
+ ret = WIMLIB_ERR_INVALID_DENTRY;
+ goto out_free_inode;
}
/* Read the filename if present. Note: if the filename is empty, there
if (!file_name) {
ERROR("Failed to allocate %hu bytes for dentry file name",
file_name_len);
- return WIMLIB_ERR_NOMEM;
+ ret = WIMLIB_ERR_NOMEM;
+ goto out_free_inode;
}
p = get_bytes(p, file_name_len, file_name);
calculated_size, dentry->length);
}
u64 lengths_to_try[3] = {calculated_size,
- dentry->length + 7 & ~7,
+ (dentry->length + 7) & ~7,
dentry->length};
ret = WIMLIB_ERR_INVALID_DENTRY;
for (size_t i = 0; i < ARRAY_LEN(lengths_to_try); i++) {