Files
Aaru/Aaru.Filesystems/SFS.cs

163 lines
6.8 KiB
C#
Raw Normal View History

// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
2016-09-14 00:13:29 +01:00
// Filename : SFS.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
2016-09-14 02:31:32 +01:00
// Component : SmartFileSystem plugin.
//
// --[ 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-01-03 17:51:30 +00:00
// Copyright © 2011-2020 Natalia Portillo
// ****************************************************************************/
using System;
using System.Runtime.InteropServices;
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;
2020-02-27 00:33:26 +00:00
namespace Aaru.Filesystems
{
public class SFS : IFilesystem
{
/// <summary>Identifier for SFS v1</summary>
const uint SFS_MAGIC = 0x53465300;
/// <summary>Identifier for SFS v2</summary>
const uint SFS2_MAGIC = 0x53465302;
2017-12-26 08:01:40 +00:00
public FileSystemType XmlFsType { get; private set; }
2018-06-22 08:08:38 +01:00
public Encoding Encoding { get; private set; }
public string Name => "SmartFileSystem";
public Guid Id => new Guid("26550C19-3671-4A2D-BC2F-F20CEB7F48DC");
2018-08-29 22:15:43 +01:00
public string Author => "Natalia Portillo";
public bool Identify(IMediaImage imagePlugin, Partition partition)
{
2020-02-29 18:03:35 +00:00
if(partition.Start >= partition.End)
return false;
2017-07-19 16:37:11 +01:00
byte[] sector = imagePlugin.ReadSector(partition.Start);
uint magic = BigEndianBitConverter.ToUInt32(sector, 0x00);
2017-08-09 04:52:36 +01:00
return magic == SFS_MAGIC || magic == SFS2_MAGIC;
}
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)
{
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);
2020-02-29 18:03:35 +00:00
var sbInformation = new StringBuilder();
2017-08-16 15:45:28 +01:00
sbInformation.AppendLine("SmartFileSystem");
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();
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();
if(rootBlock.bits.HasFlag(SFSFlags.CaseSensitive))
sbInformation.AppendLine("Volume is case sensitive");
if(rootBlock.bits.HasFlag(SFSFlags.RecyledFolder))
sbInformation.AppendLine("Volume moves deleted files to a recycled folder");
2020-02-29 18:03:35 +00: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
};
}
[Flags]
enum SFSFlags : byte
{
2020-02-29 18:03:35 +00:00
RecyledFolder = 64, CaseSensitive = 128
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct RootBlock
{
2019-04-23 01:38:33 +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 SFSFlags 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;
}
}
}