Code format.
[lwext4.git] / lwext4 / ext4_block_group.h
1 /*
2  * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
3  *
4  *
5  * HelenOS:
6  * Copyright (c) 2012 Martin Sucha
7  * Copyright (c) 2012 Frantisek Princ
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
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.
21  *
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.
32  */
33
34 /** @addtogroup lwext4
35  * @{
36  */
37 /**
38  * @file  ext4_block_group.h
39  * @brief Block group function set.
40  */
41
42 #ifndef EXT4_BLOCK_GROUP_H_
43 #define EXT4_BLOCK_GROUP_H_
44
45
46 #include <ext4_config.h>
47 #include <ext4_types.h>
48 #include <ext4_super.h>
49
50 #include <stdint.h>
51 #include <stdbool.h>
52
53 /**@brief   TODO: ...*/
54 static inline uint64_t ext4_bg_get_block_bitmap(struct ext4_bgroup *bg,
55     struct ext4_sblock *s)
56 {
57     uint64_t v = to_le32(bg->block_bitmap_lo);
58
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;
61
62     return v;
63 }
64
65 /**@brief   TODO: ...*/
66 static inline uint64_t ext4_bg_get_inode_bitmap(struct ext4_bgroup *bg,
67     struct ext4_sblock *s)
68 {
69
70     uint64_t v = to_le32(bg->inode_bitmap_lo);
71
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;
74
75     return v;
76 }
77
78 /**@brief   TODO: ...*/
79 static inline uint64_t ext4_bg_get_inode_table_first_block(
80     struct ext4_bgroup *bg, struct ext4_sblock *s)
81 {
82     uint64_t v = to_le32(bg->inode_table_first_block_lo);
83
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;
86
87     return v;
88 }
89
90 /**@brief   TODO: ...*/
91 static inline uint32_t ext4_bg_get_free_blocks_count(struct ext4_bgroup *bg,
92     struct ext4_sblock *s)
93 {
94     uint32_t v = to_le16(bg->free_blocks_count_lo);
95
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;
98
99     return v;
100 }
101
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)
105 {
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);
109 }
110
111 /**@brief   TODO: ...*/
112 static inline uint32_t ext4_bg_get_free_inodes_count(struct ext4_bgroup *bg,
113     struct ext4_sblock *s)
114 {
115     uint32_t v = to_le16(bg->free_inodes_count_lo);
116
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;
119
120     return v;
121 }
122
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)
126 {
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);
130 }
131
132 /**@brief   TODO: ...*/
133 static inline uint32_t ext4_bg_get_used_dirs_count(struct ext4_bgroup *bg,
134     struct ext4_sblock *s)
135 {
136     uint32_t v = to_le16(bg->used_dirs_count_lo);
137
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;
140
141     return v;
142 }
143
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)
147 {
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);
151 }
152
153 /**@brief   TODO: ...*/
154 static inline uint32_t ext4_bg_get_itable_unused(struct ext4_bgroup *bg,
155     struct ext4_sblock *s)
156 {
157
158     uint32_t v = to_le16(bg->itable_unused_lo);
159
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;
162
163     return v;
164 }
165
166 /**@brief   TODO: ...*/
167 static inline void ext4_bg_set_itable_unused(struct ext4_bgroup *bg,
168     struct ext4_sblock *s, uint32_t cnt)
169 {
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);
173 }
174
175 /**@brief   TODO: ...*/
176 static inline void ext4_bg_set_checksum(struct ext4_bgroup *bg,
177     uint16_t crc)
178 {
179     bg->checksum = to_le16(crc);
180 }
181
182 /**@brief   TODO: ...*/
183 static inline bool ext4_bg_has_flag(struct ext4_bgroup *bg, uint32_t f)
184 {
185     return to_le16(bg->flags) & f;
186 }
187
188 /**@brief   TODO: ...*/
189 static inline void ext4_bg_set_flag(struct ext4_bgroup *bg, uint32_t f)
190 {
191     uint16_t flags = to_le16(bg->flags);
192     flags |= f;
193     bg->flags = to_le16(flags);
194 }
195
196 /**@brief   TODO: ...*/
197 static inline void ext4_bg_clear_flag(struct ext4_bgroup *bg, uint32_t f)
198 {
199     uint16_t flags = to_le16(bg->flags);
200     flags &= ~f;
201     bg->flags = to_le16(flags);
202 }
203
204 /**@brief   TODO: ...*/
205 uint16_t ext4_bg_crc16(uint16_t crc, const uint8_t *buffer, size_t len);
206
207 #endif /* EXT4_BLOCK_GROUP_H_ */
208
209 /**
210  * @}
211  */