Now I can see great logic after this perfect explanation.<br><br>Thanks a lot Eric and Ted.<br><br>Best regards<br><br>youness<br><br><div class="gmail_quote">On Wed, Aug 19, 2009 at 12:03 AM, Theodore Tso <span dir="ltr"><<a href="mailto:tytso@mit.edu" target="_blank">tytso@mit.edu</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div>On Tue, Aug 18, 2009 at 11:43:15PM +0200, Youness HAFFANE wrote:<br>
> I see,<br>
> So for only the first 12 blocks, there is no need for extra blocks, but I<br>
> couldn't find any mathematical logic for the rest.<br>
> I explain :<br>
> I've tried to create many files to which I assigned a fixed number of<br>
> blocks, and the results are :<br>
> for a 13 block file till a 1036 block file I had 3 extra blocks added<br>
> and then it's 4 extra blocks added (for example a 3060 block file)<br>
> and for a 4000 block file, it's 5 extra blocks<br>
> for 5000 it's 6<br>
> and for 10 000 it's 11 blocks added!<br>
<br>
</div>All of this assumes a filesystem with a 4k block size....<br>
<br>
In the inode there are 12 direct block pointers, and then one indirect<br>
block pointer, one double indirect block pointer, and one triple<br>
indirect block pointer.<br>
<br>
A 4k block has room for 1024 block numbers.  Hence, so files that have<br>
between 13 and 1036 data blocks (12+1024), will need a single indirect<br>
block.  Beyond that a single double indirect block has room for 1024<br>
indirect block pointers.  So for the next 1024 blocks, one double<br>
indirect block, plus an indirect block is needed.  For the next 1024<br>
data blocks, another indirect block is needed.  After the 1024 slots<br>
in the double indirect blocks are filled, then we use a triple<br>
indirect block, which has room for 1024 double indirect blocks, and so<br>
on.<br>
<br>
If the filesystem is using 1k block sizes, then there is room for 256<br>
block numbers in each block, so the indirect block can address 256<br>
data blocks, and then the double indirect block in the inode can can<br>
address (256*256) data blocks while using 256 indirect numbers, and<br>
the triple indirect block can address 256 double indirect blocks,<br>
which when using 256*256 indirect blocks, can address up to<br>
256*256*256 data blocks.<br>
<br>
With sparse files, indirect blocks and double indirect blocks are<br>
aren't needed to address data blocks won't be allocated.  But for<br>
contiguous files it's relatively easy to predict in advance how much<br>
space is needed for the indirect, double indirect, and triple indirect<br>
blocks.<br>
<br>
                                        - Ted<br>
</blockquote></div><br><br clear="all"><br>-- <br>Y.<br>