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 Library
8 * General Public License, version 2.
21 static void ext2fs_free_inode_cache(struct ext2_inode_cache *icache);
23 void ext2fs_free(ext2_filsys fs)
25 if (!fs || (fs->magic != EXT2_ET_MAGIC_EXT2FS_FILSYS))
27 if (fs->image_io != fs->io) {
29 io_channel_close(fs->image_io);
32 io_channel_close(fs->io);
35 ext2fs_free_mem(&fs->device_name);
37 ext2fs_free_mem(&fs->super);
39 ext2fs_free_mem(&fs->orig_super);
41 ext2fs_free_mem(&fs->group_desc);
43 ext2fs_free_block_bitmap(fs->block_map);
45 ext2fs_free_inode_bitmap(fs->inode_map);
48 ext2fs_badblocks_list_free(fs->badblocks);
52 ext2fs_free_dblist(fs->dblist);
55 ext2fs_free_inode_cache(fs->icache);
58 ext2fs_free_mem(&fs->mmp_buf);
60 ext2fs_free_mem(&fs->mmp_cmp);
68 * Free the inode cache structure
70 static void ext2fs_free_inode_cache(struct ext2_inode_cache *icache)
72 if (--icache->refcount)
75 ext2fs_free_mem(&icache->buffer);
77 ext2fs_free_mem(&icache->cache);
78 icache->buffer_blk = 0;
79 ext2fs_free_mem(&icache);
83 * This procedure frees a badblocks list.
85 void ext2fs_u32_list_free(ext2_u32_list bb)
87 if (bb->magic != EXT2_ET_MAGIC_BADBLOCKS_LIST)
91 ext2fs_free_mem(&bb->list);
96 void ext2fs_badblocks_list_free(ext2_badblocks_list bb)
98 ext2fs_u32_list_free((ext2_u32_list) bb);
103 * Free a directory block list
105 void ext2fs_free_dblist(ext2_dblist dblist)
107 if (!dblist || (dblist->magic != EXT2_ET_MAGIC_DBLIST))
111 ext2fs_free_mem(&dblist->list);
113 if (dblist->fs && dblist->fs->dblist == dblist)
114 dblist->fs->dblist = 0;
116 ext2fs_free_mem(&dblist);