2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2016-09-13 19:06:05 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2016-09-14 00:13:29 +01:00
|
|
|
|
// Filename : SFS.cs
|
2016-09-13 19:06:05 +01:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2016-09-14 02:31:32 +01:00
|
|
|
|
// Component : SmartFileSystem plugin.
|
2016-09-13 19:06:05 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Identifies the SmartFileSystem and shows information.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-12-31 23:08:23 +00:00
|
|
|
|
// Copyright © 2011-2021 Natalia Portillo
|
2016-09-13 19:06:05 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Runtime.InteropServices;
|
2016-09-13 19:07:38 +01:00
|
|
|
|
using System.Text;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes;
|
|
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
2020-07-20 15:43:52 +01:00
|
|
|
|
using Aaru.Helpers;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using Schemas;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Marshal = Aaru.Helpers.Marshal;
|
2016-09-13 19:06:05 +01:00
|
|
|
|
|
2020-02-27 00:33:26 +00:00
|
|
|
|
namespace Aaru.Filesystems
|
2016-09-13 19:06:05 +01:00
|
|
|
|
{
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Implements detection of the Smart File System
|
|
|
|
|
|
/// </summary>
|
2020-07-22 13:20:25 +01:00
|
|
|
|
public sealed class SFS : IFilesystem
|
2016-09-13 19:07:38 +01:00
|
|
|
|
{
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary>Identifier for SFS v1</summary>
|
|
|
|
|
|
const uint SFS_MAGIC = 0x53465300;
|
|
|
|
|
|
/// <summary>Identifier for SFS v2</summary>
|
|
|
|
|
|
const uint SFS2_MAGIC = 0x53465302;
|
|
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2017-12-26 08:01:40 +00:00
|
|
|
|
public FileSystemType XmlFsType { get; private set; }
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2018-06-22 08:08:38 +01:00
|
|
|
|
public Encoding Encoding { get; private set; }
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2018-06-22 08:08:38 +01:00
|
|
|
|
public string Name => "SmartFileSystem";
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2018-06-22 08:08:38 +01:00
|
|
|
|
public Guid Id => new Guid("26550C19-3671-4A2D-BC2F-F20CEB7F48DC");
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2018-08-29 22:15:43 +01:00
|
|
|
|
public string Author => "Natalia Portillo";
|
2016-09-13 19:06:05 +01:00
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
2016-09-13 19:07:38 +01:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(partition.Start >= partition.End)
|
|
|
|
|
|
return false;
|
2016-09-13 19:06:05 +01:00
|
|
|
|
|
2017-07-19 16:37:11 +01:00
|
|
|
|
byte[] sector = imagePlugin.ReadSector(partition.Start);
|
2016-09-13 19:06:05 +01:00
|
|
|
|
|
2016-09-13 19:07:38 +01:00
|
|
|
|
uint magic = BigEndianBitConverter.ToUInt32(sector, 0x00);
|
2016-09-13 19:06:05 +01:00
|
|
|
|
|
2017-08-09 04:52:36 +01:00
|
|
|
|
return magic == SFS_MAGIC || magic == SFS2_MAGIC;
|
2016-09-13 19:07:38 +01:00
|
|
|
|
}
|
2016-09-13 19:06:05 +01:00
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2017-12-26 08:01:40 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
Encoding encoding)
|
2016-09-13 19:07:38 +01:00
|
|
|
|
{
|
2017-12-26 08:01:40 +00:00
|
|
|
|
Encoding = encoding ?? Encoding.GetEncoding("iso-8859-1");
|
2018-06-22 08:08:38 +01:00
|
|
|
|
byte[] rootBlockSector = imagePlugin.ReadSector(partition.Start);
|
2019-02-27 08:49:42 +00:00
|
|
|
|
RootBlock rootBlock = Marshal.ByteArrayToStructureBigEndian<RootBlock>(rootBlockSector);
|
2016-09-13 19:06:05 +01:00
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
var sbInformation = new StringBuilder();
|
2016-09-13 19:06:05 +01:00
|
|
|
|
|
2017-08-16 15:45:28 +01:00
|
|
|
|
sbInformation.AppendLine("SmartFileSystem");
|
2016-09-13 19:06:05 +01:00
|
|
|
|
|
|
|
|
|
|
sbInformation.AppendFormat("Volume version {0}", rootBlock.version).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sbInformation.AppendFormat("Volume starts on device byte {0} and ends on byte {1}", rootBlock.firstbyte,
|
|
|
|
|
|
rootBlock.lastbyte).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
sbInformation.
|
|
|
|
|
|
AppendFormat("Volume has {0} blocks of {1} bytes each", rootBlock.totalblocks, rootBlock.blocksize).
|
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sbInformation.AppendFormat("Volume created on {0}",
|
2020-02-29 18:03:35 +00:00
|
|
|
|
DateHandlers.UnixUnsignedToDateTime(rootBlock.datecreated).AddYears(8)).
|
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
2016-09-13 19:06:05 +01:00
|
|
|
|
sbInformation.AppendFormat("Bitmap starts in block {0}", rootBlock.bitmapbase).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
sbInformation.AppendFormat("Admin space container starts in block {0}", rootBlock.adminspacecontainer).
|
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
|
|
|
|
|
sbInformation.AppendFormat("Root object container starts in block {0}", rootBlock.rootobjectcontainer).
|
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
|
|
|
|
|
sbInformation.
|
|
|
|
|
|
AppendFormat("Root node of the extent B-tree resides in block {0}", rootBlock.extentbnoderoot).
|
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
|
|
|
|
|
sbInformation.AppendFormat("Root node of the object B-tree resides in block {0}", rootBlock.objectnoderoot).
|
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(rootBlock.bits.HasFlag(Flags.CaseSensitive))
|
2020-02-29 18:03:35 +00:00
|
|
|
|
sbInformation.AppendLine("Volume is case sensitive");
|
|
|
|
|
|
|
2020-07-22 13:20:25 +01:00
|
|
|
|
if(rootBlock.bits.HasFlag(Flags.RecycledFolder))
|
2016-09-13 19:06:05 +01:00
|
|
|
|
sbInformation.AppendLine("Volume moves deleted files to a recycled folder");
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2016-09-13 19:06:05 +01:00
|
|
|
|
information = sbInformation.ToString();
|
|
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType = new FileSystemType
|
2017-08-09 04:52:36 +01:00
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
CreationDate = DateHandlers.UnixUnsignedToDateTime(rootBlock.datecreated).AddYears(8),
|
2020-07-20 04:34:16 +01:00
|
|
|
|
CreationDateSpecified = true,
|
|
|
|
|
|
Clusters = rootBlock.totalblocks,
|
|
|
|
|
|
ClusterSize = rootBlock.blocksize,
|
2018-06-22 08:08:38 +01:00
|
|
|
|
Type = "SmartFileSystem"
|
2017-08-09 04:52:36 +01:00
|
|
|
|
};
|
2016-09-13 19:07:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-24 02:37:41 +00:00
|
|
|
|
[Flags]
|
2020-07-20 21:11:32 +01:00
|
|
|
|
enum Flags : byte
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
2020-07-22 13:20:25 +01:00
|
|
|
|
RecycledFolder = 64, CaseSensitive = 128
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2020-11-11 04:19:18 +00:00
|
|
|
|
readonly struct RootBlock
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
public readonly uint blockId;
|
|
|
|
|
|
public readonly uint blockChecksum;
|
|
|
|
|
|
public readonly uint blockSelfPointer;
|
|
|
|
|
|
public readonly ushort version;
|
|
|
|
|
|
public readonly ushort sequence;
|
|
|
|
|
|
public readonly uint datecreated;
|
|
|
|
|
|
public readonly Flags bits;
|
|
|
|
|
|
public readonly byte padding1;
|
|
|
|
|
|
public readonly ushort padding2;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly uint[] reserved1;
|
|
|
|
|
|
public readonly ulong firstbyte;
|
|
|
|
|
|
public readonly ulong lastbyte;
|
|
|
|
|
|
public readonly uint totalblocks;
|
|
|
|
|
|
public readonly uint blocksize;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly uint[] reserved2;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly uint[] reserved3;
|
|
|
|
|
|
public readonly uint bitmapbase;
|
|
|
|
|
|
public readonly uint adminspacecontainer;
|
|
|
|
|
|
public readonly uint rootobjectcontainer;
|
|
|
|
|
|
public readonly uint extentbnoderoot;
|
|
|
|
|
|
public readonly uint objectnoderoot;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly uint[] reserved4;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
2016-09-13 19:07:38 +01:00
|
|
|
|
}
|
2016-09-13 19:06:05 +01:00
|
|
|
|
}
|