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 uintptr_t 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. More...
 
virtual bool cacheIsCritical ()
 
- Public Member Functions inherited from Disk
 Disk (Device *p)
 
virtual Type getType ()
 
virtual SubType getSubType ()
 
virtual void dump (String &str)
 
virtual size_t getSize () const
 Gets the size of the disk. More...
 
virtual size_t getBlockSize () const
 Gets the block size of the disk. More...
 
virtual void pin (uint64_t location)
 Pins a cache page. More...
 
virtual void unpin (uint64_t location)
 
virtual void flush (uint64_t location)
 Flush a cached page to disk. More...
 
- Public Member Functions inherited from Device
 Device (Device *p)
 
DevicegetParent () const
 
void setParent (Device *p)
 
virtual 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 ()
 
virtual Vector< Address * > & addresses ()
 
virtual uintptr_t getInterruptNumber ()
 
virtual void setInterruptNumber (uintptr_t n)
 
void addChild (Device *pDevice)
 
DevicegetChild (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 &)
 
FileDiskoperator= (const FileDisk &)
 

Private Attributes

Filem_pFile
 File we're using as a disk.
 
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 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)
 
- Protected Member Functions inherited from Device
 NOT_COPYABLE_OR_ASSIGNABLE (Device)
 
- Static Protected Member Functions inherited from Device
static Deviceroot ()
 
- Protected Attributes inherited from Device
Vector< Address * > m_Addresses
 
Vector< Device * > m_Children
 
Devicem_pParent
 
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

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 46 of file LoDisk.h.

Member Enumeration Documentation

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 49 of file LoDisk.h.

Member Function Documentation

void FileDisk::align ( uint64_t  location)
virtual

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

For example, if one has a partition starting on byte 512, one will probably want 4096-byte reads to be aligned with this (so reading 4096 bytes from byte 0 on the partition will create one page of cache and not span two). Without an align point a read of the first sector of a partition starting at byte 512 will have to have a location of 512 rather than 0.

Use this function to allow reads to fit into the 4096 byte buffers manipulated in read() or write() even when location isn't aligned on a 4096 byte boundary.

Reimplemented from Disk.

Definition at line 129 of file LoDisk.cc.

References assert.

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 83 of file LoDisk.h.

virtual void FileDisk::getName ( String str)
inlinevirtual

Stores the device's name in str.

Reimplemented from Disk.

Definition at line 64 of file LoDisk.h.

References Disk::align(), Disk::read(), and Disk::write().

uintptr_t FileDisk::read ( uint64_t  location)
virtual

Read from location on disk and return a pointer to it. location must be 512 byte aligned. The pointer returned is within a page of cache that maps to 4096 bytes of disk area.

Note
If the Disk is backed by a Cache, the buffer returned should have its refcount incremented by one by a successful run of read(). Use unpin() to indicate you no longer care about the buffer.
Parameters
locationThe offset from the start of the device, in bytes, to start the read, must be multiple of 512.
Returns
Pointer to writable area of memory containing the data. 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 84 of file LoDisk.cc.

References FATAL.

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


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