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 #include <linux/ext2_fs.h>
21
22 #include "ext2fsP.h"
23
24 static int db_dir_proc(ext2_filsys fs, struct ext2_db_entry *db_info,
25                        void *private);
26
27 extern errcode_t
28         ext2fs_dblist_dir_iterate(ext2_dblist dblist,
29                                   int   flags,
30                                   char  *block_buf,
31                                   int (*func)(ino_t     dir,
32                                               int       entry,
33                                               struct ext2_dir_entry *dirent,
34                                               int       offset,
35                                               int       blocksize,
36                                               char      *buf,
37                                               void      *private),
38                                   void *private)
39 {
40         errcode_t               retval;
41         struct dir_context      ctx;
42
43         EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST);
44
45         ctx.dir = 0;
46         ctx.flags = flags;
47         if (block_buf)
48                 ctx.buf = block_buf;
49         else {
50                 retval = ext2fs_get_mem(dblist->fs->blocksize,
51                                         (void **) &ctx.buf);
52                 if (retval)
53                         return retval;
54         }
55         ctx.func = 0;
56         ctx.func2 = func;
57         ctx.private = private;
58         ctx.errcode = 0;
59
60         retval = ext2fs_dblist_iterate(dblist, db_dir_proc, &ctx);
61         
62         if (!block_buf)
63                 ext2fs_free_mem((void **) &ctx.buf);
64         if (retval)
65                 return retval;
66         return ctx.errcode;
67 }
68
69 static int db_dir_proc(ext2_filsys fs, struct ext2_db_entry *db_info,
70                        void *private)
71 {
72         struct dir_context      *ctx = private;
73
74         ctx->dir = db_info->ino;
75         
76         return ext2fs_process_dir_block(fs, &db_info->blk,
77                                         db_info->blockcnt, private);
78 }