/src/e2fsprogs/lib/ext2fs/get_num_dirs.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * get_num_dirs.c -- calculate number of directories |
3 | | * |
4 | | * Copyright 1997 by Theodore Ts'o |
5 | | * |
6 | | * %Begin-Header% |
7 | | * This file may be redistributed under the terms of the GNU Library |
8 | | * General Public License, version 2. |
9 | | * %End-Header% |
10 | | */ |
11 | | |
12 | | #include "config.h" |
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 "ext2_fs.h" |
21 | | #include "ext2fsP.h" |
22 | | |
23 | | /* |
24 | | * Returns the number of directories in the filesystem as reported by |
25 | | * the group descriptors. Of course, the group descriptors could be |
26 | | * wrong! |
27 | | */ |
28 | | errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs) |
29 | 0 | { |
30 | 0 | dgrp_t i; |
31 | 0 | ext2_ino_t num_dirs, max_dirs; |
32 | |
|
33 | 0 | EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); |
34 | | |
35 | 0 | num_dirs = 0; |
36 | 0 | max_dirs = fs->super->s_inodes_per_group; |
37 | 0 | for (i = 0; i < fs->group_desc_count; i++) { |
38 | 0 | if (ext2fs_bg_used_dirs_count(fs, i) > max_dirs) |
39 | 0 | num_dirs += max_dirs / 8; |
40 | 0 | else |
41 | 0 | num_dirs += ext2fs_bg_used_dirs_count(fs, i); |
42 | 0 | } |
43 | 0 | if (num_dirs > fs->super->s_inodes_count) |
44 | 0 | num_dirs = fs->super->s_inodes_count; |
45 | |
|
46 | 0 | *ret_num_dirs = num_dirs; |
47 | |
|
48 | 0 | return 0; |
49 | 0 | } |
50 | | |