Move same simple functions to header
[lwext4.git] / lwext4 / ext4_dir_idx.h
1 /*\r
2  * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)\r
3  *\r
4  *\r
5  * HelenOS:\r
6  * Copyright (c) 2012 Martin Sucha\r
7  * Copyright (c) 2012 Frantisek Princ\r
8  * All rights reserved.\r
9  *\r
10  * Redistribution and use in source and binary forms, with or without\r
11  * modification, are permitted provided that the following conditions\r
12  * are met:\r
13  *\r
14  * - Redistributions of source code must retain the above copyright\r
15  *   notice, this list of conditions and the following disclaimer.\r
16  * - Redistributions in binary form must reproduce the above copyright\r
17  *   notice, this list of conditions and the following disclaimer in the\r
18  *   documentation and/or other materials provided with the distribution.\r
19  * - The name of the author may not be used to endorse or promote products\r
20  *   derived from this software without specific prior written permission.\r
21  *\r
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
32  */\r
33 \r
34 /** @addtogroup lwext4\r
35  * @{\r
36  */\r
37 /**\r
38  * @file  ext4_dir_idx.h\r
39  * @brief Directory indexing procedures.\r
40  */\r
41 \r
42 #ifndef EXT4_DIR_IDX_H_\r
43 #define EXT4_DIR_IDX_H_\r
44 \r
45 #include <ext4_config.h>\r
46 #include <ext4_types.h>\r
47 \r
48 #include <stdint.h>\r
49 #include <stdbool.h>\r
50 \r
51 \r
52 /**@brief Get hash version used in directory index.\r
53  * @param root_info Pointer to root info structure of index\r
54  * @return Hash algorithm version\r
55  */\r
56 static inline uint8_t ext4_dir_dx_root_info_get_hash_version(\r
57     struct ext4_directory_dx_root_info *root_info)\r
58 {\r
59     return root_info->hash_version;\r
60 }\r
61 \r
62 /**@brief Set hash version, that will be used in directory index.\r
63  * @param root_info Pointer to root info structure of index\r
64  * @param v Hash algorithm version\r
65  */\r
66 static inline void ext4_dir_dx_root_info_set_hash_version(\r
67     struct ext4_directory_dx_root_info  *root_info, uint8_t v)\r
68 {\r
69     root_info->hash_version = v;\r
70 }\r
71 \r
72 /**@brief Get length of root_info structure in bytes.\r
73  * @param root_info Pointer to root info structure of index\r
74  * @return Length of the structure\r
75  */\r
76 static inline uint8_t ext4_dir_dx_root_info_get_info_length(\r
77     struct ext4_directory_dx_root_info *root_info)\r
78 {\r
79     return root_info->info_length;\r
80 }\r
81 \r
82 /**@brief Set length of root_info structure in bytes.\r
83  * @param root_info   Pointer to root info structure of index\r
84  * @param info_length Length of the structure\r
85  */\r
86 static inline void ext4_dir_dx_root_info_set_info_length(\r
87     struct ext4_directory_dx_root_info  *root_info, uint8_t len)\r
88 {\r
89     root_info->info_length = len;\r
90 }\r
91 \r
92 /**@brief Get number of indirect levels of HTree.\r
93  * @param root_info Pointer to root info structure of index\r
94  * @return Height of HTree (actually only 0 or 1)\r
95  */\r
96 static inline uint8_t ext4_dir_dx_root_info_get_indirect_levels(\r
97     struct ext4_directory_dx_root_info *root_info)\r
98 {\r
99     return root_info->indirect_levels;\r
100 }\r
101 \r
102 /**@brief Set number of indirect levels of HTree.\r
103  * @param root_info Pointer to root info structure of index\r
104  * @param lvl Height of HTree (actually only 0 or 1)\r
105  */\r
106 static inline void ext4_dir_dx_root_info_set_indirect_levels(\r
107     struct ext4_directory_dx_root_info *root_info, uint8_t lvl)\r
108 {\r
109     root_info->indirect_levels = lvl;\r
110 }\r
111 \r
112 /**@brief Get maximum number of index node entries.\r
113  * @param climit Pointer to counlimit structure\r
114  * @return Maximum of entries in node\r
115  */\r
116 static inline uint16_t ext4_dir_dx_countlimit_get_limit(\r
117     struct ext4_directory_dx_countlimit *climit)\r
118 {\r
119     return to_le16(climit->limit);\r
120 }\r
121 \r
122 /**@brief Set maximum number of index node entries.\r
123  * @param climit Pointer to counlimit structure\r
124  * @param limit Maximum of entries in node\r
125  */\r
126 static inline void ext4_dir_dx_countlimit_set_limit(\r
127     struct ext4_directory_dx_countlimit *climit, uint16_t limit)\r
128 {\r
129     climit->limit = to_le16(limit);\r
130 }\r
131 \r
132 \r
133 /**@brief Get current number of index node entries.\r
134  * @param climit Pointer to counlimit structure\r
135  * @return Number of entries in node\r
136  */\r
137 static inline uint16_t ext4_dir_dx_countlimit_get_count(\r
138     struct ext4_directory_dx_countlimit *climit)\r
139 {\r
140     return to_le16(climit->count);\r
141 }\r
142 \r
143 /**@brief Set current number of index node entries.\r
144  * @param climit Pointer to counlimit structure\r
145  * @param count Number of entries in node\r
146  */\r
147 static inline void ext4_dir_dx_countlimit_set_count(\r
148     struct ext4_directory_dx_countlimit *climit, uint16_t count)\r
149 {\r
150     climit->count = to_le16(count);\r
151 }\r
152 \r
153 /**@brief Get hash value of index entry.\r
154  * @param entry Pointer to index entry\r
155  * @return Hash value\r
156  */\r
157 static inline uint32_t ext4_dir_dx_entry_get_hash(\r
158     struct ext4_directory_dx_entry *entry)\r
159 {\r
160     return to_le32(entry->hash);\r
161 }\r
162 \r
163 /**@brief Set hash value of index entry.\r
164  * @param entry Pointer to index entry\r
165  * @param hash  Hash value\r
166  */\r
167 static inline void ext4_dir_dx_entry_set_hash(\r
168     struct ext4_directory_dx_entry *entry, uint32_t hash)\r
169 {\r
170     entry->hash = to_le32(hash);\r
171 }\r
172 \r
173 /**@brief Get block address where child node is located.\r
174  * @param entry Pointer to index entry\r
175  * @return Block address of child node\r
176  */\r
177 static inline uint32_t ext4_dir_dx_entry_get_block(\r
178     struct ext4_directory_dx_entry *entry)\r
179 {\r
180     return to_le32(entry->block);\r
181 }\r
182 \r
183 /**@brief Set block address where child node is located.\r
184  * @param entry Pointer to index entry\r
185  * @param block Block address of child node\r
186  */\r
187 static inline void ext4_dir_dx_entry_set_block(\r
188     struct ext4_directory_dx_entry *entry, uint32_t block)\r
189 {\r
190     entry->block = to_le32(block);\r
191 }\r
192 \r
193 /**@brief Initialize index structure of new directory.\r
194  * @param dir Pointer to directory i-node\r
195  * @return Error code\r
196  */\r
197 int ext4_dir_dx_init(struct ext4_inode_ref *dir);\r
198 \r
199 /**@brief Try to find directory entry using directory index.\r
200  * @param result    Output value - if entry will be found,\r
201  *                  than will be passed through this parameter\r
202  * @param inode_ref Directory i-node\r
203  * @param name_len  Length of name to be found\r
204  * @param name      Name to be found\r
205  * @return Error code\r
206  */\r
207 int ext4_dir_dx_find_entry(struct ext4_directory_search_result * result,\r
208     struct ext4_inode_ref *inode_ref, size_t name_len, const char *name);\r
209 \r
210 /**@brief Add new entry to indexed directory\r
211  * @param parent Directory i-node\r
212  * @param child  I-node to be referenced from directory entry\r
213  * @param name   Name of new directory entry\r
214  * @return Error code\r
215  */\r
216 int ext4_dir_dx_add_entry(struct ext4_inode_ref *parent,\r
217     struct ext4_inode_ref *child, const char *name);\r
218 \r
219 #endif /* EXT4_DIR_IDX_H_ */\r
220 \r
221 /**\r
222  * @}\r
223  */\r
224 \r