aboutsummaryrefslogtreecommitdiffstats
path: root/src/zap_inode.c
blob: f40a16bbbe22e26a5ffb98c445c5dd683ecbc4d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "project.h"

static int clear_blocks (ext2_filsys fs, blk_t *b_num,
                         e2_blkcnt_t blockcnt,
                         blk_t ref_block,
                         int ref_offset,
                         void *priv_data)
{
  ext2fs_block_alloc_stats2 (fs, *b_num, -1);

  *b_num = 0;
  return BLOCK_CHANGED;
}




int zap_inode (ext2_filsys fs, ext2_ino_t i_num, struct ext2_inode *i)
{
  int ret;

  printf ("clearing already used inode %d\n", (int) i_num);

  EXT2_MOAN_FAIL (ret, ext2fs_block_iterate2 (fs, i_num, BLOCK_FLAG_DEPTH_TRAVERSE, 0, clear_blocks, NULL));

  if (ret) return -1;

  if (i->i_mode & LINUX_S_IFDIR)
    ext2fs_inode_alloc_stats2 (fs, i_num, -1, -1);
  else
    ext2fs_inode_alloc_stats2 (fs, i_num, -1, 0);

  memset (i, 0, sizeof (*i));

  EXT2_MOAN_FAIL (ret, ext2fs_write_inode (fs, i_num, i));

  return ret;
}