Regarding ext4 allocation and deallocation of blocks

Akshay Nehe akshaynehe785 at gmail.com
Sat Jun 9 13:19:37 EDT 2012


Hi,

I've been trying to understand ext4 block allocation and deallocation
but I've not been able to figure it out completely and hopefully
someone else knows better so please help me on this.

I'm using kernel 2.6.35.6 and I have the problem as we try to modify
file on ext4 file system based partition, system deallocates all
previous blocks and allocate new blocks with modified data, so with
this behaviour system also changes inode number of file.

As I see it in the code, the ext4_free_blocks function is used to
deallocate the blocks. I have read and understood this behaviour, now
I want to protect some blocks from deallocation i.e. not allowing
blocks say 8705 from deallocation, Is it possible?

If yes what is the correct way to do so. I have written a module to
find out block numbers used by the file before modification( lets take
a.txt with block number as 8705), now if I modify file surely new
block will be allocated(say 9705) I want to protect 8705 from
deallocation, how to do it, if possible?
I was trying to put code in ext4_free_block function to avoid
deallocation of block 8705 but when I insert module, I am not able to
reach code in ext4_free_blocks.

I am observing following Behaviour,

Initially file(a.txt) with block number 8705 then I inserted my module
so came to know block number. Then I open file for modification so
after modification new block was 9217. But I was not able to protect
8705 block, as kernel should deallocate it using ext4_free_blocks
function, but this was not the case.

I again open file for modification( file with 9217 block) and new
block is 8708 but this time kernel used ext4_free_blocks to deallocate
9217 block. What is the reason behind this behaviour? Please help me
in this issue, if anyone familiar with such behaviour.

-- 
Regards,
Akshay Nehe.



More information about the Kernelnewbies mailing list