bootloader: Make Partition::Size return the partition's size.

Partition::ReadAt() and WriteAt() already do bounds-checking
based on the size, but Size() was returning the underlying FD
size, which might be that of the entire disk, not just this
partition. So, move initialization around a bit, and return
the actual size.

Should fix the bootloader menu displaying the wrong sizes
for boot partitions.
This commit is contained in:
Augustin Cavalier
2025-11-12 16:50:37 -05:00
parent f4344e53b8
commit 82b9d8f1f7
+5 -6
View File
@@ -216,11 +216,7 @@ Partition::WriteAt(void *cookie, off_t position, const void *buffer,
off_t
Partition::Size() const
{
struct stat stat;
if (fstat(fFD, &stat) == B_OK)
return stat.st_size;
return Node::Size();
return size;
}
@@ -452,7 +448,10 @@ add_partitions_for(int fd, bool mountFileSystems, bool isBootDevice)
// set some magic/default values
partition->block_size = 512;
partition->size = partition->Size();
struct stat stat;
if (fstat(fd, &stat) == B_OK)
partition->size = stat.st_size;
// add this partition to the list of partitions
// temporarily for Lookup() to work