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