FIX: ea_size accounting is not correct after resizing. (2)
[lwext4.git] / lwext4 / ext4_extent.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_extent.h
39  * @brief More complex filesystem functions.
40  */
41 #ifndef EXT4_EXTENT_H_
42 #define EXT4_EXTENT_H_
43
44 #include "ext4_config.h"
45 #include "ext4_types.h"
46
47 /**@brief Get logical number of the block covered by extent.
48  * @param extent Extent to load number from
49  * @return Logical number of the first block covered by extent */
50 uint32_t ext4_extent_get_first_block(struct ext4_extent *extent);
51
52 /**@brief Set logical number of the first block covered by extent.
53  * @param extent Extent to set number to
54  * @param iblock Logical number of the first block covered by extent */
55 void ext4_extent_set_first_block(struct ext4_extent *extent, uint32_t iblock);
56
57 /**@brief Get number of blocks covered by extent.
58  * @param extent Extent to load count from
59  * @return Number of blocks covered by extent */
60 uint16_t ext4_extent_get_block_count(struct ext4_extent *extent);
61
62 /**@brief Set number of blocks covered by extent.
63  * @param extent Extent to load count from
64  * @param count  Number of blocks covered by extent */
65 void ext4_extent_set_block_count(struct ext4_extent *extent, uint16_t count);
66
67 /**@brief Get physical number of the first block covered by extent.
68  * @param extent Extent to load number
69  * @return Physical number of the first block covered by extent */
70 uint64_t ext4_extent_get_start(struct ext4_extent *extent);
71
72 /**@brief Set physical number of the first block covered by extent.
73  * @param extent Extent to load number
74  * @param fblock Physical number of the first block covered by extent */
75 void ext4_extent_set_start(struct ext4_extent *extent, uint64_t fblock);
76
77 /**@brief Get logical number of the block covered by extent index.
78  * @param index Extent index to load number from
79  * @return Logical number of the first block covered by extent index */
80 uint32_t ext4_extent_index_get_first_block(struct ext4_extent_index *index);
81
82 /**@brief Set logical number of the block covered by extent index.
83  * @param index  Extent index to set number to
84  * @param iblock Logical number of the first block covered by extent index */
85 void ext4_extent_index_set_first_block(struct ext4_extent_index *index,
86                                        uint32_t iblock);
87
88 /**@brief Get physical number of block where the child node is located.
89  * @param index Extent index to load number from
90  * @return Physical number of the block with child node */
91 uint64_t ext4_extent_index_get_leaf(struct ext4_extent_index *index);
92
93 /**@brief Set physical number of block where the child node is located.
94  * @param index  Extent index to set number to
95  * @param fblock Ohysical number of the block with child node */
96 void ext4_extent_index_set_leaf(struct ext4_extent_index *index,
97                                 uint64_t fblock);
98
99 /**@brief Get magic value from extent header.
100  * @param header Extent header to load value from
101  * @return Magic value of extent header */
102 uint16_t ext4_extent_header_get_magic(struct ext4_extent_header *header);
103
104 /**@brief Set magic value to extent header.
105  * @param header Extent header to set value to
106  * @param magic  Magic value of extent header */
107 void ext4_extent_header_set_magic(struct ext4_extent_header *header,
108                                   uint16_t magic);
109
110 /**@brief Get number of entries from extent header
111  * @param header Extent header to get value from
112  * @return Number of entries covered by extent header */
113 uint16_t
114 ext4_extent_header_get_entries_count(struct ext4_extent_header *header);
115
116 /**@brief Set number of entries to extent header
117  * @param header Extent header to set value to
118  * @param count  Number of entries covered by extent header */
119 void ext4_extent_header_set_entries_count(struct ext4_extent_header *header,
120                                           uint16_t count);
121
122 /**@brief Get maximum number of entries from extent header
123  * @param header Extent header to get value from
124  * @return Maximum number of entries covered by extent header */
125 uint16_t
126 ext4_extent_header_get_max_entries_count(struct ext4_extent_header *header);
127
128 /**@brief Set maximum number of entries to extent header
129  * @param header    Extent header to set value to
130  * @param max_count Maximum number of entries covered by extent header */
131 void ext4_extent_header_set_max_entries_count(struct ext4_extent_header *header,
132                                               uint16_t max_count);
133
134 /**@brief Get depth of extent subtree.
135  * @param header Extent header to get value from
136  * @return Depth of extent subtree */
137 uint16_t ext4_extent_header_get_depth(struct ext4_extent_header *header);
138
139 /**@brief Set depth of extent subtree.
140  * @param header Extent header to set value to
141  * @param depth  Depth of extent subtree */
142 void ext4_extent_header_set_depth(struct ext4_extent_header *header,
143                                   uint16_t depth);
144
145 /**@brief Get generation from extent header
146  * @param header Extent header to get value from
147  * @return Generation */
148 uint32_t ext4_extent_header_get_generation(struct ext4_extent_header *header);
149
150 /**@brief Set generation to extent header
151  * @param header     Extent header to set value to
152  * @param generation Generation */
153 void ext4_extent_header_set_generation(struct ext4_extent_header *header,
154                                        uint32_t generation);
155
156 /**@brief Find physical block in the extent tree by logical block number.
157  * There is no need to save path in the tree during this algorithm.
158  * @param inode_ref I-node to load block from
159  * @param iblock    Logical block number to find
160  * @param fblock    Output value for physical block number
161  * @return Error code*/
162 int ext4_extent_find_block(struct ext4_inode_ref *inode_ref, uint32_t iblock,
163                            uint32_t *fblock);
164
165 /**@brief Release all data blocks starting from specified logical block.
166  * @param inode_ref   I-node to release blocks from
167  * @param iblock_from First logical block to release
168  * @return Error code */
169 int ext4_extent_release_blocks_from(struct ext4_inode_ref *inode_ref,
170                                     uint32_t iblock_from);
171
172 /**@brief Append data block to the i-node.
173  * This function allocates data block, tries to append it
174  * to some existing extent or creates new extents.
175  * It includes possible extent tree modifications (splitting).
176  * @param inode_ref I-node to append block to
177  * @param iblock    Output logical number of newly allocated block
178  * @param fblock    Output physical block address of newly allocated block
179  *
180  * @return Error code*/
181 int ext4_extent_append_block(struct ext4_inode_ref *inode_ref, uint32_t *iblock,
182                              uint32_t *fblock, bool update_size);
183
184 #endif /* EXT4_EXTENT_H_ */
185        /**
186         * @}
187         */