2
* Copyright (c) 2011 Martin Sucha
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
9
* - Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* - Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* - The name of the author may not be used to endorse or promote products
15
* derived from this software without specific prior written permission.
17
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
/** @addtogroup libext2
36
#ifndef LIBEXT2_LIBEXT2_SUPERBLOCK_H_
37
#define LIBEXT2_LIBEXT2_SUPERBLOCK_H_
41
typedef struct ext2_superblock {
42
uint32_t total_inode_count; // Total number of inodes
43
uint32_t total_block_count; // Total number of blocks
44
uint32_t reserved_block_count; // Total number of reserved blocks
45
uint32_t free_block_count; // Total number of free blocks
46
uint32_t free_inode_count; // Total number of free inodes
47
uint32_t first_block; // Block containing the superblock (either 0 or 1)
48
uint32_t block_size_log2; // log_2(block_size)
49
int32_t fragment_size_log2; // log_2(fragment size)
50
uint32_t blocks_per_group; // Number of blocks in one block group
51
uint32_t fragments_per_group; // Number of fragments per block group
52
uint32_t inodes_per_group; // Number of inodes per block group
54
uint16_t magic; // Magic value
55
uint16_t state; // State (mounted/unmounted)
56
uint16_t error_behavior; // What to do when errors are encountered
57
uint16_t rev_minor; // Minor revision level
59
uint32_t os; // OS that created the filesystem
60
uint32_t rev_major; // Major revision level
63
// Following is for ext2 revision 1 only
67
uint32_t features_compatible;
68
uint32_t features_incompatible;
69
uint32_t features_read_only;
70
uint8_t uuid[16]; // UUID TODO: Create a library for UUIDs
71
uint8_t volume_name[16];
73
// TODO: add __attribute__((aligned(...)) for better performance?
74
// (it is necessary to ensure the superblock is correctly aligned then
76
} __attribute__ ((packed)) ext2_superblock_t;
78
#define EXT2_SUPERBLOCK_MAGIC 0xEF53
79
#define EXT2_SUPERBLOCK_SIZE 1024
80
#define EXT2_SUPERBLOCK_OFFSET 1024
81
#define EXT2_SUPERBLOCK_LAST_BYTE (EXT2_SUPERBLOCK_OFFSET + \
82
EXT2_SUPERBLOCK_SIZE -1)
83
#define EXT2_SUPERBLOCK_OS_LINUX 0
84
#define EXT2_SUPERBLOCK_OS_HURD 1
87
extern uint16_t ext2_superblock_get_magic(ext2_superblock_t *);
88
extern uint32_t ext2_superblock_get_first_block(ext2_superblock_t *);
89
extern uint32_t ext2_superblock_get_block_size_log2(ext2_superblock_t *);
90
extern uint32_t ext2_superblock_get_block_size(ext2_superblock_t *);
91
extern int32_t ext2_superblock_get_fragment_size_log2(ext2_superblock_t *);
92
extern uint32_t ext2_superblock_get_fragment_size(ext2_superblock_t *);
93
extern uint32_t ext2_superblock_get_blocks_per_group(ext2_superblock_t *);
94
extern uint32_t ext2_superblock_get_fragments_per_group(ext2_superblock_t *);
95
extern uint16_t ext2_superblock_get_state(ext2_superblock_t *);
96
extern uint16_t ext2_superblock_get_rev_minor(ext2_superblock_t *);
97
extern uint32_t ext2_superblock_get_rev_major(ext2_superblock_t *);
98
extern uint32_t ext2_superblock_get_os(ext2_superblock_t *);
99
extern uint32_t ext2_superblock_get_first_inode(ext2_superblock_t *);
100
extern uint16_t ext2_superblock_get_inode_size(ext2_superblock_t *);
101
extern uint32_t ext2_superblock_get_total_inode_count(ext2_superblock_t *);
102
extern uint32_t ext2_superblock_get_total_block_count(ext2_superblock_t *);
103
extern uint32_t ext2_superblock_get_reserved_block_count(ext2_superblock_t *);
104
extern uint32_t ext2_superblock_get_free_block_count(ext2_superblock_t *);
105
extern uint32_t ext2_superblock_get_free_inode_count(ext2_superblock_t *);
106
extern uint32_t ext2_superblock_get_block_group_count(ext2_superblock_t *);
107
extern uint32_t ext2_superblock_get_inodes_per_group(ext2_superblock_t *);
108
extern uint32_t ext2_superblock_get_features_compatible(ext2_superblock_t *);
109
extern uint32_t ext2_superblock_get_features_incompatible(ext2_superblock_t *);
110
extern uint32_t ext2_superblock_get_features_read_only(ext2_superblock_t *);
112
extern int ext2_superblock_read_direct(devmap_handle_t, ext2_superblock_t **);
113
extern int ext2_superblock_check_sanity(ext2_superblock_t *);