2017-05-19 20:28:49 +01:00
// /***************************************************************************
2015-10-12 06:39:31 +01:00
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : Partition.cs
2016-07-28 18:13:49 +01:00
// Author(s) : Natalia Portillo <claunia@claunia.com>
2015-10-12 06:39:31 +01:00
//
2016-07-28 18:13:49 +01:00
// Component : DiscImageChef common types.
2015-10-12 06:39:31 +01:00
//
// --[ Description ] ----------------------------------------------------------
//
2016-07-28 18:13:49 +01:00
// Contains common partition types.
2015-10-12 06:39:31 +01:00
//
// --[ License ] --------------------------------------------------------------
//
2016-07-28 18:13:49 +01:00
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
2015-10-12 06:39:31 +01:00
// License, or (at your option) any later version.
//
2016-07-28 18:13:49 +01:00
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
2015-10-12 06:39:31 +01:00
//
2016-07-28 18:13:49 +01:00
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
2015-10-12 06:39:31 +01:00
//
// ----------------------------------------------------------------------------
2017-12-19 03:50:57 +00:00
// Copyright © 2011-2018 Natalia Portillo
2015-10-12 06:39:31 +01:00
// ****************************************************************************/
2017-07-25 22:27:09 +01:00
using System ;
2015-10-05 19:45:07 +01:00
namespace DiscImageChef.CommonTypes
{
/// <summary>
/// Partition structure.
/// </summary>
2017-07-25 22:27:09 +01:00
public struct Partition : IEquatable < Partition > , IComparable < Partition >
2015-10-05 19:45:07 +01:00
{
/// <summary>Partition number, 0-started</summary>
2017-07-19 16:37:11 +01:00
public ulong Sequence ;
2015-10-05 19:45:07 +01:00
/// <summary>Partition type</summary>
2017-07-19 16:37:11 +01:00
public string Type ;
2015-10-05 19:45:07 +01:00
/// <summary>Partition name (if the scheme supports it)</summary>
2017-07-19 16:37:11 +01:00
public string Name ;
2015-10-05 19:45:07 +01:00
/// <summary>Start of the partition, in bytes</summary>
2017-07-19 16:37:11 +01:00
public ulong Offset ;
2015-10-05 19:45:07 +01:00
/// <summary>LBA of partition start</summary>
2017-07-19 16:37:11 +01:00
public ulong Start ;
2015-10-05 19:45:07 +01:00
/// <summary>Length in bytes of the partition</summary>
2017-07-19 16:37:11 +01:00
public ulong Size ;
2015-10-05 19:45:07 +01:00
/// <summary>Length in sectors of the partition</summary>
2017-07-19 16:37:11 +01:00
public ulong Length ;
2015-10-05 19:45:07 +01:00
/// <summary>Information that does not find space in this struct</summary>
2017-07-19 16:37:11 +01:00
public string Description ;
2017-07-19 16:31:08 +01:00
/// <summary>LBA of last partition sector</summary>
2017-12-23 01:46:08 +00:00
public ulong End = > Start + Length - 1 ;
2017-07-23 22:54:36 +01:00
/// <summary>Name of partition scheme that contains this partition</summary>
public string Scheme ;
2017-07-25 22:27:09 +01:00
2017-12-23 01:46:08 +00:00
/// <summary>
/// Compares two partitions
/// </summary>
/// <param name="other">Partition to compare with</param>
/// <returns>0 if both partitions start and end at the same sector</returns>
2017-07-25 22:27:09 +01:00
public bool Equals ( Partition other )
{
return Start = = other . Start & & Length = = other . Length ;
}
2017-12-21 02:42:18 +00:00
public override bool Equals ( object obj )
2017-07-25 22:27:09 +01:00
{
2017-12-21 20:32:50 +00:00
if ( ! ( obj is Partition ) ) return false ;
2017-12-21 02:57:32 +00:00
return Equals ( ( Partition ) obj ) ;
2017-07-25 22:27:09 +01:00
}
public override int GetHashCode ( )
{
return Start . GetHashCode ( ) + End . GetHashCode ( ) ;
}
2017-12-23 01:46:08 +00:00
/// <summary>
/// Compares this partition with another and returns an integer that indicates whether the current partition precedes, follows, or is in the same place as the other partition.
/// </summary>
/// <param name="other">Partition to compare with</param>
/// <returns>A value that indicates the relative equality of the partitions being compared.</returns>
2017-07-25 22:27:09 +01:00
public int CompareTo ( Partition other )
{
2017-12-19 20:33:03 +00:00
if ( Start = = other . Start & & End = = other . End ) return 0 ;
2017-07-25 22:27:09 +01:00
2017-12-19 20:33:03 +00:00
if ( Start > other . Start | | End > other . End ) return 1 ;
2017-07-25 22:27:09 +01:00
return - 1 ;
}
// Define the equality operator.
public static bool operator = = ( Partition operand1 , Partition operand2 )
{
return operand1 . Equals ( operand2 ) ;
}
// Define the inequality operator.
public static bool operator ! = ( Partition operand1 , Partition operand2 )
{
return ! operand1 . Equals ( operand2 ) ;
}
// Define the is greater than operator.
public static bool operator > ( Partition operand1 , Partition operand2 )
{
return operand1 . CompareTo ( operand2 ) = = 1 ;
}
// Define the is less than operator.
public static bool operator < ( Partition operand1 , Partition operand2 )
{
return operand1 . CompareTo ( operand2 ) = = - 1 ;
}
// Define the is greater than or equal to operator.
public static bool operator > = ( Partition operand1 , Partition operand2 )
{
return operand1 . CompareTo ( operand2 ) > = 0 ;
}
// Define the is less than or equal to operator.
public static bool operator < = ( Partition operand1 , Partition operand2 )
{
return operand1 . CompareTo ( operand2 ) < = 0 ;
}
2015-10-05 19:45:07 +01:00
}
2017-12-19 20:33:03 +00:00
}