//
// 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.Collections.Generic;
using DiscUtils.Streams;
namespace DiscUtils
{
///
/// Represents the base layer, or a differencing layer of a VirtualDisk.
///
///
/// VirtualDisks are composed of one or more layers - a base layer
/// which represents the entire disk (even if not all bytes are actually stored),
/// and a number of differencing layers that store the disk sectors that are
/// logically different to the base layer.
/// Disk Layers may not store all sectors. Any sectors that are not stored
/// are logically zero's (for base layers), or holes through to the layer underneath
/// (all other layers).
///
public abstract class VirtualDiskLayer : IDisposable
{
///
/// Gets the capacity of the disk (in bytes).
///
internal abstract long Capacity { get; }
///
/// Gets and sets the logical extents that make up this layer.
///
public virtual IList Extents
{
get { return new List(); }
}
///
/// Gets the full path to this disk layer, or empty string.
///
public virtual string FullPath
{
get { return string.Empty; }
}
///
/// Gets the geometry of the virtual disk layer.
///
public abstract Geometry Geometry { get; }
///
/// Gets a value indicating whether the layer only stores meaningful sectors.
///
public abstract bool IsSparse { get; }
///
/// Gets a value indicating whether this is a differential disk.
///
public abstract bool NeedsParent { get; }
///
/// Gets a FileLocator that can resolve relative paths, or null.
///
///
/// Typically used to locate parent disks.
///
internal abstract FileLocator RelativeFileLocator { get; }
///
/// Disposes of this instance, freeing underlying resources.
///
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
///
/// Finalizes an instance of the VirtualDiskLayer class.
///
~VirtualDiskLayer()
{
Dispose(false);
}
///
/// Gets the content of this layer.
///
/// The parent stream (if any).
/// Controls ownership of the parent stream.
/// The content as a stream.
public abstract SparseStream OpenContent(SparseStream parent, Ownership ownsParent);
///
/// Gets the possible locations of the parent file (if any).
///
/// Array of strings, empty if no parent.
public abstract string[] GetParentLocations();
///
/// Disposes of underlying resources.
///
/// true if running inside Dispose(), indicating
/// graceful cleanup of all managed objects should be performed, or false
/// if running inside destructor.
protected virtual void Dispose(bool disposing) {}
}
}