]> wimlib.net Git - wimlib/blobdiff - src/dentry.c
Windows: improved error messages
[wimlib] / src / dentry.c
index 669b447ea8b88a9f4cd6cc2750809f97182816aa..e351a65cf86b17a99e6e1b48eb302e46797c4e53 100644 (file)
@@ -58,6 +58,8 @@
 #  include "config.h"
 #endif
 
+#include <errno.h>
+
 #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 <errno.h>
-
 /* On-disk format of a WIM dentry (directory entry), located in the metadata
  * resource for a WIM image.  */
 struct wim_dentry_on_disk {
@@ -925,6 +925,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 +933,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 +999,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);
        }
 }
@@ -1342,8 +1342,7 @@ read_dentry(const u8 * restrict buf, size_t buf_len,
        /* Read the filename if present.  Note: if the filename is empty, there
         * is no null terminator following it.  */
        if (file_name_nbytes) {
-               dentry->file_name = utf16le_dupz((const utf16lechar *)p,
-                                                file_name_nbytes);
+               dentry->file_name = utf16le_dupz(p, file_name_nbytes);
                if (dentry->file_name == NULL) {
                        ret = WIMLIB_ERR_NOMEM;
                        goto err_free_dentry;
@@ -1355,8 +1354,7 @@ read_dentry(const u8 * restrict buf, size_t buf_len,
        /* Read the short filename if present.  Note: if there is no short
         * filename, there is no null terminator following it. */
        if (short_name_nbytes) {
-               dentry->short_name = utf16le_dupz((const utf16lechar *)p,
-                                                 short_name_nbytes);
+               dentry->short_name = utf16le_dupz(p, short_name_nbytes);
                if (dentry->short_name == NULL) {
                        ret = WIMLIB_ERR_NOMEM;
                        goto err_free_dentry;