2017-08-07 16:06:51 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : Fossil.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Fossil filesystem plugin
|
2017-08-07 16:06:51 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-08-07 16:15:57 +01:00
|
|
|
|
// Identifies the Fossil filesystem and shows information.
|
2017-08-07 16:06:51 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ 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-12-19 03:50:57 +00:00
|
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2017-08-07 16:06:51 +01:00
|
|
|
|
// ****************************************************************************/
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2017-08-07 16:06:51 +01:00
|
|
|
|
using System;
|
2017-08-07 16:15:57 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using DiscImageChef.CommonTypes;
|
|
|
|
|
|
using DiscImageChef.Console;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using DiscImageChef.DiscImages;
|
|
|
|
|
|
using Schemas;
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2017-08-07 16:06:51 +01:00
|
|
|
|
namespace DiscImageChef.Filesystems
|
|
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public class Fossil : IFilesystem
|
2017-08-07 16:06:51 +01:00
|
|
|
|
{
|
2017-12-22 08:43:22 +00:00
|
|
|
|
const uint FOSSIL_HDR_MAGIC = 0x3776AE89;
|
|
|
|
|
|
const uint FOSSIL_SB_MAGIC = 0x2340A3B1;
|
2017-08-07 16:15:57 +01:00
|
|
|
|
// Fossil header starts at 128KiB
|
2017-12-22 08:43:22 +00:00
|
|
|
|
const ulong HEADER_POS = 128 * 1024;
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
Encoding currentEncoding;
|
|
|
|
|
|
FileSystemType xmlFsType;
|
|
|
|
|
|
public virtual FileSystemType XmlFsType => xmlFsType;
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public virtual Encoding Encoding => currentEncoding;
|
|
|
|
|
|
public virtual string Name => "Fossil Filesystem Plugin";
|
|
|
|
|
|
public virtual Guid Id => new Guid("932BF104-43F6-494F-973C-45EF58A51DA9");
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public virtual bool Identify(IMediaImage imagePlugin, Partition partition)
|
2017-08-07 16:15:57 +01:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
ulong hdrSector = HEADER_POS / imagePlugin.Info.SectorSize;
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2017-12-21 16:07:20 +00:00
|
|
|
|
FossilHeader hdr;
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(partition.Start + hdrSector > imagePlugin.Info.Sectors) return false;
|
2017-09-28 15:44:36 +01:00
|
|
|
|
|
2017-08-07 16:15:57 +01:00
|
|
|
|
byte[] sector = imagePlugin.ReadSector(partition.Start + hdrSector);
|
|
|
|
|
|
hdr = BigEndianMarshal.ByteArrayToStructureBigEndian<FossilHeader>(sector);
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Fossil plugin", "magic at 0x{0:X8} (expected 0x{1:X8})", hdr.magic,
|
2017-12-22 08:43:22 +00:00
|
|
|
|
FOSSIL_HDR_MAGIC);
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
return hdr.magic == FOSSIL_HDR_MAGIC;
|
2017-08-07 16:15:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public virtual void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding)
|
2017-08-07 16:15:57 +01:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
// Technically everything on Plan 9 from Bell Labs is in UTF-8
|
|
|
|
|
|
currentEncoding = Encoding.UTF8;
|
2017-08-07 16:15:57 +01:00
|
|
|
|
information = "";
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize < 512) return;
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
ulong hdrSector = HEADER_POS / imagePlugin.Info.SectorSize;
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2017-12-21 16:07:20 +00:00
|
|
|
|
FossilHeader hdr;
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
|
|
|
|
|
byte[] sector = imagePlugin.ReadSector(partition.Start + hdrSector);
|
|
|
|
|
|
hdr = BigEndianMarshal.ByteArrayToStructureBigEndian<FossilHeader>(sector);
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Fossil plugin", "magic at 0x{0:X8} (expected 0x{1:X8})", hdr.magic,
|
2017-12-22 08:43:22 +00:00
|
|
|
|
FOSSIL_HDR_MAGIC);
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
|
|
sb.AppendLine("Fossil");
|
|
|
|
|
|
sb.AppendFormat("Filesystem version {0}", hdr.version).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("{0} bytes per block", hdr.blockSize).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Superblock resides in block {0}", hdr.super).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Labels resides in block {0}", hdr.label).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Data starts at block {0}", hdr.data).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Volume has {0} blocks", hdr.end).AppendLine();
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
ulong sbLocation = hdr.super * (hdr.blockSize / imagePlugin.Info.SectorSize) + partition.Start;
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
xmlFsType = new FileSystemType
|
2017-08-07 16:15:57 +01:00
|
|
|
|
{
|
|
|
|
|
|
Type = "Fossil filesystem",
|
|
|
|
|
|
ClusterSize = hdr.blockSize,
|
|
|
|
|
|
Clusters = hdr.end
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if(sbLocation <= partition.End)
|
|
|
|
|
|
{
|
|
|
|
|
|
sector = imagePlugin.ReadSector(sbLocation);
|
|
|
|
|
|
FossilSuperBlock fsb = BigEndianMarshal.ByteArrayToStructureBigEndian<FossilSuperBlock>(sector);
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Fossil plugin", "magic 0x{0:X8} (expected 0x{1:X8})", fsb.magic,
|
2017-12-22 08:43:22 +00:00
|
|
|
|
FOSSIL_SB_MAGIC);
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(fsb.magic == FOSSIL_SB_MAGIC)
|
2017-08-07 16:15:57 +01:00
|
|
|
|
{
|
|
|
|
|
|
sb.AppendFormat("Epoch low {0}", fsb.epochLow).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Epoch high {0}", fsb.epochHigh).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Next QID {0}", fsb.qid).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Active root block {0}", fsb.active).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Next root block {0}", fsb.next).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Curren root block {0}", fsb.current).AppendLine();
|
2017-12-26 06:05:12 +00:00
|
|
|
|
sb.AppendFormat("Volume label: \"{0}\"", StringHandlers.CToString(fsb.name, currentEncoding))
|
2017-12-19 20:33:03 +00:00
|
|
|
|
.AppendLine();
|
2017-12-26 06:05:12 +00:00
|
|
|
|
xmlFsType.VolumeName = StringHandlers.CToString(fsb.name, currentEncoding);
|
2017-08-07 16:15:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
information = sb.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-24 02:37:41 +00:00
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct FossilHeader
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Magic number
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public uint magic;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Header version
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public ushort version;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Block size
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public ushort blockSize;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Block containing superblock
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public uint super;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Block containing labels
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public uint label;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Where do data blocks start
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public uint data;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// How many data blocks does it have
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public uint end;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct FossilSuperBlock
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Magic number
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public uint magic;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Header version
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public ushort version;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// file system low epoch
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public uint epochLow;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// file system high(active) epoch
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public uint epochHigh;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// next qid to allocate
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public ulong qid;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// data block number: root of active file system
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public int active;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// data block number: root of next file system to archive
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public int next;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// data block number: root of file system currently being archived
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public int current;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Venti score of last successful archive
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public byte[] last;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// name of file system(just a comment)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)] public byte[] name;
|
|
|
|
|
|
}
|
2017-08-07 16:06:51 +01:00
|
|
|
|
}
|
2017-08-07 16:15:57 +01:00
|
|
|
|
}
|