]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blame - lib/ext2fs/alloc_stats.c
Remove trailing whitespace for the entire source tree
[thirdparty/e2fsprogs.git] / lib / ext2fs / alloc_stats.c
CommitLineData
8bd0c959
TT
1/*
2 * alloc_stats.c --- Update allocation statistics for ext2fs
3 *
4 * Copyright (C) 2001 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%
efc6f628 10 *
8bd0c959
TT
11 */
12
13#include <stdio.h>
14
15#include "ext2_fs.h"
16#include "ext2fs.h"
17
7f961d42
TT
18void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
19 int inuse, int isdir)
8bd0c959
TT
20{
21 int group = ext2fs_group_of_ino(fs, ino);
22
23 if (inuse > 0)
24 ext2fs_mark_inode_bitmap(fs->inode_map, ino);
25 else
26 ext2fs_unmark_inode_bitmap(fs->inode_map, ino);
27 fs->group_desc[group].bg_free_inodes_count -= inuse;
7f961d42
TT
28 if (isdir)
29 fs->group_desc[group].bg_used_dirs_count += inuse;
d4f34d41 30
5711ed29 31 /* We don't strictly need to be clearing the uninit flag if inuse < 0
d4f34d41 32 * (i.e. freeing inodes) but it also means something is bad. */
5711ed29 33 fs->group_desc[group].bg_flags &= ~EXT2_BG_INODE_UNINIT;
d4f34d41
JS
34 if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
35 EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
36 ext2_ino_t first_unused_inode = fs->super->s_inodes_per_group -
37 fs->group_desc[group].bg_itable_unused +
38 group * fs->super->s_inodes_per_group + 1;
39
40 if (ino >= first_unused_inode)
41 fs->group_desc[group].bg_itable_unused =
42 group * fs->super->s_inodes_per_group +
43 fs->super->s_inodes_per_group - ino;
d4f34d41
JS
44 ext2fs_group_desc_csum_set(fs, group);
45 }
46
8bd0c959
TT
47 fs->super->s_free_inodes_count -= inuse;
48 ext2fs_mark_super_dirty(fs);
49 ext2fs_mark_ib_dirty(fs);
50}
51
7f961d42
TT
52void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse)
53{
54 ext2fs_inode_alloc_stats2(fs, ino, inuse, 0);
55}
56
8bd0c959
TT
57void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse)
58{
59 int group = ext2fs_group_of_blk(fs, blk);
60
61 if (inuse > 0)
62 ext2fs_mark_block_bitmap(fs->block_map, blk);
63 else
64 ext2fs_unmark_block_bitmap(fs->block_map, blk);
65 fs->group_desc[group].bg_free_blocks_count -= inuse;
d4f34d41
JS
66 fs->group_desc[group].bg_flags &= ~EXT2_BG_BLOCK_UNINIT;
67 ext2fs_group_desc_csum_set(fs, group);
68
8bd0c959
TT
69 fs->super->s_free_blocks_count -= inuse;
70 ext2fs_mark_super_dirty(fs);
71 ext2fs_mark_bb_dirty(fs);
f5c562e2
TT
72 if (fs->block_alloc_stats)
73 (fs->block_alloc_stats)(fs, (blk64_t) blk, inuse);
74}
75
efc6f628 76void ext2fs_set_block_alloc_stats_callback(ext2_filsys fs,
f5c562e2
TT
77 void (*func)(ext2_filsys fs,
78 blk64_t blk,
79 int inuse),
80 void (**old)(ext2_filsys fs,
81 blk64_t blk,
82 int inuse))
83{
84 if (!fs || fs->magic != EXT2_ET_MAGIC_EXT2FS_FILSYS)
85 return;
86 if (old)
87 *old = fs->block_alloc_stats;
88
89 fs->block_alloc_stats = func;
8bd0c959 90}