1 /* vi: set sw=4 ts=4: */
3 * freefs.c --- free an ext2 filesystem
5 * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
8 * This file may be redistributed under the terms of the GNU Public
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
);
34 ext2fs_free_mem(&fs
->device_name
);
35 ext2fs_free_mem(&fs
->super
);
36 ext2fs_free_mem(&fs
->orig_super
);
37 ext2fs_free_mem(&fs
->group_desc
);
38 ext2fs_free_block_bitmap(fs
->block_map
);
39 ext2fs_free_inode_bitmap(fs
->inode_map
);
41 ext2fs_badblocks_list_free(fs
->badblocks
);
44 ext2fs_free_dblist(fs
->dblist
);
47 ext2fs_free_inode_cache(fs
->icache
);
54 void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap
)
56 if (!bitmap
|| (bitmap
->magic
!= EXT2_ET_MAGIC_GENERIC_BITMAP
))
60 ext2fs_free_mem(&bitmap
->description
);
61 ext2fs_free_mem(&bitmap
->bitmap
);
62 ext2fs_free_mem(&bitmap
);
65 void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap
)
67 if (!bitmap
|| (bitmap
->magic
!= EXT2_ET_MAGIC_INODE_BITMAP
))
70 bitmap
->magic
= EXT2_ET_MAGIC_GENERIC_BITMAP
;
71 ext2fs_free_generic_bitmap(bitmap
);
74 void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap
)
76 if (!bitmap
|| (bitmap
->magic
!= EXT2_ET_MAGIC_BLOCK_BITMAP
))
79 bitmap
->magic
= EXT2_ET_MAGIC_GENERIC_BITMAP
;
80 ext2fs_free_generic_bitmap(bitmap
);
84 * Free the inode cache structure
86 static void ext2fs_free_inode_cache(struct ext2_inode_cache
*icache
)
88 if (--icache
->refcount
)
90 ext2fs_free_mem(&icache
->buffer
);
91 ext2fs_free_mem(&icache
->cache
);
92 icache
->buffer_blk
= 0;
93 ext2fs_free_mem(&icache
);
97 * This procedure frees a badblocks list.
99 void ext2fs_u32_list_free(ext2_u32_list bb
)
101 if (!bb
|| bb
->magic
!= EXT2_ET_MAGIC_BADBLOCKS_LIST
)
104 ext2fs_free_mem(&bb
->list
);
105 ext2fs_free_mem(&bb
);
108 void ext2fs_badblocks_list_free(ext2_badblocks_list bb
)
110 ext2fs_u32_list_free((ext2_u32_list
) bb
);
115 * Free a directory block list
117 void ext2fs_free_dblist(ext2_dblist dblist
)
119 if (!dblist
|| (dblist
->magic
!= EXT2_ET_MAGIC_DBLIST
))
122 ext2fs_free_mem(&dblist
->list
);
123 if (dblist
->fs
&& dblist
->fs
->dblist
== dblist
)
124 dblist
->fs
->dblist
= 0;
126 ext2fs_free_mem(&dblist
);