2 * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
6 * Copyright (c) 2012 Martin Sucha
7 * Copyright (c) 2012 Frantisek Princ
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * - Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * - Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * - The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 /** @addtogroup lwext4
38 * @file ext4_block_group.h
39 * @brief Block group function set.
42 #ifndef EXT4_BLOCK_GROUP_H_
43 #define EXT4_BLOCK_GROUP_H_
46 #include <ext4_config.h>
47 #include <ext4_types.h>
48 #include <ext4_super.h>
54 static inline uint64_t ext4_bg_get_block_bitmap(struct ext4_bgroup *bg,
55 struct ext4_sblock *s)
57 uint64_t v = to_le32(bg->block_bitmap_lo);
59 if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE)
60 v |= (uint64_t) to_le32(bg->block_bitmap_hi) << 32;
66 static inline uint64_t ext4_bg_get_inode_bitmap(struct ext4_bgroup *bg,
67 struct ext4_sblock *s)
70 uint64_t v = to_le32(bg->inode_bitmap_lo);
72 if (ext4_sb_get_desc_size(s)> EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE)
73 v |= (uint64_t) to_le32(bg->inode_bitmap_hi) << 32;
79 static inline uint64_t ext4_bg_get_inode_table_first_block(
80 struct ext4_bgroup *bg, struct ext4_sblock *s)
82 uint64_t v = to_le32(bg->inode_table_first_block_lo);
84 if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE)
85 v |= (uint64_t) to_le32(bg->inode_table_first_block_hi) << 32;
91 static inline uint32_t ext4_bg_get_free_blocks_count(struct ext4_bgroup *bg,
92 struct ext4_sblock *s)
94 uint32_t v = to_le16(bg->free_blocks_count_lo);
96 if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE)
97 v |= (uint32_t) to_le16(bg->free_blocks_count_hi) << 16;
102 /**@brief TODO: ...*/
103 static inline void ext4_bg_set_free_blocks_count(struct ext4_bgroup *bg,
104 struct ext4_sblock *s, uint32_t cnt)
106 bg->free_blocks_count_lo = to_le16((cnt << 16) >> 16);
107 if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE)
108 bg->free_blocks_count_hi = to_le16(cnt >> 16);
111 /**@brief TODO: ...*/
112 static inline uint32_t ext4_bg_get_free_inodes_count(struct ext4_bgroup *bg,
113 struct ext4_sblock *s)
115 uint32_t v = to_le16(bg->free_inodes_count_lo);
117 if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE)
118 v |= (uint32_t) to_le16(bg->free_inodes_count_hi) << 16;
123 /**@brief TODO: ...*/
124 static inline void ext4_bg_set_free_inodes_count(struct ext4_bgroup *bg,
125 struct ext4_sblock *s, uint32_t cnt)
127 bg->free_inodes_count_lo = to_le16((cnt << 16) >> 16);
128 if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE)
129 bg->free_inodes_count_hi = to_le16(cnt >> 16);
132 /**@brief TODO: ...*/
133 static inline uint32_t ext4_bg_get_used_dirs_count(struct ext4_bgroup *bg,
134 struct ext4_sblock *s)
136 uint32_t v = to_le16(bg->used_dirs_count_lo);
138 if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE)
139 v |= (uint32_t) to_le16(bg->used_dirs_count_hi) << 16;
144 /**@brief TODO: ...*/
145 static inline void ext4_bg_set_used_dirs_count(struct ext4_bgroup *bg,
146 struct ext4_sblock *s, uint32_t cnt)
148 bg->used_dirs_count_lo = to_le16((cnt << 16) >> 16);
149 if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE)
150 bg->used_dirs_count_hi = to_le16(cnt >> 16);
153 /**@brief TODO: ...*/
154 static inline uint32_t ext4_bg_get_itable_unused(struct ext4_bgroup *bg,
155 struct ext4_sblock *s)
158 uint32_t v = to_le16(bg->itable_unused_lo);
160 if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE)
161 v |= (uint32_t) to_le16(bg->itable_unused_hi) << 16;
166 /**@brief TODO: ...*/
167 static inline void ext4_bg_set_itable_unused(struct ext4_bgroup *bg,
168 struct ext4_sblock *s, uint32_t cnt)
170 bg->itable_unused_lo = to_le16((cnt << 16) >> 16);
171 if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE)
172 bg->itable_unused_hi = to_le16(cnt >> 16);
175 /**@brief TODO: ...*/
176 static inline void ext4_bg_set_checksum(struct ext4_bgroup *bg,
179 bg->checksum = to_le16(crc);
182 /**@brief TODO: ...*/
183 static inline bool ext4_bg_has_flag(struct ext4_bgroup *bg, uint32_t f)
185 return to_le16(bg->flags) & f;
188 /**@brief TODO: ...*/
189 static inline void ext4_bg_set_flag(struct ext4_bgroup *bg, uint32_t f)
191 uint16_t flags = to_le16(bg->flags);
193 bg->flags = to_le16(flags);
196 /**@brief TODO: ...*/
197 static inline void ext4_bg_clear_flag(struct ext4_bgroup *bg, uint32_t f)
199 uint16_t flags = to_le16(bg->flags);
201 bg->flags = to_le16(flags);
204 /**@brief TODO: ...*/
205 uint16_t ext4_bg_crc16(uint16_t crc, const uint8_t *buffer, size_t len);
207 #endif /* EXT4_BLOCK_GROUP_H_ */