Removing Data Blocks

In the delete operations described above, the data blocks remain untouched, partly because of the hard link problem. Removal of data blocks is closely associated with the reference counting of inode objects because two conditions must be satisfied before the data blocks can actually be deleted:

1. The link counter nlink must be zero to ensure that there are no references to the data in the filesystem.

2. The usage counter (i_count) of the inode structure must be flushed from memory.

The kernel uses the iput function to decrement the reference counter for the memory object. It therefore makes sense to introduce a check at this point to establish whether the inode is still needed and to remove it if not. This is a standard function of the virtual filesystem not discussed in detail here because the only aspect of interest is that the kernel invokes the ext2_delete_inode function to release the data associated with the inode on the hard disk (iput also returns memory data structures and memory pages reserved for data). This function builds primarily on two other functions — ext2_truncate, which releases the data blocks associated with the inode (regardless of whether the inode represents a directory or a regular file); and ext2_free_inode, which releases the memory space occupied by the inode itself.

Continue reading here: Address Space Operations

Was this article helpful?

0 0