[6c501f8] | 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_filesystem.c
|
---|
[e63ce679] | 35 | * @brief More complex filesystem operations.
|
---|
[6c501f8] | 36 | */
|
---|
| 37 |
|
---|
[9b9d37bb] | 38 | #include <byteorder.h>
|
---|
[6c501f8] | 39 | #include <errno.h>
|
---|
[01ab41b] | 40 | #include <malloc.h>
|
---|
[3711e7e] | 41 | #include "libext4.h"
|
---|
[6c501f8] | 42 |
|
---|
| 43 | int ext4_filesystem_init(ext4_filesystem_t *fs, service_id_t service_id)
|
---|
| 44 | {
|
---|
[01ab41b] | 45 | int rc;
|
---|
| 46 |
|
---|
| 47 | fs->device = service_id;
|
---|
| 48 |
|
---|
[9c0c0e1] | 49 | // TODO what does constant 2048 mean?
|
---|
[01ab41b] | 50 | rc = block_init(EXCHANGE_SERIALIZE, fs->device, 2048);
|
---|
| 51 | if (rc != EOK) {
|
---|
| 52 | return rc;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
[9c0c0e1] | 55 | /* Read superblock from device */
|
---|
[d9bbe45] | 56 | ext4_superblock_t *temp_superblock;
|
---|
[01ab41b] | 57 | rc = ext4_superblock_read_direct(fs->device, &temp_superblock);
|
---|
| 58 | if (rc != EOK) {
|
---|
| 59 | block_fini(fs->device);
|
---|
| 60 | return rc;
|
---|
| 61 | }
|
---|
| 62 |
|
---|
[9c0c0e1] | 63 | /* Read block size from superblock and check */
|
---|
[d9bbe45] | 64 | uint32_t block_size = ext4_superblock_get_block_size(temp_superblock);
|
---|
[01ab41b] | 65 | if (block_size > EXT4_MAX_BLOCK_SIZE) {
|
---|
| 66 | block_fini(fs->device);
|
---|
| 67 | return ENOTSUP;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
[9c0c0e1] | 70 | /* Initialize block caching */
|
---|
[b12ca16] | 71 | rc = block_cache_init(service_id, block_size, 0, CACHE_MODE_WT);
|
---|
[01ab41b] | 72 | if (rc != EOK) {
|
---|
| 73 | block_fini(fs->device);
|
---|
| 74 | return rc;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
[d9bbe45] | 77 | uint32_t block_ids_per_block = block_size / sizeof(uint32_t);
|
---|
[a9a0982] | 78 | fs->inode_block_limits[0] = EXT4_INODE_DIRECT_BLOCK_COUNT;
|
---|
| 79 | fs->inode_blocks_per_level[0] = 1;
|
---|
[d9bbe45] | 80 | for (int i = 1; i < 4; i++) {
|
---|
[6088193] | 81 | fs->inode_blocks_per_level[i] = fs->inode_blocks_per_level[i-1] *
|
---|
[a9a0982] | 82 | block_ids_per_block;
|
---|
| 83 | fs->inode_block_limits[i] = fs->inode_block_limits[i-1] +
|
---|
| 84 | fs->inode_blocks_per_level[i];
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[9c0c0e1] | 87 | /* Return loaded superblock */
|
---|
[01ab41b] | 88 | fs->superblock = temp_superblock;
|
---|
| 89 |
|
---|
[6c501f8] | 90 | return EOK;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
[ae3d4f8] | 93 | int ext4_filesystem_fini(ext4_filesystem_t *fs, bool write_sb)
|
---|
[3711e7e] | 94 | {
|
---|
[ae3d4f8] | 95 | int rc = EOK;
|
---|
[d9bbe45] | 96 |
|
---|
[ae3d4f8] | 97 | if (write_sb) {
|
---|
| 98 | rc = ext4_superblock_write_direct(fs->device, fs->superblock);
|
---|
| 99 | }
|
---|
| 100 |
|
---|
[3711e7e] | 101 | free(fs->superblock);
|
---|
| 102 | block_fini(fs->device);
|
---|
[ae3d4f8] | 103 |
|
---|
| 104 | return rc;
|
---|
[3711e7e] | 105 | }
|
---|
| 106 |
|
---|
[6c501f8] | 107 | int ext4_filesystem_check_sanity(ext4_filesystem_t *fs)
|
---|
| 108 | {
|
---|
[01ab41b] | 109 | int rc;
|
---|
| 110 |
|
---|
| 111 | rc = ext4_superblock_check_sanity(fs->superblock);
|
---|
| 112 | if (rc != EOK) {
|
---|
| 113 | return rc;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
[6c501f8] | 116 | return EOK;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
[9c0c0e1] | 119 | int ext4_filesystem_check_features(ext4_filesystem_t *fs, bool *o_read_only)
|
---|
[6c501f8] | 120 | {
|
---|
[9c0c0e1] | 121 | /* Feature flags are present in rev 1 and later */
|
---|
| 122 | if (ext4_superblock_get_rev_level(fs->superblock) == 0) {
|
---|
| 123 | *o_read_only = false;
|
---|
| 124 | return EOK;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | uint32_t incompatible_features;
|
---|
| 128 | incompatible_features = ext4_superblock_get_features_incompatible(fs->superblock);
|
---|
| 129 | incompatible_features &= ~EXT4_FEATURE_INCOMPAT_SUPP;
|
---|
| 130 | if (incompatible_features > 0) {
|
---|
| 131 | *o_read_only = true;
|
---|
| 132 | return ENOTSUP;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | uint32_t compatible_read_only;
|
---|
| 136 | compatible_read_only = ext4_superblock_get_features_read_only(fs->superblock);
|
---|
| 137 | compatible_read_only &= ~EXT4_FEATURE_RO_COMPAT_SUPP;
|
---|
| 138 | if (compatible_read_only > 0) {
|
---|
| 139 | *o_read_only = true;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
[6c501f8] | 142 | return EOK;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
[3711e7e] | 145 | int ext4_filesystem_get_block_group_ref(ext4_filesystem_t *fs, uint32_t bgid,
|
---|
| 146 | ext4_block_group_ref_t **ref)
|
---|
[6c501f8] | 147 | {
|
---|
[3711e7e] | 148 | int rc;
|
---|
| 149 |
|
---|
[d9bbe45] | 150 | ext4_block_group_ref_t *newref = malloc(sizeof(ext4_block_group_ref_t));
|
---|
[3711e7e] | 151 | if (newref == NULL) {
|
---|
| 152 | return ENOMEM;
|
---|
| 153 | }
|
---|
| 154 |
|
---|
[d9bbe45] | 155 | uint32_t descriptors_per_block = ext4_superblock_get_block_size(fs->superblock)
|
---|
[c25e39b] | 156 | / ext4_superblock_get_desc_size(fs->superblock);
|
---|
[3711e7e] | 157 |
|
---|
| 158 | /* Block group descriptor table starts at the next block after superblock */
|
---|
[d9bbe45] | 159 | aoff64_t block_id = ext4_superblock_get_first_data_block(fs->superblock) + 1;
|
---|
[3711e7e] | 160 |
|
---|
| 161 | /* Find the block containing the descriptor we are looking for */
|
---|
| 162 | block_id += bgid / descriptors_per_block;
|
---|
[d9bbe45] | 163 | uint32_t offset = (bgid % descriptors_per_block) * ext4_superblock_get_desc_size(fs->superblock);
|
---|
[3711e7e] | 164 |
|
---|
| 165 | rc = block_get(&newref->block, fs->device, block_id, 0);
|
---|
| 166 | if (rc != EOK) {
|
---|
| 167 | free(newref);
|
---|
| 168 | return rc;
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | newref->block_group = newref->block->data + offset;
|
---|
[12b4a7f] | 172 | newref->dirty = false;
|
---|
[3711e7e] | 173 |
|
---|
| 174 | *ref = newref;
|
---|
| 175 |
|
---|
| 176 | return EOK;
|
---|
[6c501f8] | 177 | }
|
---|
| 178 |
|
---|
[829d238] | 179 | int ext4_filesystem_put_block_group_ref(ext4_block_group_ref_t *ref)
|
---|
| 180 | {
|
---|
| 181 | int rc;
|
---|
| 182 |
|
---|
[12b4a7f] | 183 | if (ref->dirty) {
|
---|
| 184 | ref->block->dirty = true;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
[829d238] | 187 | rc = block_put(ref->block);
|
---|
| 188 | free(ref);
|
---|
| 189 |
|
---|
| 190 | return rc;
|
---|
| 191 | }
|
---|
| 192 |
|
---|
[3711e7e] | 193 | int ext4_filesystem_get_inode_ref(ext4_filesystem_t *fs, uint32_t index,
|
---|
| 194 | ext4_inode_ref_t **ref)
|
---|
| 195 | {
|
---|
| 196 | int rc;
|
---|
| 197 |
|
---|
[d9bbe45] | 198 | ext4_inode_ref_t *newref = malloc(sizeof(ext4_inode_ref_t));
|
---|
[3711e7e] | 199 | if (newref == NULL) {
|
---|
| 200 | return ENOMEM;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
[d9bbe45] | 203 | uint32_t inodes_per_group =
|
---|
| 204 | ext4_superblock_get_inodes_per_group(fs->superblock);
|
---|
[3711e7e] | 205 |
|
---|
| 206 | /* inode numbers are 1-based, but it is simpler to work with 0-based
|
---|
| 207 | * when computing indices
|
---|
| 208 | */
|
---|
| 209 | index -= 1;
|
---|
[d9bbe45] | 210 | uint32_t block_group = index / inodes_per_group;
|
---|
| 211 | uint32_t offset_in_group = index % inodes_per_group;
|
---|
[3711e7e] | 212 |
|
---|
[d9bbe45] | 213 | ext4_block_group_ref_t *bg_ref;
|
---|
[3711e7e] | 214 | rc = ext4_filesystem_get_block_group_ref(fs, block_group, &bg_ref);
|
---|
| 215 | if (rc != EOK) {
|
---|
| 216 | free(newref);
|
---|
| 217 | return rc;
|
---|
| 218 | }
|
---|
| 219 |
|
---|
[d9bbe45] | 220 | uint32_t inode_table_start = ext4_block_group_get_inode_table_first_block(
|
---|
[fe27eb4] | 221 | bg_ref->block_group, fs->superblock);
|
---|
[3711e7e] | 222 |
|
---|
[829d238] | 223 | rc = ext4_filesystem_put_block_group_ref(bg_ref);
|
---|
| 224 | if (rc != EOK) {
|
---|
| 225 | free(newref);
|
---|
| 226 | return rc;
|
---|
| 227 | }
|
---|
| 228 |
|
---|
[d9bbe45] | 229 | uint16_t inode_size = ext4_superblock_get_inode_size(fs->superblock);
|
---|
| 230 | uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
|
---|
| 231 | uint32_t byte_offset_in_group = offset_in_group * inode_size;
|
---|
[3711e7e] | 232 |
|
---|
[d9bbe45] | 233 | aoff64_t block_id = inode_table_start + (byte_offset_in_group / block_size);
|
---|
[3711e7e] | 234 | rc = block_get(&newref->block, fs->device, block_id, 0);
|
---|
| 235 | if (rc != EOK) {
|
---|
| 236 | free(newref);
|
---|
| 237 | return rc;
|
---|
| 238 | }
|
---|
| 239 |
|
---|
[d9bbe45] | 240 | uint32_t offset_in_block = byte_offset_in_group % block_size;
|
---|
[3711e7e] | 241 | newref->inode = newref->block->data + offset_in_block;
|
---|
| 242 | /* we decremented index above, but need to store the original value
|
---|
| 243 | * in the reference
|
---|
| 244 | */
|
---|
| 245 | newref->index = index+1;
|
---|
[052e82d] | 246 | newref->dirty = false;
|
---|
[3711e7e] | 247 |
|
---|
| 248 | *ref = newref;
|
---|
| 249 |
|
---|
[9b9d37bb] | 250 | return EOK;
|
---|
| 251 | }
|
---|
| 252 |
|
---|
[e68c834] | 253 |
|
---|
[9b9d37bb] | 254 | int ext4_filesystem_put_inode_ref(ext4_inode_ref_t *ref)
|
---|
| 255 | {
|
---|
| 256 | int rc;
|
---|
| 257 |
|
---|
[052e82d] | 258 | if (ref->dirty) {
|
---|
| 259 | ref->block->dirty = true;
|
---|
| 260 | }
|
---|
| 261 |
|
---|
[9b9d37bb] | 262 | rc = block_put(ref->block);
|
---|
| 263 | free(ref);
|
---|
| 264 |
|
---|
| 265 | return rc;
|
---|
| 266 | }
|
---|
| 267 |
|
---|
[304faab] | 268 | int ext4_filesystem_alloc_inode(ext4_filesystem_t *fs,
|
---|
| 269 | ext4_inode_ref_t **inode_ref, int flags)
|
---|
[2d2c6ce] | 270 | {
|
---|
[304faab] | 271 | int rc;
|
---|
[2d2c6ce] | 272 |
|
---|
[304faab] | 273 | bool is_dir = false;
|
---|
[2d2c6ce] | 274 | if (flags & L_DIRECTORY) {
|
---|
[304faab] | 275 | is_dir = true;
|
---|
| 276 | }
|
---|
| 277 |
|
---|
| 278 | // allocate inode
|
---|
| 279 | uint32_t index;
|
---|
| 280 | rc = ext4_ialloc_alloc_inode(fs, &index, is_dir);
|
---|
| 281 | if (rc != EOK) {
|
---|
| 282 | return rc;
|
---|
| 283 | }
|
---|
| 284 |
|
---|
| 285 | // TODO extents, dir_index etc...
|
---|
[ca3d77a] | 286 |
|
---|
[304faab] | 287 | rc = ext4_filesystem_get_inode_ref(fs, index, inode_ref);
|
---|
| 288 | if (rc != EOK) {
|
---|
| 289 | ext4_ialloc_free_inode(fs, index, is_dir);
|
---|
| 290 | return rc;
|
---|
| 291 | }
|
---|
| 292 |
|
---|
| 293 | // init inode
|
---|
| 294 | ext4_inode_t *inode = (*inode_ref)->inode;
|
---|
| 295 |
|
---|
| 296 | if (is_dir) {
|
---|
[2d2c6ce] | 297 | ext4_inode_set_mode(fs->superblock, inode, EXT4_INODE_MODE_DIRECTORY);
|
---|
| 298 | ext4_inode_set_links_count(inode, 1); // '.' entry
|
---|
| 299 | } else {
|
---|
| 300 | ext4_inode_set_mode(fs->superblock, inode, EXT4_INODE_MODE_FILE);
|
---|
| 301 | ext4_inode_set_links_count(inode, 0);
|
---|
| 302 | }
|
---|
| 303 |
|
---|
| 304 | ext4_inode_set_uid(inode, 0);
|
---|
| 305 | ext4_inode_set_gid(inode, 0);
|
---|
| 306 | ext4_inode_set_size(inode, 0);
|
---|
| 307 | ext4_inode_set_access_time(inode, 0);
|
---|
| 308 | ext4_inode_set_change_inode_time(inode, 0);
|
---|
| 309 | ext4_inode_set_modification_time(inode, 0);
|
---|
| 310 | ext4_inode_set_deletion_time(inode, 0);
|
---|
| 311 | ext4_inode_set_blocks_count(fs->superblock, inode, 0);
|
---|
| 312 | ext4_inode_set_flags(inode, 0);
|
---|
| 313 | ext4_inode_set_generation(inode, 0);
|
---|
| 314 |
|
---|
| 315 | for (uint32_t i = 0; i < EXT4_INODE_BLOCKS; i++) {
|
---|
| 316 | inode->blocks[i] = 0;
|
---|
| 317 | }
|
---|
| 318 |
|
---|
[304faab] | 319 | (*inode_ref)->dirty = true;
|
---|
| 320 |
|
---|
[2d2c6ce] | 321 | return EOK;
|
---|
| 322 | }
|
---|
| 323 |
|
---|
[3d4fd2c] | 324 | int ext4_filesystem_free_inode(ext4_filesystem_t *fs, ext4_inode_ref_t *inode_ref)
|
---|
| 325 | {
|
---|
| 326 | int rc;
|
---|
| 327 |
|
---|
[ca3d77a] | 328 | // release all indirect (no data) blocks
|
---|
[3d4fd2c] | 329 |
|
---|
| 330 | // 1) Single indirect
|
---|
[d9bbe45] | 331 | uint32_t fblock = ext4_inode_get_indirect_block(inode_ref->inode, 0);
|
---|
[3d4fd2c] | 332 | if (fblock != 0) {
|
---|
| 333 | rc = ext4_balloc_free_block(fs, inode_ref, fblock);
|
---|
| 334 | if (rc != EOK) {
|
---|
[ca3d77a] | 335 | return rc;
|
---|
[3d4fd2c] | 336 | }
|
---|
| 337 |
|
---|
| 338 | ext4_inode_set_indirect_block(inode_ref->inode, 0, 0);
|
---|
| 339 | }
|
---|
| 340 |
|
---|
| 341 | block_t *block;
|
---|
| 342 | uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
|
---|
| 343 | uint32_t count = block_size / sizeof(uint32_t);
|
---|
| 344 |
|
---|
| 345 | // 2) Double indirect
|
---|
| 346 | fblock = ext4_inode_get_indirect_block(inode_ref->inode, 1);
|
---|
| 347 | if (fblock != 0) {
|
---|
| 348 | rc = block_get(&block, fs->device, fblock, BLOCK_FLAGS_NONE);
|
---|
| 349 | if (rc != EOK) {
|
---|
[e63ce679] | 350 | return rc;
|
---|
[3d4fd2c] | 351 | }
|
---|
| 352 |
|
---|
| 353 | uint32_t ind_block;
|
---|
| 354 | for (uint32_t offset = 0; offset < count; ++offset) {
|
---|
| 355 | ind_block = uint32_t_le2host(((uint32_t*)block->data)[offset]);
|
---|
| 356 |
|
---|
| 357 | if (ind_block != 0) {
|
---|
| 358 | rc = ext4_balloc_free_block(fs, inode_ref, ind_block);
|
---|
| 359 | if (rc != EOK) {
|
---|
[e63ce679] | 360 | block_put(block);
|
---|
| 361 | return rc;
|
---|
[3d4fd2c] | 362 | }
|
---|
| 363 | }
|
---|
| 364 | }
|
---|
| 365 |
|
---|
| 366 | block_put(block);
|
---|
| 367 | rc = ext4_balloc_free_block(fs, inode_ref, fblock);
|
---|
| 368 | if (rc != EOK) {
|
---|
[e63ce679] | 369 | return rc;
|
---|
[3d4fd2c] | 370 | }
|
---|
| 371 |
|
---|
| 372 | ext4_inode_set_indirect_block(inode_ref->inode, 1, 0);
|
---|
| 373 | }
|
---|
| 374 |
|
---|
| 375 |
|
---|
| 376 | // 3) Tripple indirect
|
---|
| 377 | block_t *subblock;
|
---|
| 378 | fblock = ext4_inode_get_indirect_block(inode_ref->inode, 2);
|
---|
| 379 | if (fblock != 0) {
|
---|
| 380 | rc = block_get(&block, fs->device, fblock, BLOCK_FLAGS_NONE);
|
---|
| 381 | if (rc != EOK) {
|
---|
[e63ce679] | 382 | return rc;
|
---|
[3d4fd2c] | 383 | }
|
---|
| 384 |
|
---|
| 385 | uint32_t ind_block;
|
---|
| 386 | for (uint32_t offset = 0; offset < count; ++offset) {
|
---|
| 387 | ind_block = uint32_t_le2host(((uint32_t*)block->data)[offset]);
|
---|
| 388 |
|
---|
| 389 | if (ind_block != 0) {
|
---|
| 390 | rc = block_get(&subblock, fs->device, ind_block, BLOCK_FLAGS_NONE);
|
---|
| 391 | if (rc != EOK) {
|
---|
[e63ce679] | 392 | block_put(block);
|
---|
| 393 | return rc;
|
---|
[3d4fd2c] | 394 | }
|
---|
| 395 |
|
---|
| 396 | uint32_t ind_subblock;
|
---|
| 397 | for (uint32_t suboffset = 0; suboffset < count; ++suboffset) {
|
---|
| 398 | ind_subblock = uint32_t_le2host(((uint32_t*)subblock->data)[suboffset]);
|
---|
| 399 |
|
---|
| 400 | if (ind_subblock != 0) {
|
---|
| 401 | rc = ext4_balloc_free_block(fs, inode_ref, ind_subblock);
|
---|
| 402 | if (rc != EOK) {
|
---|
[e63ce679] | 403 | block_put(subblock);
|
---|
| 404 | block_put(block);
|
---|
| 405 | return rc;
|
---|
[3d4fd2c] | 406 | }
|
---|
| 407 | }
|
---|
| 408 |
|
---|
| 409 | }
|
---|
| 410 | block_put(subblock);
|
---|
| 411 |
|
---|
| 412 | }
|
---|
| 413 |
|
---|
| 414 | rc = ext4_balloc_free_block(fs, inode_ref, ind_block);
|
---|
| 415 | if (rc != EOK) {
|
---|
[e63ce679] | 416 | block_put(block);
|
---|
| 417 | return rc;
|
---|
[3d4fd2c] | 418 | }
|
---|
| 419 |
|
---|
| 420 |
|
---|
| 421 | }
|
---|
| 422 |
|
---|
| 423 | block_put(block);
|
---|
| 424 | rc = ext4_balloc_free_block(fs, inode_ref, fblock);
|
---|
| 425 | if (rc != EOK) {
|
---|
[e63ce679] | 426 | return rc;
|
---|
[3d4fd2c] | 427 | }
|
---|
| 428 |
|
---|
| 429 | ext4_inode_set_indirect_block(inode_ref->inode, 2, 0);
|
---|
| 430 | }
|
---|
| 431 |
|
---|
[e5f8762] | 432 | inode_ref->dirty = true;
|
---|
| 433 |
|
---|
[3d4fd2c] | 434 | // Free inode
|
---|
[304faab] | 435 | if (ext4_inode_is_type(fs->superblock, inode_ref->inode,
|
---|
| 436 | EXT4_INODE_MODE_DIRECTORY)) {
|
---|
| 437 | rc = ext4_ialloc_free_inode(fs, inode_ref->index, true);
|
---|
| 438 | } else {
|
---|
| 439 | rc = ext4_ialloc_free_inode(fs, inode_ref->index, false);
|
---|
| 440 | }
|
---|
[3d4fd2c] | 441 | if (rc != EOK) {
|
---|
| 442 | return rc;
|
---|
| 443 | }
|
---|
| 444 |
|
---|
| 445 | return EOK;
|
---|
| 446 | }
|
---|
| 447 |
|
---|
| 448 | int ext4_filesystem_truncate_inode(ext4_filesystem_t *fs,
|
---|
| 449 | ext4_inode_ref_t *inode_ref, aoff64_t new_size)
|
---|
| 450 | {
|
---|
[ca3d77a] | 451 | int rc;
|
---|
| 452 |
|
---|
[3d4fd2c] | 453 | if (! ext4_inode_can_truncate(fs->superblock, inode_ref->inode)) {
|
---|
| 454 | // Unable to truncate
|
---|
| 455 | return EINVAL;
|
---|
| 456 | }
|
---|
| 457 |
|
---|
[d9bbe45] | 458 | aoff64_t old_size = ext4_inode_get_size(fs->superblock, inode_ref->inode);
|
---|
[3d4fd2c] | 459 | if (old_size == new_size) {
|
---|
| 460 | // Nothing to do
|
---|
| 461 | return EOK;
|
---|
| 462 | }
|
---|
| 463 |
|
---|
[ca3d77a] | 464 | // It's not suppported to make the larger file
|
---|
[3d4fd2c] | 465 | if (old_size < new_size) {
|
---|
| 466 | return EINVAL;
|
---|
| 467 | }
|
---|
| 468 |
|
---|
[d9bbe45] | 469 | aoff64_t size_diff = old_size - new_size;
|
---|
| 470 | uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
|
---|
[ca3d77a] | 471 | uint32_t diff_blocks_count = size_diff / block_size;
|
---|
[3d4fd2c] | 472 | if (size_diff % block_size != 0) {
|
---|
[ca3d77a] | 473 | diff_blocks_count++;
|
---|
[3d4fd2c] | 474 | }
|
---|
| 475 |
|
---|
[ca3d77a] | 476 | uint32_t old_blocks_count = old_size / block_size;
|
---|
[3d4fd2c] | 477 | if (old_size % block_size != 0) {
|
---|
[ca3d77a] | 478 | old_blocks_count++;
|
---|
[3d4fd2c] | 479 | }
|
---|
| 480 |
|
---|
| 481 | // starting from 1 because of logical blocks are numbered from 0
|
---|
[ca3d77a] | 482 | for (uint32_t i = 1; i <= diff_blocks_count; ++i) {
|
---|
| 483 | rc = ext4_filesystem_release_inode_block(fs, inode_ref, old_blocks_count - i);
|
---|
| 484 | if (rc != EOK) {
|
---|
| 485 | return rc;
|
---|
| 486 | }
|
---|
[3d4fd2c] | 487 | }
|
---|
| 488 |
|
---|
| 489 | ext4_inode_set_size(inode_ref->inode, new_size);
|
---|
| 490 |
|
---|
| 491 | inode_ref->dirty = true;
|
---|
| 492 |
|
---|
| 493 | return EOK;
|
---|
| 494 | }
|
---|
| 495 |
|
---|
[9104bb5] | 496 | int ext4_filesystem_get_inode_data_block_index(ext4_filesystem_t *fs,
|
---|
| 497 | ext4_inode_ref_t *inode_ref, aoff64_t iblock, uint32_t* fblock)
|
---|
[9b9d37bb] | 498 | {
|
---|
| 499 | int rc;
|
---|
[d9bbe45] | 500 |
|
---|
| 501 |
|
---|
[9b9d37bb] | 502 | uint32_t current_block;
|
---|
| 503 |
|
---|
[8958a26] | 504 | /* Handle inode using extents */
|
---|
[a872fc09] | 505 | if (ext4_superblock_has_feature_incompatible(fs->superblock, EXT4_FEATURE_INCOMPAT_EXTENTS) &&
|
---|
[9104bb5] | 506 | ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS)) {
|
---|
| 507 | rc = ext4_extent_find_block(fs, inode_ref, iblock, ¤t_block);
|
---|
| 508 |
|
---|
| 509 | if (rc != EOK) {
|
---|
| 510 | return rc;
|
---|
| 511 | }
|
---|
| 512 |
|
---|
[acd869e] | 513 | *fblock = current_block;
|
---|
| 514 | return EOK;
|
---|
| 515 |
|
---|
| 516 | }
|
---|
| 517 |
|
---|
[9104bb5] | 518 | ext4_inode_t *inode = inode_ref->inode;
|
---|
| 519 |
|
---|
[9b9d37bb] | 520 | /* Handle simple case when we are dealing with direct reference */
|
---|
[e68c834] | 521 | if (iblock < EXT4_INODE_DIRECT_BLOCK_COUNT) {
|
---|
[9b9d37bb] | 522 | current_block = ext4_inode_get_direct_block(inode, (uint32_t)iblock);
|
---|
| 523 | *fblock = current_block;
|
---|
| 524 | return EOK;
|
---|
| 525 | }
|
---|
| 526 |
|
---|
| 527 | /* Determine the indirection level needed to get the desired block */
|
---|
[d9bbe45] | 528 | int level = -1;
|
---|
| 529 | for (int i = 1; i < 4; i++) {
|
---|
[a9a0982] | 530 | if (iblock < fs->inode_block_limits[i]) {
|
---|
[9b9d37bb] | 531 | level = i;
|
---|
| 532 | break;
|
---|
| 533 | }
|
---|
| 534 | }
|
---|
| 535 |
|
---|
| 536 | if (level == -1) {
|
---|
| 537 | return EIO;
|
---|
| 538 | }
|
---|
| 539 |
|
---|
| 540 | /* Compute offsets for the topmost level */
|
---|
[d9bbe45] | 541 | aoff64_t block_offset_in_level = iblock - fs->inode_block_limits[level-1];
|
---|
[9b9d37bb] | 542 | current_block = ext4_inode_get_indirect_block(inode, level-1);
|
---|
[d9bbe45] | 543 | uint32_t offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
|
---|
[9b9d37bb] | 544 |
|
---|
[6088193] | 545 | if (current_block == 0) {
|
---|
| 546 | *fblock = 0;
|
---|
| 547 | return EOK;
|
---|
| 548 | }
|
---|
| 549 |
|
---|
[d9bbe45] | 550 | block_t *block;
|
---|
| 551 |
|
---|
[9b9d37bb] | 552 | /* Navigate through other levels, until we find the block number
|
---|
| 553 | * or find null reference meaning we are dealing with sparse file
|
---|
| 554 | */
|
---|
| 555 | while (level > 0) {
|
---|
| 556 | rc = block_get(&block, fs->device, current_block, 0);
|
---|
| 557 | if (rc != EOK) {
|
---|
| 558 | return rc;
|
---|
| 559 | }
|
---|
| 560 |
|
---|
| 561 | current_block = uint32_t_le2host(((uint32_t*)block->data)[offset_in_block]);
|
---|
| 562 |
|
---|
| 563 | rc = block_put(block);
|
---|
| 564 | if (rc != EOK) {
|
---|
| 565 | return rc;
|
---|
| 566 | }
|
---|
| 567 |
|
---|
| 568 | if (current_block == 0) {
|
---|
| 569 | /* This is a sparse file */
|
---|
| 570 | *fblock = 0;
|
---|
| 571 | return EOK;
|
---|
| 572 | }
|
---|
| 573 |
|
---|
| 574 | level -= 1;
|
---|
| 575 |
|
---|
| 576 | /* If we are on the last level, break here as
|
---|
| 577 | * there is no next level to visit
|
---|
| 578 | */
|
---|
| 579 | if (level == 0) {
|
---|
| 580 | break;
|
---|
| 581 | }
|
---|
| 582 |
|
---|
| 583 | /* Visit the next level */
|
---|
[a9a0982] | 584 | block_offset_in_level %= fs->inode_blocks_per_level[level];
|
---|
| 585 | offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
|
---|
[9b9d37bb] | 586 | }
|
---|
| 587 |
|
---|
| 588 | *fblock = current_block;
|
---|
| 589 |
|
---|
[3711e7e] | 590 | return EOK;
|
---|
| 591 | }
|
---|
[6c501f8] | 592 |
|
---|
[d5a78e28] | 593 |
|
---|
[35f48f2] | 594 | int ext4_filesystem_set_inode_data_block_index(ext4_filesystem_t *fs,
|
---|
[1e65444] | 595 | ext4_inode_ref_t *inode_ref, aoff64_t iblock, uint32_t fblock)
|
---|
[35f48f2] | 596 | {
|
---|
[1e65444] | 597 | int rc;
|
---|
[d9bbe45] | 598 |
|
---|
[35f48f2] | 599 |
|
---|
| 600 | /* Handle inode using extents */
|
---|
| 601 | if (ext4_superblock_has_feature_compatible(fs->superblock, EXT4_FEATURE_INCOMPAT_EXTENTS) &&
|
---|
[1e65444] | 602 | ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS)) {
|
---|
[35f48f2] | 603 | // TODO
|
---|
| 604 | return ENOTSUP;
|
---|
| 605 | }
|
---|
| 606 |
|
---|
| 607 | /* Handle simple case when we are dealing with direct reference */
|
---|
| 608 | if (iblock < EXT4_INODE_DIRECT_BLOCK_COUNT) {
|
---|
[1e65444] | 609 | ext4_inode_set_direct_block(inode_ref->inode, (uint32_t)iblock, fblock);
|
---|
| 610 | inode_ref->dirty = true;
|
---|
[35f48f2] | 611 | return EOK;
|
---|
| 612 | }
|
---|
| 613 |
|
---|
[1e65444] | 614 | /* Determine the indirection level needed to get the desired block */
|
---|
[d9bbe45] | 615 | int level = -1;
|
---|
| 616 | for (int i = 1; i < 4; i++) {
|
---|
[1e65444] | 617 | if (iblock < fs->inode_block_limits[i]) {
|
---|
| 618 | level = i;
|
---|
| 619 | break;
|
---|
| 620 | }
|
---|
| 621 | }
|
---|
| 622 |
|
---|
| 623 | if (level == -1) {
|
---|
| 624 | return EIO;
|
---|
| 625 | }
|
---|
| 626 |
|
---|
[d9bbe45] | 627 | uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
|
---|
[1e65444] | 628 |
|
---|
| 629 | /* Compute offsets for the topmost level */
|
---|
[d9bbe45] | 630 | aoff64_t block_offset_in_level = iblock - fs->inode_block_limits[level-1];
|
---|
| 631 | uint32_t current_block = ext4_inode_get_indirect_block(inode_ref->inode, level-1);
|
---|
| 632 | uint32_t offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
|
---|
| 633 |
|
---|
| 634 | uint32_t new_block_addr;
|
---|
| 635 | block_t *block, *new_block;
|
---|
[1e65444] | 636 |
|
---|
| 637 | if (current_block == 0) {
|
---|
[b12ca16] | 638 | rc = ext4_balloc_alloc_block(fs, inode_ref, &new_block_addr);
|
---|
[1e65444] | 639 | if (rc != EOK) {
|
---|
[e63ce679] | 640 | return rc;
|
---|
[1e65444] | 641 | }
|
---|
| 642 |
|
---|
| 643 | ext4_inode_set_indirect_block(inode_ref->inode, level - 1, new_block_addr);
|
---|
| 644 |
|
---|
| 645 | inode_ref->dirty = true;
|
---|
| 646 |
|
---|
| 647 | rc = block_get(&new_block, fs->device, new_block_addr, BLOCK_FLAGS_NOREAD);
|
---|
| 648 | if (rc != EOK) {
|
---|
[e63ce679] | 649 | ext4_balloc_free_block(fs, inode_ref, new_block_addr);
|
---|
| 650 | return rc;
|
---|
[1e65444] | 651 | }
|
---|
| 652 |
|
---|
| 653 | memset(new_block->data, 0, block_size);
|
---|
| 654 | new_block->dirty = true;
|
---|
| 655 |
|
---|
| 656 | rc = block_put(new_block);
|
---|
| 657 | if (rc != EOK) {
|
---|
[e63ce679] | 658 | return rc;
|
---|
[1e65444] | 659 | }
|
---|
| 660 |
|
---|
| 661 | current_block = new_block_addr;
|
---|
| 662 | }
|
---|
| 663 |
|
---|
| 664 | /* Navigate through other levels, until we find the block number
|
---|
| 665 | * or find null reference meaning we are dealing with sparse file
|
---|
| 666 | */
|
---|
| 667 | while (level > 0) {
|
---|
| 668 |
|
---|
| 669 | rc = block_get(&block, fs->device, current_block, 0);
|
---|
| 670 | if (rc != EOK) {
|
---|
| 671 | return rc;
|
---|
| 672 | }
|
---|
| 673 |
|
---|
| 674 | current_block = uint32_t_le2host(((uint32_t*)block->data)[offset_in_block]);
|
---|
| 675 |
|
---|
[b12ca16] | 676 | if ((level > 1) && (current_block == 0)) {
|
---|
| 677 | rc = ext4_balloc_alloc_block(fs, inode_ref, &new_block_addr);
|
---|
| 678 | if (rc != EOK) {
|
---|
[e63ce679] | 679 | block_put(block);
|
---|
| 680 | return rc;
|
---|
[b12ca16] | 681 | }
|
---|
[1e65444] | 682 |
|
---|
[b12ca16] | 683 | rc = block_get(&new_block, fs->device, new_block_addr, BLOCK_FLAGS_NOREAD);
|
---|
| 684 | if (rc != EOK) {
|
---|
[e63ce679] | 685 | block_put(block);
|
---|
| 686 | return rc;
|
---|
[b12ca16] | 687 | }
|
---|
[e63ce679] | 688 |
|
---|
[b12ca16] | 689 | memset(new_block->data, 0, block_size);
|
---|
| 690 | new_block->dirty = true;
|
---|
[6088193] | 691 |
|
---|
[b12ca16] | 692 | rc = block_put(new_block);
|
---|
| 693 | if (rc != EOK) {
|
---|
[e63ce679] | 694 | block_put(block);
|
---|
| 695 | return rc;
|
---|
[b12ca16] | 696 | }
|
---|
[1e65444] | 697 |
|
---|
[b12ca16] | 698 | ((uint32_t*)block->data)[offset_in_block] = host2uint32_t_le(new_block_addr);
|
---|
| 699 | block->dirty = true;
|
---|
| 700 | current_block = new_block_addr;
|
---|
| 701 | }
|
---|
[1e65444] | 702 |
|
---|
[b12ca16] | 703 | if (level == 1) {
|
---|
| 704 | ((uint32_t*)block->data)[offset_in_block] = host2uint32_t_le(fblock);
|
---|
| 705 | block->dirty = true;
|
---|
[1e65444] | 706 | }
|
---|
| 707 |
|
---|
| 708 | rc = block_put(block);
|
---|
| 709 | if (rc != EOK) {
|
---|
| 710 | return rc;
|
---|
| 711 | }
|
---|
| 712 |
|
---|
| 713 | level -= 1;
|
---|
| 714 |
|
---|
| 715 | /* If we are on the last level, break here as
|
---|
| 716 | * there is no next level to visit
|
---|
| 717 | */
|
---|
| 718 | if (level == 0) {
|
---|
| 719 | break;
|
---|
| 720 | }
|
---|
| 721 |
|
---|
| 722 | /* Visit the next level */
|
---|
| 723 | block_offset_in_level %= fs->inode_blocks_per_level[level];
|
---|
| 724 | offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
|
---|
| 725 | }
|
---|
[35f48f2] | 726 |
|
---|
| 727 | return EOK;
|
---|
| 728 | }
|
---|
| 729 |
|
---|
[052e82d] | 730 | int ext4_filesystem_release_inode_block(ext4_filesystem_t *fs,
|
---|
| 731 | ext4_inode_ref_t *inode_ref, uint32_t iblock)
|
---|
[d5a78e28] | 732 | {
|
---|
| 733 | int rc;
|
---|
[d9bbe45] | 734 |
|
---|
[d5a78e28] | 735 |
|
---|
[052e82d] | 736 | /* TODO handle extents */
|
---|
[d5a78e28] | 737 |
|
---|
[12b4a7f] | 738 |
|
---|
[d9bbe45] | 739 | uint32_t fblock;
|
---|
| 740 | ext4_inode_t *inode = inode_ref->inode;
|
---|
| 741 |
|
---|
[052e82d] | 742 | /* Handle simple case when we are dealing with direct reference */
|
---|
| 743 | if (iblock < EXT4_INODE_DIRECT_BLOCK_COUNT) {
|
---|
[12b4a7f] | 744 | fblock = ext4_inode_get_direct_block(inode, iblock);
|
---|
[052e82d] | 745 | // Sparse file
|
---|
| 746 | if (fblock == 0) {
|
---|
| 747 | return EOK;
|
---|
| 748 | }
|
---|
[d5a78e28] | 749 |
|
---|
[052e82d] | 750 | ext4_inode_set_direct_block(inode, iblock, 0);
|
---|
[b12ca16] | 751 | return ext4_balloc_free_block(fs, inode_ref, fblock);
|
---|
[12b4a7f] | 752 | }
|
---|
| 753 |
|
---|
| 754 |
|
---|
| 755 | /* Determine the indirection level needed to get the desired block */
|
---|
[d9bbe45] | 756 | int level = -1;
|
---|
| 757 | for (int i = 1; i < 4; i++) {
|
---|
[12b4a7f] | 758 | if (iblock < fs->inode_block_limits[i]) {
|
---|
| 759 | level = i;
|
---|
| 760 | break;
|
---|
[052e82d] | 761 | }
|
---|
[12b4a7f] | 762 | }
|
---|
| 763 |
|
---|
| 764 | if (level == -1) {
|
---|
| 765 | return EIO;
|
---|
| 766 | }
|
---|
| 767 |
|
---|
| 768 | /* Compute offsets for the topmost level */
|
---|
[d9bbe45] | 769 | aoff64_t block_offset_in_level = iblock - fs->inode_block_limits[level-1];
|
---|
| 770 | uint32_t current_block = ext4_inode_get_indirect_block(inode, level-1);
|
---|
| 771 | uint32_t offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
|
---|
[d5a78e28] | 772 |
|
---|
[12b4a7f] | 773 | /* Navigate through other levels, until we find the block number
|
---|
| 774 | * or find null reference meaning we are dealing with sparse file
|
---|
| 775 | */
|
---|
[d9bbe45] | 776 | block_t *block;
|
---|
[12b4a7f] | 777 | while (level > 0) {
|
---|
| 778 | rc = block_get(&block, fs->device, current_block, 0);
|
---|
| 779 | if (rc != EOK) {
|
---|
| 780 | return rc;
|
---|
[052e82d] | 781 | }
|
---|
[d5a78e28] | 782 |
|
---|
[12b4a7f] | 783 | current_block = uint32_t_le2host(((uint32_t*)block->data)[offset_in_block]);
|
---|
[d5a78e28] | 784 |
|
---|
[12b4a7f] | 785 | // Set zero
|
---|
| 786 | if (level == 1) {
|
---|
| 787 | ((uint32_t*)block->data)[offset_in_block] = host2uint32_t_le(0);
|
---|
| 788 | block->dirty = true;
|
---|
[052e82d] | 789 | }
|
---|
[d5a78e28] | 790 |
|
---|
[12b4a7f] | 791 | rc = block_put(block);
|
---|
| 792 | if (rc != EOK) {
|
---|
| 793 | return rc;
|
---|
| 794 | }
|
---|
[d5a78e28] | 795 |
|
---|
[12b4a7f] | 796 | level -= 1;
|
---|
| 797 |
|
---|
| 798 | /* If we are on the last level, break here as
|
---|
| 799 | * there is no next level to visit
|
---|
| 800 | */
|
---|
| 801 | if (level == 0) {
|
---|
| 802 | break;
|
---|
[052e82d] | 803 | }
|
---|
[12b4a7f] | 804 |
|
---|
| 805 | /* Visit the next level */
|
---|
| 806 | block_offset_in_level %= fs->inode_blocks_per_level[level];
|
---|
| 807 | offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
|
---|
| 808 | }
|
---|
| 809 |
|
---|
| 810 | fblock = current_block;
|
---|
| 811 |
|
---|
| 812 | if (fblock == 0) {
|
---|
| 813 | return EOK;
|
---|
[052e82d] | 814 | }
|
---|
[d5a78e28] | 815 |
|
---|
[b12ca16] | 816 | return ext4_balloc_free_block(fs, inode_ref, fblock);
|
---|
[d5a78e28] | 817 |
|
---|
| 818 | }
|
---|
| 819 |
|
---|
[ebcaff4] | 820 | int ext4_filesystem_add_orphan(ext4_filesystem_t *fs,
|
---|
| 821 | ext4_inode_ref_t *inode_ref)
|
---|
| 822 | {
|
---|
| 823 | uint32_t next_orphan = ext4_superblock_get_last_orphan(fs->superblock);
|
---|
| 824 | ext4_inode_set_deletion_time(inode_ref->inode, next_orphan);
|
---|
| 825 | ext4_superblock_set_last_orphan(fs->superblock, inode_ref->index);
|
---|
| 826 | inode_ref->dirty = true;
|
---|
| 827 |
|
---|
| 828 | return EOK;
|
---|
| 829 | }
|
---|
| 830 |
|
---|
| 831 | int ext4_filesystem_delete_orphan(ext4_filesystem_t *fs,
|
---|
| 832 | ext4_inode_ref_t *inode_ref)
|
---|
| 833 | {
|
---|
| 834 | int rc;
|
---|
| 835 |
|
---|
| 836 | uint32_t last_orphan = ext4_superblock_get_last_orphan(fs->superblock);
|
---|
| 837 | assert(last_orphan > 0);
|
---|
| 838 |
|
---|
| 839 | uint32_t next_orphan = ext4_inode_get_deletion_time(inode_ref->inode);
|
---|
| 840 |
|
---|
| 841 | if (last_orphan == inode_ref->index) {
|
---|
| 842 | ext4_superblock_set_last_orphan(fs->superblock, next_orphan);
|
---|
| 843 | ext4_inode_set_deletion_time(inode_ref->inode, 0);
|
---|
| 844 | inode_ref->dirty = true;
|
---|
| 845 | return EOK;
|
---|
| 846 | }
|
---|
| 847 |
|
---|
| 848 | ext4_inode_ref_t *current;
|
---|
| 849 | rc = ext4_filesystem_get_inode_ref(fs, last_orphan, ¤t);
|
---|
| 850 | if (rc != EOK) {
|
---|
| 851 | return rc;
|
---|
| 852 | }
|
---|
| 853 | next_orphan = ext4_inode_get_deletion_time(current->inode);
|
---|
| 854 |
|
---|
| 855 | bool found;
|
---|
| 856 |
|
---|
| 857 | while (next_orphan != 0) {
|
---|
| 858 | if (next_orphan == inode_ref->index) {
|
---|
| 859 | next_orphan = ext4_inode_get_deletion_time(inode_ref->inode);
|
---|
| 860 | ext4_inode_set_deletion_time(current->inode, next_orphan);
|
---|
| 861 | current->dirty = true;
|
---|
| 862 | found = true;
|
---|
| 863 | break;
|
---|
| 864 | }
|
---|
| 865 |
|
---|
| 866 | ext4_filesystem_put_inode_ref(current);
|
---|
| 867 |
|
---|
| 868 | rc = ext4_filesystem_get_inode_ref(fs, next_orphan, ¤t);
|
---|
| 869 | if (rc != EOK) {
|
---|
| 870 | return rc;
|
---|
| 871 | }
|
---|
| 872 | next_orphan = ext4_inode_get_deletion_time(current->inode);
|
---|
| 873 |
|
---|
| 874 | }
|
---|
| 875 |
|
---|
| 876 | ext4_inode_set_deletion_time(inode_ref->inode, 0);
|
---|
| 877 |
|
---|
| 878 | rc = ext4_filesystem_put_inode_ref(current);
|
---|
| 879 | if (rc != EOK) {
|
---|
| 880 | return rc;
|
---|
| 881 | }
|
---|
| 882 |
|
---|
| 883 | if (!found) {
|
---|
| 884 | return ENOENT;
|
---|
| 885 | }
|
---|
| 886 |
|
---|
| 887 | return EOK;
|
---|
| 888 | }
|
---|
| 889 |
|
---|
[6c501f8] | 890 | /**
|
---|
| 891 | * @}
|
---|
| 892 | */
|
---|