2019-08-01 16:21:10 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.CommonTypes;
|
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
using Aaru.CommonTypes.Structs;
|
|
|
|
|
using Aaru.Helpers;
|
2019-08-01 23:37:21 +01:00
|
|
|
using Schemas;
|
2019-08-01 16:21:10 +01:00
|
|
|
|
2020-02-27 00:33:26 +00:00
|
|
|
namespace Aaru.Filesystems
|
2019-08-01 16:21:10 +01:00
|
|
|
{
|
|
|
|
|
public partial class OperaFS
|
|
|
|
|
{
|
|
|
|
|
public Errno Mount(IMediaImage imagePlugin, Partition partition, Encoding encoding,
|
2019-08-01 23:37:21 +01:00
|
|
|
Dictionary<string, string> options, string @namespace)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Find correct default encoding
|
|
|
|
|
Encoding = Encoding.ASCII;
|
|
|
|
|
|
2019-08-02 00:39:51 +01:00
|
|
|
if(options == null) options = GetDefaultOptions();
|
|
|
|
|
if(options.TryGetValue("debug", out string debugString)) bool.TryParse(debugString, out debug);
|
|
|
|
|
|
2019-08-01 23:37:21 +01:00
|
|
|
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);
|
2019-08-02 01:42:37 +01:00
|
|
|
directoryCache = new Dictionary<string, Dictionary<string, DirectoryEntryWithPointers>>();
|
2019-08-01 23:37:21 +01:00
|
|
|
mounted = true;
|
|
|
|
|
|
2019-08-02 01:42:37 +01:00
|
|
|
return Errno.NoError;
|
2019-08-01 23:37:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Errno Unmount()
|
|
|
|
|
{
|
|
|
|
|
if(!mounted) return Errno.AccessDenied;
|
|
|
|
|
|
|
|
|
|
mounted = false;
|
|
|
|
|
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
}
|
2019-08-01 16:21:10 +01:00
|
|
|
|
2019-08-01 23:37:21 +01:00
|
|
|
public Errno StatFs(out FileSystemInfo stat)
|
|
|
|
|
{
|
|
|
|
|
stat = null;
|
|
|
|
|
if(!mounted) return Errno.AccessDenied;
|
2019-08-01 16:21:10 +01:00
|
|
|
|
2019-08-01 23:37:21 +01:00
|
|
|
stat = statfs.ShallowCopy();
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
}
|
2019-08-01 16:21:10 +01:00
|
|
|
}
|
|
|
|
|
}
|