As far as I understand when deleting open file in ext4 filesystem we only unlink it, and inode remains allocated until filehandle is closed.
But when is inode actually deallocated? What happens if system if power cycled before file is closed?
Linux uses reference counting. This is the reason why you can not have cyclic references (directory hard links) in the file system. This would break the reference counting.
The inodes are freed when the reference count is zero.
In case of a power failure, you have a corrupted file system. The check tool e2fsck
can find those inconsistencies and moves the files to lost+found
. Then you can delete them once again hopefully without a power failure.
In general power failures with a write cache will always break your filesystem. Even journaling does not help, if the journal does not get written to disk.