1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:07:36 +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

@ -8,12 +8,7 @@
#include <AK/NonnullRefPtr.h>
#include <LibPartition/DiskPartitionMetadata.h>
#ifdef KERNEL
# include <Kernel/Devices/Storage/StorageDevice.h>
#else
# include <LibCore/Forward.h>
#endif
#include <LibPartition/PartitionableDevice.h>
namespace Partition {
@ -25,19 +20,13 @@ public:
virtual bool is_valid() const = 0;
Vector<DiskPartitionMetadata> partitions() const { return m_partitions; }
size_t block_size() const { return m_block_size; }
size_t block_size() const { return m_device.block_size(); }
protected:
#ifdef KERNEL
explicit PartitionTable(Kernel::StorageDevice&);
NonnullRefPtr<Kernel::StorageDevice> m_device;
#else
explicit PartitionTable(NonnullRefPtr<Core::DeprecatedFile>);
NonnullRefPtr<Core::DeprecatedFile> m_device_file;
#endif
explicit PartitionTable(PartitionableDevice&&);
PartitionableDevice m_device;
Vector<DiskPartitionMetadata> m_partitions;
size_t m_block_size;
};
}