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); }
// tracksPerCylinder a.k.a. heads per cylinder public static CHSAddress FromLBA(ulong lba, IDiskGeometry disk) { CHSAddress chs = new CHSAddress(); chs.Cylinder = (ushort)(lba / (ulong)(disk.SectorsPerTrack * disk.TracksPerCylinder)); chs.Head = (byte)((lba / (ulong)disk.SectorsPerTrack) % (ulong)disk.TracksPerCylinder); chs.Sector = (byte)(lba % (ulong)disk.SectorsPerTrack + 1); return(chs); }
public static void ExtendMBRPartition(MBRPartition partition, long numberOfAdditionalExtentSectors) { Disk disk = partition.Disk; MasterBootRecord mbr = MasterBootRecord.ReadFromDisk(disk); for (int index = 0; index < mbr.PartitionTable.Length; index++) { if (mbr.PartitionTable[index].FirstSectorLBA == partition.FirstSector) { mbr.PartitionTable[index].SectorCountLBA += (uint)numberOfAdditionalExtentSectors; ulong lastSectorLBA = mbr.PartitionTable[index].LastSectorLBA; mbr.PartitionTable[index].LastSectorCHS = CHSAddress.FromLBA(lastSectorLBA, disk); break; } } MasterBootRecord.WriteToDisk(disk, mbr); }
public PartitionTableEntry() { FirstSectorCHS = new CHSAddress(); LastSectorCHS = new CHSAddress(); }