Skip to content

Commit dff6d20

Browse files
committed
Finished HFEv1 support
Bug fixes
1 parent 4742ef1 commit dff6d20

File tree

18 files changed

+293
-135
lines changed

18 files changed

+293
-135
lines changed

DiskImageTool/Bitstream/IBM_MFM/IBM_MFM_Tools.vb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
Dim Track As UShort
4545
Dim Side As Byte
4646
Dim NumBytes As UInteger
47+
Dim NumBits As UInteger
4748
Dim Aligned As Boolean
4849
End Structure
4950

@@ -209,7 +210,8 @@
209210
Dim RegionData As RegionData
210211
RegionData.Regions = New List(Of BitstreamRegion)
211212
RegionData.Sectors = New List(Of BitstreamRegionSector)
212-
RegionData.NumBytes = Bitstream.Length \ MFM_BYTE_SIZE
213+
RegionData.NumBytes = Math.Ceiling(Bitstream.Length / MFM_BYTE_SIZE)
214+
RegionData.NumBits = Bitstream.Length
213215
RegionData.Aligned = True
214216

215217
Index = FindPattern(Bitstream, IAMPattern, BitstreamIndex)
@@ -433,15 +435,15 @@
433435
SectorIndex += 1
434436
Next
435437

436-
If BitstreamIndex > 0 And BitstreamIndex <= Bitstream.Length Then
437-
GapCount = (Bitstream.Length - BitstreamIndex) \ MFM_BYTE_SIZE
438+
If BitstreamIndex > 0 And BitstreamIndex < Bitstream.Length Then
439+
GapCount = Math.Ceiling((Bitstream.Length - BitstreamIndex) / MFM_BYTE_SIZE)
438440
RegionData.Regions.Add(New BitstreamRegion(MFMRegionType.Gap4B, ByteIndex, GapCount, RegionSector, BitOffset))
439441
If RegionSector IsNot Nothing Then
440-
RegionSector.Length = Bitstream.Length \ MFM_BYTE_SIZE - RegionSector.StartIndex
442+
RegionSector.Length = Math.Ceiling(Bitstream.Length / MFM_BYTE_SIZE) - RegionSector.StartIndex
441443
End If
442444
End If
443445

444-
ByteIndex = Bitstream.Length \ MFM_BYTE_SIZE
446+
ByteIndex = Math.Ceiling(Bitstream.Length / MFM_BYTE_SIZE)
445447
If RegionData.NumBytes > ByteIndex Then
446448
Dim Length = RegionData.NumBytes - ByteIndex
447449
RegionData.Regions.Add(New BitstreamRegion(MFMRegionType.Overflow, ByteIndex, Length, Nothing, BitOffset))
@@ -663,7 +665,7 @@
663665
Dim dataBit As Boolean
664666

665667
If NumBytes > 0 Then
666-
Dim Length = Bitstream.Length - 1
668+
Dim Length = Bitstream.Length
667669

668670
If Start > Length - 1 Then
669671
Start = Start Mod Length
@@ -672,12 +674,12 @@
672674
Do
673675
clockBit = Bitstream(Start)
674676
Start += 1
675-
If Start > Length Then
677+
If Start > Length - 1 Then
676678
Start = 0
677679
End If
678680
dataBit = Bitstream(Start)
679681
Start += 1
680-
If Start > Length Then
682+
If Start > Length - 1 Then
681683
Start = 0
682684
End If
683685

DiskImageTool/DiskImage/DirectoryEntry.vb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148

149149
Dim ClusterCount As UShort
150150

151-
If IsDirectory() Then
151+
If IsDirectory Then
152152
ClusterCount = 1
153153
Else
154154
ClusterCount = Math.Ceiling(FileSize / _BPB.BytesPerCluster)
@@ -259,7 +259,7 @@
259259
End Function
260260

261261
Public Function HasIncorrectFileSize() As Boolean
262-
If IsDirectory() Or IsVolumeName() Then
262+
If IsDirectory Or IsVolumeName Then
263263
Return FileSize > 0
264264
Else
265265
Return GetAllocatedSize() <> GetAllocatedSizeFromFAT()
@@ -318,11 +318,11 @@
318318
End Function
319319

320320
Public Function IsValidDirectory() As Boolean
321-
Return IsDirectory() AndAlso Not (IsVolumeName() OrElse HasInvalidStartingCluster()) AndAlso StartingCluster > 1
321+
Return IsDirectory AndAlso Not (IsVolumeName OrElse HasInvalidStartingCluster()) AndAlso StartingCluster > 1
322322
End Function
323323

324324
Public Function IsValidFile() As Boolean
325-
Return Not (IsDirectory() OrElse IsVolumeName() OrElse HasInvalidStartingCluster() OrElse HasInvalidFileSize()) AndAlso StartingCluster > 1
325+
Return Not (IsDirectory OrElse IsVolumeName OrElse HasInvalidStartingCluster() OrElse HasInvalidFileSize()) AndAlso StartingCluster > 1
326326
End Function
327327

328328
Public Function RemoveLFN() As Boolean
@@ -336,7 +336,7 @@
336336

337337
Dim ClusterCount As UShort
338338

339-
If IsDirectory() Then
339+
If IsDirectory Then
340340
ClusterCount = 1
341341
Else
342342
ClusterCount = Math.Ceiling(FileSize / _BPB.BytesPerCluster)

DiskImageTool/DiskImage/DirectoryEntryBase.vb

Lines changed: 102 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ Namespace DiskImage
55
Public Class DirectoryEntryBase
66
Public Const CHAR_DELETED As Byte = &HE5
77
Public Const DIRECTORY_ENTRY_SIZE As Byte = 32
8-
Public Shared ReadOnly EmptyDirectoryEntry() As Byte = {&HE5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
98
Public Shared ReadOnly CurrentDirectoryEntry() As Byte = {&H2E, &H20, &H20, &H20, &H20, &H20, &H20, &H20, &H20, &H20, &H20}
10-
Public Shared ReadOnly ParentDirectoryEntry() As Byte = {&H2E, &H2E, &H20, &H20, &H20, &H20, &H20, &H20, &H20, &H20, &H20}
9+
Public Shared ReadOnly EmptyDirectoryEntry() As Byte = {&HE5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
1110
Public Shared ReadOnly InvalidFileChars() As Byte = {&H22, &H2A, &H2B, &H2C, &H2E, &H2F, &H3A, &H3B, &H3C, &H3D, &H3E, &H3F, &H5B, &H5C, &H5D, &H7C}
12-
11+
Public Shared ReadOnly ParentDirectoryEntry() As Byte = {&H2E, &H2E, &H20, &H20, &H20, &H20, &H20, &H20, &H20, &H20, &H20}
1312
Private Const CHAR_EMPTY As Byte = &H0
1413
Private Const CHAR_SPACE As Byte = &H20
1514

@@ -27,6 +26,7 @@ Namespace DiskImage
2726
Private _Offset As UInteger
2827
Private _VolumeNameCache As String
2928
Private _VolumeNameIsCached As Boolean = False
29+
3030
Public Enum AttributeFlags As Byte
3131
[ReadOnly] = 1
3232
Hidden = 2
@@ -221,6 +221,84 @@ Namespace DiskImage
221221
End Set
222222
End Property
223223

224+
Public Property HasNTLowerCaseExtension As Boolean
225+
Get
226+
Return (ReservedForWinNT And NTFlags.LowerCaseExtension) > 0
227+
End Get
228+
Set(value As Boolean)
229+
ReservedForWinNT = MyBitConverter.ToggleBit(ReservedForWinNT, NTFlags.LowerCaseExtension, value)
230+
End Set
231+
End Property
232+
233+
Public Property HasNTLowerCaseFileName As Boolean
234+
Get
235+
Return (ReservedForWinNT And NTFlags.LowerCaseFileName) > 0
236+
End Get
237+
Set(value As Boolean)
238+
ReservedForWinNT = MyBitConverter.ToggleBit(ReservedForWinNT, NTFlags.LowerCaseFileName, value)
239+
End Set
240+
End Property
241+
242+
Public Property IsArchive As Boolean
243+
Get
244+
Return (Attributes And AttributeFlags.ArchiveFlag) > 0
245+
End Get
246+
Set(value As Boolean)
247+
Attributes = MyBitConverter.ToggleBit(Attributes, AttributeFlags.ArchiveFlag, value)
248+
End Set
249+
End Property
250+
251+
Public Property IsDirectory As Boolean
252+
Get
253+
Return (Attributes And AttributeFlags.Directory) > 0
254+
End Get
255+
Set(value As Boolean)
256+
Attributes = MyBitConverter.ToggleBit(Attributes, AttributeFlags.Directory, value)
257+
End Set
258+
End Property
259+
260+
Public Property IsHidden As Boolean
261+
Get
262+
Return (Attributes And AttributeFlags.Hidden) > 0
263+
End Get
264+
Set(value As Boolean)
265+
Attributes = MyBitConverter.ToggleBit(Attributes, AttributeFlags.Hidden, value)
266+
End Set
267+
End Property
268+
269+
Public ReadOnly Property IsLFN As Boolean
270+
Get
271+
Return (Attributes And AttributeFlags.LongFileName) = AttributeFlags.LongFileName
272+
End Get
273+
End Property
274+
275+
Public Property IsReadOnly As Boolean
276+
Get
277+
Return (Attributes And AttributeFlags.ReadOnly) > 0
278+
End Get
279+
Set(value As Boolean)
280+
Attributes = MyBitConverter.ToggleBit(Attributes, AttributeFlags.ReadOnly, value)
281+
End Set
282+
End Property
283+
284+
Public Property IsSystem As Boolean
285+
Get
286+
Return (Attributes And AttributeFlags.System) > 0
287+
End Get
288+
Set(value As Boolean)
289+
Attributes = MyBitConverter.ToggleBit(Attributes, AttributeFlags.System, value)
290+
End Set
291+
End Property
292+
293+
Public Property IsVolumeName As Boolean
294+
Get
295+
Return (Attributes And AttributeFlags.VolumeName) > 0
296+
End Get
297+
Set(value As Boolean)
298+
Attributes = MyBitConverter.ToggleBit(Attributes, AttributeFlags.VolumeName, value)
299+
End Set
300+
End Property
301+
224302
Public Property LastAccessDate() As UShort
225303
Get
226304
Return _FileBytes.GetBytesShort(_Offset + DirectoryEntryOffsets.LastAccessDate)
@@ -386,24 +464,6 @@ Namespace DiskImage
386464
Return File
387465
End Function
388466

389-
Public Function GetNTFileName() As String
390-
Dim File = GetFileName()
391-
Dim Ext = GetFileExtension()
392-
393-
If HasNTLowerCaseFileName() Then
394-
File = File.ToLower
395-
End If
396-
397-
If Ext <> "" Then
398-
If HasNTLowerCaseExtension() Then
399-
Ext = Ext.ToLower
400-
End If
401-
File = File & "." & Ext
402-
End If
403-
404-
Return File
405-
End Function
406-
407467
Public Function GetLastAccessDate() As ExpandedDate
408468
If Not _LastAccessDateIsCached Then
409469
_LastAccessDateCache = ExpandDate(LastAccessDate)
@@ -435,7 +495,7 @@ Namespace DiskImage
435495
End Function
436496

437497
Public Function GetLFNFileName() As String
438-
If IsLFN() Then
498+
If IsLFN Then
439499
Dim Size As Integer = LFNSizes.FilePart1 + LFNSizes.FilePart2 + LFNSizes.FilePart3
440500
Dim LFN(Size - 1) As Byte
441501

@@ -451,6 +511,23 @@ Namespace DiskImage
451511
End If
452512
End Function
453513

514+
Public Function GetNTFileName() As String
515+
Dim File = GetFileName()
516+
Dim Ext = GetFileExtension()
517+
518+
If HasNTLowerCaseFileName() Then
519+
File = File.ToLower
520+
End If
521+
522+
If Ext <> "" Then
523+
If HasNTLowerCaseExtension() Then
524+
Ext = Ext.ToLower
525+
End If
526+
File = File & "." & Ext
527+
End If
528+
529+
Return File
530+
End Function
454531
Public Function GetVolumeName() As String
455532
If Not _VolumeNameIsCached Then
456533
_VolumeNameCache = CodePage437ToUnicode(FileNameWithExtension).TrimEnd(" ")
@@ -470,15 +547,15 @@ Namespace DiskImage
470547

471548
Public Function HasInvalidExtension() As Boolean
472549
If Not _HasInvalidExtensionCache.HasValue Then
473-
_HasInvalidExtensionCache = Not CheckValidFileName(Extension, True, IsVolumeName())
550+
_HasInvalidExtensionCache = Not CheckValidFileName(Extension, True, IsVolumeName)
474551
End If
475552

476553
Return _HasInvalidExtensionCache
477554
End Function
478555

479556
Public Function HasInvalidFilename() As Boolean
480557
If Not _HasInvalidFileNameCache.HasValue Then
481-
_HasInvalidFileNameCache = Not CheckValidFileName(FileName, False, IsVolumeName())
558+
_HasInvalidFileNameCache = Not CheckValidFileName(FileName, False, IsVolumeName)
482559
End If
483560

484561
Return _HasInvalidFileNameCache
@@ -487,23 +564,10 @@ Namespace DiskImage
487564
Public Function HasLastAccessDate() As Boolean
488565
Return LastAccessDate <> 0
489566
End Function
490-
491-
Public Function HasNTLowerCaseFileName() As Boolean
492-
Return (ReservedForWinNT And NTFlags.LowerCaseFileName) > 0
493-
End Function
494-
495-
Public Function HasNTLowerCaseExtension() As Boolean
496-
Return (ReservedForWinNT And NTFlags.LowerCaseExtension) > 0
497-
End Function
498-
499567
Public Function HasNTUnknownFlags() As Boolean
500568
Return (ReservedForWinNT And &HE7) > 0
501569
End Function
502570

503-
Public Function IsArchive() As Boolean
504-
Return (Attributes And AttributeFlags.ArchiveFlag) > 0
505-
End Function
506-
507571
Public Function IsBlank() As Boolean
508572
If _IsBlankCache.HasValue Then
509573
Return _IsBlankCache.Value
@@ -535,22 +599,10 @@ Namespace DiskImage
535599
Return FileName(0) = CHAR_DELETED
536600
End Function
537601

538-
Public Function IsDirectory() As Boolean
539-
Return (Attributes And AttributeFlags.Directory) > 0
540-
End Function
541-
542602
Public Function IsEmpty() As Boolean
543603
Return FileName(0) = CHAR_EMPTY
544604
End Function
545605

546-
Public Function IsHidden() As Boolean
547-
Return (Attributes And AttributeFlags.Hidden) > 0
548-
End Function
549-
550-
Public Function IsLFN() As Boolean
551-
Return (Attributes And AttributeFlags.LongFileName) = AttributeFlags.LongFileName
552-
End Function
553-
554606
Public Function IsLink() As Boolean
555607
Dim FilePart = _FileBytes.ToUInt16(_Offset)
556608
Return (FilePart = &H202E Or FilePart = &H2E2E)
@@ -561,20 +613,8 @@ Namespace DiskImage
561613
Return (FilePart = &H2E2E)
562614
End Function
563615

564-
Public Function IsReadOnly() As Boolean
565-
Return (Attributes And AttributeFlags.ReadOnly) > 0
566-
End Function
567-
568-
Public Function IsSystem() As Boolean
569-
Return (Attributes And AttributeFlags.System) > 0
570-
End Function
571-
572616
Public Function IsValidVolumeName() As Boolean
573-
Return IsVolumeName() AndAlso Not (IsHidden() OrElse IsSystem() OrElse IsDirectory() OrElse IsDeleted()) AndAlso StartingCluster = 0
574-
End Function
575-
576-
Public Function IsVolumeName() As Boolean
577-
Return (Attributes And AttributeFlags.VolumeName) > 0
617+
Return IsVolumeName AndAlso Not (IsHidden OrElse IsSystem OrElse IsDirectory OrElse IsDeleted()) AndAlso StartingCluster = 0
578618
End Function
579619

580620
Public Sub RemoveNTExtensions()

DiskImageTool/DiskImage/FATAllocation.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
If _FAT.TableLength > 0 Then
5656
If DirectoryEntry.IsDeleted() Then
5757
Cluster = 0
58-
ElseIf DirectoryEntry.IsDirectory() AndAlso DirectoryEntry.IsLink() Then
58+
ElseIf DirectoryEntry.IsDirectory AndAlso DirectoryEntry.IsLink() Then
5959
Cluster = 0
6060
Else
6161
Cluster = DirectoryEntry.StartingCluster

DiskImageTool/DiskImage/SubDirectory.vb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@
165165

166166
Entry = New DirectoryEntryBase With {
167167
.StartingCluster = ParentEntry.StartingCluster,
168-
.FileNameWithExtension = DirectoryEntryBase.CurrentDirectoryEntry
168+
.FileNameWithExtension = DirectoryEntryBase.CurrentDirectoryEntry,
169+
.IsDirectory = True
169170
}
170-
Entry.Attributes = MyBitConverter.ToggleBit(Entry.Attributes, DirectoryEntry.AttributeFlags.Directory, True)
171171
SetEntryDates(Entry)
172172
DirectoryEntries.Item(0).Data = Entry.Data
173173

@@ -178,9 +178,9 @@
178178

179179
Entry = New DirectoryEntryBase With {
180180
.StartingCluster = StartingCluster,
181-
.FileNameWithExtension = DirectoryEntryBase.ParentDirectoryEntry
181+
.FileNameWithExtension = DirectoryEntryBase.ParentDirectoryEntry,
182+
.IsDirectory = True
182183
}
183-
Entry.Attributes = MyBitConverter.ToggleBit(Entry.Attributes, DirectoryEntry.AttributeFlags.Directory, True)
184184
SetEntryDates(Entry)
185185
DirectoryEntries.Item(1).Data = Entry.Data
186186

DiskImageTool/DiskImage/Utility.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,8 +551,8 @@ Namespace DiskImage
551551

552552
Dim NewEntry = Data.DirectoryEntry.Clone
553553
NewEntry.SetFileName(Data.ShortFileName)
554-
NewEntry.ReservedForWinNT = MyBitConverter.ToggleBit(NewEntry.ReservedForWinNT, DirectoryEntry.NTFlags.LowerCaseFileName, Data.NTLowerCaseFileName)
555-
NewEntry.ReservedForWinNT = MyBitConverter.ToggleBit(NewEntry.ReservedForWinNT, DirectoryEntry.NTFlags.LowerCaseExtension, Data.NTLowerCaseExtension)
554+
NewEntry.HasNTLowerCaseFileName = Data.NTLowerCaseFileName
555+
NewEntry.HasNTLowerCaseExtension = Data.NTLowerCaseExtension
556556

557557
Data.DirectoryEntry.Data = NewEntry.Data
558558

0 commit comments

Comments
 (0)