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
18 #include <linux/ext2_fs.h>
22 static void ext2fs_free_inode_cache(struct ext2_inode_cache *icache);
24 void ext2fs_free(ext2_filsys fs)
26 if (!fs || (fs->magic != EXT2_ET_MAGIC_EXT2FS_FILSYS))
29 io_channel_close(fs->io);
32 ext2fs_free_mem((void **) &fs->device_name);
34 ext2fs_free_mem((void **) &fs->super);
36 ext2fs_free_mem((void **) &fs->group_desc);
38 ext2fs_free_block_bitmap(fs->block_map);
40 ext2fs_free_inode_bitmap(fs->inode_map);
43 badblocks_list_free(fs->badblocks);
47 ext2fs_free_dblist(fs->dblist);
50 ext2fs_free_inode_cache(fs->icache);
54 ext2fs_free_mem((void **) &fs);
57 void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap)
59 if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_GENERIC_BITMAP))
63 if (bitmap->description) {
64 ext2fs_free_mem((void **) &bitmap->description);
65 bitmap->description = 0;
68 ext2fs_free_mem((void **) &bitmap->bitmap);
71 ext2fs_free_mem((void **) &bitmap);
74 void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap)
76 if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_INODE_BITMAP))
79 bitmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP;
80 ext2fs_free_generic_bitmap(bitmap);
83 void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap)
85 if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_BLOCK_BITMAP))
88 bitmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP;
89 ext2fs_free_generic_bitmap(bitmap);
93 * Free the inode cache structure
95 static void ext2fs_free_inode_cache(struct ext2_inode_cache *icache)
97 if (--icache->refcount)
100 ext2fs_free_mem((void **) &icache->buffer);
102 ext2fs_free_mem((void **) &icache->cache);
103 icache->buffer_blk = 0;
104 ext2fs_free_mem((void **) &icache);
108 * This procedure frees a badblocks list.
110 void ext2fs_badblocks_list_free(ext2_badblocks_list bb)
112 if (bb->magic != EXT2_ET_MAGIC_BADBLOCKS_LIST)
116 ext2fs_free_mem((void **) &bb->list);
118 ext2fs_free_mem((void **) &bb);
122 * Free a directory block list
124 void ext2fs_free_dblist(ext2_dblist dblist)
126 if (!dblist || (dblist->magic != EXT2_ET_MAGIC_DBLIST))
130 ext2fs_free_mem((void **) &dblist->list);
132 if (dblist->fs && dblist->fs->dblist == dblist)
133 dblist->fs->dblist = 0;
135 ext2fs_free_mem((void **) &dblist);