1/* vi: set sw=4 ts=4: */ 2/* 3 * dblist_dir.c --- iterate by directory entry 4 * 5 * Copyright 1997 by Theodore Ts'o 6 * 7 * %Begin-Header% 8 * This file may be redistributed under the terms of the GNU Public 9 * License. 10 * %End-Header% 11 * 12 */ 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); 58 59 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; 73 74 return ext2fs_process_dir_block(fs, &db_info->blk, 75 db_info->blockcnt, 0, 0, priv_data); 76} 77