From b6afefb5d12dbed4801272dae3048588dfc1cb9a Mon Sep 17 00:00:00 2001 From: fishsoupisgood Date: Sat, 12 May 2018 17:10:22 +0100 Subject: first working version --- src/zap_inode.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/zap_inode.c (limited to 'src/zap_inode.c') diff --git a/src/zap_inode.c b/src/zap_inode.c new file mode 100644 index 0000000..f40a16b --- /dev/null +++ b/src/zap_inode.c @@ -0,0 +1,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; +} + + + -- cgit v1.2.3