- return p;
-}
-
-static int
-write_dentry_cb(struct wim_dentry *dentry, void *_p)
-{
- u8 **p = _p;
- *p = write_dentry(dentry, *p);
- return 0;
-}
-
-static u8 *
-write_dentry_tree_recursive(const struct wim_dentry *parent, u8 *p);
-
-static int
-write_dentry_tree_recursive_cb(struct wim_dentry *dentry, void *_p)
-{
- u8 **p = _p;
- *p = write_dentry_tree_recursive(dentry, *p);
- return 0;
-}
-
-/* Recursive function that writes a dentry tree rooted at @parent, not including
- * @parent itself, which has already been written. */
-static u8 *
-write_dentry_tree_recursive(const struct wim_dentry *parent, u8 *p)
-{
- /* Nothing to do if this dentry has no children. */
- if (parent->subdir_offset == 0)
- return p;
-
- /* Write child dentries and end-of-directory entry.
- *
- * Note: we need to write all of this dentry's children before
- * recursively writing the directory trees rooted at each of the child
- * dentries, since the on-disk dentries for a dentry's children are
- * always located at consecutive positions in the metadata resource! */
- for_dentry_child(parent, write_dentry_cb, &p);
-
- /* write end of directory entry */
- *(le64*)p = cpu_to_le64(0);
- p += 8;
-
- /* Recurse on children. */
- for_dentry_child(parent, write_dentry_tree_recursive_cb, &p);
- return p;
-}
-
-/* Writes a directory tree to the metadata resource.
- *
- * @root: Root of the dentry tree.
- * @p: Pointer to a buffer with enough space for the dentry tree.
- *
- * Returns pointer to the byte after the last byte we wrote.
- */
-u8 *
-write_dentry_tree(const struct wim_dentry * restrict root, u8 * restrict p)
-{
- DEBUG("Writing dentry tree.");
- wimlib_assert(dentry_is_root(root));
-
- /* If we're the root dentry, we have no parent that already
- * wrote us, so we need to write ourselves. */
- p = write_dentry(root, p);
-
- /* Write end of directory entry after the root dentry just to be safe;
- * however the root dentry obviously cannot have any siblings. */
- *(le64*)p = cpu_to_le64(0);
- p += 8;
-
- /* Recursively write the rest of the dentry tree. */
- return write_dentry_tree_recursive(root, p);
-}
-
-
-static int
-init_wimlib_dentry(struct wimlib_dir_entry *wdentry,
- struct wim_dentry *dentry,
- const WIMStruct *wim,
- int flags)
-{
- int ret;
- size_t dummy;
- const struct wim_inode *inode = dentry->d_inode;
- struct wim_lookup_table_entry *lte;
- const u8 *hash;
-
-#if TCHAR_IS_UTF16LE
- wdentry->filename = dentry->file_name;
- wdentry->dos_name = dentry->short_name;
-#else
- if (dentry_has_long_name(dentry)) {
- ret = utf16le_to_tstr(dentry->file_name,
- dentry->file_name_nbytes,
- (tchar**)&wdentry->filename,
- &dummy);
- if (ret)
- return ret;
- }
- if (dentry_has_short_name(dentry)) {
- ret = utf16le_to_tstr(dentry->short_name,
- dentry->short_name_nbytes,
- (tchar**)&wdentry->dos_name,
- &dummy);
- if (ret)
- return ret;
- }
-#endif
- ret = calculate_dentry_full_path(dentry);
- if (ret)
- return ret;
- wdentry->full_path = dentry->_full_path;