c# System.IO.FileStream Unable to read last sector if drive has an odd sector number

52 Views Asked by At

I'm trying to read all sectors on a drive for a hashing program using C#. This works fine unless I have a source drive with an odd sector size.

The streams position is set to one sector before the end (standard 512 sector size) and when Filestream Read is called, an exception occurs

The drive cannot find the sector requested.

'_diskStream.Length' threw an exception of type 'System.IO.IOException' at
System.IO.FileStream.ReadNative(Span`1 buffer) at
System.IO.FileStream.ReadSpan(Span`1 destination) at
System.IO.FileStream.Read(Byte[] array, Int32 offset, Int32 count)

I've validated that this sector exists and is readable using other tools, so I'm unsure what the issue is with using FileStream. The disk size is correctly reported as is the 512 sector size.

0

There are 0 best solutions below