2 * freefs.c --- free an ext2 filesystem
4 * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Public
16 #include <linux/ext2_fs.h>
20 static void ext2fs_free_inode_cache(struct ext2_inode_cache *icache);
22 void ext2fs_free(ext2_filsys fs)
24 if (!fs || (fs->magic != EXT2_ET_MAGIC_EXT2FS_FILSYS))
27 io_channel_close(fs->io);
30 free(fs->device_name);
36 ext2fs_free_block_bitmap(fs->block_map);
38 ext2fs_free_inode_bitmap(fs->inode_map);
41 badblocks_list_free(fs->badblocks);
45 ext2fs_free_dblist(fs->dblist);
48 ext2fs_free_inode_cache(fs->icache);
55 void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap)
57 if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_GENERIC_BITMAP))
61 if (bitmap->description) {
62 free(bitmap->description);
63 bitmap->description = 0;
72 void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap)
74 if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_INODE_BITMAP))
77 bitmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP;
78 ext2fs_free_generic_bitmap(bitmap);
81 void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap)
83 if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_BLOCK_BITMAP))
86 bitmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP;
87 ext2fs_free_generic_bitmap(bitmap);
91 * Free the inode cache structure
93 static void ext2fs_free_inode_cache(struct ext2_inode_cache *icache)
95 if (--icache->refcount)
101 icache->buffer_blk = 0;
106 * This procedure frees a badblocks list.
108 void ext2fs_badblocks_list_free(ext2_badblocks_list bb)
110 if (bb->magic != EXT2_ET_MAGIC_BADBLOCKS_LIST)
120 * Free a directory block list
122 void ext2fs_free_dblist(ext2_dblist dblist)
124 if (!dblist || (dblist->magic != EXT2_ET_MAGIC_DBLIST))
130 if (dblist->fs && dblist->fs->dblist == dblist)
131 dblist->fs->dblist = 0;