public Fat16Partition(PartitionInfo info) { _info = base.info = info; diskFileName = String.Format("\\\\.\\{0}:", info.Letter); rootDirectoryName = String.Format("{0}:\\", info.Letter); bytesPerSector = GetBytesPerSector(); diskFile = new UnmanagedFile(diskFileName); byte[] fatInfo = diskFile.ReadFile((uint)bytesPerSector); fatCopiesNumber = fatInfo.AsWord(16); fatSize = fatInfo.AsWord(22); reservedAreaSize = fatInfo.AsWord(14); sectorsPerCluster = fatInfo.AsByte(13); fatAddress = reservedAreaSize; rootDirectoryEntities = fatInfo.AsWord(17); rootDirectorySector = reservedAreaSize + (fatCopiesNumber * fatSize); bitsPerSector = GetBitsNumber(bytesPerSector); bytesPerCluster = bytesPerSector * sectorsPerCluster; fatContentSize = (uint)(fatSize * bytesPerSector); fatContent = LoadFatContent(); info.FreeSpace = GetFreeDiskSpace(); currentDirectory = new FatDirectoryObject { Name = String.Empty, Type = DirectoryObjectType.Directory, Cluster = 0 }; directoryStack.Push(currentDirectory); LoadCurrentDirectoryObjects(); }
void Initialize() { int hddNumber = ...; int partitionAddress = ...; string hardDriveName = "\\\\.\\PHYSICALDRIVE" + hddNumber; diskFile = new UnmanagedFile(hardDriveName); bytesPerSector = GetBytesPerSector(); bitsPerSector = GetBitsNumber(bytesPerSector); diskFile.MovePointer(partitionAddress << bitsPerSector, partitionAddress >> (32 - bitsPerSector)); byte[] fatInfo = diskFile.ReadFile(bytesPerSector); fatCopiesNumber = fatInfo.AsWord(16); fatSize = fatInfo.AsWord(22); reservedAreaSize = fatInfo.AsWord(14); sectorsPerCluster = fatInfo.AsByte(13); fatAddress = reservedAreaSize; rootDirectoryEntities = fatInfo.AsWord(17); rootDirectorySector = reservedAreaSize + (fatCopiesNumber * fatSize); bytesPerCluster = bytesPerSector * sectorsPerCluster; fatContentSize = (uint)(fatSize * bytesPerSector); fatContent = LoadFatContent(); contents = LoadCurrentDirectoryObjects().ToList(); }
private byte[] ReadMbr() { int size = _sectorSize != 0 ? _sectorSize : 0x200; var buffer = _handle.ReadFile((uint)size); if (size != _sectorSize) { int i = size; int n = 0; while ((i = i / 2) != 0) { n++; } _bitsPerSector = n; _sectorSize = size; } return(buffer); }
byte[] LoadFatContent() { diskFile.MovePointer(fatAddress << bitsPerSector); return(diskFile.ReadFile(fatContentSize)); }