12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using Utilities;
- namespace DiskAccessLibrary
- {
- public class PartitionTableEntry
- {
- public const int Length = 16;
- public byte Status;
- public CHSAddress FirstSectorCHS;
- public byte PartitionType;
- public CHSAddress LastSectorCHS;
- public uint FirstSectorLBA;
- public uint SectorCountLBA;
- public PartitionTableEntry()
- {
- FirstSectorCHS = new CHSAddress();
- LastSectorCHS = new CHSAddress();
- }
- public PartitionTableEntry(byte[] buffer, int offset)
- {
- Status = buffer[offset + 0x00];
- FirstSectorCHS = new CHSAddress(buffer, offset + 0x01);
- PartitionType = buffer[offset + 0x04];
- LastSectorCHS = new CHSAddress(buffer, offset + 0x05);
- FirstSectorLBA = LittleEndianConverter.ToUInt32(buffer, offset + 0x08);
- SectorCountLBA = LittleEndianConverter.ToUInt32(buffer, offset + 0x0C);
- }
- public void WriteBytes(byte[] buffer, int offset)
- {
- buffer[offset + 0x00] = Status;
- FirstSectorCHS.WriteBytes(buffer, offset + 0x01);
- buffer[offset + 0x04] = PartitionType;
- LastSectorCHS.WriteBytes(buffer, offset + 0x05);
- LittleEndianWriter.WriteUInt32(buffer, offset + 0x08, FirstSectorLBA);
- LittleEndianWriter.WriteUInt32(buffer, offset + 0x0C, SectorCountLBA);
- }
- public PartitionTypeName PartitionTypeName
- {
- get
- {
- return (PartitionTypeName)PartitionType;
- }
- set
- {
- PartitionType = (byte)value;
- }
- }
- public bool IsBootable
- {
- get
- {
- return (Status == 0x80);
- }
- set
- {
- Status |= 0x80;
- }
- }
- public bool IsValid
- {
- get
- {
- return (Status == 0x80 || Status == 0x00);
- }
- }
- public uint LastSectorLBA
- {
- get
- {
- return this.FirstSectorLBA + this.SectorCountLBA - 1;
- }
- }
- }
- }
|