@@ -64,7 +64,7 @@ static errno_t ext4_read_file(ipc_call_t *, aoff64_t, size_t, ext4_instance_t *,
64
64
static bool ext4_is_dots (const uint8_t * , size_t );
65
65
static errno_t ext4_instance_get (service_id_t , ext4_instance_t * * );
66
66
static errno_t handle_sparse_or_unallocated_fblock (ext4_filesystem_t * ,
67
- ext4_inode_ref_t * , uint32_t , uint32_t , uint32_t * , int * );
67
+ ext4_inode_ref_t * , uint32_t , uint32_t , uint32_t * , int * , bool * );
68
68
69
69
/* Forward declarations of ext4 libfs operations. */
70
70
@@ -1287,6 +1287,8 @@ static errno_t ext4_write(service_id_t service_id, fs_index_t index, aoff64_t po
1287
1287
{
1288
1288
fs_node_t * fn ;
1289
1289
errno_t rc2 ;
1290
+ bool fblock_allocated = false;
1291
+
1290
1292
errno_t rc = ext4_node_get (& fn , service_id , index );
1291
1293
if (rc != EOK )
1292
1294
return rc ;
@@ -1326,7 +1328,7 @@ static errno_t ext4_write(service_id_t service_id, fs_index_t index, aoff64_t po
1326
1328
/* Handle sparse or unallocated block */
1327
1329
if (fblock == 0 ) {
1328
1330
rc = handle_sparse_or_unallocated_fblock (fs , inode_ref ,
1329
- block_size , iblock , & fblock , & flags );
1331
+ block_size , iblock , & fblock , & flags , & fblock_allocated );
1330
1332
if (rc != EOK ) {
1331
1333
async_answer_0 (& call , rc );
1332
1334
goto exit ;
@@ -1369,6 +1371,9 @@ static errno_t ext4_write(service_id_t service_id, fs_index_t index, aoff64_t po
1369
1371
* wbytes = bytes ;
1370
1372
1371
1373
exit :
1374
+ if (rc != EOK && fblock_allocated )
1375
+ ext4_balloc_free_block (inode_ref , fblock );
1376
+
1372
1377
rc2 = ext4_node_put (fn );
1373
1378
return rc == EOK ? rc2 : rc ;
1374
1379
}
@@ -1381,13 +1386,14 @@ static errno_t ext4_write(service_id_t service_id, fs_index_t index, aoff64_t po
1381
1386
* @param iblock Logical block
1382
1387
* @param fblock Place to store allocated block address
1383
1388
* @param flags BLOCK_FLAGS to update
1389
+ * @param allocated Place to store whether new block was allocated
1384
1390
*
1385
1391
* @return Error code
1386
1392
*
1387
1393
*/
1388
1394
static errno_t handle_sparse_or_unallocated_fblock (ext4_filesystem_t * fs ,
1389
1395
ext4_inode_ref_t * inode_ref , uint32_t block_size , uint32_t iblock ,
1390
- uint32_t * fblock , int * flags )
1396
+ uint32_t * fblock , int * flags , bool * allocated )
1391
1397
{
1392
1398
errno_t rc ;
1393
1399
@@ -1421,6 +1427,8 @@ static errno_t handle_sparse_or_unallocated_fblock(ext4_filesystem_t *fs,
1421
1427
ext4_balloc_free_block (inode_ref , * fblock );
1422
1428
return rc ;
1423
1429
}
1430
+
1431
+ * allocated = true;
1424
1432
}
1425
1433
1426
1434
* flags = BLOCK_FLAGS_NOREAD ;
0 commit comments