3
0

dblist_dir.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #include <stdio.h>
  14. #if HAVE_UNISTD_H
  15. #include <unistd.h>
  16. #endif
  17. #include <string.h>
  18. #include <time.h>
  19. #include "ext2_fs.h"
  20. #include "ext2fsP.h"
  21. static int db_dir_proc(ext2_filsys fs, struct ext2_db_entry *db_info,
  22. void *priv_data);
  23. errcode_t ext2fs_dblist_dir_iterate(ext2_dblist dblist,
  24. int flags,
  25. char *block_buf,
  26. int (*func)(ext2_ino_t dir,
  27. int entry,
  28. struct ext2_dir_entry *dirent,
  29. int offset,
  30. int blocksize,
  31. char *buf,
  32. void *priv_data),
  33. void *priv_data)
  34. {
  35. errcode_t retval;
  36. struct dir_context ctx;
  37. EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST);
  38. ctx.dir = 0;
  39. ctx.flags = flags;
  40. if (block_buf)
  41. ctx.buf = block_buf;
  42. else {
  43. retval = ext2fs_get_mem(dblist->fs->blocksize, &ctx.buf);
  44. if (retval)
  45. return retval;
  46. }
  47. ctx.func = func;
  48. ctx.priv_data = priv_data;
  49. ctx.errcode = 0;
  50. retval = ext2fs_dblist_iterate(dblist, db_dir_proc, &ctx);
  51. if (!block_buf)
  52. ext2fs_free_mem(&ctx.buf);
  53. if (retval)
  54. return retval;
  55. return ctx.errcode;
  56. }
  57. static int db_dir_proc(ext2_filsys fs, struct ext2_db_entry *db_info,
  58. void *priv_data)
  59. {
  60. struct dir_context *ctx;
  61. ctx = (struct dir_context *) priv_data;
  62. ctx->dir = db_info->ino;
  63. return ext2fs_process_dir_block(fs, &db_info->blk,
  64. db_info->blockcnt, 0, 0, priv_data);
  65. }