// // Copyright (c) 2008-2011, Kenneth Bell // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // using System; using System.Globalization; using DiscUtils.Streams; namespace DiscUtils.Partitions { /// /// Base class representing a disk partition. /// /// The purpose of this class is to provide a minimal view of a partition, /// such that callers can access existing partitions without specific knowledge of /// the partitioning system. public abstract class PartitionInfo { /// /// Gets the type of the partition, in legacy BIOS form, when available. /// /// Zero for GUID-style partitions. public abstract byte BiosType { get; } /// /// Gets the first sector of the partion (relative to start of disk) as a Logical Block Address. /// public abstract long FirstSector { get; } /// /// Gets the type of the partition, as a GUID, when available. /// /// .Empty for MBR-style partitions. public abstract Guid GuidType { get; } /// /// Gets the last sector of the partion (relative to start of disk) as a Logical Block Address (inclusive). /// public abstract long LastSector { get; } /// /// Gets the length of the partition in sectors. /// public virtual long SectorCount { get { return 1 + LastSector - FirstSector; } } /// /// Gets the partition type as a 'friendly' string. /// public abstract string TypeAsString { get; } /// /// Gets the physical volume type for this type of partition. /// internal abstract PhysicalVolumeType VolumeType { get; } /// /// Opens a stream that accesses the partition's contents. /// /// The new stream. public abstract SparseStream Open(); /// /// Gets a summary of the partition information as 'first - last (type)'. /// /// A string representation of the partition information. public override string ToString() { return string.Format(CultureInfo.InvariantCulture, "0x{0:X} - 0x{1:X} ({2})", FirstSector, LastSector, TypeAsString); } } }