blob: b2392046647e395ed0ea14a3c36be01a124c52c9 [file] [log] [blame]
"Robert P. J. Day"63fc1a92006-07-02 19:47:05 +00001/* vi: set sw=4 ts=4: */
Mike Frysinger1fd98e02005-05-09 22:10:42 +00002/*
3 * dblist_dir.c --- iterate by directory entry
4 *
5 * Copyright 1997 by Theodore Ts'o
Tim Rikerc1ef7bd2006-01-25 00:08:53 +00006 *
Mike Frysinger1fd98e02005-05-09 22:10:42 +00007 * %Begin-Header%
8 * This file may be redistributed under the terms of the GNU Public
9 * License.
10 * %End-Header%
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000011 *
Mike Frysinger1fd98e02005-05-09 22:10:42 +000012 */
13
14#include <stdio.h>
15#if HAVE_UNISTD_H
16#include <unistd.h>
17#endif
18#include <string.h>
19#include <time.h>
20
21#include "ext2_fs.h"
22#include "ext2fsP.h"
23
24static int db_dir_proc(ext2_filsys fs, struct ext2_db_entry *db_info,
25 void *priv_data);
26
27errcode_t ext2fs_dblist_dir_iterate(ext2_dblist dblist,
28 int flags,
29 char *block_buf,
30 int (*func)(ext2_ino_t dir,
31 int entry,
32 struct ext2_dir_entry *dirent,
33 int offset,
34 int blocksize,
35 char *buf,
36 void *priv_data),
37 void *priv_data)
38{
39 errcode_t retval;
40 struct dir_context ctx;
41
42 EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST);
43
44 ctx.dir = 0;
45 ctx.flags = flags;
46 if (block_buf)
47 ctx.buf = block_buf;
48 else {
49 retval = ext2fs_get_mem(dblist->fs->blocksize, &ctx.buf);
50 if (retval)
51 return retval;
52 }
53 ctx.func = func;
54 ctx.priv_data = priv_data;
55 ctx.errcode = 0;
56
57 retval = ext2fs_dblist_iterate(dblist, db_dir_proc, &ctx);
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000058
Mike Frysinger1fd98e02005-05-09 22:10:42 +000059 if (!block_buf)
60 ext2fs_free_mem(&ctx.buf);
61 if (retval)
62 return retval;
63 return ctx.errcode;
64}
65
66static int db_dir_proc(ext2_filsys fs, struct ext2_db_entry *db_info,
67 void *priv_data)
68{
69 struct dir_context *ctx;
70
71 ctx = (struct dir_context *) priv_data;
72 ctx->dir = db_info->ino;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000073
Mike Frysinger1fd98e02005-05-09 22:10:42 +000074 return ext2fs_process_dir_block(fs, &db_info->blk,
75 db_info->blockcnt, 0, 0, priv_data);
76}