Page 1 of 1

Ext2 size of block group descriptor table

Posted: Mon Dec 19, 2016 12:32 pm
by Agola
Hello again :D

In my ext2 implementation, I assume block group descriptor table is 1 block. Is that always correct? I'm not sure it is correct, because with the size of block group descriptor is 32 bytes, and with 1024 bytes of block size, a block can have only 32 block group descriptors. (1024 / 32 = 32) With 1024 bytes of block size, a block group descriptor can only handle 8 megabytes. With 32 block group descriptors, entire ext2 can handle only 256 megabytes. (8 * 32 = 256)

But I'm still not sure :|
In wiki.osdev.org/Ext2 it says we can find block group count with "Rounding up the total number of blocks divided by the number of blocks per block group".

If I round block group count to (block size in bytes / 32), can I found size of block group descriptor table in blocks?

If not, how can I?

Thanks :|

Re: Ext2 size of block group descriptor table

Posted: Mon Dec 19, 2016 12:43 pm
by iansjack
If you read the documentation ( http://www.nongnu.org/ext2-doc/ext2.html ) it explains that the table can be one or more blocks in size. That document should answer all your questions.

Re: Ext2 size of block group descriptor table

Posted: Mon Dec 19, 2016 12:45 pm
by crunch
You need to calculate how many blocks the block group descriptors occupy

Code: Select all

num_to_read = ((num_block_groups * sizeof(struct ext2_group_desc)) / blocksize) + 1;

Re: Ext2 size of block group descriptor table

Posted: Mon Dec 19, 2016 1:22 pm
by Agola
iansjack wrote:If you read the documentation ( http://www.nongnu.org/ext2-doc/ext2.html ) it explains that the table can be one or more blocks in size. That document should answer all your questions.
Oh, that was my bad. I didn't read it, but I only read the disk organization and assumed it is only one block. ("1 block - block group descriptor table" from Chapter 3, Table 3-2. Sample 20mb Partition Layout)

Thanks

Re: Ext2 size of block group descriptor table

Posted: Mon Dec 19, 2016 1:27 pm
by Agola
crunch wrote:You need to calculate how many blocks the block group descriptors occupy

Code: Select all

num_to_read = ((num_block_groups * sizeof(struct ext2_group_desc)) / blocksize) + 1;
Thanks, that works, but it reads a block more.

With 32 block groups, and 32 bytes (size of group descriptor) (1024 / 1024) + 1 equals 2
I think the correct one is

Code: Select all

num_to_read = ((num_block_groups * sizeof(struct ext2_group_desc)) - 1) / blocksize) + 1
That is (1023 / 1024) + 1 and results one.

Thanks

Re: Ext2 size of block group descriptor table

Posted: Mon Dec 19, 2016 4:36 pm
by crunch
I was just trying to see if you were paying attention :mrgreen: