Exemplo n.º 1
0
        internal static unsafe GenericPartition Create(IntPtr partitionHandle, byte *buffer, uint offset)
        {
            byte             partitionType   = buffer[offset + 4];
            bool             hiddenPartition = false;
            bool             activePartition = (0x80 == buffer[offset]);
            uint             startSector     = *((uint *)(buffer + offset + 8));
            uint             sectorsCount    = *((uint *)(buffer + offset + 12));
            GenericPartition result          = null;

            // See : https://en.wikipedia.org/wiki/Partition_type
            switch (partitionType)
            {
            case 0x00:
                // Empty entry.
                return(null);

            case 0x07:
                // TODO : Consider using a mapping that restrict viewing to the partition content.
                result = new NtfsPartition(partitionHandle, hiddenPartition, startSector, sectorsCount);
                break;

            case 0x17:
                // TODO : Should differentiate 0x17 & 0x27
                hiddenPartition = true;
                goto case 0x07;

            case 0x27:
                // See https://docs.microsoft.com/en-us/windows/deployment/mbr-to-gpt
                // See https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/configure-biosmbr-based-hard-drive-partitions
                // See https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/windows-and-gpt-faq
                hiddenPartition = true;
                goto case 0x07;

            default:
                Console.WriteLine("unsupported partition type 0x{0:X2}.", partitionType);
                return(null);
            }
            if (null != result)
            {
                result.Active = activePartition;
            }
            return(result);
        }