Files
Aaru/DiscImageChef.Filesystems/QNX6.cs

217 lines
10 KiB
C#
Raw Normal View History

// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : QNX6.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : QNX6 filesystem plugin.
//
// --[ Description ] ----------------------------------------------------------
//
// Identifies the QNX6 filesystem 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/>.
//
// ----------------------------------------------------------------------------
2018-12-29 17:34:38 +00:00
// Copyright © 2011-2019 Natalia Portillo
// ****************************************************************************/
using System;
using System.Runtime.InteropServices;
using System.Text;
using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Interfaces;
2017-12-21 14:30:38 +00:00
using Schemas;
namespace DiscImageChef.Filesystems
{
public class QNX6 : IFilesystem
{
const uint QNX6_SUPER_BLOCK_SIZE = 0x1000;
const uint QNX6_BOOT_BLOCKS_SIZE = 0x2000;
2018-06-22 08:08:38 +01:00
const uint QNX6_MAGIC = 0x68191122;
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 => "QNX6 Plugin";
public Guid Id => new Guid("3E610EA2-4D08-4D70-8947-830CD4C74FC0");
2018-08-29 22:15:43 +01:00
public string Author => "Natalia Portillo";
public bool Identify(IMediaImage imagePlugin, Partition partition)
{
2018-06-22 08:08:38 +01:00
uint sectors = QNX6_SUPER_BLOCK_SIZE / imagePlugin.Info.SectorSize;
uint bootSectors = QNX6_BOOT_BLOCKS_SIZE / imagePlugin.Info.SectorSize;
2017-12-19 20:33:03 +00:00
if(partition.Start + bootSectors + sectors >= partition.End) return false;
2017-07-23 19:58:11 +01:00
2018-06-22 08:08:38 +01:00
byte[] audiSector = imagePlugin.ReadSectors(partition.Start, sectors);
byte[] sector = imagePlugin.ReadSectors(partition.Start + bootSectors, sectors);
if(sector.Length < QNX6_SUPER_BLOCK_SIZE) return false;
QNX6_AudiSuperBlock audiSb =
Helpers.Marshal.ByteArrayToStructureLittleEndian<QNX6_AudiSuperBlock>(audiSector);
QNX6_SuperBlock qnxSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<QNX6_SuperBlock>(sector);
return qnxSb.magic == QNX6_MAGIC || audiSb.magic == QNX6_MAGIC;
}
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
2018-06-22 08:08:38 +01:00
Encoding encoding)
{
2018-06-22 08:08:38 +01:00
Encoding = encoding ?? Encoding.GetEncoding("iso-8859-15");
information = "";
2018-06-22 08:08:38 +01:00
StringBuilder sb = new StringBuilder();
uint sectors = QNX6_SUPER_BLOCK_SIZE / imagePlugin.Info.SectorSize;
uint bootSectors = QNX6_BOOT_BLOCKS_SIZE / imagePlugin.Info.SectorSize;
2018-06-22 08:08:38 +01:00
byte[] audiSector = imagePlugin.ReadSectors(partition.Start, sectors);
byte[] sector = imagePlugin.ReadSectors(partition.Start + bootSectors, sectors);
if(sector.Length < QNX6_SUPER_BLOCK_SIZE) return;
QNX6_AudiSuperBlock audiSb =
Helpers.Marshal.ByteArrayToStructureLittleEndian<QNX6_AudiSuperBlock>(audiSector);
QNX6_SuperBlock qnxSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<QNX6_SuperBlock>(sector);
bool audi = audiSb.magic == QNX6_MAGIC;
if(audi)
{
sb.AppendLine("QNX6 (Audi) filesystem");
sb.AppendFormat("Checksum: 0x{0:X8}", audiSb.checksum).AppendLine();
sb.AppendFormat("Serial: 0x{0:X16}", audiSb.checksum).AppendLine();
sb.AppendFormat("{0} bytes per block", audiSb.blockSize).AppendLine();
sb.AppendFormat("{0} inodes free of {1}", audiSb.freeInodes, audiSb.numInodes).AppendLine();
2017-12-19 20:33:03 +00:00
sb.AppendFormat("{0} blocks ({1} bytes) free of {2} ({3} bytes)", audiSb.freeBlocks,
audiSb.freeBlocks * audiSb.blockSize, audiSb.numBlocks,
2018-06-22 08:08:38 +01:00
audiSb.numBlocks * audiSb.blockSize).AppendLine();
2017-12-26 08:01:40 +00:00
XmlFsType = new FileSystemType
{
2018-06-22 08:08:38 +01:00
Type = "QNX6 (Audi) filesystem",
Clusters = audiSb.numBlocks,
ClusterSize = (int)audiSb.blockSize,
Bootable = true,
Files = audiSb.numInodes - audiSb.freeInodes,
FilesSpecified = true,
FreeClusters = audiSb.freeBlocks,
FreeClustersSpecified = true,
2018-06-22 08:08:38 +01:00
VolumeSerial = $"{audiSb.serial:X16}"
};
//xmlFSType.VolumeName = CurrentEncoding.GetString(audiSb.id);
information = sb.ToString();
return;
}
sb.AppendLine("QNX6 filesystem");
sb.AppendFormat("Checksum: 0x{0:X8}", qnxSb.checksum).AppendLine();
sb.AppendFormat("Serial: 0x{0:X16}", qnxSb.checksum).AppendLine();
2017-12-23 03:59:48 +00:00
sb.AppendFormat("Created on {0}", DateHandlers.UnixUnsignedToDateTime(qnxSb.ctime)).AppendLine();
sb.AppendFormat("Last mounted on {0}", DateHandlers.UnixUnsignedToDateTime(qnxSb.atime)).AppendLine();
sb.AppendFormat("Flags: 0x{0:X8}", qnxSb.flags).AppendLine();
sb.AppendFormat("Version1: 0x{0:X4}", qnxSb.version1).AppendLine();
sb.AppendFormat("Version2: 0x{0:X4}", qnxSb.version2).AppendLine();
//sb.AppendFormat("Volume ID: \"{0}\"", CurrentEncoding.GetString(qnxSb.volumeid)).AppendLine();
sb.AppendFormat("{0} bytes per block", qnxSb.blockSize).AppendLine();
sb.AppendFormat("{0} inodes free of {1}", qnxSb.freeInodes, qnxSb.numInodes).AppendLine();
2017-12-19 20:33:03 +00:00
sb.AppendFormat("{0} blocks ({1} bytes) free of {2} ({3} bytes)", qnxSb.freeBlocks,
qnxSb.freeBlocks * qnxSb.blockSize, qnxSb.numBlocks, qnxSb.numBlocks * qnxSb.blockSize)
.AppendLine();
2017-12-26 08:01:40 +00:00
XmlFsType = new FileSystemType
{
2018-06-22 08:08:38 +01:00
Type = "QNX6 filesystem",
Clusters = qnxSb.numBlocks,
ClusterSize = (int)qnxSb.blockSize,
Bootable = true,
Files = qnxSb.numInodes - qnxSb.freeInodes,
FilesSpecified = true,
FreeClusters = qnxSb.freeBlocks,
FreeClustersSpecified = true,
VolumeSerial = $"{qnxSb.serial:X16}",
CreationDate = DateHandlers.UnixUnsignedToDateTime(qnxSb.ctime),
CreationDateSpecified = true,
ModificationDate = DateHandlers.UnixUnsignedToDateTime(qnxSb.atime),
ModificationDateSpecified = true
};
//xmlFSType.VolumeName = CurrentEncoding.GetString(qnxSb.volumeid);
information = sb.ToString();
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct QNX6_RootNode
{
public ulong size;
2018-06-22 08:08:38 +01:00
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public uint[] pointers;
public byte levels;
public byte mode;
2018-06-22 08:08:38 +01:00
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
public byte[] spare;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct QNX6_SuperBlock
{
2018-06-22 08:08:38 +01:00
public uint magic;
public uint checksum;
public ulong serial;
public uint ctime;
public uint atime;
public uint flags;
public ushort version1;
public ushort version2;
2018-06-22 08:08:38 +01:00
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[] volumeid;
public uint blockSize;
public uint numInodes;
public uint freeInodes;
public uint numBlocks;
public uint freeBlocks;
public uint allocationGroup;
public QNX6_RootNode inode;
public QNX6_RootNode bitmap;
public QNX6_RootNode longfile;
public QNX6_RootNode unknown;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct QNX6_AudiSuperBlock
{
2018-06-22 08:08:38 +01:00
public uint magic;
public uint checksum;
public ulong serial;
2018-06-22 08:08:38 +01:00
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
public byte[] spare1;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
public byte[] id;
public uint blockSize;
public uint numInodes;
public uint freeInodes;
public uint numBlocks;
public uint freeBlocks;
public uint spare2;
public QNX6_RootNode inode;
public QNX6_RootNode bitmap;
public QNX6_RootNode longfile;
public QNX6_RootNode unknown;
}
}
}