The Pedigree Project 0.1
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Partition Class Reference

#include <Partition.h>

+ Inheritance diagram for Partition:
+ Collaboration diagram for Partition:

Public Member Functions

 Partition (const String &type, uint64_t start, uint64_t length)
 
virtual void getName (String &str) override
 
virtual void dump (String &str) override
 
virtual BufferView read (uint64_t location) override
 
bool zero (uint64_t location, size_t length) override
 
DiskReadView readView (uint64_t location) override
 
DiskWriteView writeView (uint64_t location) override
 
virtual void write (uint64_t location) override
 
virtual void flush (uint64_t location) override
 Flush a cached page to disk.
 
virtual MUST_USE_RESULT bool retireCachePage (uint64_t location) override
 
virtual bool sync (uint64_t location, bool async) override
 
MUST_USE_RESULT bool syncPages (const uint64_t *locations, size_t count) override
 
bool readInto (uint64_t location, void *buffer, size_t length) override
 
bool readIntoBatch (ReadBuffer *buffers, size_t count) override
 
bool writeFrom (uint64_t location, const void *buffer, size_t length) override
 
bool writeFromBatch (WriteBuffer *buffers, size_t count) override
 
bool syncData () override
 
virtual MUST_USE_RESULT bool syncAll () override
 
Disk * physicalDisk () override
 
virtual size_t getSize () const override
 Gets the size of the disk.
 
virtual size_t getBlockSize () const override
 Gets the preferred I/O extent of the disk.
 
size_t getNativeBlockSize () const override
 
virtual bool pin (uint64_t location) override
 Pins a cache page.
 
virtual void unpin (uint64_t location) override
 
uint64_t getStart ()
 
uint64_t getLength () const
 
const String & getPartitionType () const
 
void setPartitionIdentity (const String &uuid, const String &label)
 
bool getPartitionUuid (String &uuid) const override
 
bool getPartitionLabel (String &label) const override
 
- Public Member Functions inherited from Disk
 Disk (Device *p)
 
bool acquireUse (DiskUse &use)
 
uint32_t endpointId ()
 
virtual PagingStatus preparePagingTransport (PagingTransport *&transport)
 
void retireEndpoint ()
 
bool tryCloseEndpoint ()
 
void reopenEndpoint ()
 
virtual Type getType ()
 
virtual SubType getSubType ()
 
MUST_USE_RESULT bool readViews (uint64_t location, size_t length, BufferViewSequence &views)
 
void unpinViews (uint64_t location, BufferViewSequence &views)
 
virtual void align (uint64_t location)
 Sets the page boundary alignment after a specific location on the disk.
 
virtual bool cacheIsCritical ()
 Whether or not the cache is critical and cannot be flushed or deleted.
 
- Public Member Functions inherited from Device
 Device (Device *p)
 
Device * getParent () const
 
void setParent (Device *p)
 
virtual const String & getSpecificType ()
 
virtual void setSpecificType (String str)
 
void setPciPosition (uint32_t bus, uint32_t device, uint32_t func)
 
void setPciIdentifiers (uint8_t classCode, uint8_t subclassCode, uint16_t vendorId, uint16_t deviceId, uint8_t progIf)
 
void setPciConfigHeader (const PciBus::ConfigSpace &space)
 
PciBus::ConfigSpace getPciConfigHeader () const
 
uint8_t getPciClassCode ()
 
uint8_t getPciSubclassCode ()
 
uint16_t getPciVendorId ()
 
uint16_t getPciDeviceId ()
 
uint8_t getPciProgInterface ()
 
uint32_t getPciBusPosition ()
 
uint32_t getPciDevicePosition ()
 
uint32_t getPciFunctionNumber ()
 
Device * getPhysicalFunction () const
 
size_t getVirtualFunctionIndex () const
 
void setVirtualFunction (Device *physicalFunction, size_t index)
 
virtual Vector< Address * > & addresses ()
 
virtual uintptr_t getInterruptNumber ()
 
virtual void setInterruptNumber (uintptr_t n)
 
void addChild (Device *pDevice)
 
Device * getChild (size_t n)
 
size_t getNumChildren ()
 
void removeChild (size_t n)
 
void removeChild (Device *d)
 
void replaceChild (Device *src, Device *dest)
 

Private Member Functions

bool containsRange (uint64_t location, size_t length) const
 
bool containsCachePage (uint64_t location) const
 
void ensureAligned (Disk *pParent)
 

Private Attributes

String m_Type
 
String m_Uuid
 
String m_Label
 
uint64_t m_Start
 
uint64_t m_Length
 
Mutex m_AlignmentLock
 
bool m_bAligned
 

Additional Inherited Members

- Public Types inherited from Disk
enum  SubType { ATA = 0 , ATAPI }
 
- Public Types inherited from Device
enum  Type {
  Generic , Root , Disk , Bus ,
  Display , Network , Sound , Console ,
  Mouse , Controller , UsbController , UsbGeneric ,
  UsbContainer
}
 
typedef Device *(* Callback) (Device *)
 
- Static Public Member Functions inherited from Device
static bool treeLockHeldByCurrentThread ()
 
static void foreach (Callback callback, Device *root=0)
 
template<class F , class... Args>
static void foreach (pedigree_std::Callable< F > &callback, Device *root, Args... args)
 
static void addToRoot (Device *device)
 
static void searchByVendorId (uint16_t vendorId, void(*callback)(Device *), Device *root=0)
 
static void searchByVendorIdAndDeviceId (uint16_t vendorId, uint16_t deviceId, void(*callback)(Device *), Device *root=0)
 
static void searchByClass (uint16_t classCode, void(*callback)(Device *), Device *root=0)
 
static void searchByClassAndSubclass (uint16_t classCode, uint16_t subclassCode, void(*callback)(Device *), Device *root=0)
 
static void searchByClassSubclassAndProgInterface (uint16_t classCode, uint16_t subclassCode, uint8_t progInterface, void(*callback)(Device *), Device *root=0)
 
- Static Public Attributes inherited from Disk
static constexpr size_t MaxReadBuffers = 32
 
static constexpr size_t MaxWriteBuffers = 32
 
static constexpr size_t MaxSyncPages = 64
 
- Protected Member Functions inherited from Disk
void reserveEndpoint ()
 
void publishEndpoint ()
 
virtual BufferView acquireView (uint64_t location, bool writable, uint64_t &token)
 
virtual void releaseView (uint64_t token, bool writable)
 
- Protected Member Functions inherited from Device
 NOT_COPYABLE_OR_ASSIGNABLE (Device)
 
- Static Protected Member Functions inherited from Device
static Device & root ()
 
- Protected Attributes inherited from Device
Vector< Address * > m_Addresses
 
Vector< Device * > m_Children
 
Device * m_pParent
 
Device * m_PhysicalFunction
 
size_t m_VirtualFunctionIndex
 
uintptr_t m_InterruptNumber
 
String m_SpecificType
 
PciBus::ConfigSpace m_ConfigHeader
 
uint8_t m_ClassCode
 
uint8_t m_SubclassCode
 
uint16_t m_VendorId
 
uint16_t m_DeviceId
 
uint8_t m_ProgInterface
 
uint32_t m_PciBusPos
 
uint32_t m_PciDevicePos
 
uint32_t m_PciFunctionNum
 
- Static Protected Attributes inherited from Device
static Device m_Root
 
static Mutex m_TreeLock
 

Detailed Description

A partition is a chunk of disk.

Definition at line 34 of file Partition.h.

Constructor & Destructor Documentation

◆ Partition()

Partition::Partition ( const String &  type,
uint64_t  start,
uint64_t  length 
)

Definition at line 23 of file Partition.cc.

◆ ~Partition()

Partition::~Partition ( )
overridevirtual

Definition at line 34 of file Partition.cc.

Member Function Documentation

◆ containsCachePage()

bool Partition::containsCachePage ( uint64_t  location) const
inlineprivate

Definition at line 220 of file Partition.h.

◆ containsRange()

bool Partition::containsRange ( uint64_t  location,
size_t  length 
) const
private

Definition at line 36 of file Partition.cc.

◆ dump()

virtual void Partition::dump ( String &  str)
inlineoverridevirtual

Dumps a textual representation of the device into the given string.

Reimplemented from Disk.

Definition at line 46 of file Partition.h.

◆ ensureAligned()

void Partition::ensureAligned ( Disk *  pParent)
inlineprivate

Definition at line 230 of file Partition.h.

◆ flush()

virtual void Partition::flush ( uint64_t  location)
inlineoverridevirtual

Flush a cached page to disk.

Essentially a no-op if the given location is not actually in cache. Called either by filesystem drivers (on removable disks) or from a central cache manager which handles flushing caches back to the disk on a regular basis.

Will not remove the page from cache, that must be done by the caller.

Reimplemented from Disk.

Definition at line 114 of file Partition.h.

References Disk::flush(), and Device::getParent().

◆ getBlockSize()

virtual size_t Partition::getBlockSize ( ) const
inlineoverridevirtual

Gets the preferred I/O extent of the disk.

This may describe a native device block or a larger cache-fill/readahead extent, depending on the implementation. It is independent of the cache page boundary reported by BufferView::size().

Reimplemented from Disk.

Definition at line 164 of file Partition.h.

References Disk::getBlockSize(), and Device::getParent().

◆ getLength()

uint64_t Partition::getLength ( ) const
inline

Returns the length of this partition.

Definition at line 193 of file Partition.h.

Referenced by getSize().

+ Here is the caller graph for this function:

◆ getName()

virtual void Partition::getName ( String &  str)
inlineoverridevirtual

Stores the device's name in str.

Reimplemented from Disk.

Definition at line 39 of file Partition.h.

◆ getNativeBlockSize()

size_t Partition::getNativeBlockSize ( ) const
inlineoverridevirtual

Size of a logical sector used by on-disk LBA addressing.

Reimplemented from Disk.

Definition at line 169 of file Partition.h.

References Disk::getNativeBlockSize(), and Device::getParent().

◆ getPartitionLabel()

bool Partition::getPartitionLabel ( String &  label) const
inlineoverridevirtual

Reimplemented from Disk.

Definition at line 212 of file Partition.h.

◆ getPartitionType()

const String & Partition::getPartitionType ( ) const
inline

Returns a string giving the type of the partition.

Definition at line 198 of file Partition.h.

◆ getPartitionUuid()

bool Partition::getPartitionUuid ( String &  uuid) const
inlineoverridevirtual

GPT-style partition identity, when this endpoint represents a partition.

Reimplemented from Disk.

Definition at line 207 of file Partition.h.

◆ getSize()

virtual size_t Partition::getSize ( ) const
inlineoverridevirtual

Gets the size of the disk.

This is the size in bytes of the disk. Reads or writes beyond this size will fail.

Reimplemented from Disk.

Definition at line 160 of file Partition.h.

References getLength().

◆ getStart()

uint64_t Partition::getStart ( )

Returns the first byte of the parent disk that is in this partition.

Definition at line 136 of file Partition.cc.

◆ physicalDisk()

Disk * Partition::physicalDisk ( )
inlineoverridevirtual

Reimplemented from Disk.

Definition at line 155 of file Partition.h.

◆ pin()

virtual bool Partition::pin ( uint64_t  location)
inlineoverridevirtual

Pins a cache page.

This allows an upstream user of Disk pages to 'pin' cache pages, causing them to only be freed once all consumers have done an 'unpin'. The pin and unpin semantics allow for memory mappings to be made in a reasonably safe manner, as it can be assumed that the physical page for a particular cache block will not be freed.

Returns
True only when this call acquired a reference to the page currently published for location. Callers must not use an address obtained before a failed pin.

Implements Disk.

Definition at line 174 of file Partition.h.

References Device::getParent(), and Disk::pin().

◆ read()

virtual BufferView Partition::read ( uint64_t  location)
inlineoverridevirtual

Read from location on disk and return a view beginning at that byte. location must be 512-byte aligned. The returned view ends at the boundary of the independently owned cache page containing location; its size is unrelated to the device's block or readahead size.

Note
A successful read returns exactly one caller-owned reference to the cache page containing location. The view is non-owning: use unpin() exactly once after every copy and subview is no longer in use. Larger I/O extents do not extend this ownership.
Parameters
locationThe offset from the start of the device, in bytes, to start the read, must be multiple of 512. Prefer readView() for readers and writeView() for scoped mutation. This legacy interface treats every read()/pin() reference as potentially mutable until its matching unpin(). No derived pointers may survive that reference.
Returns
A writable view containing the data, or an empty view on failure. If the data is written, the page is marked as dirty and may be written back to disk at any time (or forced with write() or flush() ).

Reimplemented from Disk.

Definition at line 56 of file Partition.h.

References Device::getParent(), and Disk::read().

◆ readInto()

bool Partition::readInto ( uint64_t  location,
void *  buffer,
size_t  length 
)
overridevirtual

Transfers exactly length bytes using caller-owned, pinned storage. The buffer must remain valid until return and must not alias this disk's cache. No buffer reference is retained. Failure may have transferred a prefix. Existing block-cache data remains coherent; unsupported transports copy through their ordinary cache views.

Reimplemented from Disk.

Definition at line 45 of file Partition.cc.

References Device::getParent().

◆ readIntoBatch()

bool Partition::readIntoBatch ( ReadBuffer *  buffers,
size_t  count 
)
overridevirtual

Reads up to MaxReadBuffers independent ranges into caller-owned, pinned storage. Physical mappings must remain stable until return. Every issued transfer is drained before return, including on failure. complete is reset on entry and set only for fully initialised buffers; successful buffers remain usable when another range fails.

Reimplemented from Disk.

Definition at line 53 of file Partition.cc.

References Device::getParent().

◆ readView()

DiskReadView Partition::readView ( uint64_t  location)
inlineoverridevirtual

Owning views release their pin automatically. Read views cannot modify cache data. Returning a write view records changes; use sync() or syncAll() for durability.

Reimplemented from Disk.

Definition at line 81 of file Partition.h.

References Device::getParent().

◆ retireCachePage()

virtual MUST_USE_RESULT bool Partition::retireCachePage ( uint64_t  location)
inlineoverridevirtual

Synchronously writes and retires the target cache page containing location.

A successful call means the page is no longer published by this disk's cache. It does not imply that a volatile device write cache has been flushed. Callers must release their own reference to the page before entering this operation.

Returns
True when the page was retired or was already absent. False when this disk does not support retirement or the page must remain available for a later retry.

Reimplemented from Disk.

Definition at line 125 of file Partition.h.

References Device::getParent(), and Disk::retireCachePage().

◆ setPartitionIdentity()

void Partition::setPartitionIdentity ( const String &  uuid,
const String &  label 
)
inline

Definition at line 202 of file Partition.h.

◆ sync()

virtual bool Partition::sync ( uint64_t  location,
bool  async 
)
inlineoverridevirtual

Writes a cached page and reports failure. Synchronous success includes the device's write-cache flush; asynchronous success means admission only. Unsupported backends return false rather than claiming persistence.

Reimplemented from Disk.

Definition at line 136 of file Partition.h.

References Device::getParent(), and Disk::sync().

◆ syncAll()

bool Partition::syncAll ( )
overridevirtual

Drains existing cached writes and the device write cache synchronously.

Reimplemented from Disk.

Definition at line 130 of file Partition.cc.

References Device::getParent(), and Disk::syncAll().

◆ syncData()

bool Partition::syncData ( )
overridevirtual

Makes preceding successful writeFrom() calls durable. Call after all writes in a batch, including a partially failed batch. writeFrom() alone promises transfer completion, not a device write-cache barrier. Legacy fallbacks persist each write individually, so their final barrier is already done.

Reimplemented from Disk.

Definition at line 105 of file Partition.cc.

References Device::getParent(), and Disk::syncData().

◆ syncPages()

bool Partition::syncPages ( const uint64_t *  locations,
size_t  count 
)
overridevirtual

Synchronously persists every listed cached page, including the device cache.

Reimplemented from Disk.

Definition at line 110 of file Partition.cc.

References Device::getParent(), Disk::getSize(), and Disk::syncPages().

◆ unpin()

virtual void Partition::unpin ( uint64_t  location)
inlineoverridevirtual

Unpins a cache page (see pin() for more information and rationale).

Implements Disk.

Definition at line 182 of file Partition.h.

References Device::getParent(), and Disk::unpin().

◆ write()

virtual void Partition::write ( uint64_t  location)
inlineoverridevirtual

This function schedules a cache writeback of the given location. The data to be written back is fetched from the cache (pointer returned by read() ).

Parameters
locationThe offset from the start of the device, in bytes, to start the write. Must be 512byte aligned.

Reimplemented from Disk.

Definition at line 103 of file Partition.h.

References Device::getParent(), and Disk::write().

◆ writeFrom()

bool Partition::writeFrom ( uint64_t  location,
const void *  buffer,
size_t  length 
)
overridevirtual

Reimplemented from Disk.

Definition at line 75 of file Partition.cc.

◆ writeFromBatch()

bool Partition::writeFromBatch ( WriteBuffer *  buffers,
size_t  count 
)
overridevirtual

Writes caller-owned buffers, draining all issued I/O before return. complete reports each fully transferred range, including on partial failure. Storage must remain valid until return; syncData() supplies durability.

Reimplemented from Disk.

Definition at line 83 of file Partition.cc.

References Device::getParent().

◆ writeView()

DiskWriteView Partition::writeView ( uint64_t  location)
inlineoverridevirtual

Reimplemented from Disk.

Definition at line 92 of file Partition.h.

◆ zero()

bool Partition::zero ( uint64_t  location,
size_t  length 
)
inlineoverridevirtual

Zeroes a range in the cache; syncAll supplies durability. A failed call may have zeroed a prefix. Full cache pages need no old contents read.

Reimplemented from Disk.

Definition at line 73 of file Partition.h.

References Device::getParent().

Member Data Documentation

◆ m_AlignmentLock

Mutex Partition::m_AlignmentLock
private

Definition at line 245 of file Partition.h.

◆ m_bAligned

bool Partition::m_bAligned
private

Definition at line 246 of file Partition.h.

◆ m_Label

String Partition::m_Label
private

Definition at line 242 of file Partition.h.

◆ m_Length

uint64_t Partition::m_Length
private

Definition at line 244 of file Partition.h.

◆ m_Start

uint64_t Partition::m_Start
private

Definition at line 243 of file Partition.h.

◆ m_Type

String Partition::m_Type
private

Definition at line 240 of file Partition.h.

◆ m_Uuid

String Partition::m_Uuid
private

Definition at line 241 of file Partition.h.


The documentation for this class was generated from the following files: