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