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(); }
public NtfsPartition(PartitionInfo info) { _info = info; _drive = new DriveInfo(info.Letter.ToString()); info.FreeSpace = (int)(_drive.AvailableFreeSpace / 1024.0 / 1024.0); _currentDirectory = _drive.RootDirectory; }
/// <summary> /// Initializes a new instance of the <see cref="PartitionFactory"/> class. /// </summary> /// <param name="info"> /// The partition info. /// </param> public PartitionFactory(PartitionInfo info) { if (info.Letter == '?') { _partition = new Fat16Partition(info); } else { switch (info.FileSystem) { case FileSystemType.Fat16: _partition = new Fat16Partition(info); break; case FileSystemType.Fat32: _partition = new Fat32Partition(info); break; case FileSystemType.Ntfs: _partition = new NtfsPartition(info); break; case FileSystemType.Unknown: _partition = new Fat16Partition(info); break; default: _partition = new Fat16Partition(info); break; } } }
public Fat32Partition(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(bytesPerSector); fatCopiesNumber = fatInfo.AsWord(16); fatSize = fatInfo.AsWord(36); reservedAreaSize = fatInfo.AsWord(14); sectorsPerCluster = fatInfo.AsByte(13); fatAddress = reservedAreaSize; rootDirectoryCluster = fatInfo.AsInt32(44); 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 = rootDirectoryCluster }; directoryStack.Push(currentDirectory); LoadCurrentDirectoryObjects(); }
private IEnumerable <IPartition> GetHddPartitions(byte[] mbr, int additionalOffset = 0) { int partitonOffset = 0x1be; _extendedAreaAddress = 0; for (int i = 0; i < 4; i++, partitonOffset += 0x10) { var info = new PartitionInfo(); info.HddNumber = _number; info.Extended = additionalOffset != 0; int id = mbr.AsByte(partitonOffset + 4); if (id == 0) { break; } info.Active = mbr.AsByte(partitonOffset + 0) != 0; int startAddress = mbr.AsInt32(partitonOffset + 8); if ((id == 5) || (id == 15)) { _extendedAreaAddress = startAddress; continue; } int sizeInSectors = mbr.AsInt32(partitonOffset + 12); info.Size = sizeInSectors / 2048 * _sectorSize / 512; info.FreeSpace = -1; int absoluteAddress = startAddress + additionalOffset; info.SerialNumber = GetDiskSn(absoluteAddress, id); info.Letter = GetDiskLetter(info.SerialNumber); info.Address = absoluteAddress; if (info.Letter == '?') { // disks.Add(new UnknownDisk(info)); info.FileSystem = FileSystemType.Unknown; } switch (id) { case 0x01: case 0x04: case 0x06: case 0x0E: { // disks.Add(new Fat16Disk(info)); info.FileSystem = FileSystemType.Fat16; break; } case 0x07: case 0x17: { // disks.Add(new NtfsDisk(info)); info.FileSystem = FileSystemType.Ntfs; break; } case 0x0B: case 0x0C: case 0x1B: case 0x1C: case 0x8B: case 0x8C: { // disks.Add(new Fat32Disk(info)); info.FileSystem = FileSystemType.Fat32; break; } default: { // disks.Add(new UnknownDisk(info)); info.FileSystem = FileSystemType.Unknown; break; } } var partitionFactory = new PartitionFactory(info); yield return(partitionFactory.Partition); } yield break; }
public UnknownPartition(PartitionInfo info) { _info = info; }
private IEnumerable<IPartition> GetHddPartitions(byte[] mbr, int additionalOffset = 0) { int partitonOffset = 0x1be; _extendedAreaAddress = 0; for (int i = 0; i < 4; i++, partitonOffset += 0x10) { var info = new PartitionInfo(); info.HddNumber = _number; info.Extended = additionalOffset != 0; int id = mbr.AsByte(partitonOffset + 4); if (id == 0) { break; } info.Active = mbr.AsByte(partitonOffset + 0) != 0; int startAddress = mbr.AsInt32(partitonOffset + 8); if ((id == 5) || (id == 15)) { _extendedAreaAddress = startAddress; continue; } int sizeInSectors = mbr.AsInt32(partitonOffset + 12); info.Size = sizeInSectors / 2048 * _sectorSize / 512; info.FreeSpace = -1; int absoluteAddress = startAddress + additionalOffset; info.SerialNumber = GetDiskSn(absoluteAddress, id); info.Letter = GetDiskLetter(info.SerialNumber); info.Address = absoluteAddress; if (info.Letter == '?') { // disks.Add(new UnknownDisk(info)); info.FileSystem = FileSystemType.Unknown; } switch (id) { case 0x01: case 0x04: case 0x06: case 0x0E: { // disks.Add(new Fat16Disk(info)); info.FileSystem = FileSystemType.Fat16; break; } case 0x07: case 0x17: { // disks.Add(new NtfsDisk(info)); info.FileSystem = FileSystemType.Ntfs; break; } case 0x0B: case 0x0C: case 0x1B: case 0x1C: case 0x8B: case 0x8C: { // disks.Add(new Fat32Disk(info)); info.FileSystem = FileSystemType.Fat32; break; } default: { // disks.Add(new UnknownDisk(info)); info.FileSystem = FileSystemType.Unknown; break; } } var partitionFactory = new PartitionFactory(info); yield return partitionFactory.Partition; } yield break; }