Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        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;
        }