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
17 #if EXT2_FLAT_INCLUDES
20 #include <linux/ext2_fs.h>
25 static void ext2fs_free_inode_cache(struct ext2_inode_cache *icache);
27 void ext2fs_free(ext2_filsys fs)
29 if (!fs || (fs->magic != EXT2_ET_MAGIC_EXT2FS_FILSYS))
32 io_channel_close(fs->io);
35 ext2fs_free_mem((void **) &fs->device_name);
37 ext2fs_free_mem((void **) &fs->super);
39 ext2fs_free_mem((void **) &fs->group_desc);
41 ext2fs_free_block_bitmap(fs->block_map);
43 ext2fs_free_inode_bitmap(fs->inode_map);
46 ext2fs_badblocks_list_free(fs->badblocks);
50 ext2fs_free_dblist(fs->dblist);
53 ext2fs_free_inode_cache(fs->icache);
57 ext2fs_free_mem((void **) &fs);
60 void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap)
62 if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_GENERIC_BITMAP))
66 if (bitmap->description) {
67 ext2fs_free_mem((void **) &bitmap->description);
68 bitmap->description = 0;
71 ext2fs_free_mem((void **) &bitmap->bitmap);
74 ext2fs_free_mem((void **) &bitmap);
77 void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap)
79 if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_INODE_BITMAP))
82 bitmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP;
83 ext2fs_free_generic_bitmap(bitmap);
86 void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap)
88 if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_BLOCK_BITMAP))
91 bitmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP;
92 ext2fs_free_generic_bitmap(bitmap);
96 * Free the inode cache structure
98 static void ext2fs_free_inode_cache(struct ext2_inode_cache *icache)
100 if (--icache->refcount)
103 ext2fs_free_mem((void **) &icache->buffer);
105 ext2fs_free_mem((void **) &icache->cache);
106 icache->buffer_blk = 0;
107 ext2fs_free_mem((void **) &icache);
111 * This procedure frees a badblocks list.
113 void ext2fs_badblocks_list_free(ext2_badblocks_list bb)
115 if (bb->magic != EXT2_ET_MAGIC_BADBLOCKS_LIST)
119 ext2fs_free_mem((void **) &bb->list);
121 ext2fs_free_mem((void **) &bb);
125 * Free a directory block list
127 void ext2fs_free_dblist(ext2_dblist dblist)
129 if (!dblist || (dblist->magic != EXT2_ET_MAGIC_DBLIST))
133 ext2fs_free_mem((void **) &dblist->list);
135 if (dblist->fs && dblist->fs->dblist == dblist)
136 dblist->fs->dblist = 0;
138 ext2fs_free_mem((void **) &dblist);