diff --git a/headers/private/kernel/disk_device_manager/KPartition.h b/headers/private/kernel/disk_device_manager/KPartition.h index be6c2bf6cf..c05e280902 100644 --- a/headers/private/kernel/disk_device_manager/KPartition.h +++ b/headers/private/kernel/disk_device_manager/KPartition.h @@ -57,6 +57,9 @@ public: void SetSize(off_t size); off_t Size() const; + void SetContentSize(off_t size); + off_t ContentSize() const; + void SetBlockSize(uint32 blockSize); uint32 BlockSize() const; diff --git a/src/add-ons/kernel/disk_scanner/fs/bfs.c b/src/add-ons/kernel/disk_scanner/fs/bfs.c index dd98c55498..ea41de5487 100644 --- a/src/add-ons/kernel/disk_scanner/fs/bfs.c +++ b/src/add-ons/kernel/disk_scanner/fs/bfs.c @@ -397,7 +397,12 @@ bfs_scan_partition(int fd, partition_data *partition, void *cookie) partition->block_size)); superBlock = (disk_super_block*)cookie; // fill in the partition_data structure - partition->status = B_PARTITION_VALID; + partition->content_size + = (off_t)superBlock->num_blocks * superBlock->block_size; + if (partition->content_size <= partition->size) + partition->status = B_PARTITION_VALID; + else + partition->status = B_PARTITION_CORRUPT; partition->flags |= B_PARTITION_FILE_SYSTEM; partition->block_size = superBlock->block_size; partition->content_name = strdup(superBlock->name); diff --git a/src/add-ons/kernel/partitioning_systems/intel/intel.cpp b/src/add-ons/kernel/partitioning_systems/intel/intel.cpp index 453c5b340e..016a572807 100644 --- a/src/add-ons/kernel/partitioning_systems/intel/intel.cpp +++ b/src/add-ons/kernel/partitioning_systems/intel/intel.cpp @@ -533,6 +533,7 @@ pm_scan_partition(int fd, partition_data *partition, void *cookie) | B_PARTITION_READ_ONLY | B_DISK_SYSTEM_SUPPORTS_RESIZING_CHILD; // TODO: Update when write functionality is implemented. + partition->content_size = partition->size; // (no content_name and content_parameters) // (content_type is set by the system) partition->content_cookie = map; @@ -722,6 +723,7 @@ ep_scan_partition(int fd, partition_data *partition, void *cookie) partition->flags |= B_PARTITION_PARTITIONING_SYSTEM | B_PARTITION_READ_ONLY; // TODO: Update when write functionality is implemented. + partition->content_size = partition->size; // (no content_name and content_parameters) // (content_type is set by the system) partition->content_cookie = primary; diff --git a/src/kernel/core/disk_device_manager/KPartition.cpp b/src/kernel/core/disk_device_manager/KPartition.cpp index ad1f4bbec6..7ba762422f 100644 --- a/src/kernel/core/disk_device_manager/KPartition.cpp +++ b/src/kernel/core/disk_device_manager/KPartition.cpp @@ -41,6 +41,7 @@ KPartition::KPartition(partition_id id) fPartitionData.id = (id >= 0 ? id : _NextID()); fPartitionData.offset = 0; fPartitionData.size = 0; + fPartitionData.content_size = 0; fPartitionData.block_size = 0; fPartitionData.child_count = 0; fPartitionData.index = -1; @@ -255,6 +256,20 @@ KPartition::Size() const return fPartitionData.size; } +// SetContentSize +void +KPartition::SetContentSize(off_t size) +{ + fPartitionData.content_size = size; +} + +// ContentSize +off_t +KPartition::ContentSize() const +{ + return fPartitionData.content_size; +} + // SetBlockSize void KPartition::SetBlockSize(uint32 blockSize) @@ -785,6 +800,11 @@ KPartition::UninitializeContents(bool logChanges) SetContentParameters(NULL); flags |= B_PARTITION_CHANGED_CONTENT_PARAMETERS; } + // content size + if (ContentSize() > 0) { + SetContentSize(0); + flags |= B_PARTITION_CHANGED_CONTENT_SIZE; + } // block size if (Parent() && Parent()->BlockSize() != BlockSize()) { SetBlockSize(Parent()->BlockSize()); @@ -840,6 +860,7 @@ KPartition::WriteUserData(UserDataWriter &writer, user_partition_data *data) data->shadow_id = -1; data->offset = Offset(); data->size = Size(); + data->content_size = ContentSize(); data->block_size = BlockSize(); data->status = Status(); data->flags = Flags(); @@ -879,6 +900,7 @@ KPartition::Dump(bool deep, int32 level) OUT("%spartition %ld: %s\n", prefix, ID(), path); OUT("%s offset: %lld\n", prefix, Offset()); OUT("%s size: %lld\n", prefix, Size()); + OUT("%s content size: %lld\n", prefix, ContentSize()); OUT("%s block size: %lu\n", prefix, BlockSize()); OUT("%s child count: %ld\n", prefix, CountChildren()); OUT("%s index: %ld\n", prefix, Index());