Whamcloud - gitweb
Many files:
[tools/e2fsprogs.git] / lib / ext2fs / freefs.c
1 /*
2  * freefs.c --- free an ext2 filesystem
3  * 
4  * Copyright (C) 1993, 1994 Theodore Ts'o.  This file may be redistributed
5  * under the terms of the GNU Public License.
6  */
7
8 #include <stdio.h>
9 #include <unistd.h>
10 #include <stdlib.h>
11
12 #include <linux/ext2_fs.h>
13
14 #include "ext2fs.h"
15
16 void ext2fs_free(ext2_filsys fs)
17 {
18         if (!fs || (fs->magic != EXT2_ET_MAGIC_EXT2FS_FILSYS))
19                 return;
20         if (fs->io) {
21                 io_channel_close(fs->io);
22         }
23         if (fs->device_name)
24                 free(fs->device_name);
25         if (fs->super)
26                 free(fs->super);
27         if (fs->group_desc)
28                 free(fs->group_desc);
29         if (fs->block_map)
30                 ext2fs_free_block_bitmap(fs->block_map);
31         if (fs->inode_map)
32                 ext2fs_free_inode_bitmap(fs->inode_map);
33         free(fs);
34 }
35
36 void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap)
37 {
38         if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_GENERIC_BITMAP))
39                 return;
40
41         bitmap->magic = 0;
42         if (bitmap->description) {
43                 free(bitmap->description);
44                 bitmap->description = 0;
45         }
46         if (bitmap->bitmap) {
47                 free(bitmap->bitmap);
48                 bitmap->bitmap = 0;
49         }
50         free(bitmap);
51 }
52
53 void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap)
54 {
55         if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_INODE_BITMAP))
56                 return;
57
58         bitmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP;
59         ext2fs_free_generic_bitmap(bitmap);
60 }
61
62 void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap)
63 {
64         if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_BLOCK_BITMAP))
65                 return;
66
67         bitmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP;
68         ext2fs_free_generic_bitmap(bitmap);
69 }
70