X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fdentry.c;h=324fbcf8a63b4f72dba20625fa927d6cbcaf48c4;hb=65adcad3e3d5eb01aaaf0dab9d3e509364dac673;hp=862c6640c9bb54b9bef52610824604091b830e13;hpb=5f3757249c17cb9e2826f645e0f8618534c80fcc;p=wimlib diff --git a/src/dentry.c b/src/dentry.c index 862c6640..324fbcf8 100644 --- a/src/dentry.c +++ b/src/dentry.c @@ -58,6 +58,8 @@ # include "config.h" #endif +#include + #include "wimlib/assert.h" #include "wimlib/dentry.h" #include "wimlib/inode.h" @@ -66,8 +68,6 @@ #include "wimlib/metadata.h" #include "wimlib/paths.h" -#include - /* On-disk format of a WIM dentry (directory entry), located in the metadata * resource for a WIM image. */ struct wim_dentry_on_disk { @@ -348,14 +348,28 @@ ads_entry_out_total_length(const struct wim_ads_entry *entry) * though there is already a field in the dentry itself for the unnamed stream * reference, which then goes to waste. */ -static inline bool +static bool inode_needs_dummy_stream(const struct wim_inode *inode) { - return (inode->i_num_ads > 0 && - inode->i_num_ads < 0xffff && /* overflow check */ - inode->i_canonical_streams); /* assume the dentry is okay if it - already had an unnamed ADS entry - when it was read in */ + /* Normal case */ + if (likely(inode->i_num_ads <= 0)) + return false; + + /* Overflow check */ + if (inode->i_num_ads >= 0xFFFF) + return false; + + /* Assume the dentry is okay if it already had an unnamed ADS entry when + * it was read in. */ + if (!inode->i_canonical_streams) + return false; + + /* We can't use use this workaround on encrypted files because WIMGAPI + * reports that the WIM is in an incorrect format. */ + if (inode->i_attributes & FILE_ATTRIBUTE_ENCRYPTED) + return false; + + return true; } /* Calculate the total number of bytes that will be consumed when a dentry is @@ -925,6 +939,7 @@ _new_dentry_with_inode(const tchar *name, struct wim_dentry **dentry_ret, bool timeless) { struct wim_dentry *dentry; + struct wim_inode *inode; int ret; ret = new_dentry(name, &dentry); @@ -932,15 +947,16 @@ _new_dentry_with_inode(const tchar *name, struct wim_dentry **dentry_ret, return ret; if (timeless) - dentry->d_inode = new_timeless_inode(); + inode = new_timeless_inode(); else - dentry->d_inode = new_inode(); - if (dentry->d_inode == NULL) { + inode = new_inode(); + if (!inode) { free_dentry(dentry); return WIMLIB_ERR_NOMEM; } - inode_add_dentry(dentry, dentry->d_inode); + d_associate(dentry, inode); + *dentry_ret = dentry; return 0; } @@ -997,19 +1013,17 @@ dentry_tree_clear_inode_visited(struct wim_dentry *root) /* * Free a WIM dentry. * - * In addition to freeing the dentry itself, this decrements the link count of - * the corresponding inode (if any). If the inode's link count reaches 0, the - * inode is freed as well. + * In addition to freeing the dentry itself, this disassociates the dentry from + * its inode. If the inode is no longer in use, it will be freed as well. */ void free_dentry(struct wim_dentry *dentry) { if (dentry) { + d_disassociate(dentry); FREE(dentry->file_name); FREE(dentry->short_name); FREE(dentry->_full_path); - if (dentry->d_inode) - put_inode(dentry->d_inode); FREE(dentry); } }