|
8 | 8 | _FatChain = FatChain |
9 | 9 | End Sub |
10 | 10 |
|
11 | | - Private Function GetDataRoot() As DataBlock |
12 | | - Dim Result As DataBlock |
| 11 | + Private Function GetDataRoot() As List(Of DataBlock) |
| 12 | + Dim Result As New List(Of DataBlock) |
13 | 13 |
|
14 | | - Result.Offset = _Parent.BootSector.RootDirectoryRegionStart * _Parent.BootSector.BytesPerSector |
15 | | - Dim OffsetEnd As UInteger = _Parent.BootSector.DataRegionStart * _Parent.BootSector.BytesPerSector |
| 14 | + Dim SectorStart = _Parent.BootSector.RootDirectoryRegionStart |
| 15 | + Dim SectorEnd = _Parent.BootSector.DataRegionStart |
16 | 16 |
|
17 | | - Result.Data = _Parent.GetBytes(Result.Offset, OffsetEnd - Result.Offset) |
| 17 | + For Sector = SectorStart To SectorEnd - 1 |
| 18 | + Dim Block As DataBlock |
| 19 | + With Block |
| 20 | + .Cluster = 0 |
| 21 | + .Sector = Sector |
| 22 | + .Offset = _Parent.SectorToOffset(Sector) |
| 23 | + .Data = _Parent.GetBytes(.Offset, _Parent.BootSector.BytesPerSector) |
| 24 | + End With |
| 25 | + Result.Add(Block) |
| 26 | + Next |
18 | 27 |
|
19 | 28 | Return Result |
20 | 29 | End Function |
|
23 | 32 | Dim Result As New List(Of DataBlock) |
24 | 33 |
|
25 | 34 | For Each Cluster In _FatChain |
26 | | - Dim Block As DataBlock |
27 | | - |
28 | | - Block.Offset = _Parent.BootSector.DataRegionStart + ((Cluster - 2) * _Parent.BootSector.SectorsPerCluster) |
29 | | - Block.Offset *= _Parent.BootSector.BytesPerSector |
30 | | - |
31 | | - Dim Length As UInteger = _Parent.BootSector.SectorsPerCluster * _Parent.BootSector.BytesPerSector |
32 | | - |
33 | | - Block.Data = _Parent.GetBytes(Block.Offset, Length) |
34 | | - Result.Add(Block) |
| 35 | + Dim Sector = _Parent.ClusterToSector(Cluster) |
| 36 | + For Counter = 0 To _Parent.BootSector.SectorsPerCluster - 1 |
| 37 | + Dim Block As DataBlock |
| 38 | + With Block |
| 39 | + .Cluster = Cluster |
| 40 | + .Sector = Sector + Counter |
| 41 | + .Offset = _Parent.SectorToOffset(Sector + Counter) |
| 42 | + .Data = _Parent.GetBytes(.Offset, _Parent.BootSector.BytesPerSector) |
| 43 | + End With |
| 44 | + Result.Add(Block) |
| 45 | + Next |
35 | 46 | Next |
36 | 47 |
|
37 | 48 | Return Result |
|
41 | 52 | Dim Count As UInteger = 0 |
42 | 53 |
|
43 | 54 | For Each Cluster In _FatChain |
44 | | - Dim OffsetStart As UInteger = _Parent.BootSector.DataRegionStart + ((Cluster - 2) * _Parent.BootSector.SectorsPerCluster) |
45 | | - Dim OffsetEnd As UInteger = OffsetStart + _Parent.BootSector.SectorsPerCluster |
| 55 | + Dim OffsetStart As UInteger = _Parent.ClusterToOffset(Cluster) |
| 56 | + Dim OffsetLength As UInteger = _Parent.BootSector.BytesPerCluster |
46 | 57 |
|
47 | | - OffsetStart *= _Parent.BootSector.BytesPerSector |
48 | | - OffsetEnd *= _Parent.BootSector.BytesPerSector |
49 | 58 |
|
50 | | - Count += _Parent.GetDirectoryLength(OffsetStart, OffsetEnd, FileCountOnly) |
| 59 | + Count += _Parent.GetDirectoryLength(OffsetStart, OffsetStart + OffsetLength, FileCountOnly) |
51 | 60 | Next |
52 | 61 |
|
53 | 62 | Return Count |
54 | 63 | End Function |
55 | 64 |
|
56 | 65 | Private Function GetDirectoryLengthRoot(FileCountOnly As Boolean) As UInteger |
57 | | - Dim OffsetStart As UInteger = _Parent.BootSector.RootDirectoryRegionStart * _Parent.BootSector.BytesPerSector |
58 | | - Dim OffsetEnd As UInteger = _Parent.BootSector.DataRegionStart * _Parent.BootSector.BytesPerSector |
| 66 | + Dim OffsetStart As UInteger = _Parent.SectorToOffset(_Parent.BootSector.RootDirectoryRegionStart) |
| 67 | + Dim OffsetEnd As UInteger = _Parent.SectorToOffset(_Parent.BootSector.DataRegionStart) |
59 | 68 |
|
60 | 69 | Return _Parent.GetDirectoryLength(OffsetStart, OffsetEnd, FileCountOnly) |
61 | 70 | End Function |
62 | 71 |
|
63 | 72 | Private Function GetFileSubDirectory(Index As UInteger) As DiskImage.DirectoryEntry |
64 | | - Dim EntriesPerCluster As UInteger = _Parent.BootSector.BytesPerSector * _Parent.BootSector.SectorsPerCluster / 32 |
| 73 | + Dim EntriesPerCluster As UInteger = _Parent.BootSector.BytesPerCluster / 32 |
65 | 74 | Dim ChainIndex As UInteger = (Index - 1) \ EntriesPerCluster |
66 | 75 | Dim ClusterIndex As UInteger = (Index - 1) Mod EntriesPerCluster |
67 | | - Dim Offset As UInteger = _Parent.BootSector.DataRegionStart + ((_FatChain.Item(ChainIndex) - 2) * _Parent.BootSector.SectorsPerCluster) |
68 | | - Offset *= _Parent.BootSector.BytesPerSector |
69 | | - Offset += ClusterIndex * 32 |
| 76 | + Dim Offset As UInteger = _Parent.ClusterToOffset(_FatChain.Item(ChainIndex)) + ClusterIndex * 32 |
70 | 77 |
|
71 | 78 | Return New DiskImage.DirectoryEntry(_Parent, Offset) |
72 | 79 | End Function |
73 | 80 |
|
74 | 81 | Private Function GetFileRoot(Index As Integer) As DiskImage.DirectoryEntry |
75 | | - Dim Offset As UInteger = _Parent.BootSector.RootDirectoryRegionStart * _Parent.BootSector.BytesPerSector |
76 | | - Offset += (Index - 1) * 32 |
| 82 | + Dim Offset As UInteger = _Parent.SectorToOffset(_Parent.BootSector.RootDirectoryRegionStart) + (Index - 1) * 32 |
77 | 83 |
|
78 | 84 | Return New DiskImage.DirectoryEntry(_Parent, Offset) |
79 | 85 | End Function |
|
104 | 110 |
|
105 | 111 | Public Function GetData() As List(Of DataBlock) |
106 | 112 | If _FatChain Is Nothing Then |
107 | | - Return New List(Of DataBlock) From { |
108 | | - GetDataRoot() |
109 | | - } |
| 113 | + Return GetDataRoot() |
110 | 114 | Else |
111 | 115 | Return GetDataSubDirectory() |
112 | 116 | End If |
|
0 commit comments