Until recently, I thought that on ext file system, inodes have reference counters which count the number of times the file is referenced by a directory entry or a file descriptor.
Then, I learned that the reference counter only counts the number of directory entries referencing it. To falsify this, I read the reference count of a video file using
ls -l. It was 1 as I expected because I didn't create any additional hard links to it. I then opened the video file with a video player and executed the same command again. To my surprise, the reference count was still 1. Therefore, I failed at falsifying.
However, I can definitely continue watching the video after removing its only directory entry. When opening a big video file and deleting its directory entry, the amount of free storage space on the file system does not change. It only changes (by the size of the video file) when the player reached the end of the video and closes the file descriptor or the player terminates itself (depending on the video player used).
What are the exact conditions for a file to be freed on an ext file system? I'm interested in how it is handled in ext2, ext3, and ext4. Are there differences depending on the kernel used or other parts of the operating system?