2020-03-11 21:56:55 +00:00
|
|
|
// /***************************************************************************
|
|
|
|
|
// Aaru Data Preservation Suite
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Info.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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-02-18 10:02:53 +00:00
|
|
|
// Copyright © 2011-2022 Natalia Portillo
|
2020-03-11 21:56:55 +00:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
namespace Aaru.Filesystems;
|
|
|
|
|
|
2011-03-03 18:34:33 +00:00
|
|
|
using System;
|
2017-07-19 16:31:08 +01:00
|
|
|
using System.Text;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.CommonTypes;
|
2021-09-19 21:16:47 +01:00
|
|
|
using Aaru.CommonTypes.Enums;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
using Aaru.Helpers;
|
2017-12-21 14:30:38 +00:00
|
|
|
using Schemas;
|
2014-04-17 19:58:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
public sealed partial class OperaFS
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
2014-04-14 02:29:13 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
if(2 + partition.Start >= partition.End)
|
|
|
|
|
return false;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ErrorNumber errno = imagePlugin.ReadSector(0 + partition.Start, out byte[] sbSector);
|
2011-03-03 18:34:33 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
return false;
|
2016-04-19 02:11:47 +01:00
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
var syncBytes = new byte[5];
|
2016-04-19 02:11:47 +01:00
|
|
|
|
2022-03-06 13:29:38 +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
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(recordType != 1 ||
|
|
|
|
|
recordVersion != 1)
|
|
|
|
|
return false;
|
2014-04-14 02:29:13 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return Encoding.ASCII.GetString(syncBytes) == SYNC;
|
|
|
|
|
}
|
2011-03-03 18:34:33 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
2022-03-07 07:36:44 +00:00
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding)
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
// TODO: Find correct default encoding
|
|
|
|
|
Encoding = Encoding.ASCII;
|
|
|
|
|
information = "";
|
|
|
|
|
var superBlockMetadata = new StringBuilder();
|
2021-09-19 21:16:47 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ErrorNumber errno = imagePlugin.ReadSector(0 + partition.Start, out byte[] sbSector);
|
2011-03-03 18:34:33 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
return;
|
2012-08-05 00:43:49 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
SuperBlock sb = Marshal.ByteArrayToStructureBigEndian<SuperBlock>(sbSector);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(sb.record_type != 1 ||
|
|
|
|
|
sb.record_version != 1)
|
|
|
|
|
return;
|
2011-03-03 18:34:33 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(Encoding.ASCII.GetString(sb.sync_bytes) != SYNC)
|
|
|
|
|
return;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
superBlockMetadata.AppendFormat("Opera filesystem disc.").AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(!string.IsNullOrEmpty(StringHandlers.CToString(sb.volume_label, Encoding)))
|
2022-03-07 07:36:44 +00:00
|
|
|
superBlockMetadata.AppendFormat("Volume label: {0}", StringHandlers.CToString(sb.volume_label, Encoding)).
|
|
|
|
|
AppendLine();
|
2018-06-22 08:08:38 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(!string.IsNullOrEmpty(StringHandlers.CToString(sb.volume_comment, Encoding)))
|
2020-02-29 18:03:35 +00:00
|
|
|
superBlockMetadata.
|
2022-03-07 07:36:44 +00:00
|
|
|
AppendFormat("Volume comment: {0}", StringHandlers.CToString(sb.volume_comment, Encoding)).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
superBlockMetadata.AppendFormat("Volume identifier: 0x{0:X8}", sb.volume_id).AppendLine();
|
|
|
|
|
superBlockMetadata.AppendFormat("Block size: {0} bytes", sb.block_size).AppendLine();
|
|
|
|
|
|
2022-03-16 11:47:00 +00:00
|
|
|
if(imagePlugin.Info.SectorSize is 2336 or 2352 or 2448)
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
if(sb.block_size != 2048)
|
2020-02-29 18:03:35 +00:00
|
|
|
superBlockMetadata.
|
2022-03-06 13:29:38 +00:00
|
|
|
AppendFormat("WARNING: Filesystem indicates {0} bytes/block while device indicates {1} bytes/block",
|
|
|
|
|
sb.block_size, 2048);
|
|
|
|
|
}
|
|
|
|
|
else if(imagePlugin.Info.SectorSize != sb.block_size)
|
|
|
|
|
superBlockMetadata.
|
|
|
|
|
AppendFormat("WARNING: Filesystem indicates {0} bytes/block while device indicates {1} bytes/block",
|
|
|
|
|
sb.block_size, imagePlugin.Info.SectorSize);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
superBlockMetadata.
|
|
|
|
|
AppendFormat("Volume size: {0} blocks, {1} bytes", sb.block_count, sb.block_size * sb.block_count).
|
|
|
|
|
AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(sb.block_count > imagePlugin.Info.Sectors)
|
|
|
|
|
superBlockMetadata.
|
|
|
|
|
AppendFormat("WARNING: Filesystem indicates {0} blocks while device indicates {1} blocks",
|
|
|
|
|
sb.block_count, imagePlugin.Info.Sectors);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +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();
|
2011-03-03 18:34:33 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
superBlockMetadata.AppendFormat("Root directory size: {0} blocks, {1} bytes", sb.rootdir_blocks,
|
|
|
|
|
sb.rootdir_bsize * sb.rootdir_blocks).AppendLine();
|
2015-12-05 17:10:27 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
superBlockMetadata.AppendFormat("Last root directory copy: {0}", sb.last_root_copy).AppendLine();
|
|
|
|
|
|
|
|
|
|
information = superBlockMetadata.ToString();
|
|
|
|
|
|
|
|
|
|
XmlFsType = new FileSystemType
|
|
|
|
|
{
|
|
|
|
|
Type = "Opera",
|
|
|
|
|
VolumeName = StringHandlers.CToString(sb.volume_label, Encoding),
|
|
|
|
|
ClusterSize = sb.block_size,
|
|
|
|
|
Clusters = sb.block_count
|
|
|
|
|
};
|
2014-04-14 02:29:13 +00:00
|
|
|
}
|
2014-04-14 01:14:20 +00:00
|
|
|
}
|