2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2016-09-14 14:25:08 +01:00
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : Squash.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// Component : Squash file system plugin.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Identifies the Squash file system 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-14 14:25:08 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
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-14 14:25:08 +01:00
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Filesystems
|
|
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public class Squash : IFilesystem
|
2016-09-14 14:25:08 +01:00
|
|
|
|
{
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Identifier for Squash
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
const uint SQUASH_MAGIC = 0x73717368;
|
|
|
|
|
|
const uint SQUASH_CIGAM = 0x68737173;
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
Encoding currentEncoding;
|
|
|
|
|
|
FileSystemType xmlFsType;
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public FileSystemType XmlFsType => xmlFsType;
|
|
|
|
|
|
public Encoding Encoding => currentEncoding;
|
|
|
|
|
|
public string Name => "Squash filesystem";
|
|
|
|
|
|
public Guid Id => new Guid("F8F6E46F-7A2A-48E3-9C0A-46AF4DC29E09");
|
2016-09-14 14:25:08 +01:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
2016-09-14 14:25:08 +01:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(partition.Start >= partition.End) return false;
|
2016-09-14 14:25:08 +01:00
|
|
|
|
|
2017-07-19 16:37:11 +01:00
|
|
|
|
byte[] sector = imagePlugin.ReadSector(partition.Start);
|
2016-09-14 14:25:08 +01:00
|
|
|
|
|
|
|
|
|
|
uint magic = BitConverter.ToUInt32(sector, 0x00);
|
|
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
return magic == SQUASH_MAGIC || magic == SQUASH_CIGAM;
|
2016-09-14 14:25:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
|
2017-12-26 06:05:12 +00:00
|
|
|
|
Encoding encoding)
|
2016-09-14 14:25:08 +01:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
currentEncoding = encoding ?? Encoding.UTF8;
|
2017-07-19 16:37:11 +01:00
|
|
|
|
byte[] sector = imagePlugin.ReadSector(partition.Start);
|
2016-09-14 14:59:29 +01:00
|
|
|
|
uint magic = BitConverter.ToUInt32(sector, 0x00);
|
2016-09-14 14:25:08 +01:00
|
|
|
|
|
|
|
|
|
|
SquashSuperBlock sqSb = new SquashSuperBlock();
|
2016-09-14 14:59:29 +01:00
|
|
|
|
bool littleEndian = true;
|
|
|
|
|
|
|
2017-12-24 02:37:41 +00:00
|
|
|
|
switch(magic)
|
|
|
|
|
|
{
|
2017-12-22 08:43:22 +00:00
|
|
|
|
case SQUASH_MAGIC:
|
2017-12-21 04:43:29 +00:00
|
|
|
|
IntPtr sqSbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(sqSb));
|
|
|
|
|
|
Marshal.Copy(sector, 0, sqSbPtr, Marshal.SizeOf(sqSb));
|
|
|
|
|
|
sqSb = (SquashSuperBlock)Marshal.PtrToStructure(sqSbPtr, typeof(SquashSuperBlock));
|
|
|
|
|
|
Marshal.FreeHGlobal(sqSbPtr);
|
|
|
|
|
|
break;
|
2017-12-22 08:43:22 +00:00
|
|
|
|
case SQUASH_CIGAM:
|
2017-12-21 04:43:29 +00:00
|
|
|
|
sqSb = BigEndianMarshal.ByteArrayToStructureBigEndian<SquashSuperBlock>(sector);
|
|
|
|
|
|
littleEndian = false;
|
|
|
|
|
|
break;
|
2016-09-14 14:59:29 +01:00
|
|
|
|
}
|
2016-09-14 14:25:08 +01:00
|
|
|
|
|
|
|
|
|
|
StringBuilder sbInformation = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
|
|
sbInformation.AppendLine("Squash file system");
|
2017-12-22 08:43:22 +00:00
|
|
|
|
sbInformation.AppendLine(littleEndian ? "Little-endian" : "Big-endian");
|
2016-09-14 14:25:08 +01:00
|
|
|
|
sbInformation.AppendFormat("Volume version {0}.{1}", sqSb.s_major, sqSb.s_minor).AppendLine();
|
|
|
|
|
|
sbInformation.AppendFormat("Volume has {0} bytes", sqSb.bytes_used).AppendLine();
|
|
|
|
|
|
sbInformation.AppendFormat("Volume has {0} bytes per block", sqSb.block_size).AppendLine();
|
2017-12-23 03:59:48 +00:00
|
|
|
|
sbInformation.AppendFormat("Volume created on {0}", DateHandlers.UnixUnsignedToDateTime(sqSb.mkfs_time))
|
2017-12-19 20:33:03 +00:00
|
|
|
|
.AppendLine();
|
2016-09-14 14:25:08 +01:00
|
|
|
|
sbInformation.AppendFormat("Volume has {0} inodes", sqSb.inodes).AppendLine();
|
|
|
|
|
|
switch(sqSb.compression)
|
|
|
|
|
|
{
|
|
|
|
|
|
case (ushort)SquashCompression.Lz4:
|
|
|
|
|
|
sbInformation.AppendLine("Volume is compressed using LZ4");
|
|
|
|
|
|
break;
|
|
|
|
|
|
case (ushort)SquashCompression.Lzo:
|
|
|
|
|
|
sbInformation.AppendLine("Volume is compressed using LZO");
|
|
|
|
|
|
break;
|
|
|
|
|
|
case (ushort)SquashCompression.Lzma:
|
|
|
|
|
|
sbInformation.AppendLine("Volume is compressed using LZMA");
|
|
|
|
|
|
break;
|
|
|
|
|
|
case (ushort)SquashCompression.Xz:
|
|
|
|
|
|
sbInformation.AppendLine("Volume is compressed using XZ");
|
|
|
|
|
|
break;
|
|
|
|
|
|
case (ushort)SquashCompression.Zlib:
|
|
|
|
|
|
sbInformation.AppendLine("Volume is compressed using GZIP");
|
|
|
|
|
|
break;
|
2017-11-12 22:27:06 +00:00
|
|
|
|
case (ushort)SquashCompression.Zstd:
|
|
|
|
|
|
sbInformation.AppendLine("Volume is compressed using Zstandard");
|
|
|
|
|
|
break;
|
2016-09-14 14:25:08 +01:00
|
|
|
|
default:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sbInformation.AppendFormat("Volume is compressed using unknown algorithm {0}", sqSb.compression)
|
|
|
|
|
|
.AppendLine();
|
2016-09-14 14:25:08 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
information = sbInformation.ToString();
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
xmlFsType = new FileSystemType
|
2017-12-22 08:43:22 +00:00
|
|
|
|
{
|
|
|
|
|
|
Type = "Squash file system",
|
2017-12-23 03:59:48 +00:00
|
|
|
|
CreationDate = DateHandlers.UnixUnsignedToDateTime(sqSb.mkfs_time),
|
2017-12-22 08:43:22 +00:00
|
|
|
|
CreationDateSpecified = true,
|
|
|
|
|
|
Clusters =
|
2017-12-26 06:05:12 +00:00
|
|
|
|
(long)((partition.End - partition.Start + 1) * imagePlugin.Info.SectorSize / sqSb.block_size),
|
2017-12-22 08:43:22 +00:00
|
|
|
|
ClusterSize = (int)sqSb.block_size,
|
|
|
|
|
|
Files = sqSb.inodes,
|
|
|
|
|
|
FilesSpecified = true,
|
|
|
|
|
|
FreeClusters = 0,
|
|
|
|
|
|
FreeClustersSpecified = true
|
|
|
|
|
|
};
|
2016-09-14 14:25:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-24 02:37:41 +00:00
|
|
|
|
enum SquashCompression : ushort
|
|
|
|
|
|
{
|
|
|
|
|
|
Zlib = 1,
|
|
|
|
|
|
Lzma = 2,
|
|
|
|
|
|
Lzo = 3,
|
|
|
|
|
|
Xz = 4,
|
|
|
|
|
|
Lz4 = 5,
|
|
|
|
|
|
Zstd = 6
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct SquashSuperBlock
|
|
|
|
|
|
{
|
|
|
|
|
|
public uint magic;
|
|
|
|
|
|
public uint inodes;
|
|
|
|
|
|
public uint mkfs_time;
|
|
|
|
|
|
public uint block_size;
|
|
|
|
|
|
public uint fragments;
|
|
|
|
|
|
public ushort compression;
|
|
|
|
|
|
public ushort block_log;
|
|
|
|
|
|
public ushort flags;
|
|
|
|
|
|
public ushort no_ids;
|
|
|
|
|
|
public ushort s_major;
|
|
|
|
|
|
public ushort s_minor;
|
|
|
|
|
|
public ulong root_inode;
|
|
|
|
|
|
public ulong bytes_used;
|
|
|
|
|
|
public ulong id_table_start;
|
|
|
|
|
|
public ulong xattr_id_table_start;
|
|
|
|
|
|
public ulong inode_table_start;
|
|
|
|
|
|
public ulong directory_table_start;
|
|
|
|
|
|
public ulong fragment_table_start;
|
|
|
|
|
|
public ulong lookup_table_start;
|
|
|
|
|
|
}
|
2016-09-14 14:25:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|