| 1 | /*
|
|---|
| 2 | * Copyright (c) 2011 Frantisek Princ
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup libext4
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 |
|
|---|
| 33 | /**
|
|---|
| 34 | * @file libext4_directory_index.c
|
|---|
| 35 | * @brief Ext4 directory index operations.
|
|---|
| 36 | */
|
|---|
| 37 |
|
|---|
| 38 | #include <byteorder.h>
|
|---|
| 39 | #include <errno.h>
|
|---|
| 40 | #include <malloc.h>
|
|---|
| 41 | #include <sort.h>
|
|---|
| 42 | #include <string.h>
|
|---|
| 43 | #include "libext4.h"
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 | uint8_t ext4_directory_dx_root_info_get_hash_version(
|
|---|
| 47 | ext4_directory_dx_root_info_t *root_info)
|
|---|
| 48 | {
|
|---|
| 49 | return root_info->hash_version;
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | void ext4_directory_dx_root_info_set_hash_version(
|
|---|
| 53 | ext4_directory_dx_root_info_t *root_info, uint8_t version)
|
|---|
| 54 | {
|
|---|
| 55 | root_info->hash_version = version;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | uint8_t ext4_directory_dx_root_info_get_info_length(
|
|---|
| 59 | ext4_directory_dx_root_info_t *root_info)
|
|---|
| 60 | {
|
|---|
| 61 | return root_info->info_length;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | void ext4_directory_dx_root_info_set_info_length(
|
|---|
| 65 | ext4_directory_dx_root_info_t *root_info, uint8_t info_length)
|
|---|
| 66 | {
|
|---|
| 67 | root_info->info_length = info_length;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | uint8_t ext4_directory_dx_root_info_get_indirect_levels(
|
|---|
| 71 | ext4_directory_dx_root_info_t *root_info)
|
|---|
| 72 | {
|
|---|
| 73 | return root_info->indirect_levels;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | void ext4_directory_dx_root_info_set_indirect_levels(
|
|---|
| 77 | ext4_directory_dx_root_info_t *root_info, uint8_t levels)
|
|---|
| 78 | {
|
|---|
| 79 | root_info->indirect_levels = levels;
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | uint16_t ext4_directory_dx_countlimit_get_limit(
|
|---|
| 83 | ext4_directory_dx_countlimit_t *countlimit)
|
|---|
| 84 | {
|
|---|
| 85 | return uint16_t_le2host(countlimit->limit);
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | void ext4_directory_dx_countlimit_set_limit(
|
|---|
| 89 | ext4_directory_dx_countlimit_t *countlimit, uint16_t limit)
|
|---|
| 90 | {
|
|---|
| 91 | countlimit->limit = host2uint16_t_le(limit);
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | uint16_t ext4_directory_dx_countlimit_get_count(
|
|---|
| 95 | ext4_directory_dx_countlimit_t *countlimit)
|
|---|
| 96 | {
|
|---|
| 97 | return uint16_t_le2host(countlimit->count);
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | void ext4_directory_dx_countlimit_set_count(
|
|---|
| 101 | ext4_directory_dx_countlimit_t *countlimit, uint16_t count)
|
|---|
| 102 | {
|
|---|
| 103 | countlimit->count = host2uint16_t_le(count);
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | uint32_t ext4_directory_dx_entry_get_hash(ext4_directory_dx_entry_t *entry)
|
|---|
| 107 | {
|
|---|
| 108 | return uint32_t_le2host(entry->hash);
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | void ext4_directory_dx_entry_set_hash(ext4_directory_dx_entry_t *entry,
|
|---|
| 112 | uint32_t hash)
|
|---|
| 113 | {
|
|---|
| 114 | entry->hash = host2uint32_t_le(hash);
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | uint32_t ext4_directory_dx_entry_get_block(ext4_directory_dx_entry_t *entry)
|
|---|
| 118 | {
|
|---|
| 119 | return uint32_t_le2host(entry->block);
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | void ext4_directory_dx_entry_set_block(ext4_directory_dx_entry_t *entry,
|
|---|
| 123 | uint32_t block)
|
|---|
| 124 | {
|
|---|
| 125 | entry->block = host2uint32_t_le(block);
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 | /**************************************************************************/
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 | static int ext4_directory_hinfo_init(ext4_hash_info_t *hinfo, block_t *root_block,
|
|---|
| 133 | ext4_superblock_t *sb, size_t name_len, const char *name)
|
|---|
| 134 | {
|
|---|
| 135 |
|
|---|
| 136 | ext4_directory_dx_root_t *root = (ext4_directory_dx_root_t *)root_block->data;
|
|---|
| 137 |
|
|---|
| 138 | if (root->info.hash_version != EXT4_HASH_VERSION_TEA &&
|
|---|
| 139 | root->info.hash_version != EXT4_HASH_VERSION_HALF_MD4 &&
|
|---|
| 140 | root->info.hash_version != EXT4_HASH_VERSION_LEGACY) {
|
|---|
| 141 | return EXT4_ERR_BAD_DX_DIR;
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | // Check unused flags
|
|---|
| 145 | if (root->info.unused_flags != 0) {
|
|---|
| 146 | EXT4FS_DBG("ERR: unused_flags = \%u", root->info.unused_flags);
|
|---|
| 147 | return EXT4_ERR_BAD_DX_DIR;
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | // Check indirect levels
|
|---|
| 151 | if (root->info.indirect_levels > 1) {
|
|---|
| 152 | EXT4FS_DBG("ERR: indirect_levels = \%u", root->info.indirect_levels);
|
|---|
| 153 | return EXT4_ERR_BAD_DX_DIR;
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | uint32_t block_size = ext4_superblock_get_block_size(sb);
|
|---|
| 157 |
|
|---|
| 158 | uint32_t entry_space = block_size;
|
|---|
| 159 | entry_space -= 2 * sizeof(ext4_directory_dx_dot_entry_t);
|
|---|
| 160 | entry_space -= sizeof(ext4_directory_dx_root_info_t);
|
|---|
| 161 | entry_space = entry_space / sizeof(ext4_directory_dx_entry_t);
|
|---|
| 162 |
|
|---|
| 163 | uint16_t limit = ext4_directory_dx_countlimit_get_limit((ext4_directory_dx_countlimit_t *)&root->entries);
|
|---|
| 164 | if (limit != entry_space) {
|
|---|
| 165 | return EXT4_ERR_BAD_DX_DIR;
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | hinfo->hash_version = ext4_directory_dx_root_info_get_hash_version(&root->info);
|
|---|
| 169 | if ((hinfo->hash_version <= EXT4_HASH_VERSION_TEA)
|
|---|
| 170 | && (ext4_superblock_has_flag(sb, EXT4_SUPERBLOCK_FLAGS_UNSIGNED_HASH))) {
|
|---|
| 171 | // 3 is magic from ext4 linux implementation
|
|---|
| 172 | hinfo->hash_version += 3;
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | hinfo->seed = ext4_superblock_get_hash_seed(sb);
|
|---|
| 176 |
|
|---|
| 177 | if (name) {
|
|---|
| 178 | ext4_hash_string(hinfo, name_len, name);
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | return EOK;
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | static int ext4_directory_dx_get_leaf(ext4_hash_info_t *hinfo,
|
|---|
| 185 | ext4_filesystem_t *fs, ext4_inode_t *inode, block_t *root_block,
|
|---|
| 186 | ext4_directory_dx_block_t **dx_block, ext4_directory_dx_block_t *dx_blocks)
|
|---|
| 187 | {
|
|---|
| 188 | int rc;
|
|---|
| 189 |
|
|---|
| 190 | ext4_directory_dx_block_t *tmp_dx_block = dx_blocks;
|
|---|
| 191 |
|
|---|
| 192 | ext4_directory_dx_root_t *root = (ext4_directory_dx_root_t *)root_block->data;
|
|---|
| 193 | ext4_directory_dx_entry_t *entries = (ext4_directory_dx_entry_t *)&root->entries;
|
|---|
| 194 |
|
|---|
| 195 | uint16_t limit = ext4_directory_dx_countlimit_get_limit((ext4_directory_dx_countlimit_t *)entries);
|
|---|
| 196 | uint8_t indirect_level = ext4_directory_dx_root_info_get_indirect_levels(&root->info);
|
|---|
| 197 |
|
|---|
| 198 | block_t *tmp_block = root_block;
|
|---|
| 199 | ext4_directory_dx_entry_t *p, *q, *m, *at;
|
|---|
| 200 | while (true) {
|
|---|
| 201 |
|
|---|
| 202 | uint16_t count = ext4_directory_dx_countlimit_get_count((ext4_directory_dx_countlimit_t *)entries);
|
|---|
| 203 | if ((count == 0) || (count > limit)) {
|
|---|
| 204 | return EXT4_ERR_BAD_DX_DIR;
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 | p = entries + 1;
|
|---|
| 208 | q = entries + count - 1;
|
|---|
| 209 |
|
|---|
| 210 | while (p <= q) {
|
|---|
| 211 | m = p + (q - p) / 2;
|
|---|
| 212 | if (ext4_directory_dx_entry_get_hash(m) > hinfo->hash) {
|
|---|
| 213 | q = m - 1;
|
|---|
| 214 | } else {
|
|---|
| 215 | p = m + 1;
|
|---|
| 216 | }
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | at = p - 1;
|
|---|
| 220 |
|
|---|
| 221 | tmp_dx_block->block = tmp_block;
|
|---|
| 222 | tmp_dx_block->entries = entries;
|
|---|
| 223 | tmp_dx_block->position = at;
|
|---|
| 224 |
|
|---|
| 225 | if (indirect_level == 0) {
|
|---|
| 226 | *dx_block = tmp_dx_block;
|
|---|
| 227 | return EOK;
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | uint32_t next_block = ext4_directory_dx_entry_get_block(at);
|
|---|
| 231 |
|
|---|
| 232 | indirect_level--;
|
|---|
| 233 |
|
|---|
| 234 | uint32_t fblock;
|
|---|
| 235 | rc = ext4_filesystem_get_inode_data_block_index(fs, inode, next_block, &fblock);
|
|---|
| 236 | if (rc != EOK) {
|
|---|
| 237 | return rc;
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | rc = block_get(&tmp_block, fs->device, fblock, BLOCK_FLAGS_NONE);
|
|---|
| 241 | if (rc != EOK) {
|
|---|
| 242 | return rc;
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 | entries = ((ext4_directory_dx_node_t *) tmp_block->data)->entries;
|
|---|
| 246 | limit = ext4_directory_dx_countlimit_get_limit((ext4_directory_dx_countlimit_t *)entries);
|
|---|
| 247 |
|
|---|
| 248 | uint16_t entry_space = ext4_superblock_get_block_size(fs->superblock)
|
|---|
| 249 | - sizeof(ext4_directory_dx_dot_entry_t);
|
|---|
| 250 | entry_space = entry_space / sizeof(ext4_directory_dx_entry_t);
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 | if (limit != entry_space) {
|
|---|
| 254 | block_put(tmp_block);
|
|---|
| 255 | return EXT4_ERR_BAD_DX_DIR;
|
|---|
| 256 | }
|
|---|
| 257 |
|
|---|
| 258 | ++tmp_dx_block;
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | // Unreachable
|
|---|
| 262 | return EOK;
|
|---|
| 263 | }
|
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 | static int ext4_directory_dx_find_dir_entry(block_t *block,
|
|---|
| 267 | ext4_superblock_t *sb, size_t name_len, const char *name,
|
|---|
| 268 | ext4_directory_entry_ll_t **res_entry, aoff64_t *block_offset)
|
|---|
| 269 | {
|
|---|
| 270 |
|
|---|
| 271 | aoff64_t offset = 0;
|
|---|
| 272 | ext4_directory_entry_ll_t *dentry = (ext4_directory_entry_ll_t *)block->data;
|
|---|
| 273 | uint8_t *addr_limit = block->data + ext4_superblock_get_block_size(sb);
|
|---|
| 274 |
|
|---|
| 275 | while ((uint8_t *)dentry < addr_limit) {
|
|---|
| 276 |
|
|---|
| 277 | if ((uint8_t*) dentry + name_len > addr_limit) {
|
|---|
| 278 | break;
|
|---|
| 279 | }
|
|---|
| 280 |
|
|---|
| 281 | if (dentry->inode != 0) {
|
|---|
| 282 | if (name_len == ext4_directory_entry_ll_get_name_length(sb, dentry)) {
|
|---|
| 283 | // Compare names
|
|---|
| 284 | if (bcmp((uint8_t *)name, dentry->name, name_len) == 0) {
|
|---|
| 285 | *block_offset = offset;
|
|---|
| 286 | *res_entry = dentry;
|
|---|
| 287 | return 1;
|
|---|
| 288 | }
|
|---|
| 289 | }
|
|---|
| 290 | }
|
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 | // Goto next entry
|
|---|
| 294 | uint16_t dentry_len = ext4_directory_entry_ll_get_entry_length(dentry);
|
|---|
| 295 |
|
|---|
| 296 | if (dentry_len == 0) {
|
|---|
| 297 | // Error
|
|---|
| 298 | return -1;
|
|---|
| 299 | }
|
|---|
| 300 |
|
|---|
| 301 | offset += dentry_len;
|
|---|
| 302 | dentry = (ext4_directory_entry_ll_t *)((uint8_t *)dentry + dentry_len);
|
|---|
| 303 | }
|
|---|
| 304 |
|
|---|
| 305 | return 0;
|
|---|
| 306 | }
|
|---|
| 307 |
|
|---|
| 308 | static int ext4_directory_dx_next_block(ext4_filesystem_t *fs, ext4_inode_t *inode, uint32_t hash,
|
|---|
| 309 | ext4_directory_dx_block_t *handle, ext4_directory_dx_block_t *handles)
|
|---|
| 310 | {
|
|---|
| 311 | int rc;
|
|---|
| 312 |
|
|---|
| 313 |
|
|---|
| 314 | uint32_t num_handles = 0;
|
|---|
| 315 | ext4_directory_dx_block_t *p = handle;
|
|---|
| 316 |
|
|---|
| 317 | while (1) {
|
|---|
| 318 |
|
|---|
| 319 | p->position++;
|
|---|
| 320 | uint16_t count = ext4_directory_dx_countlimit_get_count((ext4_directory_dx_countlimit_t *)p->entries);
|
|---|
| 321 |
|
|---|
| 322 | if (p->position < p->entries + count) {
|
|---|
| 323 | break;
|
|---|
| 324 | }
|
|---|
| 325 |
|
|---|
| 326 | if (p == handles) {
|
|---|
| 327 | return 0;
|
|---|
| 328 | }
|
|---|
| 329 |
|
|---|
| 330 | num_handles++;
|
|---|
| 331 | p--;
|
|---|
| 332 | }
|
|---|
| 333 |
|
|---|
| 334 | uint32_t current_hash = ext4_directory_dx_entry_get_hash(p->position);
|
|---|
| 335 |
|
|---|
| 336 | if ((hash & 1) == 0) {
|
|---|
| 337 | if ((current_hash & ~1) != hash) {
|
|---|
| 338 | return 0;
|
|---|
| 339 | }
|
|---|
| 340 | }
|
|---|
| 341 |
|
|---|
| 342 |
|
|---|
| 343 | while (num_handles--) {
|
|---|
| 344 |
|
|---|
| 345 | uint32_t block_idx = ext4_directory_dx_entry_get_block(p->position);
|
|---|
| 346 | uint32_t block_addr;
|
|---|
| 347 | rc = ext4_filesystem_get_inode_data_block_index(fs, inode, block_idx, &block_addr);
|
|---|
| 348 | if (rc != EOK) {
|
|---|
| 349 | return rc;
|
|---|
| 350 | }
|
|---|
| 351 |
|
|---|
| 352 | block_t *block;
|
|---|
| 353 | rc = block_get(&block, fs->device, block_addr, BLOCK_FLAGS_NONE);
|
|---|
| 354 | if (rc != EOK) {
|
|---|
| 355 | return rc;
|
|---|
| 356 | }
|
|---|
| 357 |
|
|---|
| 358 | p++;
|
|---|
| 359 |
|
|---|
| 360 | block_put(p->block);
|
|---|
| 361 | p->block = block;
|
|---|
| 362 | p->entries = ((ext4_directory_dx_node_t *) block->data)->entries;
|
|---|
| 363 | p->position = p->entries;
|
|---|
| 364 | }
|
|---|
| 365 |
|
|---|
| 366 | return 1;
|
|---|
| 367 |
|
|---|
| 368 | }
|
|---|
| 369 |
|
|---|
| 370 | int ext4_directory_dx_find_entry(ext4_directory_iterator_t *it,
|
|---|
| 371 | ext4_filesystem_t *fs, ext4_inode_ref_t *inode_ref, size_t len, const char *name)
|
|---|
| 372 | {
|
|---|
| 373 | int rc;
|
|---|
| 374 |
|
|---|
| 375 | // get direct block 0 (index root)
|
|---|
| 376 | uint32_t root_block_addr;
|
|---|
| 377 | rc = ext4_filesystem_get_inode_data_block_index(fs, inode_ref->inode, 0, &root_block_addr);
|
|---|
| 378 | if (rc != EOK) {
|
|---|
| 379 | return rc;
|
|---|
| 380 | }
|
|---|
| 381 |
|
|---|
| 382 | block_t *root_block;
|
|---|
| 383 | rc = block_get(&root_block, fs->device, root_block_addr, BLOCK_FLAGS_NONE);
|
|---|
| 384 | if (rc != EOK) {
|
|---|
| 385 | it->current_block = NULL;
|
|---|
| 386 | return rc;
|
|---|
| 387 | }
|
|---|
| 388 |
|
|---|
| 389 | ext4_hash_info_t hinfo;
|
|---|
| 390 | rc = ext4_directory_hinfo_init(&hinfo, root_block, fs->superblock, len, name);
|
|---|
| 391 | if (rc != EOK) {
|
|---|
| 392 | block_put(root_block);
|
|---|
| 393 | return EXT4_ERR_BAD_DX_DIR;
|
|---|
| 394 | }
|
|---|
| 395 |
|
|---|
| 396 | // Hardcoded number 2 means maximum height of index tree !!!
|
|---|
| 397 | ext4_directory_dx_block_t dx_blocks[2];
|
|---|
| 398 | ext4_directory_dx_block_t *dx_block;
|
|---|
| 399 | rc = ext4_directory_dx_get_leaf(&hinfo, fs, inode_ref->inode, root_block, &dx_block, dx_blocks);
|
|---|
| 400 | if (rc != EOK) {
|
|---|
| 401 | block_put(root_block);
|
|---|
| 402 | return EXT4_ERR_BAD_DX_DIR;
|
|---|
| 403 | }
|
|---|
| 404 |
|
|---|
| 405 |
|
|---|
| 406 | do {
|
|---|
| 407 |
|
|---|
| 408 | uint32_t leaf_block_idx = ext4_directory_dx_entry_get_block(dx_block->position);
|
|---|
| 409 | uint32_t leaf_block_addr;
|
|---|
| 410 | rc = ext4_filesystem_get_inode_data_block_index(fs, inode_ref->inode, leaf_block_idx, &leaf_block_addr);
|
|---|
| 411 | if (rc != EOK) {
|
|---|
| 412 | return EXT4_ERR_BAD_DX_DIR;
|
|---|
| 413 | }
|
|---|
| 414 |
|
|---|
| 415 | block_t *leaf_block;
|
|---|
| 416 | rc = block_get(&leaf_block, fs->device, leaf_block_addr, BLOCK_FLAGS_NONE);
|
|---|
| 417 | if (rc != EOK) {
|
|---|
| 418 | return EXT4_ERR_BAD_DX_DIR;
|
|---|
| 419 | }
|
|---|
| 420 |
|
|---|
| 421 | aoff64_t block_offset;
|
|---|
| 422 | ext4_directory_entry_ll_t *res_dentry;
|
|---|
| 423 | rc = ext4_directory_dx_find_dir_entry(leaf_block, fs->superblock, len, name,
|
|---|
| 424 | &res_dentry, &block_offset);
|
|---|
| 425 |
|
|---|
| 426 | // Found => return it
|
|---|
| 427 | if (rc == 1) {
|
|---|
| 428 | it->fs = fs;
|
|---|
| 429 | it->inode_ref = inode_ref;
|
|---|
| 430 | it->current_block = leaf_block;
|
|---|
| 431 | it->current_offset = block_offset;
|
|---|
| 432 | it->current = res_dentry;
|
|---|
| 433 | return EOK;
|
|---|
| 434 | }
|
|---|
| 435 |
|
|---|
| 436 | block_put(leaf_block);
|
|---|
| 437 |
|
|---|
| 438 | // ERROR - corrupted index
|
|---|
| 439 | if (rc == -1) {
|
|---|
| 440 | // TODO cleanup
|
|---|
| 441 | return EXT4_ERR_BAD_DX_DIR;
|
|---|
| 442 | }
|
|---|
| 443 |
|
|---|
| 444 | rc = ext4_directory_dx_next_block(fs, inode_ref->inode, hinfo.hash, dx_block, &dx_blocks[0]);
|
|---|
| 445 | if (rc < 0) {
|
|---|
| 446 | // TODO cleanup
|
|---|
| 447 | return EXT4_ERR_BAD_DX_DIR;
|
|---|
| 448 | }
|
|---|
| 449 |
|
|---|
| 450 | } while (rc == 1);
|
|---|
| 451 |
|
|---|
| 452 | return ENOENT;
|
|---|
| 453 | }
|
|---|
| 454 |
|
|---|
| 455 | typedef struct ext4_dx_sort_entry {
|
|---|
| 456 | uint32_t hash;
|
|---|
| 457 | uint32_t rec_len;
|
|---|
| 458 | void *dentry;
|
|---|
| 459 | } ext4_dx_sort_entry_t;
|
|---|
| 460 |
|
|---|
| 461 | static int dx_entry_comparator(void *arg1, void *arg2, void *dummy)
|
|---|
| 462 | {
|
|---|
| 463 | ext4_dx_sort_entry_t *entry1 = arg1;
|
|---|
| 464 | ext4_dx_sort_entry_t *entry2 = arg2;
|
|---|
| 465 |
|
|---|
| 466 | if (entry1->hash == entry2->hash) {
|
|---|
| 467 | return 0;
|
|---|
| 468 | }
|
|---|
| 469 |
|
|---|
| 470 | if (entry1->hash < entry2->hash) {
|
|---|
| 471 | return -1;
|
|---|
| 472 | } else {
|
|---|
| 473 | return 1;
|
|---|
| 474 | }
|
|---|
| 475 |
|
|---|
| 476 | }
|
|---|
| 477 |
|
|---|
| 478 | static int ext4_directory_dx_split_data(ext4_filesystem_t *fs,
|
|---|
| 479 | ext4_inode_ref_t *inode_ref, ext4_hash_info_t *hinfo,
|
|---|
| 480 | block_t *old_data_block, ext4_directory_dx_block_t *index_block, block_t **new_data_block)
|
|---|
| 481 | {
|
|---|
| 482 | int rc;
|
|---|
| 483 |
|
|---|
| 484 | uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
|
|---|
| 485 | void *entry_buffer = malloc(block_size);
|
|---|
| 486 | if (entry_buffer == NULL) {
|
|---|
| 487 | return ENOMEM;
|
|---|
| 488 | }
|
|---|
| 489 |
|
|---|
| 490 | // Copy data to buffer
|
|---|
| 491 | memcpy(entry_buffer, old_data_block->data, block_size);
|
|---|
| 492 |
|
|---|
| 493 | // dot entry has the smallest size available
|
|---|
| 494 | uint32_t max_entry_count = block_size / sizeof(ext4_directory_dx_dot_entry_t);
|
|---|
| 495 |
|
|---|
| 496 | ext4_dx_sort_entry_t *sort_array = malloc(max_entry_count * sizeof(ext4_dx_sort_entry_t));
|
|---|
| 497 | if (sort_array == NULL) {
|
|---|
| 498 | free(entry_buffer);
|
|---|
| 499 | return ENOMEM;
|
|---|
| 500 | }
|
|---|
| 501 |
|
|---|
| 502 | ext4_directory_entry_ll_t *dentry = old_data_block->data;
|
|---|
| 503 |
|
|---|
| 504 | uint32_t idx = 0;
|
|---|
| 505 | uint32_t real_size = 0;
|
|---|
| 506 | void *entry_buffer_ptr = entry_buffer;
|
|---|
| 507 |
|
|---|
| 508 | ext4_hash_info_t tmp_hinfo;
|
|---|
| 509 | memcpy(&tmp_hinfo, hinfo, sizeof(ext4_hash_info_t));
|
|---|
| 510 |
|
|---|
| 511 | while ((void *)dentry < old_data_block->data + block_size) {
|
|---|
| 512 |
|
|---|
| 513 | // Read only valid entries
|
|---|
| 514 | if (ext4_directory_entry_ll_get_inode(dentry) != 0) {
|
|---|
| 515 | char *name = (char *)dentry->name;
|
|---|
| 516 |
|
|---|
| 517 | uint8_t len = ext4_directory_entry_ll_get_name_length(fs->superblock, dentry);
|
|---|
| 518 | ext4_hash_string(&tmp_hinfo, len, name);
|
|---|
| 519 |
|
|---|
| 520 | uint32_t rec_len = 8 + len;
|
|---|
| 521 |
|
|---|
| 522 | if ((rec_len % 4) != 0) {
|
|---|
| 523 | rec_len += 4 - (rec_len % 4);
|
|---|
| 524 | }
|
|---|
| 525 |
|
|---|
| 526 | memcpy(entry_buffer_ptr, dentry, rec_len);
|
|---|
| 527 |
|
|---|
| 528 | sort_array[idx].dentry = entry_buffer_ptr;
|
|---|
| 529 | sort_array[idx].rec_len = rec_len;
|
|---|
| 530 | sort_array[idx].hash = tmp_hinfo.hash;
|
|---|
| 531 |
|
|---|
| 532 | entry_buffer_ptr += rec_len;
|
|---|
| 533 | real_size += rec_len;
|
|---|
| 534 | idx++;
|
|---|
| 535 | }
|
|---|
| 536 |
|
|---|
| 537 | dentry = (void *)dentry + ext4_directory_entry_ll_get_entry_length(dentry);
|
|---|
| 538 | }
|
|---|
| 539 |
|
|---|
| 540 | qsort(sort_array, idx, sizeof(ext4_dx_sort_entry_t), dx_entry_comparator, NULL);
|
|---|
| 541 |
|
|---|
| 542 | uint32_t new_fblock;
|
|---|
| 543 | uint32_t new_iblock;
|
|---|
| 544 | rc = ext4_directory_append_block(fs, inode_ref, &new_fblock, &new_iblock);
|
|---|
| 545 | if (rc != EOK) {
|
|---|
| 546 | free(sort_array);
|
|---|
| 547 | free(entry_buffer);
|
|---|
| 548 | return rc;
|
|---|
| 549 | }
|
|---|
| 550 |
|
|---|
| 551 | // EXT4FS_DBG("new block appended (iblock = \%u, fblock = \%u)", new_iblock, new_fblock);
|
|---|
| 552 |
|
|---|
| 553 | // Load new block
|
|---|
| 554 | block_t *new_data_block_tmp;
|
|---|
| 555 | rc = block_get(&new_data_block_tmp, fs->device, new_fblock, BLOCK_FLAGS_NOREAD);
|
|---|
| 556 | if (rc != EOK) {
|
|---|
| 557 | free(sort_array);
|
|---|
| 558 | free(entry_buffer);
|
|---|
| 559 | return rc;
|
|---|
| 560 | }
|
|---|
| 561 |
|
|---|
| 562 | // Distribute entries to splitted blocks (by size)
|
|---|
| 563 |
|
|---|
| 564 | uint32_t new_hash = 0;
|
|---|
| 565 | uint32_t current_size = 0;
|
|---|
| 566 | uint32_t mid = 0;
|
|---|
| 567 | for (uint32_t i = 0; i < idx; ++i) {
|
|---|
| 568 | if ((current_size + sort_array[i].rec_len) > (real_size / 2)) {
|
|---|
| 569 | new_hash = sort_array[i].hash;
|
|---|
| 570 | mid = i;
|
|---|
| 571 | break;
|
|---|
| 572 | }
|
|---|
| 573 |
|
|---|
| 574 | current_size += sort_array[i].rec_len;
|
|---|
| 575 | }
|
|---|
| 576 |
|
|---|
| 577 | uint32_t continued = 0;
|
|---|
| 578 | if (new_hash == sort_array[mid-1].hash) {
|
|---|
| 579 | continued = 1;
|
|---|
| 580 | }
|
|---|
| 581 |
|
|---|
| 582 | uint32_t offset = 0;
|
|---|
| 583 | void *ptr;
|
|---|
| 584 |
|
|---|
| 585 | // First part - to the old block
|
|---|
| 586 | for (uint32_t i = 0; i < mid; ++i) {
|
|---|
| 587 | ptr = old_data_block->data + offset;
|
|---|
| 588 | memcpy(ptr, sort_array[i].dentry, sort_array[i].rec_len);
|
|---|
| 589 |
|
|---|
| 590 | ext4_directory_entry_ll_t *tmp = ptr;
|
|---|
| 591 | if (i < (mid - 1)) {
|
|---|
| 592 | ext4_directory_entry_ll_set_entry_length(tmp, sort_array[i].rec_len);
|
|---|
| 593 | } else {
|
|---|
| 594 | ext4_directory_entry_ll_set_entry_length(tmp, block_size - offset);
|
|---|
| 595 | }
|
|---|
| 596 |
|
|---|
| 597 | offset += sort_array[i].rec_len;
|
|---|
| 598 | }
|
|---|
| 599 |
|
|---|
| 600 | // Second part - to the new block
|
|---|
| 601 | offset = 0;
|
|---|
| 602 | for (uint32_t i = mid; i < idx; ++i) {
|
|---|
| 603 | ptr = new_data_block_tmp->data + offset;
|
|---|
| 604 | memcpy(ptr, sort_array[i].dentry, sort_array[i].rec_len);
|
|---|
| 605 |
|
|---|
| 606 | ext4_directory_entry_ll_t *tmp = ptr;
|
|---|
| 607 | if (i < (idx - 1)) {
|
|---|
| 608 | ext4_directory_entry_ll_set_entry_length(tmp, sort_array[i].rec_len);
|
|---|
| 609 | } else {
|
|---|
| 610 | ext4_directory_entry_ll_set_entry_length(tmp, block_size - offset);
|
|---|
| 611 | }
|
|---|
| 612 |
|
|---|
| 613 | offset += sort_array[i].rec_len;
|
|---|
| 614 | }
|
|---|
| 615 |
|
|---|
| 616 | old_data_block->dirty = true;
|
|---|
| 617 | new_data_block_tmp->dirty = true;
|
|---|
| 618 |
|
|---|
| 619 | free(sort_array);
|
|---|
| 620 | free(entry_buffer);
|
|---|
| 621 |
|
|---|
| 622 | ext4_directory_dx_entry_t *old_index_entry = index_block->position;
|
|---|
| 623 | ext4_directory_dx_entry_t *new_index_entry = old_index_entry + 1;
|
|---|
| 624 |
|
|---|
| 625 | ext4_directory_dx_countlimit_t *countlimit =
|
|---|
| 626 | (ext4_directory_dx_countlimit_t *)index_block->entries;
|
|---|
| 627 | uint32_t count = ext4_directory_dx_countlimit_get_count(countlimit);
|
|---|
| 628 |
|
|---|
| 629 | ext4_directory_dx_entry_t *start_index = index_block->entries;
|
|---|
| 630 | size_t bytes = (void *)(start_index + count) - (void *)(new_index_entry);
|
|---|
| 631 |
|
|---|
| 632 | memmove(new_index_entry + 1, new_index_entry, bytes);
|
|---|
| 633 |
|
|---|
| 634 | ext4_directory_dx_entry_set_block(new_index_entry, new_iblock);
|
|---|
| 635 | ext4_directory_dx_entry_set_hash(new_index_entry, new_hash + continued);
|
|---|
| 636 |
|
|---|
| 637 | ext4_directory_dx_countlimit_set_count(countlimit, count + 1);
|
|---|
| 638 |
|
|---|
| 639 | index_block->block->dirty = true;
|
|---|
| 640 |
|
|---|
| 641 | *new_data_block = new_data_block_tmp;
|
|---|
| 642 |
|
|---|
| 643 | return EOK;
|
|---|
| 644 | }
|
|---|
| 645 |
|
|---|
| 646 |
|
|---|
| 647 | int ext4_directory_dx_add_entry(ext4_filesystem_t *fs,
|
|---|
| 648 | ext4_inode_ref_t *parent, ext4_inode_ref_t *child,
|
|---|
| 649 | size_t name_size, const char *name)
|
|---|
| 650 | {
|
|---|
| 651 | int rc;
|
|---|
| 652 |
|
|---|
| 653 | // get direct block 0 (index root)
|
|---|
| 654 | uint32_t root_block_addr;
|
|---|
| 655 | rc = ext4_filesystem_get_inode_data_block_index(fs, parent->inode, 0, &root_block_addr);
|
|---|
| 656 | if (rc != EOK) {
|
|---|
| 657 | return rc;
|
|---|
| 658 | }
|
|---|
| 659 |
|
|---|
| 660 | block_t *root_block;
|
|---|
| 661 | rc = block_get(&root_block, fs->device, root_block_addr, BLOCK_FLAGS_NONE);
|
|---|
| 662 | if (rc != EOK) {
|
|---|
| 663 | return rc;
|
|---|
| 664 | }
|
|---|
| 665 |
|
|---|
| 666 | ext4_hash_info_t hinfo;
|
|---|
| 667 | rc = ext4_directory_hinfo_init(&hinfo, root_block, fs->superblock, name_size, name);
|
|---|
| 668 | if (rc != EOK) {
|
|---|
| 669 | block_put(root_block);
|
|---|
| 670 | return EXT4_ERR_BAD_DX_DIR;
|
|---|
| 671 | }
|
|---|
| 672 |
|
|---|
| 673 | // Hardcoded number 2 means maximum height of index tree !!!
|
|---|
| 674 | ext4_directory_dx_block_t dx_blocks[2];
|
|---|
| 675 | ext4_directory_dx_block_t *dx_block;
|
|---|
| 676 | rc = ext4_directory_dx_get_leaf(&hinfo, fs, parent->inode, root_block, &dx_block, dx_blocks);
|
|---|
| 677 | if (rc != EOK) {
|
|---|
| 678 | block_put(root_block);
|
|---|
| 679 | return EXT4_ERR_BAD_DX_DIR;
|
|---|
| 680 | }
|
|---|
| 681 |
|
|---|
| 682 |
|
|---|
| 683 | // Try to insert to existing data block
|
|---|
| 684 | uint32_t leaf_block_idx = ext4_directory_dx_entry_get_block(dx_block->position);
|
|---|
| 685 | uint32_t leaf_block_addr;
|
|---|
| 686 | rc = ext4_filesystem_get_inode_data_block_index(fs, parent->inode, leaf_block_idx, &leaf_block_addr);
|
|---|
| 687 | if (rc != EOK) {
|
|---|
| 688 | return EXT4_ERR_BAD_DX_DIR;
|
|---|
| 689 | }
|
|---|
| 690 |
|
|---|
| 691 |
|
|---|
| 692 | block_t *target_block;
|
|---|
| 693 | rc = block_get(&target_block, fs->device, leaf_block_addr, BLOCK_FLAGS_NONE);
|
|---|
| 694 | if (rc != EOK) {
|
|---|
| 695 | return EXT4_ERR_BAD_DX_DIR;
|
|---|
| 696 | }
|
|---|
| 697 |
|
|---|
| 698 | uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
|
|---|
| 699 | uint16_t required_len = 8 + name_size + (4 - name_size % 4);
|
|---|
| 700 |
|
|---|
| 701 | ext4_directory_entry_ll_t *de = target_block->data;
|
|---|
| 702 | ext4_directory_entry_ll_t *stop = target_block->data + block_size;
|
|---|
| 703 |
|
|---|
| 704 | while (de < stop) {
|
|---|
| 705 |
|
|---|
| 706 | uint32_t de_inode = ext4_directory_entry_ll_get_inode(de);
|
|---|
| 707 | uint16_t de_rec_len = ext4_directory_entry_ll_get_entry_length(de);
|
|---|
| 708 |
|
|---|
| 709 | if ((de_inode == 0) && (de_rec_len >= required_len)) {
|
|---|
| 710 | ext4_directory_write_entry(fs->superblock, de, de_rec_len,
|
|---|
| 711 | child, name, name_size);
|
|---|
| 712 |
|
|---|
| 713 | // TODO cleanup
|
|---|
| 714 | target_block->dirty = true;
|
|---|
| 715 | rc = block_put(target_block);
|
|---|
| 716 | if (rc != EOK) {
|
|---|
| 717 | return EXT4_ERR_BAD_DX_DIR;
|
|---|
| 718 | }
|
|---|
| 719 | return EOK;
|
|---|
| 720 | }
|
|---|
| 721 |
|
|---|
| 722 | if (de_inode != 0) {
|
|---|
| 723 | uint16_t used_name_len = ext4_directory_entry_ll_get_name_length(
|
|---|
| 724 | fs->superblock, de);
|
|---|
| 725 |
|
|---|
| 726 | uint16_t used_space = 8 + used_name_len;
|
|---|
| 727 | if ((used_name_len % 4) != 0) {
|
|---|
| 728 | used_space += 4 - (used_name_len % 4);
|
|---|
| 729 | }
|
|---|
| 730 | uint16_t free_space = de_rec_len - used_space;
|
|---|
| 731 |
|
|---|
| 732 | if (free_space >= required_len) {
|
|---|
| 733 |
|
|---|
| 734 | // Cut tail of current entry
|
|---|
| 735 | ext4_directory_entry_ll_set_entry_length(de, used_space);
|
|---|
| 736 | ext4_directory_entry_ll_t *new_entry = (void *)de + used_space;
|
|---|
| 737 | ext4_directory_write_entry(fs->superblock, new_entry,
|
|---|
| 738 | free_space, child, name, name_size);
|
|---|
| 739 |
|
|---|
| 740 | // TODO cleanup
|
|---|
| 741 | target_block->dirty = true;
|
|---|
| 742 | rc = block_put(target_block);
|
|---|
| 743 | if (rc != EOK) {
|
|---|
| 744 | return EXT4_ERR_BAD_DX_DIR;
|
|---|
| 745 | }
|
|---|
| 746 | return EOK;
|
|---|
| 747 |
|
|---|
| 748 | }
|
|---|
| 749 |
|
|---|
| 750 | }
|
|---|
| 751 |
|
|---|
| 752 | de = (void *)de + de_rec_len;
|
|---|
| 753 | }
|
|---|
| 754 |
|
|---|
| 755 | EXT4FS_DBG("no free space found");
|
|---|
| 756 |
|
|---|
| 757 | ext4_directory_dx_entry_t *entries = ((ext4_directory_dx_node_t *) dx_block->block->data)->entries;
|
|---|
| 758 | uint16_t leaf_limit = ext4_directory_dx_countlimit_get_limit((ext4_directory_dx_countlimit_t *)entries);
|
|---|
| 759 | uint16_t leaf_count = ext4_directory_dx_countlimit_get_count((ext4_directory_dx_countlimit_t *)entries);
|
|---|
| 760 |
|
|---|
| 761 | // ext4_directory_dx_entry_t *root_entries = ((ext4_directory_dx_node_t *) dx_blocks[0].block->data)->entries;
|
|---|
| 762 |
|
|---|
| 763 | if (leaf_limit == leaf_count) {
|
|---|
| 764 | EXT4FS_DBG("need to split index block !!!");
|
|---|
| 765 |
|
|---|
| 766 | // unsigned int levels = dx_block - dx_blocks;
|
|---|
| 767 | //
|
|---|
| 768 | // uint16_t root_limit = ext4_directory_dx_countlimit_get_limit((ext4_directory_dx_countlimit_t *)root_entries);
|
|---|
| 769 | // uint16_t root_count = ext4_directory_dx_countlimit_get_count((ext4_directory_dx_countlimit_t *)root_entries);
|
|---|
| 770 | //
|
|---|
| 771 | // if ((levels > 0) && (root_limit == root_count)) {
|
|---|
| 772 | // EXT4FS_DBG("Directory index is full");
|
|---|
| 773 | //
|
|---|
| 774 | // // ENOSPC - cleanup !!!
|
|---|
| 775 | // return ENOSPC;
|
|---|
| 776 | // }
|
|---|
| 777 | //
|
|---|
| 778 | // uint32_t fblock;
|
|---|
| 779 | // rc = ext4_directory_append_block(fs, parent, &fblock);
|
|---|
| 780 | // if (rc != EOK) {
|
|---|
| 781 | // // TODO error
|
|---|
| 782 | // }
|
|---|
| 783 | //
|
|---|
| 784 | // // New block allocated
|
|---|
| 785 | // block_t * new_block;
|
|---|
| 786 | // rc = block_get(&new_block, fs->device, fblock, BLOCK_FLAGS_NOREAD);
|
|---|
| 787 | // if (rc != EOK) {
|
|---|
| 788 | // // TODO error
|
|---|
| 789 | // }
|
|---|
| 790 | //
|
|---|
| 791 | // memset(new_block->data, 0, block_size);
|
|---|
| 792 | //
|
|---|
| 793 | // if (levels > 0) {
|
|---|
| 794 | // EXT4FS_DBG("split index");
|
|---|
| 795 | // } else {
|
|---|
| 796 | // EXT4FS_DBG("create second level");
|
|---|
| 797 | // }
|
|---|
| 798 | }
|
|---|
| 799 |
|
|---|
| 800 | block_t *new_block = NULL;
|
|---|
| 801 | rc = ext4_directory_dx_split_data(fs, parent, &hinfo, target_block, dx_block, &new_block);
|
|---|
| 802 | if (rc != EOK) {
|
|---|
| 803 | // TODO error
|
|---|
| 804 | }
|
|---|
| 805 |
|
|---|
| 806 | // TODO Where to save new entry
|
|---|
| 807 | uint32_t new_block_hash = ext4_directory_dx_entry_get_hash(dx_block->position + 1);
|
|---|
| 808 | if (hinfo.hash >= new_block_hash) {
|
|---|
| 809 | de = new_block->data;
|
|---|
| 810 | stop = new_block->data + block_size;
|
|---|
| 811 | } else {
|
|---|
| 812 | de = target_block->data;
|
|---|
| 813 | stop = target_block->data + block_size;
|
|---|
| 814 | }
|
|---|
| 815 |
|
|---|
| 816 | while (de < stop) {
|
|---|
| 817 |
|
|---|
| 818 | uint32_t de_inode = ext4_directory_entry_ll_get_inode(de);
|
|---|
| 819 | uint16_t de_rec_len = ext4_directory_entry_ll_get_entry_length(de);
|
|---|
| 820 |
|
|---|
| 821 | if ((de_inode == 0) && (de_rec_len >= required_len)) {
|
|---|
| 822 | ext4_directory_write_entry(fs->superblock, de, de_rec_len,
|
|---|
| 823 | child, name, name_size);
|
|---|
| 824 | goto success;
|
|---|
| 825 | }
|
|---|
| 826 |
|
|---|
| 827 | if (de_inode != 0) {
|
|---|
| 828 | uint16_t used_name_len = ext4_directory_entry_ll_get_name_length(
|
|---|
| 829 | fs->superblock, de);
|
|---|
| 830 |
|
|---|
| 831 | uint16_t used_space = 8 + used_name_len;
|
|---|
| 832 | if ((used_name_len % 4) != 0) {
|
|---|
| 833 | used_space += 4 - (used_name_len % 4);
|
|---|
| 834 | }
|
|---|
| 835 | uint16_t free_space = de_rec_len - used_space;
|
|---|
| 836 |
|
|---|
| 837 | if (free_space >= required_len) {
|
|---|
| 838 |
|
|---|
| 839 | // Cut tail of current entry
|
|---|
| 840 | ext4_directory_entry_ll_set_entry_length(de, used_space);
|
|---|
| 841 | ext4_directory_entry_ll_t *new_entry = (void *)de + used_space;
|
|---|
| 842 | ext4_directory_write_entry(fs->superblock, new_entry,
|
|---|
| 843 | free_space, child, name, name_size);
|
|---|
| 844 |
|
|---|
| 845 | goto success;
|
|---|
| 846 | }
|
|---|
| 847 |
|
|---|
| 848 | }
|
|---|
| 849 |
|
|---|
| 850 | de = (void *)de + de_rec_len;
|
|---|
| 851 | }
|
|---|
| 852 |
|
|---|
| 853 | success:
|
|---|
| 854 |
|
|---|
| 855 | rc = block_put(target_block);
|
|---|
| 856 | if (rc != EOK) {
|
|---|
| 857 | EXT4FS_DBG("error writing target block");
|
|---|
| 858 | }
|
|---|
| 859 | rc = block_put(new_block);
|
|---|
| 860 | if (rc != EOK) {
|
|---|
| 861 | EXT4FS_DBG("error writing new block");
|
|---|
| 862 | }
|
|---|
| 863 |
|
|---|
| 864 | ext4_directory_dx_block_t *dx_it = dx_blocks;
|
|---|
| 865 |
|
|---|
| 866 | while (dx_it <= dx_block) {
|
|---|
| 867 | rc = block_put(dx_it->block);
|
|---|
| 868 | if (rc != EOK) {
|
|---|
| 869 | EXT4FS_DBG("error writing index block \%u", (uint32_t)dx_it->block->pba);
|
|---|
| 870 | }
|
|---|
| 871 | dx_it++;
|
|---|
| 872 | }
|
|---|
| 873 |
|
|---|
| 874 | return EOK;
|
|---|
| 875 | }
|
|---|
| 876 |
|
|---|
| 877 |
|
|---|
| 878 | /**
|
|---|
| 879 | * @}
|
|---|
| 880 | */
|
|---|