MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / Truncate

Method Truncate

Kernel/src/fs/ext2.cpp:1451–1472  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1449 }
1450
1451 int Ext2Volume::Truncate(Ext2Node* node, off_t length){
1452 if(length < 0){
1453 return -EINVAL;
1454 }
1455
1456 if(length > node->e2inode.blockCount * 512){ // We need to allocate blocks
1457 uint64_t blocksNeeded = (length + blocksize - 1) / blocksize;
1458 uint64_t blocksAllocated = node->e2inode.blockCount / (blocksize / 512);
1459
1460 while(blocksAllocated < blocksNeeded){
1461 SetInodeBlock(blocksAllocated++, node->e2inode, AllocateBlock());
1462 }
1463
1464 node->e2inode.blockCount = blocksNeeded * (blocksize / 512);
1465 }
1466
1467 node->size = node->e2inode.size = length; // TODO: Actually free blocks in inode if possible
1468
1469 SyncNode(node);
1470
1471 return 0;
1472 }
1473
1474 void Ext2Volume::CleanNode(Ext2Node* node){
1475 if(node->handleCount > 0){

Callers 1

SysOpenFunction · 0.45

Calls 2

AcquireWriteMethod · 0.80
ReleaseWriteMethod · 0.80

Tested by

no test coverage detected