2 * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
6 * Copyright (c) 2012 Martin Sucha
7 * Copyright (c) 2012 Frantisek Princ
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
34 /** @addtogroup lwext4
39 * @brief More complex filesystem functions.
41 #ifndef EXT4_EXTENT_H_
42 #define EXT4_EXTENT_H_
44 #include "ext4_config.h"
45 #include "ext4_types.h"
47 #if !CONFIG_EXTENT_FULL
49 /**@brief Get logical number of the block covered by extent.
50 * @param extent Extent to load number from
51 * @return Logical number of the first block covered by extent */
52 uint32_t ext4_extent_get_first_block(struct ext4_extent *extent);
54 /**@brief Set logical number of the first block covered by extent.
55 * @param extent Extent to set number to
56 * @param iblock Logical number of the first block covered by extent */
57 void ext4_extent_set_first_block(struct ext4_extent *extent, uint32_t iblock);
59 /**@brief Get number of blocks covered by extent.
60 * @param extent Extent to load count from
61 * @return Number of blocks covered by extent */
62 uint16_t ext4_extent_get_block_count(struct ext4_extent *extent);
64 /**@brief Set number of blocks covered by extent.
65 * @param extent Extent to load count from
66 * @param count Number of blocks covered by extent
67 * @param unwritten Whether the extent is unwritten or not */
68 void ext4_extent_set_block_count(struct ext4_extent *extent, uint16_t count,
71 /**@brief Get physical number of the first block covered by extent.
72 * @param extent Extent to load number
73 * @return Physical number of the first block covered by extent */
74 uint64_t ext4_extent_get_start(struct ext4_extent *extent);
76 /**@brief Set physical number of the first block covered by extent.
77 * @param extent Extent to load number
78 * @param fblock Physical number of the first block covered by extent */
79 void ext4_extent_set_start(struct ext4_extent *extent, uint64_t fblock);
81 /**@brief Get logical number of the block covered by extent index.
82 * @param index Extent index to load number from
83 * @return Logical number of the first block covered by extent index */
84 uint32_t ext4_extent_index_get_first_block(struct ext4_extent_index *index);
86 /**@brief Set logical number of the block covered by extent index.
87 * @param index Extent index to set number to
88 * @param iblock Logical number of the first block covered by extent index */
89 void ext4_extent_index_set_first_block(struct ext4_extent_index *index,
92 /**@brief Get physical number of block where the child node is located.
93 * @param index Extent index to load number from
94 * @return Physical number of the block with child node */
95 uint64_t ext4_extent_index_get_leaf(struct ext4_extent_index *index);
97 /**@brief Set physical number of block where the child node is located.
98 * @param index Extent index to set number to
99 * @param fblock Ohysical number of the block with child node */
100 void ext4_extent_index_set_leaf(struct ext4_extent_index *index,
103 /**@brief Get magic value from extent header.
104 * @param header Extent header to load value from
105 * @return Magic value of extent header */
106 uint16_t ext4_extent_header_get_magic(struct ext4_extent_header *header);
108 /**@brief Set magic value to extent header.
109 * @param header Extent header to set value to
110 * @param magic Magic value of extent header */
111 void ext4_extent_header_set_magic(struct ext4_extent_header *header,
114 /**@brief Get number of entries from extent header
115 * @param header Extent header to get value from
116 * @return Number of entries covered by extent header */
118 ext4_extent_header_get_entries_count(struct ext4_extent_header *header);
120 /**@brief Set number of entries to extent header
121 * @param header Extent header to set value to
122 * @param count Number of entries covered by extent header */
123 void ext4_extent_header_set_entries_count(struct ext4_extent_header *header,
126 /**@brief Get maximum number of entries from extent header
127 * @param header Extent header to get value from
128 * @return Maximum number of entries covered by extent header */
130 ext4_extent_header_get_max_entries_count(struct ext4_extent_header *header);
132 /**@brief Set maximum number of entries to extent header
133 * @param header Extent header to set value to
134 * @param max_count Maximum number of entries covered by extent header */
135 void ext4_extent_header_set_max_entries_count(struct ext4_extent_header *header,
138 /**@brief Get depth of extent subtree.
139 * @param header Extent header to get value from
140 * @return Depth of extent subtree */
141 uint16_t ext4_extent_header_get_depth(struct ext4_extent_header *header);
143 /**@brief Set depth of extent subtree.
144 * @param header Extent header to set value to
145 * @param depth Depth of extent subtree */
146 void ext4_extent_header_set_depth(struct ext4_extent_header *header,
149 /**@brief Get generation from extent header
150 * @param header Extent header to get value from
151 * @return Generation */
152 uint32_t ext4_extent_header_get_generation(struct ext4_extent_header *header);
154 /**@brief Set generation to extent header
155 * @param header Extent header to set value to
156 * @param generation Generation */
157 void ext4_extent_header_set_generation(struct ext4_extent_header *header,
158 uint32_t generation);
160 /**@brief Find physical block in the extent tree by logical block number.
161 * There is no need to save path in the tree during this algorithm.
162 * @param inode_ref I-node to load block from
163 * @param iblock Logical block number to find
164 * @param fblock Output value for physical block number
165 * @return Error code*/
166 int ext4_extent_find_block(struct ext4_inode_ref *inode_ref, uint32_t iblock,
169 /**@brief Release all data blocks starting from specified logical block.
170 * @param inode_ref I-node to release blocks from
171 * @param iblock_from First logical block to release
172 * @return Error code */
173 int ext4_extent_release_blocks_from(struct ext4_inode_ref *inode_ref,
174 uint32_t iblock_from);
176 /**@brief Append data block to the i-node.
177 * This function allocates data block, tries to append it
178 * to some existing extent or creates new extents.
179 * It includes possible extent tree modifications (splitting).
180 * @param inode_ref I-node to append block to
181 * @param iblock Output logical number of newly allocated block
182 * @param fblock Output physical block address of newly allocated block
184 * @return Error code*/
185 int ext4_extent_append_block(struct ext4_inode_ref *inode_ref, uint32_t *iblock,
186 uint32_t *fblock, bool update_size);
190 #endif /* EXT4_EXTENT_H_ */