2016-07-28 18:13:49 +01:00
|
|
|
// /***************************************************************************
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Filesystem.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : DiscImageChef filesystem plugins.
|
|
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Skeleton and interface for filesystem plugins.
|
|
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// 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
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// 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.
|
|
|
|
|
//
|
|
|
|
|
// 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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-05-19 20:28:49 +01:00
|
|
|
// Copyright © 2011-2017 Natalia Portillo
|
2016-07-28 18:13:49 +01:00
|
|
|
// ****************************************************************************/
|
2014-04-17 19:58:14 +00:00
|
|
|
|
2011-03-03 18:34:33 +00:00
|
|
|
using System;
|
2016-07-21 16:15:39 +01:00
|
|
|
using System.Collections.Generic;
|
2017-06-06 21:23:20 +01:00
|
|
|
using System.Text;
|
2017-07-19 16:31:08 +01:00
|
|
|
using DiscImageChef.CommonTypes;
|
2011-03-03 18:34:33 +00:00
|
|
|
|
2016-07-21 16:15:39 +01:00
|
|
|
namespace DiscImageChef.Filesystems
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2014-06-07 05:57:17 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Abstract class to implement filesystem plugins.
|
|
|
|
|
/// </summary>
|
2016-07-21 16:15:39 +01:00
|
|
|
public abstract class Filesystem
|
2016-04-19 02:11:47 +01:00
|
|
|
{
|
2014-06-07 05:57:17 +01:00
|
|
|
/// <summary>Plugin name.</summary>
|
2011-03-03 18:34:33 +00:00
|
|
|
public string Name;
|
2014-06-07 05:57:17 +01:00
|
|
|
/// <summary>Plugin UUID.</summary>
|
2011-03-03 18:34:33 +00:00
|
|
|
public Guid PluginUUID;
|
2015-12-05 17:10:27 +00:00
|
|
|
internal Schemas.FileSystemType xmlFSType;
|
2017-06-06 21:23:20 +01:00
|
|
|
public Encoding CurrentEncoding;
|
2015-12-05 17:10:27 +00:00
|
|
|
|
2015-12-06 05:18:30 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Information about the filesystem as expected by CICM Metadata XML
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>Information about the filesystem as expected by CICM Metadata XML</value>
|
2015-12-05 17:10:27 +00:00
|
|
|
public Schemas.FileSystemType XmlFSType
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return xmlFSType;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-03 18:34:33 +00:00
|
|
|
|
2016-07-21 16:15:39 +01:00
|
|
|
protected Filesystem()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a filesystem instance prepared for reading contents
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="imagePlugin">Image plugin.</param>
|
2017-07-19 16:31:08 +01:00
|
|
|
/// <param name="partition">Partition.</param>
|
2017-06-06 21:23:20 +01:00
|
|
|
/// <param name="encoding">Which encoding to use for this filesystem.</param>
|
2017-07-19 16:31:08 +01:00
|
|
|
protected Filesystem(ImagePlugins.ImagePlugin imagePlugin, Partition partition, Encoding encoding)
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
|
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
|
2014-06-07 05:57:17 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Identifies the filesystem in the specified LBA
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="imagePlugin">Disk image.</param>
|
2017-07-19 16:31:08 +01:00
|
|
|
/// <param name="partition">Partition.</param>
|
2014-06-07 05:57:17 +01:00
|
|
|
/// <returns><c>true</c>, if the filesystem is recognized, <c>false</c> otherwise.</returns>
|
2017-07-19 16:31:08 +01:00
|
|
|
public abstract bool Identify(ImagePlugins.ImagePlugin imagePlugin, Partition partition);
|
2014-06-07 05:57:17 +01:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets information about the identified filesystem.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="imagePlugin">Disk image.</param>
|
2017-07-19 16:31:08 +01:00
|
|
|
/// <param name="partition">Partition.</param>
|
2014-06-07 05:57:17 +01:00
|
|
|
/// <param name="information">Filesystem information.</param>
|
2017-07-19 16:31:08 +01:00
|
|
|
public abstract void GetInformation(ImagePlugins.ImagePlugin imagePlugin, Partition partition, out string information);
|
2016-07-21 17:16:08 +01:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializates whatever internal structures the filesystem plugin needs to be able to read files and directories from the filesystem.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract Errno Mount();
|
|
|
|
|
|
2016-07-22 00:43:22 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Initializates whatever internal structures the filesystem plugin needs to be able to read files and directories from the filesystem.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract Errno Mount(bool debug);
|
|
|
|
|
|
2016-07-21 17:16:08 +01:00
|
|
|
/// <summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
/// Frees all internal structures created by <see cref="Mount()"/>
|
2016-07-21 17:16:08 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public abstract Errno Unmount();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Maps a filesystem block from a file to a block from the underlying device.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Error number.</returns>
|
|
|
|
|
/// <param name="path">File path.</param>
|
|
|
|
|
/// <param name="fileBlock">File block.</param>
|
|
|
|
|
/// <param name="deviceBlock">Device block.</param>
|
|
|
|
|
public abstract Errno MapBlock(string path, long fileBlock, ref long deviceBlock);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the attributes of a file or directory
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Error number.</returns>
|
|
|
|
|
/// <param name="path">File path.</param>
|
|
|
|
|
/// <param name="attributes">File attributes.</param>
|
|
|
|
|
public abstract Errno GetAttributes(string path, ref FileAttributes attributes);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Lists all extended attributes, alternate data streams and forks of the given file.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Error number.</returns>
|
|
|
|
|
/// <param name="path">Path.</param>
|
|
|
|
|
/// <param name="xattrs">List of extended attributes, alternate data streams and forks.</param>
|
|
|
|
|
public abstract Errno ListXAttr(string path, ref List<string> xattrs);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reads an extended attribute, alternate data stream or fork from the given file.
|
|
|
|
|
/// </summary>
|
2016-07-29 02:22:24 +01:00
|
|
|
/// <returns>Error number.</returns>
|
2016-07-21 17:16:08 +01:00
|
|
|
/// <param name="path">File path.</param>
|
|
|
|
|
/// <param name="xattr">Extendad attribute, alternate data stream or fork name.</param>
|
|
|
|
|
/// <param name="buf">Buffer.</param>
|
|
|
|
|
public abstract Errno GetXattr(string path, string xattr, ref byte[] buf);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reads data from a file (main/only data stream or data fork).
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="path">File path.</param>
|
|
|
|
|
/// <param name="offset">Offset.</param>
|
|
|
|
|
/// <param name="size">Bytes to read.</param>
|
|
|
|
|
/// <param name="buf">Buffer.</param>
|
|
|
|
|
public abstract Errno Read(string path, long offset, long size, ref byte[] buf);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Lists contents from a directory.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="path">Directory path.</param>
|
|
|
|
|
/// <param name="contents">Directory contents.</param>
|
|
|
|
|
public abstract Errno ReadDir(string path, ref List<string> contents);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets information about the mounted volume.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="stat">Information about the mounted volume.</param>
|
|
|
|
|
public abstract Errno StatFs(ref FileSystemInfo stat);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets information about a file or directory.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="path">File path.</param>
|
|
|
|
|
/// <param name="stat">File information.</param>
|
|
|
|
|
public abstract Errno Stat(string path, ref FileEntryInfo stat);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Solves a symbolic link.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="path">Link path.</param>
|
|
|
|
|
/// <param name="dest">Link destination.</param>
|
|
|
|
|
public abstract Errno ReadLink(string path, ref string dest);
|
2016-04-19 02:11:47 +01:00
|
|
|
}
|
2011-03-03 18:34:33 +00:00
|
|
|
}
|
|
|
|
|
|