btrfs: Add more validation checks in IsValid()
Check that sector_size and node_size are powers of 2, that node_size >= sector_size, total_size is non-zero, and num_devices is non-zero. Addresses the TODO comment in IsValid(). Change-Id: Id2c084f6b649a0315de1454a072ab1dcf3d0a3dd Reviewed-on: https://review.haiku-os.org/c/haiku/+/10448 Haiku-Format: Haiku-format Bot <[email protected]> Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
committed by
Adrien Destugues
parent
d754d09549
commit
ba83d20148
@@ -49,10 +49,21 @@ btrfs_super_block::IsMagicValid() const
|
||||
bool
|
||||
btrfs_super_block::IsValid() const
|
||||
{
|
||||
// TODO: check some more values!
|
||||
if (!IsMagicValid())
|
||||
return false;
|
||||
|
||||
if (SectorSize() < 512 || (SectorSize() & (SectorSize() - 1)) != 0)
|
||||
return false;
|
||||
|
||||
if (BlockSize() < SectorSize() || (BlockSize() & (BlockSize() - 1)) != 0)
|
||||
return false;
|
||||
|
||||
if (TotalSize() == 0)
|
||||
return false;
|
||||
|
||||
if (B_LENDIAN_TO_HOST_INT64(num_devices) == 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user