- ret = utf16le_to_tstr(inode->i_ads_entries[i].stream_name,
- inode->i_ads_entries[i].stream_name_nbytes,
- (tchar**)&wdentry->streams[
- wdentry->num_named_streams].stream_name,
- &dummy);
- if (ret)
- return ret;
- #endif
- }
- return 0;
-}
-
-static void
-free_wimlib_dentry(struct wimlib_wim_dentry *wdentry)
-{
-#if !TCHAR_IS_UTF16LE
- FREE((tchar*)wdentry->filename);
- FREE((tchar*)wdentry->dos_name);
- for (unsigned i = 1; i <= wdentry->num_named_streams; i++)
- FREE((tchar*)wdentry->streams[i].stream_name);
-#endif
- FREE(wdentry);
-}
-
-struct iterate_dir_tree_ctx {
- WIMStruct *wim;
- int flags;
- wimlib_iterate_dir_tree_callback_t cb;
- void *user_ctx;
-};
-
-static int
-do_iterate_dir_tree(WIMStruct *wim,
- struct wim_dentry *dentry, int flags,
- wimlib_iterate_dir_tree_callback_t cb,
- void *user_ctx);
-
-static int
-call_do_iterate_dir_tree(struct wim_dentry *dentry, void *_ctx)
-{
- struct iterate_dir_tree_ctx *ctx = _ctx;
- return do_iterate_dir_tree(ctx->wim, dentry, ctx->flags,
- ctx->cb, ctx->user_ctx);
-}
-
-static int
-do_iterate_dir_tree(WIMStruct *wim,
- struct wim_dentry *dentry, int flags,
- wimlib_iterate_dir_tree_callback_t cb,
- void *user_ctx)
-{
- u32 level;
- struct wimlib_wim_dentry *wdentry;
- int ret = WIMLIB_ERR_NOMEM;
-
-
- wdentry = CALLOC(1, sizeof(struct wimlib_wim_dentry) +
- (1 + dentry->d_inode->i_num_ads) *
- sizeof(struct wimlib_stream_entry));
- if (!wdentry)
- goto out;
-
- ret = init_wimlib_dentry(wdentry, dentry, wim);
- if (ret)
- goto out_free_wimlib_dentry;
-
- if (!(flags & WIMLIB_ITERATE_DIR_TREE_FLAG_CHILDREN)) {
- ret = (*cb)(wdentry, user_ctx);
- if (ret)
- goto out_free_wimlib_dentry;
- }
-
- if (flags & (WIMLIB_ITERATE_DIR_TREE_FLAG_RECURSIVE |
- WIMLIB_ITERATE_DIR_TREE_FLAG_CHILDREN))
- {
- struct iterate_dir_tree_ctx ctx = {
- .wim = wim,
- .flags = flags &= ~WIMLIB_ITERATE_DIR_TREE_FLAG_CHILDREN,
- .cb = cb,
- .user_ctx = user_ctx,
- };
- ret = for_dentry_child(dentry, call_do_iterate_dir_tree, &ctx);
- }
-out_free_wimlib_dentry:
- free_wimlib_dentry(wdentry);
-out:
- return ret;
-}
-
-struct image_iterate_dir_tree_ctx {
- const tchar *path;
- int flags;
- wimlib_iterate_dir_tree_callback_t cb;
- void *user_ctx;
-};
-
-
-static int
-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)
- return WIMLIB_ERR_PATH_DOES_NOT_EXIST;
- return do_iterate_dir_tree(wim, dentry, ctx->flags, ctx->cb, ctx->user_ctx);
-}
-
-WIMLIBAPI int
-wimlib_iterate_dir_tree(WIMStruct *wim, int image, const tchar *path,
- int flags,
- wimlib_iterate_dir_tree_callback_t cb, void *user_ctx)
-{
- int ret;
- struct wim_dentry *dentry;
- struct image_iterate_dir_tree_ctx ctx = {
- .path = path,
- .flags = flags,
- .cb = cb,
- .user_ctx = user_ctx,
- };
- wim->private = &ctx;
- return for_image(wim, image, image_do_iterate_dir_tree);