Page 1 of 1

Ext2 block allocation

Posted: Mon Feb 02, 2009 3:02 pm
by dosfan
I'm looking for some advice on block allocation.

For example, assuming blocksize is 1024, file is 0 bytes in length.

If do a 1k write starting at offset 0. I allocate a new block and stuff it in i_block[0], write the physical block to disk and update the inode. Job done.....

Then I write 1k starting at offset 4096 (4th block in inode obviously). Same procedure as above, but am I supposed to allocate the 2nd and 3rd blocks and zero fill?? :shock:

It feels "wrong" not to, although it just seems wasteful.

Re: Ext2 block allocation

Posted: Mon Feb 02, 2009 3:23 pm
by xyzzy
No, you don't need to fill them in. If a block is set to 0, things reading should see that and act as though the block was filled with zeros.

Re: Ext2 block allocation

Posted: Mon Feb 09, 2009 6:20 am
by xlq
This is known as 'sparse' files.