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

#include <LoDisk.h>

+ Inheritance diagram for FileDisk:
+ Collaboration diagram for FileDisk:

Public Types

enum  AccessType { RamOnly = 0 , Standard }
 
- 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 *)
 

Public Member Functions

 FileDisk (String file, AccessType mode=Standard)
 
virtual void getName (String &str)
 
bool initialise ()
 
virtual BufferView read (uint64_t location)
 
virtual void write (uint64_t location)
 
virtual void align (uint64_t location)
 Sets the page boundary alignment after a specific location on the disk.
 
virtual size_t getSize () const
 Gets the size of the disk.
 
virtual bool pin (uint64_t location)
 Pins a cache page.
 
virtual void unpin (uint64_t location)
 
virtual bool cacheIsCritical ()
 
- Public Member Functions inherited from Disk
 Disk (Device *p)
 
virtual Disk * physicalDisk ()
 
bool acquireUse (DiskUse &use)
 
uint32_t endpointId ()
 
virtual bool getPartitionUuid (String &uuid) const
 
virtual bool getPartitionLabel (String &label) const
 
virtual PagingStatus preparePagingTransport (PagingTransport *&transport)
 
void retireEndpoint ()
 
bool tryCloseEndpoint ()
 
void reopenEndpoint ()
 
virtual Type getType ()
 
virtual SubType getSubType ()
 
virtual void dump (String &str)
 
virtual DiskReadView readView (uint64_t location)
 
virtual DiskWriteView writeView (uint64_t location)
 
virtual MUST_USE_RESULT bool readInto (uint64_t location, void *buffer, size_t length)
 
virtual MUST_USE_RESULT bool writeFrom (uint64_t location, const void *buffer, size_t length)
 
virtual MUST_USE_RESULT bool writeFromBatch (WriteBuffer *buffers, size_t count)
 
virtual MUST_USE_RESULT bool readIntoBatch (ReadBuffer *buffers, size_t count)
 
virtual MUST_USE_RESULT bool syncData ()
 
MUST_USE_RESULT bool readViews (uint64_t location, size_t length, BufferViewSequence &views)
 
void unpinViews (uint64_t location, BufferViewSequence &views)
 
virtual size_t getBlockSize () const
 Gets the preferred I/O extent of the disk.
 
virtual size_t getNativeBlockSize () const
 
virtual void flush (uint64_t location)
 Flush a cached page to disk.
 
virtual bool sync (uint64_t location, bool async)
 
virtual MUST_USE_RESULT bool syncPages (const uint64_t *locations, size_t count)
 
virtual MUST_USE_RESULT bool syncAll ()
 
virtual MUST_USE_RESULT bool retireCachePage (uint64_t location)
 
virtual MUST_USE_RESULT bool zero (uint64_t location, size_t length)
 
- 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

 FileDisk (const FileDisk &)
 
FileDisk & operator= (const FileDisk &)
 

Private Attributes

File * m_pFile
 File we're using as a disk.
 
bool m_bVfsReference
 Whether this disk owns a persistent VFS reference to m_pFile.
 
AccessType m_Mode
 Access mode.
 
Cache m_Cache
 
MemoryRegion m_MemRegion
 
Mutex m_ReqMutex
 
uint64_t m_AlignPoints [8]
 
size_t m_nAlignPoints
 

Additional Inherited Members

- 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

Todo:
Expose functionality here as a Service - specifically creating/removing disks.

Abstraction for Files as Disks This allows disk images to be opened as a real disk for installer ramdisks or for testing.

Specifying RamOnly causes the file to be stored only in RAM with no changes committed to the file.

Definition at line 43 of file LoDisk.h.

Member Enumeration Documentation

◆ AccessType

Enumerator
RamOnly 

Read from file into RAM, changes persist in RAM, never written to file

Standard 

Read from file, changes go to file

Definition at line 45 of file LoDisk.h.

Constructor & Destructor Documentation

◆ FileDisk()

FileDisk::FileDisk ( String  file,
AccessType  mode = Standard 
)

Definition at line 33 of file LoDisk.cc.

◆ ~FileDisk()

FileDisk::~FileDisk ( )
virtual

Definition at line 81 of file LoDisk.cc.

Member Function Documentation

◆ align()

void FileDisk::align ( uint64_t  location)
virtual

Sets the page boundary alignment after a specific location on the disk.

For example, a partition beginning at byte 512 should align its first cache page with that boundary rather than with byte zero of the parent.

Use this function to keep the cache pages manipulated in read() and write() aligned with a child device whose start is not naturally page-aligned on the parent.

Reimplemented from Disk.

Definition at line 156 of file LoDisk.cc.

◆ cacheIsCritical()

virtual bool FileDisk::cacheIsCritical ( )
inlinevirtual

None of our writes ever end up back on the loaded file.

Todo:
Could it be possible to allow writes to go through to the file we've mounted? Then this could return true if the backing device is read-only, false otherwise.

Reimplemented from Disk.

Definition at line 80 of file LoDisk.h.

◆ getName()

virtual void FileDisk::getName ( String &  str)
inlinevirtual

Stores the device's name in str.

Reimplemented from Disk.

Definition at line 59 of file LoDisk.h.

◆ getSize()

size_t FileDisk::getSize ( ) const
virtual

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 167 of file LoDisk.cc.

References m_pFile.

◆ initialise()

bool FileDisk::initialise ( )

Definition at line 93 of file LoDisk.cc.

◆ pin()

bool FileDisk::pin ( uint64_t  location)
virtual

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 171 of file LoDisk.cc.

References TargetInfo::getPageSize(), m_pFile, and Cache::pin().

◆ read()

BufferView FileDisk::read ( uint64_t  location)
virtual

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 97 of file LoDisk.cc.

References Cache::discardEditing(), TargetInfo::getPageSize(), Cache::insert(), Cache::lookup(), m_pFile, Cache::markNoLongerEditing(), and File::read().

◆ unpin()

void FileDisk::unpin ( uint64_t  location)
virtual

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

Implements Disk.

Definition at line 190 of file LoDisk.cc.

References TargetInfo::getPageSize(), m_pFile, and Cache::release().

◆ write()

void FileDisk::write ( uint64_t  location)
virtual

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.
Todo:
implement this

Reimplemented from Disk.

Definition at line 148 of file LoDisk.cc.

References m_pFile.

Member Data Documentation

◆ m_AlignPoints

uint64_t FileDisk::m_AlignPoints[8]
private

Definition at line 105 of file LoDisk.h.

◆ m_bVfsReference

bool FileDisk::m_bVfsReference
private

Whether this disk owns a persistent VFS reference to m_pFile.

Definition at line 92 of file LoDisk.h.

◆ m_Cache

Cache FileDisk::m_Cache
private

Definition at line 97 of file LoDisk.h.

◆ m_MemRegion

MemoryRegion FileDisk::m_MemRegion
private

Definition at line 100 of file LoDisk.h.

◆ m_Mode

AccessType FileDisk::m_Mode
private

Access mode.

Definition at line 95 of file LoDisk.h.

◆ m_nAlignPoints

size_t FileDisk::m_nAlignPoints
private

Definition at line 106 of file LoDisk.h.

◆ m_pFile

File* FileDisk::m_pFile
private

File we're using as a disk.

Definition at line 89 of file LoDisk.h.

Referenced by getSize(), pin(), read(), unpin(), and write().

◆ m_ReqMutex

Mutex FileDisk::m_ReqMutex
private

Definition at line 103 of file LoDisk.h.


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