2020-03-11 21:56:55 +00:00
|
|
|
// /***************************************************************************
|
|
|
|
|
// Aaru Data Preservation Suite
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Super.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : Opera filesystem plugin.
|
|
|
|
|
//
|
|
|
|
|
// --[ 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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2024-12-19 10:45:18 +00:00
|
|
|
// Copyright © 2011-2025 Natalia Portillo
|
2020-03-11 21:56:55 +00:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
2019-08-01 16:21:10 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
2022-12-15 22:21:07 +00:00
|
|
|
using Aaru.CommonTypes.AaruMetadata;
|
2021-09-16 04:42:14 +01:00
|
|
|
using Aaru.CommonTypes.Enums;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
using Aaru.CommonTypes.Structs;
|
|
|
|
|
using Aaru.Helpers;
|
2025-08-14 15:51:32 +01:00
|
|
|
using FileSystemInfo = Aaru.CommonTypes.Structs.FileSystemInfo;
|
2022-12-15 22:21:07 +00:00
|
|
|
using Partition = Aaru.CommonTypes.Partition;
|
2019-08-01 16:21:10 +01:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
namespace Aaru.Filesystems;
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
public sealed partial class OperaFS
|
2019-08-01 16:21:10 +01:00
|
|
|
{
|
2023-10-03 23:22:08 +01:00
|
|
|
#region IReadOnlyFilesystem Members
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
2023-10-03 23:22:08 +01:00
|
|
|
public ErrorNumber Mount(IMediaImage imagePlugin, Partition partition, Encoding encoding,
|
|
|
|
|
Dictionary<string, string> options, string @namespace)
|
2019-08-01 16:21:10 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
// TODO: Find correct default encoding
|
2022-12-17 23:17:18 +00:00
|
|
|
_encoding = Encoding.ASCII;
|
2019-08-01 23:37:21 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
options ??= GetDefaultOptions();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(options.TryGetValue("debug", out string debugString)) bool.TryParse(debugString, out _debug);
|
2019-08-02 00:39:51 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ErrorNumber errno = imagePlugin.ReadSector(0 + partition.Start, out byte[] sbSector);
|
2021-09-19 21:16:47 +01:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(errno != ErrorNumber.NoError) return errno;
|
2019-08-01 23:37:21 +01:00
|
|
|
|
2025-10-21 11:43:05 +01:00
|
|
|
SuperBlock sb = Marshal.ByteArrayToStructureBigEndian<SuperBlock>(sbSector);
|
2019-08-01 23:37:21 +01:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(sb.record_type != 1 || sb.record_version != 1) return ErrorNumber.InvalidArgument;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(Encoding.ASCII.GetString(sb.sync_bytes) != SYNC) return ErrorNumber.InvalidArgument;
|
2019-08-01 23:37:21 +01:00
|
|
|
|
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
|
|
|
_volumeBlockSizeRatio = sb.block_size / 2048;
|
|
|
|
|
else
|
|
|
|
|
_volumeBlockSizeRatio = sb.block_size / imagePlugin.Info.SectorSize;
|
2019-08-01 23:37:21 +01:00
|
|
|
|
2022-12-15 22:21:07 +00:00
|
|
|
Metadata = new FileSystem
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
2022-11-28 02:59:53 +00:00
|
|
|
Type = FS_TYPE,
|
2022-12-17 23:17:18 +00:00
|
|
|
VolumeName = StringHandlers.CToString(sb.volume_label, _encoding),
|
2022-03-06 13:29:38 +00:00
|
|
|
ClusterSize = sb.block_size,
|
|
|
|
|
Clusters = sb.block_count,
|
|
|
|
|
Bootable = true,
|
|
|
|
|
VolumeSerial = $"{sb.volume_id:X8}"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_statfs = new FileSystemInfo
|
2019-08-01 23:37:21 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
Blocks = sb.block_count,
|
|
|
|
|
FilenameLength = MAX_NAME,
|
|
|
|
|
FreeBlocks = 0,
|
|
|
|
|
Id = new FileSystemId
|
|
|
|
|
{
|
|
|
|
|
IsInt = true,
|
|
|
|
|
Serial32 = sb.volume_id
|
|
|
|
|
},
|
|
|
|
|
PluginId = Id,
|
2022-11-28 02:59:53 +00:00
|
|
|
Type = FS_TYPE
|
2022-03-06 13:29:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_image = imagePlugin;
|
2025-08-14 15:51:32 +01:00
|
|
|
int firstRootBlock = BigEndianBitConverter.ToInt32(sbSector, Marshal.SizeOf<SuperBlock>());
|
2022-03-06 13:29:38 +00:00
|
|
|
_rootDirectoryCache = DecodeDirectory(firstRootBlock);
|
|
|
|
|
_directoryCache = new Dictionary<string, Dictionary<string, DirectoryEntryWithPointers>>();
|
|
|
|
|
_mounted = true;
|
|
|
|
|
|
|
|
|
|
return ErrorNumber.NoError;
|
|
|
|
|
}
|
2019-08-01 23:37:21 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public ErrorNumber Unmount()
|
|
|
|
|
{
|
2024-05-01 04:05:22 +01:00
|
|
|
if(!_mounted) return ErrorNumber.AccessDenied;
|
2019-08-01 23:37:21 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
_mounted = false;
|
2019-08-01 16:21:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return ErrorNumber.NoError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public ErrorNumber StatFs(out FileSystemInfo stat)
|
|
|
|
|
{
|
|
|
|
|
stat = null;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(!_mounted) return ErrorNumber.AccessDenied;
|
2019-08-01 16:21:10 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
stat = _statfs.ShallowCopy();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return ErrorNumber.NoError;
|
2019-08-01 16:21:10 +01:00
|
|
|
}
|
2023-10-03 23:22:08 +01:00
|
|
|
|
|
|
|
|
#endregion
|
2019-08-01 16:21:10 +01:00
|
|
|
}
|