2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2016-09-13 19:06:05 +01:00
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2016-09-13 19:06:05 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Runtime.InteropServices;
|
2016-09-13 19:07:38 +01:00
|
|
|
|
using System.Text;
|
2017-07-19 16:31:08 +01:00
|
|
|
|
using DiscImageChef.CommonTypes;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using DiscImageChef.DiscImages;
|
|
|
|
|
|
using Schemas;
|
2016-09-13 19:06:05 +01:00
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Filesystems
|
|
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public 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;
|
2017-12-26 06:05:12 +00:00
|
|
|
|
FileSystemType xmlFsType;
|
|
|
|
|
|
public virtual FileSystemType XmlFsType => xmlFsType;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
Encoding currentEncoding;
|
|
|
|
|
|
public virtual Encoding Encoding => currentEncoding;
|
|
|
|
|
|
public virtual string Name => "SmartFileSystem";
|
|
|
|
|
|
public virtual Guid Id => new Guid("26550C19-3671-4A2D-BC2F-F20CEB7F48DC");
|
2016-09-13 19:06:05 +01:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public virtual bool Identify(IMediaImage imagePlugin, Partition partition)
|
2016-09-13 19:07:38 +01:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(partition.Start >= partition.End) return false;
|
2016-09-13 19:06:05 +01:00
|
|
|
|
|
2016-09-13 19:07:38 +01:00
|
|
|
|
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
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
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public virtual void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding)
|
2016-09-13 19:07:38 +01:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
currentEncoding = encoding ?? Encoding.GetEncoding("iso-8859-1");
|
2017-12-22 08:43:22 +00:00
|
|
|
|
byte[] rootBlockSector = imagePlugin.ReadSector(partition.Start);
|
|
|
|
|
|
RootBlock rootBlock = BigEndianMarshal.ByteArrayToStructureBigEndian<RootBlock>(rootBlockSector);
|
2016-09-13 19:06:05 +01:00
|
|
|
|
|
2016-09-13 19:07:38 +01:00
|
|
|
|
StringBuilder 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();
|
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();
|
|
|
|
|
|
sbInformation
|
|
|
|
|
|
.AppendFormat("Volume has {0} blocks of {1} bytes each", rootBlock.totalblocks, rootBlock.blocksize)
|
|
|
|
|
|
.AppendLine();
|
|
|
|
|
|
sbInformation.AppendFormat("Volume created on {0}",
|
2017-12-23 03:59:48 +00:00
|
|
|
|
DateHandlers.UnixUnsignedToDateTime(rootBlock.datecreated).AddYears(8))
|
2017-12-19 20:33:03 +00:00
|
|
|
|
.AppendLine();
|
2016-09-13 19:06:05 +01:00
|
|
|
|
sbInformation.AppendFormat("Bitmap starts in block {0}", rootBlock.bitmapbase).AppendLine();
|
2017-12-19 20:33:03 +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");
|
2016-09-13 19:06:05 +01:00
|
|
|
|
if(rootBlock.bits.HasFlag(SFSFlags.RecyledFolder))
|
|
|
|
|
|
sbInformation.AppendLine("Volume moves deleted files to a recycled folder");
|
|
|
|
|
|
information = sbInformation.ToString();
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
xmlFsType = new FileSystemType
|
2017-08-09 04:52:36 +01:00
|
|
|
|
{
|
2017-12-23 03:59:48 +00:00
|
|
|
|
CreationDate = DateHandlers.UnixUnsignedToDateTime(rootBlock.datecreated).AddYears(8),
|
2017-08-09 04:52:36 +01:00
|
|
|
|
CreationDateSpecified = true,
|
|
|
|
|
|
Clusters = rootBlock.totalblocks,
|
2017-08-16 15:45:28 +01:00
|
|
|
|
ClusterSize = (int)rootBlock.blocksize,
|
|
|
|
|
|
Type = "SmartFileSystem"
|
2017-08-09 04:52:36 +01:00
|
|
|
|
};
|
2016-09-13 19:07:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public virtual Errno Mount(IMediaImage imagePlugin, Partition partition, Encoding encoding, bool debug)
|
2016-09-13 19:07:38 +01:00
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public virtual Errno Unmount()
|
2016-09-13 19:07:38 +01:00
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public virtual Errno MapBlock(string path, long fileBlock, ref long deviceBlock)
|
2016-09-13 19:07:38 +01:00
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public virtual Errno GetAttributes(string path, ref FileAttributes attributes)
|
2016-09-13 19:07:38 +01:00
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public virtual Errno ListXAttr(string path, ref List<string> xattrs)
|
2016-09-13 19:07:38 +01:00
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public virtual Errno GetXattr(string path, string xattr, ref byte[] buf)
|
2016-09-13 19:07:38 +01:00
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public virtual Errno Read(string path, long offset, long size, ref byte[] buf)
|
2016-09-13 19:07:38 +01:00
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public virtual Errno ReadDir(string path, ref List<string> contents)
|
2016-09-13 19:07:38 +01:00
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public virtual Errno StatFs(ref FileSystemInfo stat)
|
2016-09-13 19:07:38 +01:00
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public virtual Errno Stat(string path, ref FileEntryInfo stat)
|
2016-09-13 19:07:38 +01:00
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public virtual Errno ReadLink(string path, ref string dest)
|
2016-09-13 19:07:38 +01:00
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
2017-12-24 02:37:41 +00:00
|
|
|
|
|
|
|
|
|
|
[Flags]
|
|
|
|
|
|
enum SFSFlags : byte
|
|
|
|
|
|
{
|
|
|
|
|
|
RecyledFolder = 64,
|
|
|
|
|
|
CaseSensitive = 128
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct RootBlock
|
|
|
|
|
|
{
|
|
|
|
|
|
public uint blockId;
|
|
|
|
|
|
public uint blockChecksum;
|
|
|
|
|
|
public uint blockSelfPointer;
|
|
|
|
|
|
public ushort version;
|
|
|
|
|
|
public ushort sequence;
|
|
|
|
|
|
public uint datecreated;
|
|
|
|
|
|
public SFSFlags bits;
|
|
|
|
|
|
public byte padding1;
|
|
|
|
|
|
public ushort padding2;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public uint[] reserved1;
|
|
|
|
|
|
public ulong firstbyte;
|
|
|
|
|
|
public ulong lastbyte;
|
|
|
|
|
|
public uint totalblocks;
|
|
|
|
|
|
public uint blocksize;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public uint[] reserved2;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public uint[] reserved3;
|
|
|
|
|
|
public uint bitmapbase;
|
|
|
|
|
|
public uint adminspacecontainer;
|
|
|
|
|
|
public uint rootobjectcontainer;
|
|
|
|
|
|
public uint extentbnoderoot;
|
|
|
|
|
|
public uint objectnoderoot;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public uint[] reserved4;
|
|
|
|
|
|
}
|
2016-09-13 19:07:38 +01:00
|
|
|
|
}
|
2016-09-13 19:06:05 +01:00
|
|
|
|
}
|