ext4_journal: journal write skeleton code part 2.
[lwext4.git] / lwext4 / ext4_inode.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_inode.h
39  * @brief Inode handle functions
40  */
41
42 #ifndef EXT4_INODE_H_
43 #define EXT4_INODE_H_
44
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48
49 #include "ext4_config.h"
50
51 #include <stdint.h>
52
53 /**@brief Get mode of the i-node.
54  * @param sb    Superblock
55  * @param inode I-node to load mode from
56  * @return Mode of the i-node
57  */
58 uint32_t ext4_inode_get_mode(struct ext4_sblock *sb, struct ext4_inode *inode);
59
60 /**@brief Set mode of the i-node.
61  * @param sb    Superblock
62  * @param inode I-node to set mode to
63  * @param mode  Mode to set to i-node
64  */
65 void ext4_inode_set_mode(struct ext4_sblock *sb, struct ext4_inode *inode,
66                          uint32_t mode);
67
68 /**@brief Get ID of the i-node owner (user id).
69  * @param inode I-node to load uid from
70  * @return User ID of the i-node owner
71  */
72 uint32_t ext4_inode_get_uid(struct ext4_inode *inode);
73
74 /**@brief Set ID of the i-node owner.
75  * @param inode I-node to set uid to
76  * @param uid   ID of the i-node owner
77  */
78 void ext4_inode_set_uid(struct ext4_inode *inode, uint32_t uid);
79
80 /**@brief Get real i-node size.
81  * @param sb    Superblock
82  * @param inode I-node to load size from
83  * @return Real size of i-node
84  */
85 uint64_t ext4_inode_get_size(struct ext4_sblock *sb, struct ext4_inode *inode);
86
87 /**@brief Set real i-node size.
88  * @param inode I-node to set size to
89  * @param size  Size of the i-node
90  */
91 void ext4_inode_set_size(struct ext4_inode *inode, uint64_t size);
92
93 /**@brief Get time, when i-node was last accessed.
94  * @param inode I-node
95  * @return Time of the last access (POSIX)
96  */
97 uint32_t ext4_inode_get_access_time(struct ext4_inode *inode);
98
99 /**@brief Set time, when i-node was last accessed.
100  * @param inode I-node
101  * @param time  Time of the last access (POSIX)
102  */
103 void ext4_inode_set_access_time(struct ext4_inode *inode, uint32_t time);
104
105 /**@brief Get time, when i-node was last changed.
106  * @param inode I-node
107  * @return Time of the last change (POSIX)
108  */
109 uint32_t ext4_inode_get_change_inode_time(struct ext4_inode *inode);
110
111 /**@brief Set time, when i-node was last changed.
112  * @param inode I-node
113  * @param time  Time of the last change (POSIX)
114  */
115 void ext4_inode_set_change_inode_time(struct ext4_inode *inode, uint32_t time);
116
117 /**@brief Get time, when i-node content was last modified.
118  * @param inode I-node
119  * @return Time of the last content modification (POSIX)
120  */
121 uint32_t ext4_inode_get_modif_time(struct ext4_inode *inode);
122
123 /**@brief Set time, when i-node content was last modified.
124  * @param inode I-node
125  * @param time  Time of the last content modification (POSIX)
126  */
127 void ext4_inode_set_modif_time(struct ext4_inode *inode, uint32_t time);
128
129 /**@brief Get time, when i-node was deleted.
130  * @param inode I-node
131  * @return Time of the delete action (POSIX)
132  */
133 uint32_t ext4_inode_get_del_time(struct ext4_inode *inode);
134
135 /**@brief Set time, when i-node was deleted.
136  * @param inode I-node
137  * @param time  Time of the delete action (POSIX)
138  */
139 void ext4_inode_set_del_time(struct ext4_inode *inode, uint32_t time);
140
141 /**@brief Get ID of the i-node owner's group.
142  * @param inode I-node to load gid from
143  * @return Group ID of the i-node owner
144  */
145 uint32_t ext4_inode_get_gid(struct ext4_inode *inode);
146
147 /**@brief Set ID to the i-node owner's group.
148  * @param inode I-node to set gid to
149  * @param gid   Group ID of the i-node owner
150  */
151 void ext4_inode_set_gid(struct ext4_inode *inode, uint32_t gid);
152
153 /**@brief Get number of links to i-node.
154  * @param inode I-node to load number of links from
155  * @return Number of links to i-node
156  */
157 uint16_t ext4_inode_get_links_cnt(struct ext4_inode *inode);
158
159 /**@brief Set number of links to i-node.
160  * @param inode I-node to set number of links to
161  * @param count Number of links to i-node
162  */
163 void ext4_inode_set_links_cnt(struct ext4_inode *inode, uint16_t cnt);
164
165 /**@brief Get number of 512-bytes blocks used for i-node.
166  * @param sb    Superblock
167  * @param inode I-node
168  * @return Number of 512-bytes blocks
169  */
170 uint64_t ext4_inode_get_blocks_count(struct ext4_sblock *sb,
171                                      struct ext4_inode *inode);
172
173 /**@brief Set number of 512-bytes blocks used for i-node.
174  * @param sb    Superblock
175  * @param inode I-node
176  * @param count Number of 512-bytes blocks
177  * @return Error code
178  */
179 int ext4_inode_set_blocks_count(struct ext4_sblock *sb,
180                                 struct ext4_inode *inode, uint64_t cnt);
181
182 /**@brief Get flags (features) of i-node.
183  * @param inode I-node to get flags from
184  * @return Flags (bitmap)
185  */
186 uint32_t ext4_inode_get_flags(struct ext4_inode *inode);
187
188 /**@brief Set flags (features) of i-node.
189  * @param inode I-node to set flags to
190  * @param flags Flags to set to i-node
191  */
192 void ext4_inode_set_flags(struct ext4_inode *inode, uint32_t flags);
193
194 /**@brief Get file generation (used by NFS).
195  * @param inode I-node
196  * @return File generation
197  */
198 uint32_t ext4_inode_get_generation(struct ext4_inode *inode);
199
200 /**@brief Set file generation (used by NFS).
201  * @param inode      I-node
202  * @param generation File generation
203  */
204 void ext4_inode_set_generation(struct ext4_inode *inode, uint32_t gen);
205
206 /**@brief Get extra I-node size field.
207  * @param inode      I-node
208  * @return extra I-node size
209  */
210 uint16_t ext4_inode_get_extra_isize(struct ext4_inode *inode);
211
212 /**@brief Set extra I-node size field.
213  * @param inode      I-node
214  * @param size       extra I-node size
215  */
216 void ext4_inode_set_extra_isize(struct ext4_inode *inode, uint16_t size);
217
218 /**@brief Get address of block, where are extended attributes located.
219  * @param inode I-node
220  * @param sb    Superblock
221  * @return Block address
222  */
223 uint64_t ext4_inode_get_file_acl(struct ext4_inode *inode,
224                                  struct ext4_sblock *sb);
225
226 /**@brief Set address of block, where are extended attributes located.
227  * @param inode    I-node
228  * @param sb       Superblock
229  * @param file_acl Block address
230  */
231 void ext4_inode_set_file_acl(struct ext4_inode *inode, struct ext4_sblock *sb,
232                              uint64_t acl);
233
234 /**@brief Get block address of specified direct block.
235  * @param inode I-node to load block from
236  * @param idx   Index of logical block
237  * @return Physical block address
238  */
239 uint32_t ext4_inode_get_direct_block(struct ext4_inode *inode, uint32_t idx);
240
241 /**@brief Set block address of specified direct block.
242  * @param inode  I-node to set block address to
243  * @param idx    Index of logical block
244  * @param fblock Physical block address
245  */
246 void ext4_inode_set_direct_block(struct ext4_inode *inode, uint32_t idx,
247                                  uint32_t block);
248
249 /**@brief Get block address of specified indirect block.
250  * @param inode I-node to get block address from
251  * @param idx   Index of indirect block
252  * @return Physical block address
253  */
254 uint32_t ext4_inode_get_indirect_block(struct ext4_inode *inode, uint32_t idx);
255
256 /**@brief Set block address of specified indirect block.
257  * @param inode  I-node to set block address to
258  * @param idx    Index of indirect block
259  * @param fblock Physical block address
260  */
261 void ext4_inode_set_indirect_block(struct ext4_inode *inode, uint32_t idx,
262                                    uint32_t block);
263
264 /**@brief return the type of i-node
265  * @param sb    Superblock
266  * @param inode I-node to return the type of
267  * @return Result of check operation
268  */
269 uint32_t ext4_inode_type(struct ext4_sblock *sb, struct ext4_inode *inode);
270
271 /**@brief Check if i-node has specified type.
272  * @param sb    Superblock
273  * @param inode I-node to check type of
274  * @param type  Type to check
275  * @return Result of check operation
276  */
277 bool ext4_inode_is_type(struct ext4_sblock *sb, struct ext4_inode *inode,
278                         uint32_t type);
279
280 /**@brief Check if i-node has specified flag.
281  * @param inode I-node to check flags of
282  * @param flag  Flag to check
283  * @return Result of check operation
284  */
285 bool ext4_inode_has_flag(struct ext4_inode *inode, uint32_t f);
286
287 /**@brief Remove specified flag from i-node.
288  * @param inode      I-node to clear flag on
289  * @param clear_flag Flag to be cleared
290  */
291 void ext4_inode_clear_flag(struct ext4_inode *inode, uint32_t f);
292
293 /**@brief Set specified flag to i-node.
294  * @param inode    I-node to set flag on
295  * @param set_flag Flag to be set
296  */
297 void ext4_inode_set_flag(struct ext4_inode *inode, uint32_t f);
298
299 /**@brief Get inode checksum(crc32)
300  * @param sb    Superblock
301  * @param inode I-node to get checksum value from
302  */
303 uint32_t
304 ext4_inode_get_csum(struct ext4_sblock *sb, struct ext4_inode *inode);
305
306 /**@brief Get inode checksum(crc32)
307  * @param sb    Superblock
308  * @param inode I-node to get checksum value from
309  */
310 void
311 ext4_inode_set_csum(struct ext4_sblock *sb, struct ext4_inode *inode,
312                         uint32_t checksum);
313
314 /**@brief Check if i-node can be truncated.
315  * @param sb    Superblock
316  * @param inode I-node to check
317  * @return Result of the check operation
318  */
319 bool ext4_inode_can_truncate(struct ext4_sblock *sb, struct ext4_inode *inode);
320
321 /**@brief Get extent header from the root of the extent tree.
322  * @param inode I-node to get extent header from
323  * @return Pointer to extent header of the root node
324  */
325 struct ext4_extent_header *
326 ext4_inode_get_extent_header(struct ext4_inode *inode);
327
328 #ifdef __cplusplus
329 }
330 #endif
331
332 #endif /* EXT4_INODE_H_ */
333
334 /**
335  * @}
336  */