mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Implement decoding Opera directories.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using DiscImageChef.Helpers;
|
||||
|
||||
namespace DiscImageChef.Filesystems
|
||||
{
|
||||
public partial class OperaFS
|
||||
@@ -18,6 +20,7 @@ namespace DiscImageChef.Filesystems
|
||||
/// Catapult
|
||||
/// </summary>
|
||||
const uint TYPE_ZAP = 0x2A7A6170;
|
||||
static readonly int DirectoryEntrySize = Marshal.SizeOf<DirectoryEntry>();
|
||||
|
||||
enum FileFlags : uint
|
||||
{
|
||||
|
||||
@@ -1,11 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DiscImageChef.CommonTypes.Structs;
|
||||
using DiscImageChef.Helpers;
|
||||
|
||||
namespace DiscImageChef.Filesystems
|
||||
{
|
||||
public partial class OperaFS
|
||||
{
|
||||
public Errno ReadDir(string path, out List<string> contents) => throw new NotImplementedException();
|
||||
|
||||
Dictionary<string, DirectoryEntryWithPointers> DecodeDirectory(int firstBlock)
|
||||
{
|
||||
Dictionary<string, DirectoryEntryWithPointers> entries =
|
||||
new Dictionary<string, DirectoryEntryWithPointers>();
|
||||
|
||||
int nextBlock = firstBlock;
|
||||
|
||||
do
|
||||
{
|
||||
byte[] data =
|
||||
image.ReadSectors((ulong)(nextBlock * volumeBlockSizeRatio), volumeBlockSizeRatio);
|
||||
DirectoryHeader header = Marshal.ByteArrayToStructureBigEndian<DirectoryHeader>(data);
|
||||
nextBlock = header.next_block;
|
||||
|
||||
int off = (int)header.first_used;
|
||||
|
||||
DirectoryEntry entry = new DirectoryEntry();
|
||||
|
||||
while(off + DirectoryEntrySize < data.Length)
|
||||
{
|
||||
entry = Marshal.ByteArrayToStructureBigEndian<DirectoryEntry>(data, off, DirectoryEntrySize);
|
||||
string name = StringHandlers.CToString(entry.name, Encoding);
|
||||
|
||||
DirectoryEntryWithPointers entryWithPointers =
|
||||
new DirectoryEntryWithPointers {entry = entry, pointers = new uint[entry.last_copy + 1]};
|
||||
|
||||
for(int i = 0; i <= entry.last_copy; i++)
|
||||
entryWithPointers.pointers[i] =
|
||||
BigEndianBitConverter.ToUInt32(data, off + DirectoryEntrySize + i * 4);
|
||||
|
||||
entries.Add(name, entryWithPointers);
|
||||
|
||||
if((entry.flags & (uint)FileFlags.LastEntry) != 0 ||
|
||||
(entry.flags & (uint)FileFlags.LastEntryInBlock) != 0) break;
|
||||
|
||||
off += (int)(DirectoryEntrySize + (entry.last_copy + 1) * 4);
|
||||
}
|
||||
|
||||
if((entry.flags & (uint)FileFlags.LastEntry) != 0) break;
|
||||
}
|
||||
while(nextBlock != -1);
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,12 @@ namespace DiscImageChef.Filesystems
|
||||
{
|
||||
public partial class OperaFS : IReadOnlyFilesystem
|
||||
{
|
||||
IMediaImage image;
|
||||
bool mounted;
|
||||
Dictionary<string, DirectoryEntryWithPointers> rootDirectoryCache;
|
||||
FileSystemInfo statfs;
|
||||
uint volumeBlockSizeRatio;
|
||||
|
||||
public FileSystemType XmlFsType { get; private set; }
|
||||
public Encoding Encoding { get; private set; }
|
||||
public string Name => "Opera Filesystem Plugin";
|
||||
|
||||
@@ -4,17 +4,74 @@ using System.Text;
|
||||
using DiscImageChef.CommonTypes;
|
||||
using DiscImageChef.CommonTypes.Interfaces;
|
||||
using DiscImageChef.CommonTypes.Structs;
|
||||
using DiscImageChef.Helpers;
|
||||
using Schemas;
|
||||
|
||||
namespace DiscImageChef.Filesystems
|
||||
{
|
||||
public partial class OperaFS
|
||||
{
|
||||
public Errno Mount(IMediaImage imagePlugin, Partition partition, Encoding encoding,
|
||||
Dictionary<string, string> options, string @namespace) =>
|
||||
Dictionary<string, string> options, string @namespace)
|
||||
{
|
||||
// TODO: Find correct default encoding
|
||||
Encoding = Encoding.ASCII;
|
||||
|
||||
byte[] sbSector = imagePlugin.ReadSector(0 + partition.Start);
|
||||
|
||||
SuperBlock sb = Marshal.ByteArrayToStructureBigEndian<SuperBlock>(sbSector);
|
||||
|
||||
if(sb.record_type != 1 || sb.record_version != 1) return Errno.InvalidArgument;
|
||||
if(Encoding.ASCII.GetString(sb.sync_bytes) != SYNC) return Errno.InvalidArgument;
|
||||
|
||||
if(imagePlugin.Info.SectorSize == 2336 || imagePlugin.Info.SectorSize == 2352 ||
|
||||
imagePlugin.Info.SectorSize == 2448) volumeBlockSizeRatio = sb.block_size / 2048;
|
||||
else volumeBlockSizeRatio = sb.block_size / imagePlugin.Info.SectorSize;
|
||||
|
||||
XmlFsType = new FileSystemType
|
||||
{
|
||||
Type = "Opera",
|
||||
VolumeName = StringHandlers.CToString(sb.volume_label, Encoding),
|
||||
ClusterSize = sb.block_size,
|
||||
Clusters = sb.block_count,
|
||||
Bootable = true,
|
||||
VolumeSerial = $"{sb.volume_id:X8}"
|
||||
};
|
||||
|
||||
statfs = new FileSystemInfo
|
||||
{
|
||||
Blocks = sb.block_count,
|
||||
FilenameLength = MAX_NAME,
|
||||
FreeBlocks = 0,
|
||||
Id = new FileSystemId {IsInt = true, Serial32 = sb.volume_id},
|
||||
PluginId = Id,
|
||||
Type = "Opera"
|
||||
};
|
||||
|
||||
image = imagePlugin;
|
||||
int firstRootBlock = BigEndianBitConverter.ToInt32(sbSector, Marshal.SizeOf<SuperBlock>());
|
||||
rootDirectoryCache = DecodeDirectory(firstRootBlock);
|
||||
mounted = true;
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Errno Unmount() => throw new NotImplementedException();
|
||||
public Errno Unmount()
|
||||
{
|
||||
if(!mounted) return Errno.AccessDenied;
|
||||
|
||||
public Errno StatFs(out FileSystemInfo stat) => throw new NotImplementedException();
|
||||
mounted = false;
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
public Errno StatFs(out FileSystemInfo stat)
|
||||
{
|
||||
stat = null;
|
||||
if(!mounted) return Errno.AccessDenied;
|
||||
|
||||
stat = statfs.ShallowCopy();
|
||||
return Errno.NoError;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user