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
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))
26 if (fs->image_io != fs->io) {
28 io_channel_close(fs->image_io);
31 io_channel_close(fs->io);
33 ext2fs_free_mem(&fs->device_name);
34 ext2fs_free_mem(&fs->super);
35 ext2fs_free_mem(&fs->orig_super);
36 ext2fs_free_mem(&fs->group_desc);
37 ext2fs_free_block_bitmap(fs->block_map);
38 ext2fs_free_inode_bitmap(fs->inode_map);
40 ext2fs_badblocks_list_free(fs->badblocks);
43 ext2fs_free_dblist(fs->dblist);
46 ext2fs_free_inode_cache(fs->icache);
53 void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap)
55 if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_GENERIC_BITMAP))
59 ext2fs_free_mem(&bitmap->description);
60 ext2fs_free_mem(&bitmap->bitmap);
61 ext2fs_free_mem(&bitmap);
64 void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap)
66 if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_INODE_BITMAP))
69 bitmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP;
70 ext2fs_free_generic_bitmap(bitmap);
73 void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap)
75 if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_BLOCK_BITMAP))
78 bitmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP;
79 ext2fs_free_generic_bitmap(bitmap);
83 * Free the inode cache structure
85 static void ext2fs_free_inode_cache(struct ext2_inode_cache *icache)
87 if (--icache->refcount)
89 ext2fs_free_mem(&icache->buffer);
90 ext2fs_free_mem(&icache->cache);
91 icache->buffer_blk = 0;
92 ext2fs_free_mem(&icache);
96 * This procedure frees a badblocks list.
98 void ext2fs_u32_list_free(ext2_u32_list bb)
100 if (!bb || bb->magic != EXT2_ET_MAGIC_BADBLOCKS_LIST)
103 ext2fs_free_mem(&bb->list);
104 ext2fs_free_mem(&bb);
107 void ext2fs_badblocks_list_free(ext2_badblocks_list bb)
109 ext2fs_u32_list_free((ext2_u32_list) bb);
114 * Free a directory block list
116 void ext2fs_free_dblist(ext2_dblist dblist)
118 if (!dblist || (dblist->magic != EXT2_ET_MAGIC_DBLIST))
121 ext2fs_free_mem(&dblist->list);
122 if (dblist->fs && dblist->fs->dblist == dblist)
123 dblist->fs->dblist = 0;
125 ext2fs_free_mem(&dblist);