1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:38:12 +00:00

LibPartition: Migrate from DeprecatedFile to File

The implemented cloning mechanism should be sound:
- If a PartitionTable is passed a File with
  ShouldCloseFileDescriptor::Yes, then it will keep it alive until the
  PartitionTable is destroyed.
- If a PartitionTable is passed a File with
  ShouldCloseFileDescriptor::No, then the caller has to ensure that the
  file descriptor remains alive.
If the caller is EBRPartitionTable, the same consideration holds.
If the caller is PartitionEditor::PartitionModel, this is satisfied by
keeping an OwnPtr<Core::File> around which is the originally opened
file.

Therefore, we never leak any fds, and never access a Core::File or fd
after destroying it.
This commit is contained in:
Ben Wiederhake 2023-05-21 20:33:09 +02:00 committed by Jelle Raaijmakers
parent c197fb4037
commit 3d6b838df3
14 changed files with 221 additions and 177 deletions

View file

@ -7,25 +7,15 @@
#include <LibPartition/PartitionTable.h>
#ifndef KERNEL
# include <LibCore/DeprecatedFile.h>
# include <sys/ioctl.h>
#endif
namespace Partition {
#ifdef KERNEL
PartitionTable::PartitionTable(Kernel::StorageDevice& device)
: m_device(device)
, m_block_size(device.block_size())
PartitionTable::PartitionTable(PartitionableDevice&& device)
: m_device(move(device))
{
}
#else
PartitionTable::PartitionTable(NonnullRefPtr<Core::DeprecatedFile> device_file)
: m_device_file(device_file)
{
VERIFY(ioctl(m_device_file->leak_fd(), STORAGE_DEVICE_GET_BLOCK_SIZE, &m_block_size) >= 0);
}
#endif
Optional<DiskPartitionMetadata> PartitionTable::partition(unsigned index) const
{