dblist_dir.c 1.5 KB

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