Changes in / [2ba48bf1:5caad1d] in mainline


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext4/src/ops.c

    r2ba48bf1 r5caad1d  
    6464static bool ext4_is_dots(const uint8_t *, size_t);
    6565static errno_t ext4_instance_get(service_id_t, ext4_instance_t **);
    66 static errno_t handle_sparse_or_unallocated_fblock(ext4_filesystem_t *,
    67     ext4_inode_ref_t *, uint32_t, uint32_t, uint32_t *, int *, bool *);
    6866
    6967/* Forward declarations of ext4 libfs operations. */
     
    160158}
    161159
     160/*
     161 * Ext4 libfs operations.
     162 */
     163
    162164/** Get instance from internal table by service_id.
    163165 *
     
    168170 *
    169171 */
    170 static errno_t ext4_instance_get(service_id_t service_id, ext4_instance_t **inst)
     172errno_t ext4_instance_get(service_id_t service_id, ext4_instance_t **inst)
    171173{
    172174        fibril_mutex_lock(&instance_list_mutex);
     
    188190        return EINVAL;
    189191}
    190 
    191 /*
    192  * Ext4 libfs operations.
    193  */
    194192
    195193/** Get root node of filesystem specified by service_id.
     
    12881286        fs_node_t *fn;
    12891287        errno_t rc2;
    1290         bool fblock_allocated = false;
    1291 
    12921288        errno_t rc = ext4_node_get(&fn, service_id, index);
    12931289        if (rc != EOK)
     
    13261322        }
    13271323
    1328         /* Handle sparse or unallocated block */
     1324        /* Check for sparse file */
    13291325        if (fblock == 0) {
    1330                 rc = handle_sparse_or_unallocated_fblock(fs, inode_ref,
    1331                     block_size, iblock, &fblock, &flags, &fblock_allocated);
    1332                 if (rc != EOK) {
    1333                         async_answer_0(&call, rc);
    1334                         goto exit;
     1326                if ((ext4_superblock_has_feature_incompatible(fs->superblock,
     1327                    EXT4_FEATURE_INCOMPAT_EXTENTS)) &&
     1328                    (ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS))) {
     1329                        uint32_t last_iblock =
     1330                            ext4_inode_get_size(fs->superblock, inode_ref->inode) /
     1331                            block_size;
     1332
     1333                        while (last_iblock < iblock) {
     1334                                rc = ext4_extent_append_block(inode_ref, &last_iblock,
     1335                                    &fblock, true);
     1336                                if (rc != EOK) {
     1337                                        async_answer_0(&call, rc);
     1338                                        goto exit;
     1339                                }
     1340                        }
     1341
     1342                        rc = ext4_extent_append_block(inode_ref, &last_iblock,
     1343                            &fblock, false);
     1344                        if (rc != EOK) {
     1345                                async_answer_0(&call, rc);
     1346                                goto exit;
     1347                        }
     1348                } else {
     1349                        rc = ext4_balloc_alloc_block(inode_ref, &fblock);
     1350                        if (rc != EOK) {
     1351                                async_answer_0(&call, rc);
     1352                                goto exit;
     1353                        }
     1354
     1355                        rc = ext4_filesystem_set_inode_data_block_index(inode_ref,
     1356                            iblock, fblock);
     1357                        if (rc != EOK) {
     1358                                ext4_balloc_free_block(inode_ref, fblock);
     1359                                async_answer_0(&call, rc);
     1360                                goto exit;
     1361                        }
    13351362                }
     1363
     1364                flags = BLOCK_FLAGS_NOREAD;
     1365                inode_ref->dirty = true;
    13361366        }
    13371367
     
    13721402
    13731403exit:
    1374         if (rc != EOK && fblock_allocated)
    1375                 ext4_balloc_free_block(inode_ref, fblock);
    1376 
    13771404        rc2 = ext4_node_put(fn);
    13781405        return rc == EOK ? rc2 : rc;
    1379 }
    1380 
    1381 /** Handle sparse or unallocated block.
    1382  *
    1383  * @param fs            Filesystem handle
    1384  * @param inode_ref     I-node reference
    1385  * @param block_size    Filesystem block size
    1386  * @param iblock        Logical block
    1387  * @param fblock        Place to store allocated block address
    1388  * @param flags         BLOCK_FLAGS to update
    1389  * @param allocated     Place to store whether new block was allocated
    1390  *
    1391  * @return Error code
    1392  *
    1393  */
    1394 static errno_t handle_sparse_or_unallocated_fblock(ext4_filesystem_t *fs,
    1395     ext4_inode_ref_t *inode_ref, uint32_t block_size, uint32_t iblock,
    1396     uint32_t *fblock, int *flags, bool *allocated)
    1397 {
    1398         errno_t rc;
    1399 
    1400         /* Check for sparse file */
    1401         if ((ext4_superblock_has_feature_incompatible(fs->superblock,
    1402             EXT4_FEATURE_INCOMPAT_EXTENTS)) &&
    1403             (ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS))) {
    1404                 uint32_t last_iblock =
    1405                     ext4_inode_get_size(fs->superblock, inode_ref->inode) /
    1406                     block_size;
    1407 
    1408                 while (last_iblock < iblock) {
    1409                         rc = ext4_extent_append_block(inode_ref, &last_iblock,
    1410                             fblock, true);
    1411                         if (rc != EOK)
    1412                                 return rc;
    1413                 }
    1414 
    1415                 rc = ext4_extent_append_block(inode_ref, &last_iblock, fblock,
    1416                     false);
    1417                 if (rc != EOK)
    1418                         return rc;
    1419         } else { /* Allocate new block */
    1420                 rc = ext4_balloc_alloc_block(inode_ref, fblock);
    1421                 if (rc != EOK)
    1422                         return rc;
    1423 
    1424                 rc = ext4_filesystem_set_inode_data_block_index(inode_ref,
    1425                     iblock, *fblock);
    1426                 if (rc != EOK) {
    1427                         ext4_balloc_free_block(inode_ref, *fblock);
    1428                         return rc;
    1429                 }
    1430 
    1431                 *allocated = true;
    1432         }
    1433 
    1434         *flags = BLOCK_FLAGS_NOREAD;
    1435         inode_ref->dirty = true;
    1436 
    1437         return EOK;
    14381406}
    14391407
Note: See TracChangeset for help on using the changeset viewer.