// // 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. // namespace DiscUtils { /// /// Class whose instances represent a CHS (Cylinder, Head, Sector) address on a disk. /// /// Instances of this class are immutable. public sealed class ChsAddress { /// /// The address of the first sector on any disk. /// public static readonly ChsAddress First = new ChsAddress(0, 0, 1); /// /// Initializes a new instance of the ChsAddress class. /// /// The number of cylinders of the disk. /// The number of heads (aka platters) of the disk. /// The number of sectors per track/cylinder of the disk. public ChsAddress(int cylinder, int head, int sector) { Cylinder = cylinder; Head = head; Sector = sector; } /// /// Gets the cylinder number (zero-based). /// public int Cylinder { get; } /// /// Gets the head (zero-based). /// public int Head { get; } /// /// Gets the sector number (one-based). /// public int Sector { get; } /// /// Determines if this object is equivalent to another. /// /// The object to test against. /// true if the is equivalent, else false. public override bool Equals(object obj) { if (obj == null || obj.GetType() != GetType()) { return false; } ChsAddress other = (ChsAddress)obj; return Cylinder == other.Cylinder && Head == other.Head && Sector == other.Sector; } /// /// Calculates the hash code for this object. /// /// The hash code. public override int GetHashCode() { return Cylinder.GetHashCode() ^ Head.GetHashCode() ^ Sector.GetHashCode(); } /// /// Gets a string representation of this object, in the form (C/H/S). /// /// The string representation. public override string ToString() { return "(" + Cylinder + "/" + Head + "/" + Sector + ")"; } } }