Now I know how does file deletion work in Linux In ext2 it mark "unused", and in ext3 not only mark "unused" but also change the size, block pointers to zero.
But I wonder when I create a hard link to a file, and then delete the original file will the inode be marked "unuse"? Or it will happen until all hard link be deleted?
thanks.
i-nodes contain a link count (visible in ls -l
output). Each hard link increments that count. Unlinking (removing a link, be it the original filename->inode link, or some hard link added later, which is the only thing users can request) decrements the count. The file won't be deleted until the count reaches 0 and there are no open file descriptors left pointing at that file (which is similarly tracked by an in-kernel reference count).