Whamcloud - gitweb
e2fsck: add support for dirdata feature
[tools/e2fsprogs.git] / lib / ext2fs / freefs.c
index 029ffaa..68b8e9a 100644 (file)
@@ -1,14 +1,15 @@
 /*
  * freefs.c --- free an ext2 filesystem
- * 
+ *
  * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
  *
  * %Begin-Header%
- * This file may be redistributed under the terms of the GNU Public
- * License.
+ * This file may be redistributed under the terms of the GNU Library
+ * General Public License, version 2.
  * %End-Header%
  */
 
+#include "config.h"
 #include <stdio.h>
 #if HAVE_UNISTD_H
 #include <unistd.h>
@@ -16,8 +17,7 @@
 
 #include "ext2_fs.h"
 #include "ext2fsP.h"
-
-static void ext2fs_free_inode_cache(struct ext2_inode_cache *icache);
+#include "hashmap.h"
 
 void ext2fs_free(ext2_filsys fs)
 {
@@ -42,6 +42,8 @@ void ext2fs_free(ext2_filsys fs)
                ext2fs_free_block_bitmap(fs->block_map);
        if (fs->inode_map)
                ext2fs_free_inode_bitmap(fs->inode_map);
+       if (fs->image_header)
+               ext2fs_free_mem(&fs->image_header);
 
        if (fs->badblocks)
                ext2fs_badblocks_list_free(fs->badblocks);
@@ -52,60 +54,19 @@ void ext2fs_free(ext2_filsys fs)
 
        if (fs->icache)
                ext2fs_free_inode_cache(fs->icache);
-       
-       fs->magic = 0;
-
-       ext2fs_free_mem(&fs);
-}
-
-void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap)
-{
-       if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_GENERIC_BITMAP))
-               return;
-
-       bitmap->magic = 0;
-       if (bitmap->description) {
-               ext2fs_free_mem(&bitmap->description);
-               bitmap->description = 0;
-       }
-       if (bitmap->bitmap) {
-               ext2fs_free_mem(&bitmap->bitmap);
-               bitmap->bitmap = 0;
-       }
-       ext2fs_free_mem(&bitmap);
-}
 
-void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap)
-{
-       if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_INODE_BITMAP))
-               return;
+       if (fs->mmp_buf)
+               ext2fs_free_mem(&fs->mmp_buf);
+       if (fs->mmp_cmp)
+               ext2fs_free_mem(&fs->mmp_cmp);
 
-       bitmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP;
-       ext2fs_free_generic_bitmap(bitmap);
-}
+       if (fs->block_sha_map)
+               ext2fs_hashmap_free(fs->block_sha_map);
 
-void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap)
-{
-       if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_BLOCK_BITMAP))
-               return;
-
-       bitmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP;
-       ext2fs_free_generic_bitmap(bitmap);
-}
+       fs->magic = 0;
 
-/*
- * Free the inode cache structure
- */
-static void ext2fs_free_inode_cache(struct ext2_inode_cache *icache)
-{
-       if (--icache->refcount)
-               return;
-       if (icache->buffer)
-               ext2fs_free_mem(&icache->buffer);
-       if (icache->cache)
-               ext2fs_free_mem(&icache->cache);
-       icache->buffer_blk = 0;
-       ext2fs_free_mem(&icache);
+       ext2fs_zero_blocks2(NULL, 0, 0, NULL, NULL);
+       ext2fs_free_mem(&fs);
 }
 
 /*