Changeset 1239
- Timestamp:
- 9/30/2009 9:01:05 AM (4 years ago)
- Location:
- trunk/eraser6/Eraser.Util.FileSystem
- Files:
-
- 6 edited
-
Fat12Api.cpp (modified) (1 diff)
-
Fat12Or16Api.cpp (modified) (2 diffs)
-
Fat16Api.cpp (modified) (1 diff)
-
Fat32Api.cpp (modified) (2 diffs)
-
FatApi.cpp (modified) (5 diffs)
-
FatApi.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser6/Eraser.Util.FileSystem/Fat12Api.cpp
r1233 r1239 79 79 throw gcnew ArgumentException(L"Invalid FAT cluster: cluster is marked bad."); 80 80 else if (nextCluster >= 0xFF8) 81 return result * ClusterSize;81 return ClusterSizeToSize(result); 82 82 else 83 83 cluster = nextCluster; -
trunk/eraser6/Eraser.Util.FileSystem/Fat12Or16Api.cpp
r1238 r1239 66 66 long long Fat12Or16Api::ClusterToOffset(unsigned cluster) 67 67 { 68 unsigned long long sector = BootSector->ReservedSectorCount + //Reserved area 69 BootSector->FatCount * BootSector->SectorsPerFat + //FAT area 70 (BootSector->RootDirectoryEntryCount * sizeof(::FatDirectoryEntry) / SectorSize) + //Root directory area 71 (static_cast<unsigned long long>(cluster) - 2) * (ClusterSize / SectorSize); 68 unsigned long long sector = BootSector->ReservedSectorCount + //Reserved area 69 BootSector->FatCount * BootSector->SectorsPerFat + //FAT area 70 (BootSector->RootDirectoryEntryCount * sizeof(::FatDirectoryEntry) / //Root directory area 71 BootSector->BytesPerSector) + 72 (static_cast<unsigned long long>(cluster) - 2) * BootSector->SectorsPerCluster; 72 73 return SectorToOffset(sector); 73 74 } … … 111 112 BootSector->ReservedSectorCount + //Reserved area 112 113 BootSector->FatCount * BootSector->SectorsPerFat + //FAT area 113 (BootSector->RootDirectoryEntryCount * sizeof(::FatDirectoryEntry) / SectorSize) //Root directory area 114 (BootSector->RootDirectoryEntryCount * sizeof(::FatDirectoryEntry) / //Root directory area 115 BootSector->BytesPerSector) 114 116 ); 115 unsigned long long numberOfClusters = availableSectors / (ClusterSize / SectorSize);117 unsigned long long numberOfClusters = availableSectors / BootSector->SectorsPerCluster; 116 118 117 119 return numberOfClusters <= 0xFF0; -
trunk/eraser6/Eraser.Util.FileSystem/Fat16Api.cpp
r1227 r1239 78 78 throw gcnew ArgumentException(L"Invalid FAT cluster: cluster is marked bad."); 79 79 else if (fatPtr[cluster] >= 0xFFF8) 80 return result * ClusterSize;80 return ClusterSizeToSize(result); 81 81 else 82 82 cluster = fatPtr[cluster]; -
trunk/eraser6/Eraser.Util.FileSystem/Fat32Api.cpp
r1238 r1239 65 65 unsigned long long sector = BootSector->ReservedSectorCount + //Reserved area 66 66 BootSector->FatCount * BootSector->Fat32ParameterBlock.SectorsPerFat + //FAT area 67 (static_cast<unsigned long long>(cluster) - 2) * (ClusterSize / SectorSize);67 (static_cast<unsigned long long>(cluster) - 2) * BootSector->SectorsPerCluster; 68 68 return SectorToOffset(sector); 69 69 } … … 105 105 throw gcnew ArgumentException(L"Invalid FAT cluster: cluster is marked bad."); 106 106 else if (fatPtr[cluster] >= 0x0FFFFFF8) 107 return result * ClusterSize;107 return ClusterSizeToSize(result); 108 108 else 109 109 cluster = fatPtr[cluster]; -
trunk/eraser6/Eraser.Util.FileSystem/FatApi.cpp
r1238 r1239 33 33 FatApi::FatApi(VolumeInfo^ info) 34 34 { 35 SectorSize = info->SectorSize;36 ClusterSize = info->ClusterSize;37 38 35 BootSector = new FatBootSector(); 39 36 memset(BootSector, 0, sizeof(*BootSector)); … … 55 52 FatApi::FatApi(VolumeInfo^ info, Stream^ stream) 56 53 { 57 SectorSize = info->SectorSize;58 ClusterSize = info->ClusterSize;59 60 54 BootSector = new FatBootSector(); 61 55 memset(BootSector, 0, sizeof(*BootSector)); … … 89 83 unsigned long long FatApi::SectorToOffset(unsigned long long sector) 90 84 { 91 return sector * SectorSize;85 return sector * BootSector->BytesPerSector; 92 86 } 93 87 94 88 unsigned FatApi::SectorSizeToSize(unsigned size) 95 89 { 96 return size * SectorSize;90 return size * BootSector->BytesPerSector; 97 91 } 98 92 99 93 unsigned FatApi::ClusterSizeToSize(unsigned size) 100 94 { 101 return size * ClusterSize;95 return size * (BootSector->BytesPerSector * BootSector->SectorsPerCluster); 102 96 } 103 97 … … 109 103 std::vector<char> result; 110 104 result.reserve(FileSize(cluster)); 111 array<Byte>^ buffer = gcnew array<Byte>(ClusterSize );105 array<Byte>^ buffer = gcnew array<Byte>(ClusterSizeToSize(1)); 112 106 113 107 do 114 108 { 115 109 VolumeStream->Seek(ClusterToOffset(cluster), SeekOrigin::Begin); 116 VolumeStream->Read(buffer, 0, ClusterSize);117 118 result.insert(result.end(), ClusterSize, 0);119 Marshal::Copy(buffer, 0, static_cast<IntPtr>(&result.back() - ClusterSize+ 1),120 ClusterSize);110 VolumeStream->Read(buffer, 0, buffer->Length); 111 112 result.insert(result.end(), buffer->Length, 0); 113 Marshal::Copy(buffer, 0, static_cast<IntPtr>(&result.back() - buffer->Length + 1), 114 buffer->Length); 121 115 } 122 116 while ((cluster = GetNextCluster(cluster)) != 0xFFFFFFFF); … … 133 127 gcnew String(L"allocated file.")); 134 128 135 array<Byte>^ buffer = gcnew array<Byte>(ClusterSize); 136 for (size_t i = 0; i < length; i += ClusterSize) 129 size_t clusterSize = ClusterSizeToSize(1); 130 array<Byte>^ buffer = gcnew array<Byte>(clusterSize); 131 for (size_t i = 0; i < length; i += clusterSize) 137 132 { 138 133 Marshal::Copy(static_cast<IntPtr>(reinterpret_cast<intptr_t>(static_cast<const char*>(data) + i)), 139 buffer, 0, ClusterSize);134 buffer, 0, clusterSize); 140 135 VolumeStream->Seek(ClusterToOffset(cluster), SeekOrigin::Begin); 141 VolumeStream->Write(buffer, 0, ClusterSize);136 VolumeStream->Write(buffer, 0, clusterSize); 142 137 cluster = GetNextCluster(cluster); 143 138 } -
trunk/eraser6/Eraser.Util.FileSystem/FatApi.h
r1238 r1239 111 111 112 112 protected: 113 IO::Stream^ VolumeStream; 114 115 unsigned SectorSize; // Size of one sector, in bytes 116 unsigned ClusterSize; // Size of one cluster, in bytes 117 FatBootSector* BootSector; 118 char* Fat; 113 /// The stream used to access the volume. 114 property IO::Stream^ VolumeStream 115 { 116 IO::Stream^ get() { return volumeStream; } 117 private: 118 void set(IO::Stream^ value) { volumeStream = value; } 119 } 120 121 property FatBootSector* BootSector 122 { 123 FatBootSector* get() { return bootSector; } 124 private: 125 void set(FatBootSector* value) { bootSector = value; } 126 } 127 128 property char* Fat 129 { 130 char* get() { return fat; } 131 void set(char* value) { fat = value; } 132 } 133 134 private: 135 IO::Stream^ volumeStream; 136 FatBootSector* bootSector; 137 char* fat; 119 138 }; 120 139 … … 230 249 protected: 231 250 /// A pointer to the directory structure. 232 ::FatDirectory Directory; 251 property ::FatDirectory Directory 252 { 253 ::FatDirectory get() { return directory; } 254 void set(::FatDirectory value) { directory = value; } 255 } 233 256 234 257 /// The number of entries in the directory 235 size_t DirectorySize; 258 property size_t DirectorySize 259 { 260 size_t get() { return directorySize; } 261 void set(size_t value) { directorySize = value; } 262 } 236 263 237 264 private: 238 265 /// The list of parsed entries in the folder. 239 266 Collections::Generic::Dictionary<String^, FatDirectoryEntry^>^ Entries; 267 268 size_t directorySize; 269 ::FatDirectory directory; 240 270 }; 241 271
Note: See TracChangeset
for help on using the changeset viewer.
