2 * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
\r
6 * Copyright (c) 2012 Martin Sucha
\r
7 * Copyright (c) 2012 Frantisek Princ
\r
8 * All rights reserved.
\r
10 * Redistribution and use in source and binary forms, with or without
\r
11 * modification, are permitted provided that the following conditions
\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
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
34 /** @addtogroup lwext4
\r
39 * @brief Directory handle procedures.
\r
45 #include <ext4_config.h>
\r
46 #include <ext4_types.h>
\r
47 #include <ext4_blockdev.h>
\r
48 #include <ext4_super.h>
\r
52 /**@brief Get i-node number from directory entry.
\r
53 * @param de Directory entry
\r
54 * @return I-node number
\r
56 uint32_t ext4_dir_entry_ll_get_inode(struct ext4_directory_entry_ll *de);
\r
58 /**@brief Set i-node number to directory entry.
\r
59 * @param de Directory entry
\r
60 * @param inode I-node number
\r
62 void ext4_dir_entry_ll_set_inode(struct ext4_directory_entry_ll *de,
\r
65 /**@brief Get directory entry length.
\r
66 * @param de Directory entry
\r
67 * @return Entry length
\r
69 uint16_t ext4_dir_entry_ll_get_entry_length(struct ext4_directory_entry_ll *de);
\r
71 /**@brief Set directory entry length.
\r
72 * @param de Directory entry
\r
73 * @param length Entry length
\r
75 void ext4_dir_entry_ll_set_entry_length(struct ext4_directory_entry_ll *de,
\r
78 /**@brief Get directory entry name length.
\r
79 * @param sb Superblock
\r
80 * @param de Directory entry
\r
81 * @return Entry name length
\r
83 uint16_t ext4_dir_entry_ll_get_name_length(struct ext4_sblock *sb,
\r
84 struct ext4_directory_entry_ll *de);
\r
86 /**@brief Set directory entry name length.
\r
87 * @param sb Superblock
\r
88 * @param de Directory entry
\r
89 * @param length Entry name length
\r
91 void ext4_dir_entry_ll_set_name_length(struct ext4_sblock *sb,
\r
92 struct ext4_directory_entry_ll *de, uint16_t len);
\r
94 /**@brief Get i-node type of directory entry.
\r
95 * @param sb Superblock
\r
96 * @param de Directory entry
\r
97 * @return I-node type (file, dir, etc.)
\r
99 uint8_t ext4_dir_entry_ll_get_inode_type(struct ext4_sblock *sb,
\r
100 struct ext4_directory_entry_ll *de);
\r
102 /**@brief Set i-node type of directory entry.
\r
103 * @param sb Superblock
\r
104 * @param de Directory entry
\r
105 * @param type I-node type (file, dir, etc.)
\r
107 void ext4_dir_entry_ll_set_inode_type(struct ext4_sblock *sb,
\r
108 struct ext4_directory_entry_ll *de, uint8_t type);
\r
110 /**@brief Initialize directory iterator.
\r
111 * Set position to the first valid entry from the required position.
\r
112 * @param it Pointer to iterator to be initialized
\r
113 * @param inode_ref Directory i-node
\r
114 * @param pos Position to start reading entries from
\r
115 * @return Error code
\r
117 int ext4_dir_iterator_init(struct ext4_directory_iterator *it,
\r
118 struct ext4_inode_ref *inode_ref, uint64_t pos);
\r
120 /**@brief Jump to the next valid entry
\r
121 * @param it Initialized iterator
\r
122 * @return Error code
\r
124 int ext4_dir_iterator_next(struct ext4_directory_iterator *it);
\r
126 /**@brief Uninitialize directory iterator.
\r
127 * Release all allocated structures.
\r
128 * @param it Iterator to be finished
\r
129 * @return Error code
\r
131 int ext4_dir_iterator_fini(struct ext4_directory_iterator *it);
\r
133 /**@brief Write directory entry to concrete data block.
\r
134 * @param sb Superblock
\r
135 * @param entry Pointer to entry to be written
\r
136 * @param entry_len Length of new entry
\r
137 * @param child Child i-node to be written to new entry
\r
138 * @param name Name of the new entry
\r
139 * @param name_len Length of entry name
\r
141 void ext4_dir_write_entry(struct ext4_sblock *sb,
\r
142 struct ext4_directory_entry_ll *entry, uint16_t entry_len,
\r
143 struct ext4_inode_ref *child, const char *name, size_t name_len);
\r
145 /**@brief Add new entry to the directory.
\r
146 * @param parent Directory i-node
\r
147 * @param name Name of new entry
\r
148 * @param child I-node to be referenced from new entry
\r
149 * @return Error code
\r
151 int ext4_dir_add_entry(struct ext4_inode_ref *parent, const char *name,
\r
152 uint32_t name_len, struct ext4_inode_ref *child);
\r
154 /**@brief Find directory entry with passed name.
\r
155 * @param result Result structure to be returned if entry found
\r
156 * @param parent Directory i-node
\r
157 * @param name Name of entry to be found
\r
158 * @param name_len Name length
\r
159 * @return Error code
\r
161 int ext4_dir_find_entry(struct ext4_directory_search_result *result,
\r
162 struct ext4_inode_ref *parent, const char *name, uint32_t name_len);
\r
164 /**@brief Remove directory entry.
\r
165 * @param parent Directory i-node
\r
166 * @param name Name of the entry to be removed
\r
167 * @param name_len Name length
\r
168 * @return Error code
\r
170 int ext4_dir_remove_entry(struct ext4_inode_ref *parent, const char *name,
\r
171 uint32_t name_len);
\r
173 /**@brief Try to insert entry to concrete data block.
\r
174 * @param sb Superblock
\r
175 * @param target_block Block to try to insert entry to
\r
176 * @param child Child i-node to be inserted by new entry
\r
177 * @param name Name of the new entry
\r
178 * @param name_len Length of the new entry name
\r
179 * @return Error code
\r
181 int ext4_dir_try_insert_entry(struct ext4_sblock *sb,
\r
182 struct ext4_block *target_block, struct ext4_inode_ref *child,
\r
183 const char *name, uint32_t name_len);
\r
185 /**@brief Try to find entry in block by name.
\r
186 * @param block Block containing entries
\r
187 * @param sb Superblock
\r
188 * @param name_len Length of entry name
\r
189 * @param name Name of entry to be found
\r
190 * @param res_entry Output pointer to found entry, NULL if not found
\r
191 * @return Error code
\r
193 int ext4_dir_find_in_block(struct ext4_block *block, struct ext4_sblock *sb,
\r
194 size_t name_len, const char *name,
\r
195 struct ext4_directory_entry_ll **res_entry);
\r
197 /**@brief Simple function to release allocated data from result.
\r
198 * @param parent Parent inode
\r
199 * @param result Search result to destroy
\r
200 * @return Error code
\r
203 int ext4_dir_destroy_result(struct ext4_inode_ref *parent,
\r
204 struct ext4_directory_search_result *result);
\r
206 #endif /* EXT4_DIR_H_ */
\r