dblist_dir.c revision ab13b5a9795a8c20f1d6da8fe1da340f545ec0e0
1/*
2 * dblist_dir.c --- iterate by directory entry
3 *
4 * Copyright 1997 by Theodore Ts'o
5 *
6 * %Begin-Header%
7 * This file may be redistributed under the terms of the GNU Library
8 * General Public License, version 2.
9 * %End-Header%
10 */
11
12#include <stdio.h>
13#if HAVE_UNISTD_H
14#include <unistd.h>
15#endif
16#include <string.h>
17#include <time.h>
18
19#include "ext2_fs.h"
20#include "ext2fsP.h"
21
22static int db_dir_proc(ext2_filsys fs, struct ext2_db_entry2 *db_info,
23		       void *priv_data);
24
25errcode_t ext2fs_dblist_dir_iterate(ext2_dblist dblist,
26				    int	flags,
27				    char	*block_buf,
28				    int (*func)(ext2_ino_t dir,
29						int	entry,
30						struct ext2_dir_entry *dirent,
31						int	offset,
32						int	blocksize,
33						char	*buf,
34						void	*priv_data),
35				    void *priv_data)
36{
37	errcode_t		retval;
38	struct dir_context	ctx;
39
40	EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST);
41
42	ctx.dir = 0;
43	ctx.flags = flags;
44	if (block_buf)
45		ctx.buf = block_buf;
46	else {
47		retval = ext2fs_get_mem(dblist->fs->blocksize, &ctx.buf);
48		if (retval)
49			return retval;
50	}
51	ctx.func = func;
52	ctx.priv_data = priv_data;
53	ctx.errcode = 0;
54
55	retval = ext2fs_dblist_iterate2(dblist, db_dir_proc, &ctx);
56
57	if (!block_buf)
58		ext2fs_free_mem(&ctx.buf);
59	if (retval)
60		return retval;
61	return ctx.errcode;
62}
63
64static int db_dir_proc(ext2_filsys fs, struct ext2_db_entry2 *db_info,
65		       void *priv_data)
66{
67	struct dir_context	*ctx;
68	int			ret;
69
70	ctx = (struct dir_context *) priv_data;
71	ctx->dir = db_info->ino;
72	ctx->errcode = 0;
73
74	ret = ext2fs_process_dir_block(fs, &db_info->blk,
75				       db_info->blockcnt, 0, 0, priv_data);
76	if ((ret & BLOCK_ABORT) && !ctx->errcode)
77		return DBLIST_ABORT;
78	return 0;
79}
80