Ext2 block allocation

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
dosfan
Member
Member
Posts: 65
Joined: Tue Oct 14, 2008 1:18 pm
Location: Scotland

Ext2 block allocation

Post 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.
All your base are belong to us.
xyzzy
Member
Member
Posts: 391
Joined: Wed Jul 25, 2007 8:45 am
Libera.chat IRC: aejsmith
Location: London, UK
Contact:

Re: Ext2 block allocation

Post 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.
xlq
Member
Member
Posts: 36
Joined: Mon Dec 11, 2006 7:51 am

Re: Ext2 block allocation

Post by xlq »

This is known as 'sparse' files.
Marionette the flexible kernel
Post Reply