Use Aaru Metadata instead of CICM Metadata.

This commit is contained in:
2022-12-15 22:21:07 +00:00
parent 031f871a2d
commit cfbcde35f5
346 changed files with 11377 additions and 8653 deletions

View File

@@ -154,7 +154,7 @@ public sealed partial class FAT
bool correctSpcApricot = apricotBpb.mainBPB.spc is 1 or 2 or 4 or 8 or 16 or 32 or 64;
// This is to support FAT partitions on hybrid ISO/USB images
if(imagePlugin.Info.XmlMediaType == XmlMediaType.OpticalDisc)
if(imagePlugin.Info.MetadataMediaType == MetadataMediaType.OpticalDisc)
{
atariBpb.sectors /= 4;
msxBpb.sectors /= 4;

View File

@@ -30,9 +30,9 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using Aaru.CommonTypes.AaruMetadata;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using Schemas;
namespace Aaru.Filesystems;
@@ -64,7 +64,7 @@ public sealed partial class FAT : IReadOnlyFilesystem
bool _useFirstFat;
/// <inheritdoc />
public FileSystemType XmlFsType { get; private set; }
public FileSystem Metadata { get; private set; }
/// <inheritdoc />
public Encoding Encoding { get; private set; }
/// <inheritdoc />

View File

@@ -225,7 +225,7 @@ public sealed partial class FAT
if(startCluster == 0)
return Array.Empty<uint>();
if(startCluster >= XmlFsType.Clusters)
if(startCluster >= Metadata.Clusters)
return null;
List<uint> clusters = new();

View File

@@ -33,13 +33,13 @@ using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using Aaru.Checksums;
using Aaru.CommonTypes;
using Aaru.CommonTypes.AaruMetadata;
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces;
using Aaru.Console;
using Aaru.Helpers;
using Schemas;
using Marshal = Aaru.Helpers.Marshal;
using Partition = Aaru.CommonTypes.Partition;
namespace Aaru.Filesystems;
@@ -197,7 +197,7 @@ public sealed partial class FAT
AaruConsole.DebugWriteLine("FAT plugin", "apricot_fat_sectors = {0}", apricotFatSectors);
// This is to support FAT partitions on hybrid ISO/USB images
if(imagePlugin.Info.XmlMediaType == XmlMediaType.OpticalDisc)
if(imagePlugin.Info.MetadataMediaType == MetadataMediaType.OpticalDisc)
{
sectors /= 4;
bigSectors /= 4;
@@ -427,7 +427,7 @@ public sealed partial class FAT
information = "";
var sb = new StringBuilder();
XmlFsType = new FileSystemType();
Metadata = new FileSystem();
uint sectorsPerBpb = imagePlugin.Info.SectorSize < 512 ? 512 / imagePlugin.Info.SectorSize : 1;
@@ -446,7 +446,7 @@ public sealed partial class FAT
ulong rootDirectorySector = 0;
string extraInfo = null;
string bootChk = null;
XmlFsType.Bootable = bootable;
Metadata.Bootable = bootable;
// This is needed because for FAT16, GEMDOS increases bytes per sector count instead of using big_sectors field.
uint sectorsPerRealSector;
@@ -474,7 +474,7 @@ public sealed partial class FAT
Marshal.ByteArrayToStructureLittleEndian<Fat32ParameterBlockShort>(bpbSector);
// This is to support FAT partitions on hybrid ISO/USB images
if(imagePlugin.Info.XmlMediaType == XmlMediaType.OpticalDisc)
if(imagePlugin.Info.MetadataMediaType == MetadataMediaType.OpticalDisc)
{
fat32Bpb.bps *= 4;
fat32Bpb.spc /= 4;
@@ -486,12 +486,12 @@ public sealed partial class FAT
if(fat32Bpb.version != 0)
{
sb.AppendLine(Localization.FAT_Plus);
XmlFsType.Type = FS_TYPE_FAT_PLUS;
Metadata.Type = FS_TYPE_FAT_PLUS;
}
else
{
sb.AppendLine(Localization.Microsoft_FAT32);
XmlFsType.Type = FS_TYPE_FAT32;
Metadata.Type = FS_TYPE_FAT32;
}
if(fat32Bpb.oem_name != null)
@@ -500,14 +500,14 @@ public sealed partial class FAT
fat32Bpb.oem_name[7] == 0x43)
sb.AppendLine(Localization.Volume_has_been_modified_by_Windows_9x_Me_Volume_Tracker);
else
XmlFsType.SystemIdentifier = StringHandlers.CToString(fat32Bpb.oem_name);
Metadata.SystemIdentifier = StringHandlers.CToString(fat32Bpb.oem_name);
if(!string.IsNullOrEmpty(XmlFsType.SystemIdentifier))
sb.AppendFormat(Localization.OEM_name_0, XmlFsType.SystemIdentifier.Trim()).AppendLine();
if(!string.IsNullOrEmpty(Metadata.SystemIdentifier))
sb.AppendFormat(Localization.OEM_name_0, Metadata.SystemIdentifier.Trim()).AppendLine();
sb.AppendFormat(Localization._0_bytes_per_sector, fat32Bpb.bps).AppendLine();
sb.AppendFormat(Localization._0_sectors_per_cluster, fat32Bpb.spc).AppendLine();
XmlFsType.ClusterSize = (uint)(fat32Bpb.bps * fat32Bpb.spc);
Metadata.ClusterSize = (uint)(fat32Bpb.bps * fat32Bpb.spc);
sb.AppendFormat(Localization._0_sectors_reserved_between_BPB_and_FAT, fat32Bpb.rsectors).AppendLine();
if(fat32Bpb is { big_sectors: 0, signature: 0x28 })
@@ -515,24 +515,24 @@ public sealed partial class FAT
sb.AppendFormat(Localization._0_sectors_on_volume_1_bytes, shortFat32Bpb.huge_sectors,
shortFat32Bpb.huge_sectors * shortFat32Bpb.bps).AppendLine();
XmlFsType.Clusters = shortFat32Bpb.huge_sectors / shortFat32Bpb.spc;
Metadata.Clusters = shortFat32Bpb.huge_sectors / shortFat32Bpb.spc;
}
else if(fat32Bpb.sectors == 0)
{
sb.AppendFormat(Localization._0_sectors_on_volume_1_bytes, fat32Bpb.big_sectors,
fat32Bpb.big_sectors * fat32Bpb.bps).AppendLine();
XmlFsType.Clusters = fat32Bpb.big_sectors / fat32Bpb.spc;
Metadata.Clusters = fat32Bpb.big_sectors / fat32Bpb.spc;
}
else
{
sb.AppendFormat(Localization._0_sectors_on_volume_1_bytes, fat32Bpb.sectors,
fat32Bpb.sectors * fat32Bpb.bps).AppendLine();
XmlFsType.Clusters = (ulong)(fat32Bpb.sectors / fat32Bpb.spc);
Metadata.Clusters = (ulong)(fat32Bpb.sectors / fat32Bpb.spc);
}
sb.AppendFormat(Localization._0_clusters_on_volume, XmlFsType.Clusters).AppendLine();
sb.AppendFormat(Localization._0_clusters_on_volume, Metadata.Clusters).AppendLine();
sb.AppendFormat(Localization.Media_descriptor_0, fat32Bpb.media).AppendLine();
sb.AppendFormat(Localization._0_sectors_per_FAT, fat32Bpb.big_spfat).AppendLine();
sb.AppendFormat(Localization._0_sectors_per_track, fat32Bpb.sptrk).AppendLine();
@@ -546,14 +546,14 @@ public sealed partial class FAT
sb.AppendFormat(Localization.Drive_number_0, fat32Bpb.drive_no).AppendLine();
sb.AppendFormat(Localization.Volume_Serial_Number_0, fat32Bpb.serial_no).AppendLine();
XmlFsType.VolumeSerial = $"{fat32Bpb.serial_no:X8}";
Metadata.VolumeSerial = $"{fat32Bpb.serial_no:X8}";
if((fat32Bpb.flags & 0xF8) == 0x00)
{
if((fat32Bpb.flags & 0x01) == 0x01)
{
sb.AppendLine(Localization.Volume_should_be_checked_on_next_mount);
XmlFsType.Dirty = true;
Metadata.Dirty = true;
}
if((fat32Bpb.flags & 0x02) == 0x02)
@@ -573,8 +573,8 @@ public sealed partial class FAT
if(fat32Bpb.signature == 0x29)
{
XmlFsType.VolumeName = StringHandlers.SpacePaddedToString(fat32Bpb.volume_label, Encoding);
XmlFsType.VolumeName = XmlFsType.VolumeName?.Replace("\0", "");
Metadata.VolumeName = StringHandlers.SpacePaddedToString(fat32Bpb.volume_label, Encoding);
Metadata.VolumeName = Metadata.VolumeName?.Replace("\0", "");
sb.AppendFormat(Localization.Filesystem_type_0, Encoding.ASCII.GetString(fat32Bpb.fs_type)).
AppendLine();
@@ -586,7 +586,7 @@ public sealed partial class FAT
// Check that jumps to a correct boot code position and has boot signature set.
// This will mean that the volume will boot, even if just to say "this is not bootable change disk"......
XmlFsType.Bootable =
Metadata.Bootable =
(fat32Bpb.jump[0] == 0xEB && fat32Bpb.jump[1] >= minBootNearJump && fat32Bpb.jump[1] < 0x80) ||
(fat32Bpb.jump[0] == 0xE9 && fat32Bpb.jump.Length >= 3 &&
BitConverter.ToUInt16(fat32Bpb.jump, 1) >= minBootNearJump &&
@@ -616,8 +616,7 @@ public sealed partial class FAT
if(fsInfo.free_clusters < 0xFFFFFFFF)
{
sb.AppendFormat(Localization._0_free_clusters, fsInfo.free_clusters).AppendLine();
XmlFsType.FreeClusters = fsInfo.free_clusters;
XmlFsType.FreeClustersSpecified = true;
Metadata.FreeClusters = fsInfo.free_clusters;
}
if(fsInfo.last_cluster is > 2 and < 0xFFFFFFFF)
@@ -639,7 +638,7 @@ public sealed partial class FAT
// TODO: Check this
if(sum == 0x1234)
{
XmlFsType.Bootable = true;
Metadata.Bootable = true;
var atariSb = new StringBuilder();
atariSb.AppendFormat(Localization.cmdload_will_be_loaded_with_value_0,
@@ -680,7 +679,7 @@ public sealed partial class FAT
}
case BpbKind.Human:
XmlFsType.Bootable = true;
Metadata.Bootable = true;
break;
}
@@ -688,7 +687,7 @@ public sealed partial class FAT
if(!isFat32)
{
// This is to support FAT partitions on hybrid ISO/USB images
if(imagePlugin.Info.XmlMediaType == XmlMediaType.OpticalDisc)
if(imagePlugin.Info.MetadataMediaType == MetadataMediaType.OpticalDisc)
{
fakeBpb.bps *= 4;
fakeBpb.spc /= 4;
@@ -803,7 +802,7 @@ public sealed partial class FAT
break;
}
XmlFsType.Type = FS_TYPE_FAT12;
Metadata.Type = FS_TYPE_FAT12;
}
else if(isFat16)
{
@@ -814,7 +813,7 @@ public sealed partial class FAT
_ => Localization.Microsoft_FAT16
});
XmlFsType.Type = FS_TYPE_FAT16;
Metadata.Type = FS_TYPE_FAT16;
}
if(bpbKind == BpbKind.Atari)
@@ -824,13 +823,13 @@ public sealed partial class FAT
atariBpb.serial_no[2] == 0x43)
sb.AppendLine(Localization.Volume_has_been_modified_by_Windows_9x_Me_Volume_Tracker);
else
XmlFsType.VolumeSerial = $"{atariBpb.serial_no[0]:X2}{atariBpb.serial_no[1]:X2}{
atariBpb.serial_no[2]:X2}";
Metadata.VolumeSerial = $"{atariBpb.serial_no[0]:X2}{atariBpb.serial_no[1]:X2}{atariBpb.serial_no[2]
:X2}";
XmlFsType.SystemIdentifier = StringHandlers.CToString(atariBpb.oem_name);
Metadata.SystemIdentifier = StringHandlers.CToString(atariBpb.oem_name);
if(string.IsNullOrEmpty(XmlFsType.SystemIdentifier))
XmlFsType.SystemIdentifier = null;
if(string.IsNullOrEmpty(Metadata.SystemIdentifier))
Metadata.SystemIdentifier = null;
}
else if(fakeBpb.oem_name != null)
{
@@ -839,7 +838,7 @@ public sealed partial class FAT
fakeBpb.oem_name[7] == 0x43)
sb.AppendLine(Localization.Volume_has_been_modified_by_Windows_9x_Me_Volume_Tracker);
else
XmlFsType.SystemIdentifier = fakeBpb.oem_name[0] switch
Metadata.SystemIdentifier = fakeBpb.oem_name[0] switch
{
// Later versions of Windows create a DOS 3 BPB without OEM name on 8 sectors/track floppies
// OEM ID should be ASCII, otherwise ignore it
@@ -861,15 +860,15 @@ public sealed partial class FAT
fakeBpb.oem_name[7] >= 0x20 &&
fakeBpb.oem_name[7] <= 0x7F => StringHandlers.CToString(fakeBpb.oem_name, Encoding,
start: 1),
_ => XmlFsType.SystemIdentifier
_ => Metadata.SystemIdentifier
};
if(fakeBpb.signature is 0x28 or 0x29)
XmlFsType.VolumeSerial = $"{fakeBpb.serial_no:X8}";
Metadata.VolumeSerial = $"{fakeBpb.serial_no:X8}";
}
if(XmlFsType.SystemIdentifier != null)
sb.AppendFormat(Localization.OEM_name_0, XmlFsType.SystemIdentifier.Trim()).AppendLine();
if(Metadata.SystemIdentifier != null)
sb.AppendFormat(Localization.OEM_name_0, Metadata.SystemIdentifier.Trim()).AppendLine();
sb.AppendFormat(Localization._0_bytes_per_sector, fakeBpb.bps).AppendLine();
@@ -885,10 +884,10 @@ public sealed partial class FAT
clusters * humanBpb.bpc / imagePlugin.Info.SectorSize, clusters * humanBpb.bpc).
AppendLine();
XmlFsType.Clusters = clusters;
Metadata.Clusters = clusters;
sb.AppendFormat(Localization._0_sectors_per_cluster, fakeBpb.spc).AppendLine();
sb.AppendFormat(Localization._0_clusters_on_volume, XmlFsType.Clusters).AppendLine();
XmlFsType.ClusterSize = (uint)(fakeBpb.bps * fakeBpb.spc);
sb.AppendFormat(Localization._0_clusters_on_volume, Metadata.Clusters).AppendLine();
Metadata.ClusterSize = (uint)(fakeBpb.bps * fakeBpb.spc);
sb.AppendFormat(Localization._0_sectors_reserved_between_BPB_and_FAT, fakeBpb.rsectors).AppendLine();
sb.AppendFormat(Localization._0_FATs, fakeBpb.fats_no).AppendLine();
sb.AppendFormat(Localization._0_entries_on_root_directory, fakeBpb.root_ent).AppendLine();
@@ -912,15 +911,15 @@ public sealed partial class FAT
{
sb.AppendFormat(Localization.Drive_number_0, fakeBpb.drive_no).AppendLine();
if(XmlFsType.VolumeSerial != null)
sb.AppendFormat(Localization.Volume_Serial_Number_0, XmlFsType.VolumeSerial).AppendLine();
if(Metadata.VolumeSerial != null)
sb.AppendFormat(Localization.Volume_Serial_Number_0, Metadata.VolumeSerial).AppendLine();
if((fakeBpb.flags & 0xF8) == 0x00)
{
if((fakeBpb.flags & 0x01) == 0x01)
{
sb.AppendLine(Localization.Volume_should_be_checked_on_next_mount);
XmlFsType.Dirty = true;
Metadata.Dirty = true;
}
if((fakeBpb.flags & 0x02) == 0x02)
@@ -929,28 +928,28 @@ public sealed partial class FAT
if(fakeBpb.signature == 0x29 || andosOemCorrect)
{
XmlFsType.VolumeName = StringHandlers.SpacePaddedToString(fakeBpb.volume_label, Encoding);
XmlFsType.VolumeName = XmlFsType.VolumeName?.Replace("\0", "");
Metadata.VolumeName = StringHandlers.SpacePaddedToString(fakeBpb.volume_label, Encoding);
Metadata.VolumeName = Metadata.VolumeName?.Replace("\0", "");
sb.AppendFormat(Localization.Filesystem_type_0, Encoding.ASCII.GetString(fakeBpb.fs_type)).
AppendLine();
}
}
else if(bpbKind == BpbKind.Atari &&
XmlFsType.VolumeSerial != null)
sb.AppendFormat(Localization.Volume_Serial_Number_0, XmlFsType.VolumeSerial).AppendLine();
else if(bpbKind == BpbKind.Atari &&
Metadata.VolumeSerial != null)
sb.AppendFormat(Localization.Volume_Serial_Number_0, Metadata.VolumeSerial).AppendLine();
bootChk = Sha1Context.Data(fakeBpb.boot_code, out _);
// Workaround that PCExchange jumps into "FAT16 "...
if(XmlFsType.SystemIdentifier == "PCX 2.0 ")
if(Metadata.SystemIdentifier == "PCX 2.0 ")
fakeBpb.jump[1] += 8;
// Check that jumps to a correct boot code position and has boot signature set.
// This will mean that the volume will boot, even if just to say "this is not bootable change disk"......
if(XmlFsType.Bootable == false &&
fakeBpb.jump != null)
XmlFsType.Bootable |=
if(Metadata.Bootable == false &&
fakeBpb.jump != null)
Metadata.Bootable |=
(fakeBpb.jump[0] == 0xEB && fakeBpb.jump[1] >= minBootNearJump && fakeBpb.jump[1] < 0x80) ||
(fakeBpb.jump[0] == 0xE9 && fakeBpb.jump.Length >= 3 &&
BitConverter.ToUInt16(fakeBpb.jump, 1) >= minBootNearJump &&
@@ -968,7 +967,7 @@ public sealed partial class FAT
sb.Append(extraInfo);
if(rootDirectorySector + partition.Start < partition.End &&
imagePlugin.Info.XmlMediaType != XmlMediaType.OpticalDisc)
imagePlugin.Info.MetadataMediaType != MetadataMediaType.OpticalDisc)
{
errno = imagePlugin.ReadSectors(rootDirectorySector + partition.Start, sectorsForRootDirectory,
out byte[] rootDirectory);
@@ -1021,24 +1020,22 @@ public sealed partial class FAT
string volname = Encoding.GetString(fullname).Trim();
if(!string.IsNullOrEmpty(volname))
XmlFsType.VolumeName = entry.caseinfo.HasFlag(CaseInfo.AllLowerCase) ? volname.ToLower() : volname;
Metadata.VolumeName = entry.caseinfo.HasFlag(CaseInfo.AllLowerCase) ? volname.ToLower() : volname;
if(entry is { ctime: > 0, cdate: > 0 })
{
XmlFsType.CreationDate = DateHandlers.DosToDateTime(entry.cdate, entry.ctime);
Metadata.CreationDate = DateHandlers.DosToDateTime(entry.cdate, entry.ctime);
if(entry.ctime_ms > 0)
XmlFsType.CreationDate = XmlFsType.CreationDate.AddMilliseconds(entry.ctime_ms * 10);
Metadata.CreationDate = Metadata.CreationDate?.AddMilliseconds(entry.ctime_ms * 10);
XmlFsType.CreationDateSpecified = true;
sb.AppendFormat(Localization.Volume_created_on_0, XmlFsType.CreationDate).AppendLine();
sb.AppendFormat(Localization.Volume_created_on_0, Metadata.CreationDate).AppendLine();
}
if(entry is { mtime: > 0, mdate: > 0 })
{
XmlFsType.ModificationDate = DateHandlers.DosToDateTime(entry.mdate, entry.mtime);
XmlFsType.ModificationDateSpecified = true;
sb.AppendFormat(Localization.Volume_last_modified_on_0, XmlFsType.ModificationDate).AppendLine();
Metadata.ModificationDate = DateHandlers.DosToDateTime(entry.mdate, entry.mtime);
sb.AppendFormat(Localization.Volume_last_modified_on_0, Metadata.ModificationDate).AppendLine();
}
if(entry.adate > 0)
@@ -1049,10 +1046,10 @@ public sealed partial class FAT
}
}
if(!string.IsNullOrEmpty(XmlFsType.VolumeName))
sb.AppendFormat(Localization.Volume_label_0, XmlFsType.VolumeName).AppendLine();
if(!string.IsNullOrEmpty(Metadata.VolumeName))
sb.AppendFormat(Localization.Volume_label_0, Metadata.VolumeName).AppendLine();
if(XmlFsType.Bootable)
if(Metadata.Bootable)
{
switch(bpbSector[0])
{

View File

@@ -33,15 +33,15 @@ using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using Aaru.CommonTypes;
using Aaru.CommonTypes.AaruMetadata;
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using Aaru.Console;
using Aaru.Helpers;
using Schemas;
using FileSystemInfo = Aaru.CommonTypes.Structs.FileSystemInfo;
using Marshal = Aaru.Helpers.Marshal;
using Partition = Aaru.CommonTypes.Partition;
namespace Aaru.Filesystems;
@@ -54,7 +54,7 @@ public sealed partial class FAT
public ErrorNumber Mount(IMediaImage imagePlugin, Partition partition, Encoding encoding,
Dictionary<string, string> options, string @namespace)
{
XmlFsType = new FileSystemType();
Metadata = new FileSystem();
options ??= GetDefaultOptions();
@@ -106,11 +106,11 @@ public sealed partial class FAT
out HumanParameterBlock humanBpb, out AtariParameterBlock atariBpb,
out byte minBootNearJump, out bool andosOemCorrect, out bool bootable);
_fat12 = false;
_fat16 = false;
_fat32 = false;
_useFirstFat = true;
XmlFsType.Bootable = bootable;
_fat12 = false;
_fat16 = false;
_fat32 = false;
_useFirstFat = true;
Metadata.Bootable = bootable;
_statfs = new FileSystemInfo
{
@@ -153,7 +153,7 @@ public sealed partial class FAT
rootDirectoryCluster = fat32Bpb.root_cluster;
// This is to support FAT partitions on hybrid ISO/USB images
if(imagePlugin.Info.XmlMediaType == XmlMediaType.OpticalDisc)
if(imagePlugin.Info.MetadataMediaType == MetadataMediaType.OpticalDisc)
{
fat32Bpb.bps *= 4;
fat32Bpb.spc /= 4;
@@ -162,25 +162,25 @@ public sealed partial class FAT
fat32Bpb.sptrk /= 4;
}
XmlFsType.Type = fat32Bpb.version != 0 ? FS_TYPE_FAT_PLUS : FS_TYPE_FAT32;
Metadata.Type = fat32Bpb.version != 0 ? FS_TYPE_FAT_PLUS : FS_TYPE_FAT32;
if(fat32Bpb.oem_name != null &&
(fat32Bpb.oem_name[5] != 0x49 || fat32Bpb.oem_name[6] != 0x48 || fat32Bpb.oem_name[7] != 0x43))
XmlFsType.SystemIdentifier = StringHandlers.CToString(fat32Bpb.oem_name);
Metadata.SystemIdentifier = StringHandlers.CToString(fat32Bpb.oem_name);
_sectorsPerCluster = fat32Bpb.spc;
XmlFsType.ClusterSize = (uint)(fat32Bpb.bps * fat32Bpb.spc);
_reservedSectors = fat32Bpb.rsectors;
_sectorsPerCluster = fat32Bpb.spc;
Metadata.ClusterSize = (uint)(fat32Bpb.bps * fat32Bpb.spc);
_reservedSectors = fat32Bpb.rsectors;
if(fat32Bpb is { big_sectors: 0, signature: 0x28 })
XmlFsType.Clusters = shortFat32Bpb.huge_sectors / shortFat32Bpb.spc;
Metadata.Clusters = shortFat32Bpb.huge_sectors / shortFat32Bpb.spc;
else if(fat32Bpb.sectors == 0)
XmlFsType.Clusters = fat32Bpb.big_sectors / fat32Bpb.spc;
Metadata.Clusters = fat32Bpb.big_sectors / fat32Bpb.spc;
else
XmlFsType.Clusters = (ulong)(fat32Bpb.sectors / fat32Bpb.spc);
Metadata.Clusters = (ulong)(fat32Bpb.sectors / fat32Bpb.spc);
_sectorsPerFat = fat32Bpb.big_spfat;
XmlFsType.VolumeSerial = $"{fat32Bpb.serial_no:X8}";
_sectorsPerFat = fat32Bpb.big_spfat;
Metadata.VolumeSerial = $"{fat32Bpb.serial_no:X8}";
_statfs.Id = new FileSystemId
{
@@ -190,20 +190,20 @@ public sealed partial class FAT
if((fat32Bpb.flags & 0xF8) == 0x00)
if((fat32Bpb.flags & 0x01) == 0x01)
XmlFsType.Dirty = true;
Metadata.Dirty = true;
if((fat32Bpb.mirror_flags & 0x80) == 0x80)
_useFirstFat = (fat32Bpb.mirror_flags & 0xF) != 1;
if(fat32Bpb.signature == 0x29)
{
XmlFsType.VolumeName = StringHandlers.SpacePaddedToString(fat32Bpb.volume_label, Encoding);
XmlFsType.VolumeName = XmlFsType.VolumeName?.Replace("\0", "");
Metadata.VolumeName = StringHandlers.SpacePaddedToString(fat32Bpb.volume_label, Encoding);
Metadata.VolumeName = Metadata.VolumeName?.Replace("\0", "");
}
// Check that jumps to a correct boot code position and has boot signature set.
// This will mean that the volume will boot, even if just to say "this is not bootable change disk"......
XmlFsType.Bootable =
Metadata.Bootable =
(fat32Bpb.jump[0] == 0xEB && fat32Bpb.jump[1] >= minBootNearJump && fat32Bpb.jump[1] < 0x80) ||
(fat32Bpb.jump[0] == 0xE9 && fat32Bpb.jump.Length >= 3 &&
BitConverter.ToUInt16(fat32Bpb.jump, 1) >= minBootNearJump &&
@@ -229,8 +229,7 @@ public sealed partial class FAT
if(fsInfo is { signature1: FSINFO_SIGNATURE1, signature2 : FSINFO_SIGNATURE2 }
and { signature3 : FSINFO_SIGNATURE3, free_clusters: < 0xFFFFFFFF })
{
XmlFsType.FreeClusters = fsInfo.free_clusters;
XmlFsType.FreeClustersSpecified = true;
Metadata.FreeClusters = fsInfo.free_clusters;
}
}
@@ -247,7 +246,7 @@ public sealed partial class FAT
// TODO: Check this
if(sum == 0x1234)
XmlFsType.Bootable = true;
Metadata.Bootable = true;
// BGM changes the bytes per sector instead of changing the sectors per cluster. Why?! WHY!?
uint ratio = fakeBpb.bps / imagePlugin.Info.SectorSize;
@@ -267,7 +266,7 @@ public sealed partial class FAT
if(!_debug)
_namespace = Namespace.Human;
XmlFsType.Bootable = true;
Metadata.Bootable = true;
break;
}
@@ -277,7 +276,7 @@ public sealed partial class FAT
if(!_fat32)
{
// This is to support FAT partitions on hybrid ISO/USB images
if(imagePlugin.Info.XmlMediaType == XmlMediaType.OpticalDisc)
if(imagePlugin.Info.MetadataMediaType == MetadataMediaType.OpticalDisc)
{
fakeBpb.bps *= 4;
fakeBpb.spc /= 4;
@@ -373,9 +372,9 @@ public sealed partial class FAT
}
if(_fat12)
XmlFsType.Type = FS_TYPE_FAT12;
Metadata.Type = FS_TYPE_FAT12;
else if(_fat16)
XmlFsType.Type = FS_TYPE_FAT16;
Metadata.Type = FS_TYPE_FAT16;
if(bpbKind == BpbKind.Atari)
{
@@ -383,8 +382,8 @@ public sealed partial class FAT
atariBpb.serial_no[1] != 0x48 ||
atariBpb.serial_no[2] != 0x43)
{
XmlFsType.VolumeSerial = $"{atariBpb.serial_no[0]:X2}{atariBpb.serial_no[1]:X2}{
atariBpb.serial_no[2]:X2}";
Metadata.VolumeSerial = $"{atariBpb.serial_no[0]:X2}{atariBpb.serial_no[1]:X2}{atariBpb.serial_no[2]
:X2}";
_statfs.Id = new FileSystemId
{
@@ -394,17 +393,17 @@ public sealed partial class FAT
};
}
XmlFsType.SystemIdentifier = StringHandlers.CToString(atariBpb.oem_name);
Metadata.SystemIdentifier = StringHandlers.CToString(atariBpb.oem_name);
if(string.IsNullOrEmpty(XmlFsType.SystemIdentifier))
XmlFsType.SystemIdentifier = null;
if(string.IsNullOrEmpty(Metadata.SystemIdentifier))
Metadata.SystemIdentifier = null;
}
else if(fakeBpb.oem_name != null)
{
if(fakeBpb.oem_name[5] != 0x49 ||
fakeBpb.oem_name[6] != 0x48 ||
fakeBpb.oem_name[7] != 0x43)
XmlFsType.SystemIdentifier = fakeBpb.oem_name[0] switch
Metadata.SystemIdentifier = fakeBpb.oem_name[0] switch
{
// Later versions of Windows create a DOS 3 BPB without OEM name on 8 sectors/track floppies
// OEM ID should be ASCII, otherwise ignore it
@@ -426,12 +425,12 @@ public sealed partial class FAT
fakeBpb.oem_name[7] >= 0x20 &&
fakeBpb.oem_name[7] <= 0x7F => StringHandlers.CToString(fakeBpb.oem_name, Encoding,
start: 1),
_ => XmlFsType.SystemIdentifier
_ => Metadata.SystemIdentifier
};
if(fakeBpb.signature is 0x28 or 0x29)
{
XmlFsType.VolumeSerial = $"{fakeBpb.serial_no:X8}";
Metadata.VolumeSerial = $"{fakeBpb.serial_no:X8}";
_statfs.Id = new FileSystemId
{
@@ -441,34 +440,34 @@ public sealed partial class FAT
}
}
XmlFsType.Clusters = clusters;
_sectorsPerCluster = fakeBpb.spc;
XmlFsType.ClusterSize = (uint)(fakeBpb.bps * fakeBpb.spc);
_reservedSectors = fakeBpb.rsectors;
_sectorsPerFat = fakeBpb.spfat;
Metadata.Clusters = clusters;
_sectorsPerCluster = fakeBpb.spc;
Metadata.ClusterSize = (uint)(fakeBpb.bps * fakeBpb.spc);
_reservedSectors = fakeBpb.rsectors;
_sectorsPerFat = fakeBpb.spfat;
if(fakeBpb.signature is 0x28 or 0x29 || andosOemCorrect)
{
if((fakeBpb.flags & 0xF8) == 0x00)
if((fakeBpb.flags & 0x01) == 0x01)
XmlFsType.Dirty = true;
Metadata.Dirty = true;
if(fakeBpb.signature == 0x29 || andosOemCorrect)
{
XmlFsType.VolumeName = StringHandlers.SpacePaddedToString(fakeBpb.volume_label, Encoding);
XmlFsType.VolumeName = XmlFsType.VolumeName?.Replace("\0", "");
Metadata.VolumeName = StringHandlers.SpacePaddedToString(fakeBpb.volume_label, Encoding);
Metadata.VolumeName = Metadata.VolumeName?.Replace("\0", "");
}
}
// Workaround that PCExchange jumps into "FAT16 "...
if(XmlFsType.SystemIdentifier == "PCX 2.0 ")
if(Metadata.SystemIdentifier == "PCX 2.0 ")
fakeBpb.jump[1] += 8;
// Check that jumps to a correct boot code position and has boot signature set.
// This will mean that the volume will boot, even if just to say "this is not bootable change disk"......
if(XmlFsType.Bootable == false &&
fakeBpb.jump != null)
XmlFsType.Bootable |=
if(Metadata.Bootable == false &&
fakeBpb.jump != null)
Metadata.Bootable |=
(fakeBpb.jump[0] == 0xEB && fakeBpb.jump[1] >= minBootNearJump && fakeBpb.jump[1] < 0x80) ||
(fakeBpb.jump[0] == 0xE9 && fakeBpb.jump.Length >= 3 &&
BitConverter.ToUInt16(fakeBpb.jump, 1) >= minBootNearJump &&
@@ -631,25 +630,22 @@ public sealed partial class FAT
string volname = Encoding.GetString(fullname).Trim();
if(!string.IsNullOrEmpty(volname))
XmlFsType.VolumeName = entry.caseinfo.HasFlag(CaseInfo.AllLowerCase) && _namespace == Namespace.Nt
? volname.ToLower() : volname;
Metadata.VolumeName = entry.caseinfo.HasFlag(CaseInfo.AllLowerCase) && _namespace == Namespace.Nt
? volname.ToLower() : volname;
XmlFsType.VolumeName = XmlFsType.VolumeName?.Replace("\0", "");
Metadata.VolumeName = Metadata.VolumeName?.Replace("\0", "");
if(entry is { ctime: > 0, cdate: > 0 })
{
XmlFsType.CreationDate = DateHandlers.DosToDateTime(entry.cdate, entry.ctime);
Metadata.CreationDate = DateHandlers.DosToDateTime(entry.cdate, entry.ctime);
if(entry.ctime_ms > 0)
XmlFsType.CreationDate = XmlFsType.CreationDate.AddMilliseconds(entry.ctime_ms * 10);
XmlFsType.CreationDateSpecified = true;
Metadata.CreationDate = Metadata.CreationDate?.AddMilliseconds(entry.ctime_ms * 10);
}
if(entry is { mtime: > 0, mdate: > 0 })
{
XmlFsType.ModificationDate = DateHandlers.DosToDateTime(entry.mdate, entry.mtime);
XmlFsType.ModificationDateSpecified = true;
Metadata.ModificationDate = DateHandlers.DosToDateTime(entry.mdate, entry.mtime);
}
continue;
@@ -764,14 +760,14 @@ public sealed partial class FAT
lastLfnChecksum = 0;
}
XmlFsType.VolumeName = XmlFsType.VolumeName?.Trim();
_statfs.Blocks = XmlFsType.Clusters;
Metadata.VolumeName = Metadata.VolumeName?.Trim();
_statfs.Blocks = Metadata.Clusters;
switch(bpbKind)
{
case BpbKind.ShortFat32:
case BpbKind.LongFat32:
_statfs.Type = XmlFsType.Type == FS_TYPE_FAT_PLUS ? FS_TYPE_FAT_PLUS : FS_TYPE_FAT32;
_statfs.Type = Metadata.Type == FS_TYPE_FAT_PLUS ? FS_TYPE_FAT_PLUS : FS_TYPE_FAT32;
break;
default:
@@ -970,8 +966,8 @@ public sealed partial class FAT
_mounted = true;
if(string.IsNullOrWhiteSpace(XmlFsType.VolumeName))
XmlFsType.VolumeName = null;
if(string.IsNullOrWhiteSpace(Metadata.VolumeName))
Metadata.VolumeName = null;
return ErrorNumber.NoError;
}