When a process deletes a file or truncates it to 0 length, all its data blocks must be reclaimed. This is done by ext2_truncate( ), which receives the address of the file's inode object as its parameter. The function essentially scans the disk inode's i_block array to locate all data blocks and all blocks used for the indirect addressing. These blocks are then released by repeatedly invoking ext2_free_blocks( ).
The ext2_free_blocks( ) function releases a group of one or more adjacent data blocks. Besides its use by ext2_truncate( ), the function is invoked mainly when discarding the preallocated blocks of a file (see the earlier section Section 17.6.5). Its parameters are:
The address of the inode object that describes the file block
The logical block number of the first block to be released count
The function invokes down( ) on the s_lock superblock's semaphore to get exclusive access to the filesystem's superblock, and then performs the following actions for each block to be released:
1. Gets the block bitmap of the block group, including the block to be released
2. Clears the bit in the block bitmap that corresponds to the block to be released and
3. Increments the bg_free_blocks_count field in the block group descriptor and marks the corresponding buffer as dirty
4. Increments the s_free_blocks_count field of the disk superblock, marks the corresponding buffer as dirty, and sets the s_dirt flag of the superblock object
5. If the filesystem has been mounted with the ms_synchronous flag set, invokes ll_rw_block( ) and waits until the write operation on the bitmap's buffer terminates
Finally, the function invokes up( ) to release the superblock's s_lock semaphore.
I [email protected] RuBoard nmm
Was this article helpful?