Whamcloud - gitweb
Many files:
[tools/e2fsprogs.git] / lib / ext2fs / dblist_dir.c
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
13 #include <stdio.h>
14 #if HAVE_UNISTD_H
15 #include <unistd.h>
16 #endif
17 #include <string.h>
18 #include <time.h>
19
20 #if EXT2_FLAT_INCLUDES
21 #include "ext2_fs.h"
22 #else
23 #include <linux/ext2_fs.h>
24 #endif
25
26 #include "ext2fsP.h"
27
28 static int db_dir_proc(ext2_filsys fs, struct ext2_db_entry *db_info,
29                        void *priv_data);
30
31 extern errcode_t
32         ext2fs_dblist_dir_iterate(ext2_dblist dblist,
33                                   int   flags,
34                                   char  *block_buf,
35                                   int (*func)(ino_t     dir,
36                                               int       entry,
37                                               struct ext2_dir_entry *dirent,
38                                               int       offset,
39                                               int       blocksize,
40                                               char      *buf,
41                                               void      *priv_data),
42                                   void *priv_data)
43 {
44         errcode_t               retval;
45         struct dir_context      ctx;
46
47         EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST);
48
49         ctx.dir = 0;
50         ctx.flags = flags;
51         if (block_buf)
52                 ctx.buf = block_buf;
53         else {
54                 retval = ext2fs_get_mem(dblist->fs->blocksize,
55                                         (void **) &ctx.buf);
56                 if (retval)
57                         return retval;
58         }
59         ctx.func = 0;
60         ctx.func2 = func;
61         ctx.priv_data = priv_data;
62         ctx.errcode = 0;
63
64         retval = ext2fs_dblist_iterate(dblist, db_dir_proc, &ctx);
65         
66         if (!block_buf)
67                 ext2fs_free_mem((void **) &ctx.buf);
68         if (retval)
69                 return retval;
70         return ctx.errcode;
71 }
72
73 static int db_dir_proc(ext2_filsys fs, struct ext2_db_entry *db_info,
74                        void *priv_data)
75 {
76         struct dir_context      *ctx;
77
78         ctx = (struct dir_context *) priv_data;
79         ctx->dir = db_info->ino;
80         
81         return ext2fs_process_dir_block(fs, &db_info->blk,
82                                         db_info->blockcnt, 0, 0, priv_data);
83 }