/// <inheritdoc />
 public int ReadFrom(byte[] buffer, int offset)
 {
     Label         = EndianUtilities.BytesToString(buffer, offset, 0x8);
     Sector        = EndianUtilities.ToUInt64LittleEndian(buffer, offset + 0x8);
     Crc           = EndianUtilities.ToUInt32LittleEndian(buffer, offset + 0x10);
     CalculatedCrc = PhysicalVolume.CalcCrc(buffer, offset + 0x14, PhysicalVolume.SECTOR_SIZE - 0x14);
     Offset        = EndianUtilities.ToUInt32LittleEndian(buffer, offset + 0x14);
     Label2        = EndianUtilities.BytesToString(buffer, offset + 0x18, 0x8);
     return(Size);
 }
        /// <summary>
        /// Determines if a physical volume contains LVM data.
        /// </summary>
        /// <param name="volumeInfo">The volume to inspect.</param>
        /// <returns><c>true</c> if the physical volume contains LVM data, else <c>false</c>.</returns>
        public static bool HandlesPhysicalVolume(PhysicalVolumeInfo volumeInfo)
        {
            var partition = volumeInfo.Partition;

            if (partition == null)
            {
                return(false);
            }
            return(partition.BiosType == BiosPartitionTypes.LinuxLvm ||
                   partition.GuidType == GuidPartitionTypes.LinuxLvm ||
                   PhysicalVolume.CanOpen(partition));
        }
Example #3
0
        public static bool TryOpen(Stream content, out PhysicalVolume pv)
        {
            PhysicalVolumeLabel label;

            pv = null;
            if (!SearchLabel(content, out label))
            {
                return(false);
            }
            pv = new PhysicalVolume(label, content);

            return(true);
        }
        /// <inheritdoc />
        public int ReadFrom(byte[] buffer, int offset)
        {
            Crc           = Utilities.ToUInt32LittleEndian(buffer, offset);
            CalculatedCrc = PhysicalVolume.CalcCrc(buffer, offset + 0x4, PhysicalVolume.SECTOR_SIZE - 0x4);
            Magic         = Utilities.BytesToString(buffer, offset + 0x4, 0x10);
            Version       = Utilities.ToUInt32LittleEndian(buffer, offset + 0x14);
            Start         = Utilities.ToUInt64LittleEndian(buffer, offset + 0x18);
            Length        = Utilities.ToUInt64LittleEndian(buffer, offset + 0x20);

            var locations      = new List <RawLocation>();
            var locationOffset = offset + 0x28;

            while (true)
            {
                var location = new RawLocation();
                locationOffset += location.ReadFrom(buffer, locationOffset);
                if (location.Offset == 0 && location.Length == 0 && location.Checksum == 0 && location.Flags == 0)
                {
                    break;
                }
                locations.Add(location);
            }
            RawLocations = locations.ToArray();
            foreach (var location in RawLocations)
            {
                if ((location.Flags & RawLocationFlags.Ignored) != 0)
                {
                    continue;
                }
                var checksum = PhysicalVolume.CalcCrc(buffer, (int)location.Offset, (int)location.Length);
                if (location.Checksum != checksum)
                {
                    throw new IOException("invalid metadata checksum");
                }
                Metadata       = Utilities.BytesToString(buffer, (int)location.Offset, (int)location.Length);
                ParsedMetadata = Lvm.Metadata.Parse(Metadata);
                break;
            }
            return(Size);
        }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the LogicalVolumeManager class.
 /// </summary>
 /// <param name="disks">The initial set of disks to manage.</param>
 public LogicalVolumeManager(IEnumerable <VirtualDisk> disks)
 {
     _devices      = new List <PhysicalVolume>();
     _volumeGroups = new List <MetadataVolumeGroupSection>();
     foreach (var disk in disks)
     {
         if (disk.IsPartitioned)
         {
             foreach (var partition in disk.Partitions.Partitions)
             {
                 PhysicalVolume pv;
                 if (PhysicalVolume.TryOpen(partition, out pv))
                 {
                     _devices.Add(pv);
                 }
             }
         }
         else
         {
             PhysicalVolume pv;
             if (PhysicalVolume.TryOpen(disk.Content, out pv))
             {
                 _devices.Add(pv);
             }
         }
     }
     foreach (var device in _devices)
     {
         foreach (var vg in device.VgMetadata.ParsedMetadata.VolumeGroupSections)
         {
             if (!_volumeGroups.Exists(x => x.Id == vg.Id))
             {
                 _volumeGroups.Add(vg);
             }
         }
     }
 }
Example #6
0
        public static bool TryOpen(PartitionInfo volumeInfo, out PhysicalVolume pv)
        {
            var content = volumeInfo.Open();

            return(TryOpen(content, out pv));
        }