예제 #1
0
        public PhysicalVolume(PhysicalVolumeLabel physicalVolumeLabel, Stream content)
        {
            PhysicalVolumeLabel = physicalVolumeLabel;
            PvHeader            = new PvHeader();
            content.Position    = (long)(physicalVolumeLabel.Sector * SECTOR_SIZE);
            var buffer = Utilities.ReadFully(content, SECTOR_SIZE);

            PvHeader.ReadFrom(buffer, (int)physicalVolumeLabel.Offset);
            if (PvHeader.MetadataDiskAreas.Length > 0)
            {
                var area     = PvHeader.MetadataDiskAreas[0];
                var metadata = new VolumeGroupMetadata();
                content.Position = (long)area.Offset;
                buffer           = Utilities.ReadFully(content, (int)area.Length);
                metadata.ReadFrom(buffer, 0x0);
                VgMetadata = metadata;
            }

            Content = content;
        }
예제 #2
0
        private static bool SearchLabel(Stream content, out PhysicalVolumeLabel pvLabel)
        {
            pvLabel          = null;
            content.Position = 0;
            byte[] buffer = new byte[SECTOR_SIZE];
            for (uint i = 0; i < 4; i++)
            {
                if (StreamUtilities.ReadMaximum(content, buffer, 0, SECTOR_SIZE) != SECTOR_SIZE)
                {
                    return(false);
                }

                var label = EndianUtilities.BytesToString(buffer, 0x0, 0x8);
                if (label == PhysicalVolumeLabel.LABEL_ID)
                {
                    pvLabel = new PhysicalVolumeLabel();
                    pvLabel.ReadFrom(buffer, 0x0);
                    if (pvLabel.Sector != i)
                    {
                        //Invalid PV Sector;
                        return(false);
                    }
                    if (pvLabel.Crc != pvLabel.CalculatedCrc)
                    {
                        //Invalid PV CRC
                        return(false);
                    }
                    if (pvLabel.Label2 != PhysicalVolumeLabel.LVM2_LABEL)
                    {
                        //Invalid LVM2 Label
                        return(false);
                    }
                    return(true);
                }
            }
            return(false);
        }