/// <summary> /// Reads the volume descriptors for /// </summary> /// <param name="extentVds">The anchor volume extent information.</param> /// <returns>Returns true if the volume descriptors were read from the image successfully.</returns> private bool ReadVolumeDescriptors(UdfFileExtent extentVds) { byte[] buffer = new byte[SectorSize]; long location = extentVds.Position; while (location < extentVds.Length && location < this.imageSize) { this.stream.Seek(location << SectorSizeLog, (int)SeekOrigin.Begin, IntPtr.Zero); if (!this.stream.ReadSafe(buffer, buffer.Length)) { return false; } VolumeTag tag = new VolumeTag(); tag.Parse(0, buffer, buffer.Length); switch ((VolumeDescriptorType)tag.Identifier) { case VolumeDescriptorType.Terminating: // Found terminating descriptor. Image is valid. return true; case VolumeDescriptorType.Partition: if (this.Partitions.Count >= MaxPartitions) { return false; } this.ReadPartitionDescriptor(buffer); break; case VolumeDescriptorType.LogicalVolume: if (this.LogicalVolumes.Count >= MaxLogicalVolumes || !this.ReadLogicalDescriptor(buffer)) { return false; } break; } location++; } // Did not find the terminating descriptor. Not a valid image. return false; }
/// <summary> /// Reads the Anchor Volume pointer from the image. /// </summary> /// <returns>Returns true if the pointer was found.</returns> private UdfFileExtent ReadAnchorVolumePointer() { UdfFileExtent result = null; byte[] buffer = new byte[SectorSize]; this.stream.Seek(-buffer.Length, (int)SeekOrigin.End, IntPtr.Zero); if (!this.stream.ReadSafe(buffer, buffer.Length)) { return result; } VolumeTag tag = new VolumeTag(); if (tag.Parse(0, buffer, buffer.Length) && tag.Identifier == (short)VolumeDescriptorType.AnchorVolumePtr) { result = new UdfFileExtent(); result.Parse(16, buffer); } return result; }