aboutsummaryrefslogtreecommitdiffstats
path: root/src/zap_inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/zap_inode.c')
-rw-r--r--src/zap_inode.c41
1 files changed, 41 insertions, 0 deletions
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;
+}
+
+
+