Ejemplo n.º 1
0
        public DeviceElementValue(Guid parentObject, PhysicalVolumeInfo pvi)
        {
            _parentObject = parentObject;

            PartitionRecord record = new PartitionRecord();
            record.Type = 6;
            if (pvi.VolumeType == PhysicalVolumeType.BiosPartition)
            {
                record.PartitionType = 1;
                record.DiskIdentity = new byte[4];
                Utilities.WriteBytesLittleEndian(pvi.DiskSignature, record.DiskIdentity, 0);
                record.PartitionIdentity = new byte[8];
                Utilities.WriteBytesLittleEndian(pvi.PhysicalStartSector * 512, record.PartitionIdentity, 0);
            }
            else if (pvi.VolumeType == PhysicalVolumeType.GptPartition)
            {
                record.PartitionType = 0;
                record.DiskIdentity = new byte[16];
                Utilities.WriteBytesLittleEndian(pvi.DiskIdentity, record.DiskIdentity, 0);
                record.PartitionIdentity = new byte[16];
                Utilities.WriteBytesLittleEndian(pvi.PartitionIdentity, record.PartitionIdentity, 0);
            }
            else
            {
                throw new NotImplementedException(string.Format(CultureInfo.InvariantCulture, "Unknown how to convert volume type {0} to a Device element", pvi.VolumeType));
            }

            _record = record;
        }
Ejemplo n.º 2
0
        public DeviceElementValue(Guid parentObject, PhysicalVolumeInfo pvi)
        {
            _parentObject = parentObject;

            PartitionRecord record = new PartitionRecord();

            record.Type = 6;
            if (pvi.VolumeType == PhysicalVolumeType.BiosPartition)
            {
                record.PartitionType = 1;
                record.DiskIdentity  = new byte[4];
                Utilities.WriteBytesLittleEndian(pvi.DiskSignature, record.DiskIdentity, 0);
                record.PartitionIdentity = new byte[8];
                Utilities.WriteBytesLittleEndian(pvi.PhysicalStartSector * 512, record.PartitionIdentity, 0);
            }
            else if (pvi.VolumeType == PhysicalVolumeType.GptPartition)
            {
                record.PartitionType = 0;
                record.DiskIdentity  = new byte[16];
                Utilities.WriteBytesLittleEndian(pvi.DiskIdentity, record.DiskIdentity, 0);
                record.PartitionIdentity = new byte[16];
                Utilities.WriteBytesLittleEndian(pvi.PartitionIdentity, record.PartitionIdentity, 0);
            }
            else
            {
                throw new NotImplementedException(string.Format(CultureInfo.InvariantCulture, "Unknown how to convert volume type {0} to a Device element", pvi.VolumeType));
            }

            _record = record;
        }
Ejemplo n.º 3
0
        public static DeviceRecord Parse(byte[] data, int offset)
        {
            int type = Utilities.ToInt32LittleEndian(data, offset);
            int length = Utilities.ToInt32LittleEndian(data, offset + 0x8);
            if (offset + length > data.Length)
            {
                throw new InvalidDataException("Device record is truncated");
            }

            DeviceRecord newRecord = null;
            switch (type)
            {
                case 0:
                    newRecord = new DeviceAndPathRecord();
                    break;
                case 5: // Logical 'boot' device
                case 6: // Disk partition
                    newRecord = new PartitionRecord();
                    break;
                case 8: // custom:nnnnnn
                    break;
                default:
                    throw new NotImplementedException("Unknown device type: " + type);
            }

            if (newRecord != null)
            {
                newRecord.DoParse(data, offset);
            }

            return newRecord;
        }
Ejemplo n.º 4
0
        public DeviceElementValue()
        {
            _parentObject = Guid.Empty;

            PartitionRecord record = new PartitionRecord();
            record.Type = 5;
            _record = record;
        }
Ejemplo n.º 5
0
        public DeviceElementValue()
        {
            _parentObject = Guid.Empty;

            PartitionRecord record = new PartitionRecord();

            record.Type = 5;
            _record     = record;
        }
Ejemplo n.º 6
0
        public static DeviceRecord Parse(byte[] data, int offset)
        {
            int type   = Utilities.ToInt32LittleEndian(data, offset);
            int length = Utilities.ToInt32LittleEndian(data, offset + 0x8);

            if (offset + length > data.Length)
            {
                throw new InvalidDataException("Device record is truncated");
            }

            DeviceRecord newRecord = null;

            switch (type)
            {
            case 0:
                newRecord = new DeviceAndPathRecord();
                break;

            case 5:     // Logical 'boot' device
            case 6:     // Disk partition
                newRecord = new PartitionRecord();
                break;

            case 8:     // custom:nnnnnn
                break;

            default:
                throw new NotImplementedException("Unknown device type: " + type);
            }

            if (newRecord != null)
            {
                newRecord.DoParse(data, offset);
            }

            return(newRecord);
        }