Inside WBFS
A few truths about WBFS
While I'm working with my WBFS tool (WWT) I take some deeper looks into the WBFS subsystem and found some interest things.
Overall in the internet you can read that the maximal number of discs is that a WBFS partition can contain is about 500. This is true but not the whole truth. The value depends of the sector size parameter. It defines the number of bytes of 1 hd sector. The first sector of a WBFS partition is reserved for the WBFS header (12 bytes) and for a disc table (all other bytes, 1 byte per disc).
The user/tool can set the sector size while formatting a WBFS partition. The default sector size is 512. WWT knows the option --sector-size and may format a WBFS partition with different sector sizes. This is nice for testing.
The following dump shows the specific parameters of a WBFS partition with about 2 tera bytes (a file with exact 2.000.000.000.000 bytes). WWT creates this as sparse file so that the WBFS partition only needs 16 KiB disc space after formatting:
With sector size 512 the maximal number of discs is set to 500 (=512-12). But when a WBFS is formatted with sector size 2048 than it may contain up to 2036 (2048-12) discs. See the dump:
I don't know if other tools and the usb loaders support other sector sizes (this is subject of later tests, perhaps others will do that) but the solution is very easy: Read the WBFS sectors before calling the function wbfs_open_partition() and calculate the sector size:
CODEwbfs_head_t whead;
stat = ReadAt(file,0,&whead,sizeof(whead));
if (stat) { ERROR_HANDLING; }
sector_size = 1
A few truths about WBFS
While I'm working with my WBFS tool (WWT) I take some deeper looks into the WBFS subsystem and found some interest things.
Overall in the internet you can read that the maximal number of discs is that a WBFS partition can contain is about 500. This is true but not the whole truth. The value depends of the sector size parameter. It defines the number of bytes of 1 hd sector. The first sector of a WBFS partition is reserved for the WBFS header (12 bytes) and for a disc table (all other bytes, 1 byte per disc).
The user/tool can set the sector size while formatting a WBFS partition. The default sector size is 512. WWT knows the option --sector-size and may format a WBFS partition with different sector sizes. This is nice for testing.
The following dump shows the specific parameters of a WBFS partition with about 2 tera bytes (a file with exact 2.000.000.000.000 bytes). WWT creates this as sparse file so that the WBFS partition only needs 16 KiB disc space after formatting:
Code:
DUMP of a.wbfs
WBFS-Header:
MAGIC: 'WBFS' = 57 42 46 53
number of sectors: 279303400
hd sector size: 9 -> 512
WBFS sector size: 26 -> 67108864
hd: sector size: 512 = 2^9
hd: num of sectors: 3906250000
hd: total size: 1907349 MiB
wii: sector size: 32768 = 2^15
wii: num of sectors: 61035008
wii: sectors/disc: 286864
wii: total size: 1907344 MiB
wbfs: sector size: 67108864 = 2^26
wbfs: num of sectors: 29802
wbfs: sectors/disc: 140
wbfs: total size: 1907328 MiB
partition lba: 0
free blocks lba: 131064
disc info size: 1024
used disk space: 640 MiB = 1%
free disk space: 1906688 MiB = 99%
total disk space: 1907328 MiB = 100%
number of wii discs: 0 = 0%
max disc: 500
disc open: 0
With sector size 512 the maximal number of discs is set to 500 (=512-12). But when a WBFS is formatted with sector size 2048 than it may contain up to 2036 (2048-12) discs. See the dump:
Code:
DUMP of a.wbfs
WBFS-Header:
MAGIC: 'WBFS' = 57 42 46 53
number of sectors: 1143551290
hd sector size: 11 -> 2048
WBFS sector size: 25 -> 33554432
hd: sector size: 2048 = 2^11
hd: num of sectors: 976562500
hd: total size: 1907349 MiB
wii: sector size: 32768 = 2^15
wii: num of sectors: 61034496
wii: sectors/disc: 286864
wii: total size: 1907328 MiB
wbfs: sector size: 33554432 = 2^25
wbfs: num of sectors: 59604
wbfs: sectors/disc: 280
wbfs: total size: 1907328 MiB
partition lba: 0
free blocks lba: 16380
disc info size: 2048
used disk space: 640 MiB = 1%
free disk space: 1906688 MiB = 99%
total disk space: 1907328 MiB = 100%
number of wii discs: 0 = 0%
max disc: 2036
disc open: 0
I don't know if other tools and the usb loaders support other sector sizes (this is subject of later tests, perhaps others will do that) but the solution is very easy: Read the WBFS sectors before calling the function wbfs_open_partition() and calculate the sector size:
CODEwbfs_head_t whead;
stat = ReadAt(file,0,&whead,sizeof(whead));
if (stat) { ERROR_HANDLING; }
sector_size = 1