Skip to content

Commit 890a5ab

Browse files
committed
Rename Device to BaseDevice
1 parent a1b22c1 commit 890a5ab

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

src/GPT/GptDeviceWriter.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
using BlockIO.GPT;
2-
using BlockIO.Arch.Windows;
1+
using BlockIO.Arch.Windows;
2+
using BlockIO.GPT;
3+
using System.Buffers.Binary;
4+
using System.IO.Hashing;
35

46
namespace BlockIO.GPT
57
{
@@ -8,17 +10,28 @@ namespace BlockIO.GPT
810
/// </summary>
911
public static class GptDeviceWriter
1012
{
13+
//TODO: ADD TO UTILS CLASS
14+
private static uint CreateCRC32(byte[] buffer)
15+
{
16+
var span = buffer.AsSpan();
17+
BinaryPrimitives.WriteUInt32LittleEndian(span.Slice(16, 4), 0);
18+
19+
var crc32 = new System.IO.Hashing.Crc32();
20+
crc32.Append(span);
21+
return crc32.GetCurrentHashAsUInt32();
22+
}
23+
1124
/// <summary>
1225
/// Writes a default GPT header, empty partition entry array, and backup header to the device.
1326
/// </summary>
1427
/// <param name="stream">The GPT-capable device stream.</param>
1528
public static void WriteDefaultGpt(GPTDeviceStream stream)
1629
{
17-
var sectorSize = stream.Partition.SectorSize;
18-
var sectorCount = stream.Partition.SectorCount;
30+
var sectorSize = stream.SectorSize;
31+
var sectorCount = stream.Device.SectorCount;
1932

2033
// 1. Protective MBR at sector 0
21-
var protectiveMbr = ProtectiveMBR.Create(sectorSize, sectorCount);
34+
var protectiveMbr = ProtectiveMBR.Create((ulong)sectorSize, sectorCount);
2235
stream.WriteSector(0, protectiveMbr);
2336

2437
// 2. Primary GPT header
@@ -29,7 +42,8 @@ public static void WriteDefaultGpt(GPTDeviceStream stream)
2942

3043
// 3. Empty partition entry array (sectors 2–33)
3144
var entryArray = new byte[header.NumberOfEntries * header.EntrySize];
32-
header.PartitionArrayCRC32 = Crc32Helper.Compute(entryArray);
45+
46+
header.PartitionArrayCRC32 = CreateCRC32(entryArray);
3347
var entrySectors = entryArray.Length / (int)sectorSize;
3448

3549
for (int i = 0; i < entrySectors; i++)

src/Generic/BaseDevice.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class BaseDevice : AbstractDevice
3030
/// <param name="devicePath">The device path used for access.</param>
3131
/// <param name="parser">The parser responsible for partition discovery.</param>
3232
/// <param name="bInitialisOnConstruct">If true, calls <see cref="Initialis"/> during construction.</param>
33-
public Device(string devicePath, AbstractParser parser, bool bInitialisOnConstruct = false)
33+
public BaseDevice(string devicePath, AbstractParser parser, bool bInitialisOnConstruct = false)
3434
: base(devicePath, parser)
3535
{
3636
if (bInitialisOnConstruct)

src/Interface/AbstractDevice.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public void Unlock()
254254
/// <returns>A <see cref="DeviceStream"/> instance.</returns>
255255
public DeviceStream CreateDevicenStream(FileAccess access)
256256
{
257-
return new DeviceStream(this, access);
257+
return new DeviceStream(this, 0, access);
258258
}
259259

260260
/// <summary>

0 commit comments

Comments
 (0)