TDiskPartitioner

From Ultibo.org
Jump to: navigation, search

Return to Unit Filesystem


Description


To be documented

Class definitions



TDiskPartitioner = class(TObject)

constructor Create(ADriver:TFileSysDriver; ARecognizer:TRecognizer);  
destructor Destroy; override;  
private
FLock:TSynchronizerHandle;  
FLocalLock:TMutexHandle;  
protected
FDriver:TFileSysDriver;  
FRecognizer:TRecognizer;  
 
FInitChar:Byte; Character to initialize sectors when adding partitions
 
function AcquireLock:Boolean;  
function ReleaseLock:Boolean;  
 
function CheckLogical(ADevice:TDiskDevice; AParent:TDiskPartition; APartitionId:Byte):Boolean; virtual;  
function CheckExtended(ADevice:TDiskDevice; AParent:TDiskPartition; APartitionId:Byte):Boolean; virtual;  
 
function GetLogicalChild(ADevice:TDiskDevice; APartition:TDiskPartition; ALock:Boolean; AState:LongWord):TDiskPartition;  
function GetExtendedSibling(ADevice:TDiskDevice; AParent:TDiskPartition; ALock:Boolean; AState:LongWord):TDiskPartition;  
function GetExtendedParent(ADevice:TDiskDevice; AParent:TDiskPartition; AStart:LongWord; ALock:Boolean; AState:LongWord):TDiskPartition;  
 
function GetEndCHS(ADevice:TDiskDevice; AStart,ACount:LongWord; var ACylinder,AHead,ASector:Word):Boolean; virtual;  
function GetStartCHS(ADevice:TDiskDevice; AStart,ACount:LongWord; var ACylinder,AHead,ASector:Word):Boolean; virtual;  
 
function GetSectorCount(ADevice:TDiskDevice; AStart,ACount:LongWord):LongWord; virtual;  
function GetStartSector(ADevice:TDiskDevice; AExtended,ALogical:Boolean; AStart:LongWord; var ACount:LongWord):LongWord; virtual;  
function GetSectorOffset(ADevice:TDiskDevice; AParent:TDiskPartition; AExtended:Boolean; AStart:LongWord):LongWord; virtual;  
function GetPartitionId(ADevice:TDiskDevice; AParent:TDiskPartition; AStart,ACount:LongWord; APartitionId:Byte):Byte; virtual;  
 
function InitPartition(ADevice:TDiskDevice; AParent:TDiskPartition; AStart,ACount:LongWord; APartitionId:Byte):Boolean; virtual;  
 
function CreatePartitionRecord(ADevice:TDiskDevice; ARecord:PPartitionRecord):Boolean;  
function CreatePartitionEntry(ADevice:TDiskDevice; AStart,ACount,AOffset:LongWord; APartitionId:Byte; AActive:Boolean; var AEntry:TPartitionEntry):Boolean;  
 
function FillSectors(ADevice:TDiskDevice; APartition:TDiskPartition; ASector,ACount:LongWord; AValue:Byte):Boolean;  
function ReadSectors(ADevice:TDiskDevice; APartition:TDiskPartition; ASector,ACount:LongWord; var ABuffer):Boolean;  
function WriteSectors(ADevice:TDiskDevice; APartition:TDiskPartition; ASector,ACount:LongWord; const ABuffer):Boolean;  
public
property InitChar:Byte read FInitChar write FInitChar;  
 
function ReaderLock:Boolean;  
function ReaderUnlock:Boolean;  
function WriterLock:Boolean;  
function WriterUnlock:Boolean;  
 
function AcceptPartition(ADevice:TDiskDevice; APartition,AParent:TDiskPartition; APartitionId:Byte):Boolean; virtual;  
 
function CreatePartition(ADevice:TDiskDevice; AParent:TDiskPartition; APartitionId:Byte; ACount:LongWord; AActive:Boolean):Boolean; virtual;  
function DeletePartition(APartition:TDiskPartition):Boolean; virtual;  
function ModifyPartition(APartition:TDiskPartition; APartitionId:Byte; AOverride:Boolean):Boolean; virtual;  
function ActivatePartition(APartition:TDiskPartition; AActive:Boolean):Boolean; virtual;  


Function declarations



constructor TDiskPartitioner.Create(ADriver:TFileSysDriver; ARecognizer:TRecognizer);
Description: To be documented
Note None documented


destructor TDiskPartitioner.Destroy;
Description: To be documented
Note None documented


function TDiskPartitioner.AcquireLock:Boolean;
Description: To be documented
Note None documented


function TDiskPartitioner.ReleaseLock:Boolean;
Description: To be documented
Note None documented


function TDiskPartitioner.CheckLogical(ADevice:TDiskDevice; AParent:TDiskPartition; APartitionId:Byte):Boolean;
Description: Check if the Partition is of a Logical type
Note Caller must hold the device and partition lock


function TDiskPartitioner.CheckExtended(ADevice:TDiskDevice; AParent:TDiskPartition; APartitionId:Byte):Boolean;
Description: Check if the Partition is of an Extended type
Note Caller must hold the device and partition lock


function TDiskPartitioner.GetLogicalChild(ADevice:TDiskDevice; APartition:TDiskPartition; ALock:Boolean; AState:LongWord):TDiskPartition;
Description: Get the logical Child for an extended partition based on Parent
Note Used to find the logical child of a Partition being deleted

Caller must hold the device and partition lock


function TDiskPartitioner.GetExtendedSibling(ADevice:TDiskDevice; AParent:TDiskPartition; ALock:Boolean; AState:LongWord):TDiskPartition;
Description: Get the next Sibling for an extended partition based on Parent
Note Passed Parent should be the actual Parent

Also used to find the next sibling of a Partition being deleted
Caller must hold the device and partition lock


function TDiskPartitioner.GetExtendedParent(ADevice:TDiskDevice; AParent:TDiskPartition; AStart:LongWord; ALock:Boolean; AState:LongWord):TDiskPartition;
Description: Get the actual Parent for an extended partition based on Start sector
Note Passed Parent should be the Root extended

Caller must hold the device and partition lock


function TDiskPartitioner.GetEndCHS(ADevice:TDiskDevice; AStart,ACount:LongWord; var ACylinder,AHead,ASector:Word):Boolean;
Description: Get the End CHS values or dummy values if larger than 8GB
Note Start and Count must be Cylinder aligned when passed

Caller must hold the device lock


function TDiskPartitioner.GetStartCHS(ADevice:TDiskDevice; AStart,ACount:LongWord; var ACylinder,AHead,ASector:Word):Boolean;
Description: Get the Start CHS values or dummy values if larger than 8GB
Note Start and Count must be Cylinder aligned when passed

Caller must hold the device lock


function TDiskPartitioner.GetSectorCount(ADevice:TDiskDevice; AStart,ACount:LongWord):LongWord;
Description: Determine the actual sector Count given an actual Start sector and nominal sector Count
Start Start must be Cylinder aligned when passed
Note The actual result will be a Count that is aligned to a Cylinder boundary

Caller must hold the device lock


function TDiskPartitioner.GetStartSector(ADevice:TDiskDevice; AExtended,ALogical:Boolean; AStart:LongWord; var ACount:LongWord):LongWord;
Description: Determine the actual Start sector given a nominal Start sector
Note The actual result will be a Start that is aligned to a Cylinder boundary

For first Partition (not Extended) and Logical the Start is aligned to a Head boundary
Caller must hold the device lock


function TDiskPartitioner.GetSectorOffset(ADevice:TDiskDevice; AParent:TDiskPartition; AExtended:Boolean; AStart:LongWord):LongWord;
Description: Determine the actual sector Offset given an actual Start sector
Start Start must be Cylinder aligned when passed
Note Accounts for Offset behaviour of second level extended and logical partitions

Caller must hold the device and partition lock


function TDiskPartitioner.GetPartitionId(ADevice:TDiskDevice; AParent:TDiskPartition; AStart,ACount:LongWord; APartitionId:Byte):Byte;
Description: Determine the actual partition Type given a Start, Count and nominal Type
Note Caller must hold the device and partition lock


function TDiskPartitioner.InitPartition(ADevice:TDiskDevice; AParent:TDiskPartition; AStart,ACount:LongWord; APartitionId:Byte):Boolean;
Description: Perform any initialization of a new partition such as filling the boot sector etc
Start Start is the absolute start sector on the device
Note Caller must hold the device and partition lock


function TDiskPartitioner.CreatePartitionRecord(ADevice:TDiskDevice; ARecord:PPartitionRecord):Boolean;
Description: Check for a valid Partition record (or Master Boot Record)
Note Create an empty Partition record (or Master Boot Record) if not valid

Caller must hold the device lock


function TDiskPartitioner.CreatePartitionEntry(ADevice:TDiskDevice; AStart,ACount,AOffset:LongWord; APartitionId:Byte; AActive:Boolean; var AEntry:TPartitionEntry):Boolean;
Description: Fill the Partitition entry with the supplied values
Note Caller must hold the device lock


function TDiskPartitioner.FillSectors(ADevice:TDiskDevice; APartition:TDiskPartition; ASector,ACount:LongWord; AValue:Byte):Boolean;
Description: Fill specified number of sectors with the supplied value
Sector Sector is relative to the StartSector of the Partition
Note Caller must hold the device and partition lock


function TDiskPartitioner.ReadSectors(ADevice:TDiskDevice; APartition:TDiskPartition; ASector,ACount:LongWord; var ABuffer):Boolean;
Description: Read Sectors from the Device or Partition using Cache
Sector Sector is relative to the StartSector of the Device or Partition
Note Caller must hold the device and partition lock, cache will serialize access to device.


function TDiskPartitioner.WriteSectors(ADevice:TDiskDevice; APartition:TDiskPartition; ASector,ACount:LongWord; const ABuffer):Boolean;
Description: Write Sectors to the Device or Partition using Cache
Sector Sector is relative to the StartSector of the Device or Partition
Note Caller must hold the device and partition lock, cache will serialize access to device.


function TDiskPartitioner.ReaderLock:Boolean;
Description: To be documented
Note None documented


function TDiskPartitioner.ReaderUnlock:Boolean;
Description: To be documented
Note None documented


function TDiskPartitioner.WriterLock:Boolean;
Description: To be documented
Note None documented


function TDiskPartitioner.WriterUnlock:Boolean;
Description: To be documented
Note None documented


function TDiskPartitioner.AcceptPartition(ADevice:TDiskDevice; APartition,AParent:TDiskPartition; APartitionId:Byte):Boolean;
Description: Check if the Partition can be accepted for Create, Delete, Modify, Activate
Note Caller must hold the device and partition and parent lock


function TDiskPartitioner.CreatePartition(ADevice:TDiskDevice; AParent:TDiskPartition; APartitionId:Byte; ACount:LongWord; AActive:Boolean):Boolean;
Description: Create a new Partition on the specified Device with the specified Parent (Optional)
Note When creating Logical partitions the passed Parent must be the Root Extended

Caller must hold the device and parent writer locks


function TDiskPartitioner.DeletePartition(APartition:TDiskPartition):Boolean;
Description: Delete the specified Partition from the specified Device
Note Caller must hold the device and partition writer locks


function TDiskPartitioner.ModifyPartition(APartition:TDiskPartition; APartitionId:Byte; AOverride:Boolean):Boolean;
Description: Modify the type of the specified Partition
Note Override disables the normalisation of PartitionId to suit size and type and also disables dismount and remount of any volumes and drives etc

Caller must hold the partition writer lock


function TDiskPartitioner.ActivatePartition(APartition:TDiskPartition; AActive:Boolean):Boolean;
Description: Make the specified Partition active and all siblings inactive
Note Also allows making the specified Partition inactive

No need to check for Extended as AcceptPartition does
Caller must hold the partition writer lock


Return to Unit Reference