2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : Opera.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// Component : Opera filesystem plugin.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Identifies the Opera 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// ****************************************************************************/
|
2014-04-17 19:58:14 +00:00
|
|
|
|
|
2011-03-03 18:34:33 +00:00
|
|
|
|
using System;
|
2016-07-21 17:16:08 +01:00
|
|
|
|
using System.Collections.Generic;
|
2017-07-23 21:01:26 +01:00
|
|
|
|
using System.Runtime.InteropServices;
|
2017-07-19 16:31:08 +01:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
using DiscImageChef.CommonTypes;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using DiscImageChef.DiscImages;
|
|
|
|
|
|
using Schemas;
|
2014-04-17 19:58:14 +00:00
|
|
|
|
|
2016-07-21 16:15:39 +01:00
|
|
|
|
namespace DiscImageChef.Filesystems
|
2011-03-03 18:34:33 +00:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public class OperaFS : IFilesystem
|
2014-04-14 02:29:13 +00:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
Encoding currentEncoding;
|
|
|
|
|
|
FileSystemType xmlFsType;
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public FileSystemType XmlFsType => xmlFsType;
|
2014-04-14 02:29:13 +00:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public Encoding Encoding => currentEncoding;
|
|
|
|
|
|
public string Name => "Opera Filesystem Plugin";
|
|
|
|
|
|
public Guid Id => new Guid("0ec84ec7-eae6-4196-83fe-943b3fe46dbd");
|
2016-07-27 13:32:45 +01:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
2014-04-14 02:29:13 +00:00
|
|
|
|
{
|
2017-12-20 17:26:28 +00:00
|
|
|
|
if(2 + partition.Start >= partition.End) return false;
|
2014-07-09 19:49:14 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
byte[] sbSector = imagePlugin.ReadSector(0 + partition.Start);
|
2011-03-03 18:34:33 +00:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
byte[] syncBytes = new byte[5];
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
byte recordType = sbSector[0x000];
|
|
|
|
|
|
Array.Copy(sbSector, 0x001, syncBytes, 0, 5);
|
|
|
|
|
|
byte recordVersion = sbSector[0x006];
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(recordType != 1 || recordVersion != 1) return false;
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
return Encoding.ASCII.GetString(syncBytes) == "ZZZZZ";
|
2014-04-14 02:29:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding)
|
2014-04-14 02:29:13 +00:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
// TODO: Find correct default encoding
|
|
|
|
|
|
currentEncoding = Encoding.ASCII;
|
2014-04-14 02:29:13 +00:00
|
|
|
|
information = "";
|
2017-12-22 08:43:22 +00:00
|
|
|
|
StringBuilder superBlockMetadata = new StringBuilder();
|
2011-03-03 18:34:33 +00:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
byte[] sbSector = imagePlugin.ReadSector(0 + partition.Start);
|
2011-03-03 18:34:33 +00:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
OperaSuperBlock sb = BigEndianMarshal.ByteArrayToStructureBigEndian<OperaSuperBlock>(sbSector);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
sb.sync_bytes = new byte[5];
|
2012-08-05 00:43:49 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(sb.record_type != 1 || sb.record_version != 1) return;
|
|
|
|
|
|
if(Encoding.ASCII.GetString(sb.sync_bytes) != "ZZZZZ") return;
|
2011-03-03 18:34:33 +00:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
superBlockMetadata.AppendFormat("Opera filesystem disc.").AppendLine();
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(!string.IsNullOrEmpty(StringHandlers.CToString(sb.volume_label, currentEncoding)))
|
2017-12-22 08:43:22 +00:00
|
|
|
|
superBlockMetadata
|
2017-12-26 06:05:12 +00:00
|
|
|
|
.AppendFormat("Volume label: {0}", StringHandlers.CToString(sb.volume_label, currentEncoding))
|
2017-12-19 20:33:03 +00:00
|
|
|
|
.AppendLine();
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(!string.IsNullOrEmpty(StringHandlers.CToString(sb.volume_comment, currentEncoding)))
|
2017-12-22 08:43:22 +00:00
|
|
|
|
superBlockMetadata.AppendFormat("Volume comment: {0}",
|
2017-12-26 06:05:12 +00:00
|
|
|
|
StringHandlers.CToString(sb.volume_comment, currentEncoding))
|
2017-12-19 20:33:03 +00:00
|
|
|
|
.AppendLine();
|
2017-12-22 08:43:22 +00:00
|
|
|
|
superBlockMetadata.AppendFormat("Volume identifier: 0x{0:X8}", sb.volume_id).AppendLine();
|
|
|
|
|
|
superBlockMetadata.AppendFormat("Block size: {0} bytes", sb.block_size).AppendLine();
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize == 2336 || imagePlugin.Info.SectorSize == 2352 ||
|
|
|
|
|
|
imagePlugin.Info.SectorSize == 2448)
|
2014-04-14 01:14:20 +00:00
|
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(sb.block_size != 2048)
|
2017-12-22 08:43:22 +00:00
|
|
|
|
superBlockMetadata
|
2017-12-19 20:33:03 +00:00
|
|
|
|
.AppendFormat("WARNING: Filesystem indicates {0} bytes/block while device indicates {1} bytes/block",
|
|
|
|
|
|
sb.block_size, 2048);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|
2017-12-26 06:05:12 +00:00
|
|
|
|
else if(imagePlugin.Info.SectorSize != sb.block_size)
|
2017-12-22 08:43:22 +00:00
|
|
|
|
superBlockMetadata
|
2017-12-19 20:33:03 +00:00
|
|
|
|
.AppendFormat("WARNING: Filesystem indicates {0} bytes/block while device indicates {1} bytes/block",
|
2017-12-26 06:05:12 +00:00
|
|
|
|
sb.block_size, imagePlugin.Info.SectorSize);
|
2017-12-22 08:43:22 +00:00
|
|
|
|
superBlockMetadata
|
2017-12-19 20:33:03 +00:00
|
|
|
|
.AppendFormat("Volume size: {0} blocks, {1} bytes", sb.block_count, sb.block_size * sb.block_count)
|
|
|
|
|
|
.AppendLine();
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if((ulong)sb.block_count > imagePlugin.Info.Sectors)
|
2017-12-22 08:43:22 +00:00
|
|
|
|
superBlockMetadata
|
2017-12-19 20:33:03 +00:00
|
|
|
|
.AppendFormat("WARNING: Filesystem indicates {0} blocks while device indicates {1} blocks",
|
2017-12-26 06:05:12 +00:00
|
|
|
|
sb.block_count, imagePlugin.Info.Sectors);
|
2017-12-22 08:43:22 +00:00
|
|
|
|
superBlockMetadata.AppendFormat("Root directory identifier: 0x{0:X8}", sb.root_dirid).AppendLine();
|
|
|
|
|
|
superBlockMetadata.AppendFormat("Root directory block size: {0} bytes", sb.rootdir_bsize).AppendLine();
|
|
|
|
|
|
superBlockMetadata.AppendFormat("Root directory size: {0} blocks, {1} bytes", sb.rootdir_blocks,
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sb.rootdir_bsize * sb.rootdir_blocks).AppendLine();
|
2017-12-22 08:43:22 +00:00
|
|
|
|
superBlockMetadata.AppendFormat("Last root directory copy: {0}", sb.last_root_copy).AppendLine();
|
2011-03-03 18:34:33 +00:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
information = superBlockMetadata.ToString();
|
2015-12-05 17:10:27 +00:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
xmlFsType = new FileSystemType
|
2017-07-23 21:01:26 +01:00
|
|
|
|
{
|
|
|
|
|
|
Type = "Opera",
|
2017-12-26 06:05:12 +00:00
|
|
|
|
VolumeName = StringHandlers.CToString(sb.volume_label, currentEncoding),
|
2017-07-23 21:01:26 +01:00
|
|
|
|
ClusterSize = sb.block_size,
|
|
|
|
|
|
Clusters = sb.block_count
|
|
|
|
|
|
};
|
2014-04-14 02:29:13 +00:00
|
|
|
|
}
|
2012-08-05 00:43:49 +00:00
|
|
|
|
|
2017-12-24 02:37:41 +00:00
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct OperaSuperBlock
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>0x000, Record type, must be 1</summary>
|
|
|
|
|
|
public byte record_type;
|
|
|
|
|
|
/// <summary>0x001, 5 bytes, "ZZZZZ"</summary>
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)] public byte[] sync_bytes;
|
|
|
|
|
|
/// <summary>0x006, Record version, must be 1</summary>
|
|
|
|
|
|
public byte record_version;
|
|
|
|
|
|
/// <summary>0x007, Volume flags</summary>
|
|
|
|
|
|
public byte volume_flags;
|
|
|
|
|
|
/// <summary>0x008, 32 bytes, volume comment</summary>
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] public byte[] volume_comment;
|
|
|
|
|
|
/// <summary>0x028, 32 bytes, volume label</summary>
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] public byte[] volume_label;
|
|
|
|
|
|
/// <summary>0x048, Volume ID</summary>
|
|
|
|
|
|
public int volume_id;
|
|
|
|
|
|
/// <summary>0x04C, Block size in bytes</summary>
|
|
|
|
|
|
public int block_size;
|
|
|
|
|
|
/// <summary>0x050, Blocks in volume</summary>
|
|
|
|
|
|
public int block_count;
|
|
|
|
|
|
/// <summary>0x054, Root directory ID</summary>
|
|
|
|
|
|
public int root_dirid;
|
|
|
|
|
|
/// <summary>0x058, Root directory blocks</summary>
|
|
|
|
|
|
public int rootdir_blocks;
|
|
|
|
|
|
/// <summary>0x05C, Root directory block size</summary>
|
|
|
|
|
|
public int rootdir_bsize;
|
|
|
|
|
|
/// <summary>0x060, Last root directory copy</summary>
|
|
|
|
|
|
public int last_root_copy;
|
|
|
|
|
|
}
|
2014-04-14 02:29:13 +00:00
|
|
|
|
}
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|