Redo Reformat and cleanup.

Rider EAP was having a bug interpreting .editorconfig that didn't generate the code style as we wanted.
This is now done with Rider-stable.
This commit is contained in:
2023-10-04 17:34:40 +01:00
parent bc8bf7a2dc
commit 7363a5d9c5
453 changed files with 7241 additions and 7126 deletions

View File

@@ -60,11 +60,21 @@ public sealed partial class FAT
: humanBpb.clusters == expectedClusters;
// Check OEM for Human68k is correct
bool humanOemCorrect = bpbSector[2] >= 0x20 && bpbSector[3] >= 0x20 && bpbSector[4] >= 0x20 &&
bpbSector[5] >= 0x20 && bpbSector[6] >= 0x20 && bpbSector[7] >= 0x20 &&
bpbSector[8] >= 0x20 && bpbSector[9] >= 0x20 && bpbSector[10] >= 0x20 &&
bpbSector[11] >= 0x20 && bpbSector[12] >= 0x20 && bpbSector[13] >= 0x20 &&
bpbSector[14] >= 0x20 && bpbSector[15] >= 0x20 && bpbSector[16] >= 0x20 &&
bool humanOemCorrect = bpbSector[2] >= 0x20 &&
bpbSector[3] >= 0x20 &&
bpbSector[4] >= 0x20 &&
bpbSector[5] >= 0x20 &&
bpbSector[6] >= 0x20 &&
bpbSector[7] >= 0x20 &&
bpbSector[8] >= 0x20 &&
bpbSector[9] >= 0x20 &&
bpbSector[10] >= 0x20 &&
bpbSector[11] >= 0x20 &&
bpbSector[12] >= 0x20 &&
bpbSector[13] >= 0x20 &&
bpbSector[14] >= 0x20 &&
bpbSector[15] >= 0x20 &&
bpbSector[16] >= 0x20 &&
bpbSector[17] >= 0x20;
// Check correct branch for Human68k
@@ -176,10 +186,14 @@ public sealed partial class FAT
apricotBpb.mainBPB.sectors /= 4;
}
andosOemCorrect = dos33Bpb.oem_name[0] < 0x20 && dos33Bpb.oem_name[1] >= 0x20 &&
dos33Bpb.oem_name[2] >= 0x20 && dos33Bpb.oem_name[3] >= 0x20 &&
dos33Bpb.oem_name[4] >= 0x20 && dos33Bpb.oem_name[5] >= 0x20 &&
dos33Bpb.oem_name[6] >= 0x20 && dos33Bpb.oem_name[7] >= 0x20;
andosOemCorrect = dos33Bpb.oem_name[0] < 0x20 &&
dos33Bpb.oem_name[1] >= 0x20 &&
dos33Bpb.oem_name[2] >= 0x20 &&
dos33Bpb.oem_name[3] >= 0x20 &&
dos33Bpb.oem_name[4] >= 0x20 &&
dos33Bpb.oem_name[5] >= 0x20 &&
dos33Bpb.oem_name[6] >= 0x20 &&
dos33Bpb.oem_name[7] >= 0x20;
if(bitsInBpsFat32 == 1 &&
correctSpcFat32 &&
@@ -285,7 +299,8 @@ public sealed partial class FAT
dos33Bpb.sectors <= partition.End - partition.Start + 1)
{
if(atariBpb.jump[0] == 0x60 ||
atariBpb.jump[0] == 0xE9 && atariBpb.jump[1] == 0x00 &&
atariBpb.jump[0] == 0xE9 &&
atariBpb.jump[1] == 0x00 &&
Encoding.ASCII.GetString(dos33Bpb.oem_name) != "NEXT " ||
partition.Type is "GEM" or "BGM")
{
@@ -308,11 +323,11 @@ public sealed partial class FAT
useDos32Bpb = true;
minBootNearJump = 0x1E;
}
else if(dos30Bpb.sptrk is > 0 and < 64 &&
dos30Bpb.heads is > 0 and < 256)
else if(dos30Bpb.sptrk is > 0 and < 64 && dos30Bpb.heads is > 0 and < 256)
{
if(atariBpb.jump[0] == 0x60 ||
atariBpb.jump[0] == 0xE9 && atariBpb.jump[1] == 0x00 &&
atariBpb.jump[0] == 0xE9 &&
atariBpb.jump[1] == 0x00 &&
Encoding.ASCII.GetString(dos33Bpb.oem_name) != "NEXT ")
{
AaruConsole.DebugWriteLine(MODULE_NAME, Localization.Using_Atari_BPB);
@@ -328,7 +343,8 @@ public sealed partial class FAT
else
{
if(atariBpb.jump[0] == 0x60 ||
atariBpb.jump[0] == 0xE9 && atariBpb.jump[1] == 0x00 &&
atariBpb.jump[0] == 0xE9 &&
atariBpb.jump[1] == 0x00 &&
Encoding.ASCII.GetString(dos33Bpb.oem_name) != "NEXT ")
{
AaruConsole.DebugWriteLine(MODULE_NAME, Localization.Using_Atari_BPB);
@@ -372,7 +388,10 @@ public sealed partial class FAT
// Volume is software interleaved 2:1
var rootMs = new MemoryStream();
foreach(ulong rootSector in new ulong[] { 0x17, 0x19, 0x1B, 0x1D, 0x1E, 0x20 })
foreach(ulong rootSector in new ulong[]
{
0x17, 0x19, 0x1B, 0x1D, 0x1E, 0x20
})
{
imagePlugin.ReadSector(rootSector, out byte[] tmp);
rootMs.Write(tmp, 0, tmp.Length);
@@ -613,8 +632,9 @@ public sealed partial class FAT
}
// This assumes a bootable sector will jump somewhere or disable interrupts in x86 code
bootable |= bpbSector[0] == 0xFA || bpbSector[0] == 0xEB && bpbSector[1] <= 0x7F ||
bpbSector[0] == 0xE9 && BitConverter.ToUInt16(bpbSector, 1) <= 0x1FC;
bootable |= bpbSector[0] == 0xFA ||
bpbSector[0] == 0xEB && bpbSector[1] <= 0x7F ||
bpbSector[0] == 0xE9 && BitConverter.ToUInt16(bpbSector, 1) <= 0x1FC;
fakeBpb.boot_code = bpbSector;
@@ -794,8 +814,7 @@ public sealed partial class FAT
fakeBpb.sptrk = apricotBpb.spt;
bootable = apricotBpb.bootType > 0;
if(apricotBpb.bootLocation > 0 &&
apricotBpb.bootLocation + apricotBpb.bootSize < imagePlugin.Info.Sectors)
if(apricotBpb.bootLocation > 0 && apricotBpb.bootLocation + apricotBpb.bootSize < imagePlugin.Info.Sectors)
{
imagePlugin.ReadSectors(apricotBpb.bootLocation,
(uint)(apricotBpb.sectorSize * apricotBpb.bootSize) / imagePlugin.Info.SectorSize,

View File

@@ -61,8 +61,7 @@ public sealed partial class FAT
if(!_mounted)
return ErrorNumber.AccessDenied;
if(string.IsNullOrWhiteSpace(path) ||
path == "/")
if(string.IsNullOrWhiteSpace(path) || path == "/")
{
node = new FatDirNode
{
@@ -90,7 +89,10 @@ public sealed partial class FAT
return ErrorNumber.NoError;
}
string[] pieces = cutPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
string[] pieces = cutPath.Split(new[]
{
'/'
}, StringSplitOptions.RemoveEmptyEntries);
KeyValuePair<string, CompleteDirectoryEntry> entry =
_rootDirectoryCache.FirstOrDefault(t => t.Key.ToLower(_cultureInfo) == pieces[0]);
@@ -172,8 +174,7 @@ public sealed partial class FAT
if(dirent.attributes.HasFlag(FatAttributes.LFN))
{
if(_namespace != Namespace.Lfn &&
_namespace != Namespace.Ecs)
if(_namespace != Namespace.Lfn && _namespace != Namespace.Ecs)
continue;
LfnEntry lfnEntry =
@@ -207,8 +208,7 @@ public sealed partial class FAT
}
// Not a correct entry
if(dirent.filename[0] < DIRENT_MIN &&
dirent.filename[0] != DIRENT_E5)
if(dirent.filename[0] < DIRENT_MIN && dirent.filename[0] != DIRENT_E5)
continue;
// Self
@@ -233,8 +233,7 @@ public sealed partial class FAT
Dirent = dirent
};
if(_namespace is Namespace.Lfn or Namespace.Ecs &&
lastLfnName != null)
if(_namespace is Namespace.Lfn or Namespace.Ecs && lastLfnName != null)
{
byte calculatedLfnChecksum = LfnChecksum(dirent.filename, dirent.extension);
@@ -254,13 +253,11 @@ public sealed partial class FAT
string name = _encoding.GetString(dirent.filename).TrimEnd();
string extension = _encoding.GetString(dirent.extension).TrimEnd();
if(name == "" &&
extension == "")
if(name == "" && extension == "")
{
AaruConsole.DebugWriteLine(MODULE_NAME, Localization.Found_empty_filename_in_0, path);
if(!_debug ||
dirent is { size: > 0, start_cluster: 0 })
if(!_debug || dirent is { size: > 0, start_cluster: 0 })
continue; // Skip invalid name
// If debug, add it
@@ -325,12 +322,9 @@ public sealed partial class FAT
}
// Check OS/2 .LONGNAME
if(_eaCache != null &&
_namespace is Namespace.Os2 or Namespace.Ecs &&
!_fat32)
if(_eaCache != null && _namespace is Namespace.Os2 or Namespace.Ecs && !_fat32)
{
var filesWithEas =
currentDirectory.Where(t => t.Value.Dirent.ea_handle != 0).ToList();
var filesWithEas = currentDirectory.Where(t => t.Value.Dirent.ea_handle != 0).ToList();
foreach(KeyValuePair<string, CompleteDirectoryEntry> fileWithEa in filesWithEas)
{
@@ -371,8 +365,8 @@ public sealed partial class FAT
// Check FAT32.IFS EAs
if(_fat32 || _debug)
{
var fat32EaSidecars =
currentDirectory.Where(t => t.Key.EndsWith(FAT32_EA_TAIL, true, _cultureInfo)).ToList();
var fat32EaSidecars = currentDirectory.Where(t => t.Key.EndsWith(FAT32_EA_TAIL, true, _cultureInfo)).
ToList();
foreach(KeyValuePair<string, CompleteDirectoryEntry> sidecar in fat32EaSidecars)
{

View File

@@ -88,17 +88,29 @@ public sealed partial class FAT : IReadOnlyFilesystem
/// <inheritdoc />
public Dictionary<string, string> Namespaces => new()
{
{ "dos", Localization.DOS_8_3_all_uppercase },
{ "nt", Localization.Windows_NT_8_3_mixed_case },
{ "os2", Localization.OS2_LONGNAME_extended_attribute },
{ "ecs", Localization.Use_LFN_when_available_with_fallback_to_LONGNAME_default },
{ "lfn", Localization.Long_file_names }
{
"dos", Localization.DOS_8_3_all_uppercase
},
{
"nt", Localization.Windows_NT_8_3_mixed_case
},
{
"os2", Localization.OS2_LONGNAME_extended_attribute
},
{
"ecs", Localization.Use_LFN_when_available_with_fallback_to_LONGNAME_default
},
{
"lfn", Localization.Long_file_names
}
};
#endregion
static Dictionary<string, string> GetDefaultOptions() => new()
{
{ "debug", false.ToString() }
{
"debug", false.ToString()
}
};
}

View File

@@ -73,8 +73,7 @@ public sealed partial class FAT
if(err != ErrorNumber.NoError)
return err;
if(stat.Attributes.HasFlag(FileAttributes.Directory) &&
!_debug)
if(stat.Attributes.HasFlag(FileAttributes.Directory) && !_debug)
return ErrorNumber.IsDirectory;
uint[] clusters = GetClusters((uint)stat.Inode);
@@ -115,8 +114,7 @@ public sealed partial class FAT
if(!_mounted)
return ErrorNumber.AccessDenied;
if(buffer is null ||
buffer.Length < length)
if(buffer is null || buffer.Length < length)
return ErrorNumber.InvalidArgument;
if(node is not FatFileNode mynode)
@@ -183,14 +181,12 @@ public sealed partial class FAT
Links = 1
};
if(entry.cdate > 0 ||
entry.ctime > 0)
if(entry.cdate > 0 || entry.ctime > 0)
stat.CreationTime = DateHandlers.DosToDateTime(entry.cdate, entry.ctime);
if(_namespace != Namespace.Human)
{
if(entry.mdate > 0 ||
entry.mtime > 0)
if(entry.mdate > 0 || entry.mtime > 0)
stat.LastWriteTime = DateHandlers.DosToDateTime(entry.mdate, entry.mtime);
if(entry.ctime_ms > 0)
@@ -204,8 +200,7 @@ public sealed partial class FAT
{
stat.Attributes |= FileAttributes.Directory;
if(_fat32 && entry.ea_handle << 16 > 0 ||
entry.start_cluster > 0)
if(_fat32 && entry.ea_handle << 16 > 0 || entry.start_cluster > 0)
{
stat.Blocks = _fat32
? GetClusters((uint)((entry.ea_handle << 16) + entry.start_cluster))?.Length ?? 0
@@ -259,8 +254,7 @@ public sealed partial class FAT
if(_fat32)
{
while((nextCluster & FAT32_MASK) > 0 &&
(nextCluster & FAT32_MASK) <= FAT32_RESERVED)
while((nextCluster & FAT32_MASK) > 0 && (nextCluster & FAT32_MASK) <= FAT32_RESERVED)
{
clusters.Add(nextCluster);
@@ -276,8 +270,7 @@ public sealed partial class FAT
nextCluster = BitConverter.ToUInt32(fatData, nextEntry * 4);
nextSector = nextCluster / _fatEntriesPerSector + _fatFirstSector +
(_useFirstFat ? 0 : _sectorsPerFat);
nextSector = nextCluster / _fatEntriesPerSector + _fatFirstSector + (_useFirstFat ? 0 : _sectorsPerFat);
nextEntry = (int)(nextCluster % _fatEntriesPerSector);
}
@@ -314,7 +307,10 @@ public sealed partial class FAT
string cutPath = path.StartsWith('/') ? path[1..].ToLower(_cultureInfo) : path.ToLower(_cultureInfo);
string[] pieces = cutPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
string[] pieces = cutPath.Split(new[]
{
'/'
}, StringSplitOptions.RemoveEmptyEntries);
if(pieces.Length == 0)
return ErrorNumber.InvalidArgument;

View File

@@ -100,11 +100,21 @@ public sealed partial class FAT
: humanBpb.clusters == expectedClusters;
// Check OEM for Human68k is correct
bool humanOemCorrect = bpbSector[2] >= 0x20 && bpbSector[3] >= 0x20 && bpbSector[4] >= 0x20 &&
bpbSector[5] >= 0x20 && bpbSector[6] >= 0x20 && bpbSector[7] >= 0x20 &&
bpbSector[8] >= 0x20 && bpbSector[9] >= 0x20 && bpbSector[10] >= 0x20 &&
bpbSector[11] >= 0x20 && bpbSector[12] >= 0x20 && bpbSector[13] >= 0x20 &&
bpbSector[14] >= 0x20 && bpbSector[15] >= 0x20 && bpbSector[16] >= 0x20 &&
bool humanOemCorrect = bpbSector[2] >= 0x20 &&
bpbSector[3] >= 0x20 &&
bpbSector[4] >= 0x20 &&
bpbSector[5] >= 0x20 &&
bpbSector[6] >= 0x20 &&
bpbSector[7] >= 0x20 &&
bpbSector[8] >= 0x20 &&
bpbSector[9] >= 0x20 &&
bpbSector[10] >= 0x20 &&
bpbSector[11] >= 0x20 &&
bpbSector[12] >= 0x20 &&
bpbSector[13] >= 0x20 &&
bpbSector[14] >= 0x20 &&
bpbSector[15] >= 0x20 &&
bpbSector[16] >= 0x20 &&
bpbSector[17] >= 0x20;
// Check correct branch for Human68k
@@ -115,10 +125,7 @@ public sealed partial class FAT
AaruConsole.DebugWriteLine(MODULE_NAME, "humanBranchCorrect = {0}", humanBranchCorrect);
// If all Human68k checks are correct, it is a Human68k FAT16
if(humanClustersCorrect &&
humanOemCorrect &&
humanBranchCorrect &&
expectedClusters > 0)
if(humanClustersCorrect && humanOemCorrect && humanBranchCorrect && expectedClusters > 0)
return true;
Array.Copy(bpbSector, 0x02, atariOem, 0, 6);
@@ -147,11 +154,21 @@ public sealed partial class FAT
string msxString = Encoding.ASCII.GetString(msxId);
string fat32String = Encoding.ASCII.GetString(fat32Id);
bool atariOemCorrect = atariOem[0] >= 0x20 && atariOem[1] >= 0x20 && atariOem[2] >= 0x20 &&
atariOem[3] >= 0x20 && atariOem[4] >= 0x20 && atariOem[5] >= 0x20;
bool atariOemCorrect = atariOem[0] >= 0x20 &&
atariOem[1] >= 0x20 &&
atariOem[2] >= 0x20 &&
atariOem[3] >= 0x20 &&
atariOem[4] >= 0x20 &&
atariOem[5] >= 0x20;
bool dosOemCorrect = dosOem[0] >= 0x20 && dosOem[1] >= 0x20 && dosOem[2] >= 0x20 && dosOem[3] >= 0x20 &&
dosOem[4] >= 0x20 && dosOem[5] >= 0x20 && dosOem[6] >= 0x20 && dosOem[7] >= 0x20;
bool dosOemCorrect = dosOem[0] >= 0x20 &&
dosOem[1] >= 0x20 &&
dosOem[2] >= 0x20 &&
dosOem[3] >= 0x20 &&
dosOem[4] >= 0x20 &&
dosOem[5] >= 0x20 &&
dosOem[6] >= 0x20 &&
dosOem[7] >= 0x20;
string oemString = Encoding.ASCII.GetString(dosOem);
@@ -234,16 +251,18 @@ public sealed partial class FAT
var hpfsMagic1 = BitConverter.ToUInt32(hpfsSbSector, 0x000);
var hpfsMagic2 = BitConverter.ToUInt32(hpfsSbSector, 0x004);
if(hpfsMagic1 == 0xF995E849 &&
hpfsMagic2 == 0xFA53E9C5)
if(hpfsMagic1 == 0xF995E849 && hpfsMagic2 == 0xFA53E9C5)
return false;
}
switch(bitsInBps)
{
// FAT32 for sure
case 1 when correctSpc && numberOfFats <= 2 && fatSectors == 0 && fat32Signature == 0x29 &&
fat32String == "FAT32 ":
case 1 when correctSpc &&
numberOfFats <= 2 &&
fatSectors == 0 &&
fat32Signature == 0x29 &&
fat32String == "FAT32 ":
return true;
// short FAT32
@@ -255,21 +274,30 @@ public sealed partial class FAT
: sectors <= partition.End - partition.Start + 1;
// MSX-DOS FAT12
case 1 when correctSpc && numberOfFats <= 2 && rootEntries > 0 &&
sectors <= partition.End - partition.Start + 1 && fatSectors > 0 &&
msxString == "VOL_ID":
case 1 when correctSpc &&
numberOfFats <= 2 &&
rootEntries > 0 &&
sectors <= partition.End - partition.Start + 1 &&
fatSectors > 0 &&
msxString == "VOL_ID":
return true;
// EBPB
case 1 when correctSpc && numberOfFats <= 2 && rootEntries > 0 && fatSectors > 0 &&
case 1 when correctSpc &&
numberOfFats <= 2 &&
rootEntries > 0 &&
fatSectors > 0 &&
bpbSignature is 0x28 or 0x29:
return sectors == 0
? bigSectors <= partition.End - partition.Start + 1
: sectors <= partition.End - partition.Start + 1;
// BPB
case 1 when correctSpc && reservedSecs < partition.End - partition.Start && numberOfFats <= 2 &&
rootEntries > 0 && fatSectors > 0:
case 1 when correctSpc &&
reservedSecs < partition.End - partition.Start &&
numberOfFats <= 2 &&
rootEntries > 0 &&
fatSectors > 0:
return sectors == 0
? bigSectors <= partition.End - partition.Start + 1
: sectors <= partition.End - partition.Start + 1;
@@ -313,7 +341,10 @@ public sealed partial class FAT
// Volume is software interleaved 2:1
var rootMs = new MemoryStream();
foreach(ulong rootSector in new ulong[] { 0x17, 0x19, 0x1B, 0x1D, 0x1E, 0x20 })
foreach(ulong rootSector in new ulong[]
{
0x17, 0x19, 0x1B, 0x1D, 0x1E, 0x20
})
{
errno = imagePlugin.ReadSector(rootSector, out byte[] tmp);
@@ -409,8 +440,7 @@ public sealed partial class FAT
break;
}
if(fat2SectorNo > partition.End ||
fat2SectorNo == 0)
if(fat2SectorNo > partition.End || fat2SectorNo == 0)
return false;
AaruConsole.DebugWriteLine(MODULE_NAME, Localization.Second_fat_starts_at_0, fat2SectorNo);
@@ -507,9 +537,7 @@ public sealed partial class FAT
if(fat32Bpb.oem_name != null)
{
if(fat32Bpb.oem_name[5] == 0x49 &&
fat32Bpb.oem_name[6] == 0x48 &&
fat32Bpb.oem_name[7] == 0x43)
if(fat32Bpb.oem_name[5] == 0x49 && fat32Bpb.oem_name[6] == 0x48 && fat32Bpb.oem_name[7] == 0x43)
sb.AppendLine(Localization.Volume_has_been_modified_by_Windows_9x_Me_Volume_Tracker);
else
metadata.SystemIdentifier = StringHandlers.CToString(fat32Bpb.oem_name);
@@ -526,21 +554,24 @@ public sealed partial class FAT
if(fat32Bpb is { big_sectors: 0, signature: 0x28 })
{
sb.AppendFormat(Localization._0_sectors_on_volume_1_bytes, shortFat32Bpb.huge_sectors,
shortFat32Bpb.huge_sectors * shortFat32Bpb.bps).AppendLine();
shortFat32Bpb.huge_sectors * shortFat32Bpb.bps).
AppendLine();
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();
fat32Bpb.big_sectors * fat32Bpb.bps).
AppendLine();
metadata.Clusters = fat32Bpb.big_sectors / fat32Bpb.spc;
}
else
{
sb.AppendFormat(Localization._0_sectors_on_volume_1_bytes, fat32Bpb.sectors,
fat32Bpb.sectors * fat32Bpb.bps).AppendLine();
fat32Bpb.sectors * fat32Bpb.bps).
AppendLine();
metadata.Clusters = (ulong)(fat32Bpb.sectors / fat32Bpb.spc);
}
@@ -603,7 +634,8 @@ public sealed partial class FAT
// This will mean that the volume will boot, even if just to say "this is not bootable change disk"......
metadata.Bootable =
fat32Bpb.jump[0] == 0xEB && fat32Bpb.jump[1] >= minBootNearJump && fat32Bpb.jump[1] < 0x80 ||
fat32Bpb.jump[0] == 0xE9 && fat32Bpb.jump.Length >= 3 &&
fat32Bpb.jump[0] == 0xE9 &&
fat32Bpb.jump.Length >= 3 &&
BitConverter.ToUInt16(fat32Bpb.jump, 1) >= minBootNearJump &&
BitConverter.ToUInt16(fat32Bpb.jump, 1) <= 0x1FC;
@@ -611,8 +643,10 @@ public sealed partial class FAT
// First root directory sector
rootDirectorySector =
(ulong)((fat32Bpb.root_cluster - 2) * fat32Bpb.spc + fat32Bpb.big_spfat * fat32Bpb.fats_no +
fat32Bpb.rsectors) * sectorsPerRealSector;
(ulong)((fat32Bpb.root_cluster - 2) * fat32Bpb.spc +
fat32Bpb.big_spfat * fat32Bpb.fats_no +
fat32Bpb.rsectors) *
sectorsPerRealSector;
sectorsForRootDirectory = 1;
@@ -657,7 +691,8 @@ public sealed partial class FAT
var atariSb = new StringBuilder();
atariSb.AppendFormat(Localization.cmdload_will_be_loaded_with_value_0,
BigEndianBitConverter.ToUInt16(bpbSector, 0x01E)).AppendLine();
BigEndianBitConverter.ToUInt16(bpbSector, 0x01E)).
AppendLine();
atariSb.AppendFormat(Localization.Boot_program_will_be_loaded_at_address_0, atariBpb.ldaaddr).
AppendLine();
@@ -721,8 +756,9 @@ public sealed partial class FAT
if(bpbKind != BpbKind.Human)
{
int reservedSectors = fakeBpb.rsectors + fakeBpb.fats_no * fakeBpb.spfat +
fakeBpb.root_ent * 32 / fakeBpb.bps;
int reservedSectors = fakeBpb.rsectors +
fakeBpb.fats_no * fakeBpb.spfat +
fakeBpb.root_ent * 32 / fakeBpb.bps;
if(fakeBpb.sectors == 0)
{
@@ -743,8 +779,7 @@ public sealed partial class FAT
// This will walk all the FAT entries and check if they're valid FAT12 or FAT16 entries.
// If the whole table is valid in both senses, it considers the type entry in the BPB.
// BeOS is known to set the type as FAT16 but treat it as FAT12.
if(!isFat12 &&
!isFat16)
if(!isFat12 && !isFat16)
{
if(clusters < 4089)
{
@@ -795,8 +830,7 @@ public sealed partial class FAT
isFat16 = fakeBpb.fs_type != null && Encoding.ASCII.GetString(fakeBpb.fs_type) == "FAT16 ";
}
if(!isFat12 &&
!isFat16)
if(!isFat12 && !isFat16)
isFat12 = true;
}
else
@@ -841,9 +875,7 @@ public sealed partial class FAT
if(bpbKind == BpbKind.Atari)
{
if(atariBpb.serial_no[0] == 0x49 &&
atariBpb.serial_no[1] == 0x48 &&
atariBpb.serial_no[2] == 0x43)
if(atariBpb.serial_no[0] == 0x49 && atariBpb.serial_no[1] == 0x48 && atariBpb.serial_no[2] == 0x43)
sb.AppendLine(Localization.Volume_has_been_modified_by_Windows_9x_Me_Volume_Tracker);
else
{
@@ -858,9 +890,7 @@ public sealed partial class FAT
}
else if(fakeBpb.oem_name != null)
{
if(fakeBpb.oem_name[5] == 0x49 &&
fakeBpb.oem_name[6] == 0x48 &&
fakeBpb.oem_name[7] == 0x43)
if(fakeBpb.oem_name[5] == 0x49 && fakeBpb.oem_name[6] == 0x48 && fakeBpb.oem_name[7] == 0x43)
sb.AppendLine(Localization.Volume_has_been_modified_by_Windows_9x_Me_Volume_Tracker);
else
{
@@ -896,9 +926,8 @@ public sealed partial class FAT
fakeBpb.oem_name[6] >= 0x20 &&
fakeBpb.oem_name[6] <= 0x7F &&
fakeBpb.oem_name[7] >= 0x20 &&
fakeBpb.oem_name[7] <= 0x7F => StringHandlers.CToString(
fakeBpb.oem_name, encoding,
start: 1),
fakeBpb.oem_name[7] <= 0x7F =>
StringHandlers.CToString(fakeBpb.oem_name, encoding, start: 1),
_ => metadata.SystemIdentifier
};
}
@@ -917,12 +946,14 @@ public sealed partial class FAT
if(fakeBpb.sectors == 0)
{
sb.AppendFormat(Localization._0_sectors_on_volume_1_bytes, fakeBpb.big_sectors,
fakeBpb.big_sectors * fakeBpb.bps).AppendLine();
fakeBpb.big_sectors * fakeBpb.bps).
AppendLine();
}
else
{
sb.AppendFormat(Localization._0_sectors_on_volume_1_bytes, fakeBpb.sectors,
fakeBpb.sectors * fakeBpb.bps).AppendLine();
fakeBpb.sectors * fakeBpb.bps).
AppendLine();
}
}
else
@@ -945,8 +976,7 @@ public sealed partial class FAT
sb.AppendFormat(Localization._0_sectors_per_FAT, fakeBpb.spfat).AppendLine();
if(fakeBpb.sptrk is > 0 and < 64 &&
fakeBpb.heads is > 0 and < 256)
if(fakeBpb.sptrk is > 0 and < 64 && fakeBpb.heads is > 0 and < 256)
{
sb.AppendFormat(Localization._0_sectors_per_track, fakeBpb.sptrk).AppendLine();
sb.AppendFormat(Localization._0_heads, fakeBpb.heads).AppendLine();
@@ -983,8 +1013,7 @@ public sealed partial class FAT
AppendLine();
}
}
else if(bpbKind == BpbKind.Atari &&
metadata.VolumeSerial != null)
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 _);
@@ -995,12 +1024,12 @@ 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"......
if(metadata.Bootable == false &&
fakeBpb.jump != null)
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 &&
fakeBpb.jump[0] == 0xE9 &&
fakeBpb.jump.Length >= 3 &&
BitConverter.ToUInt16(fakeBpb.jump, 1) >= minBootNearJump &&
BitConverter.ToUInt16(fakeBpb.jump, 1) <= 0x1FC;
}
@@ -1029,7 +1058,10 @@ public sealed partial class FAT
{
var rootMs = new MemoryStream();
foreach(ulong rootSector in new ulong[] { 0x17, 0x19, 0x1B, 0x1D, 0x1E, 0x20 })
foreach(ulong rootSector in new ulong[]
{
0x17, 0x19, 0x1B, 0x1D, 0x1E, 0x20
})
{
errno = imagePlugin.ReadSector(rootSector, out byte[] tmp);
@@ -1045,18 +1077,15 @@ public sealed partial class FAT
for(var i = 0; i < rootDirectory.Length; i += 32)
{
// Not a correct entry
if(rootDirectory[i] < DIRENT_MIN &&
rootDirectory[i] != DIRENT_E5)
if(rootDirectory[i] < DIRENT_MIN && rootDirectory[i] != DIRENT_E5)
continue;
// Deleted or subdirectory entry
if(rootDirectory[i] == DIRENT_SUBDIR ||
rootDirectory[i] == DIRENT_DELETED)
if(rootDirectory[i] == DIRENT_SUBDIR || rootDirectory[i] == DIRENT_DELETED)
continue;
// Not a volume label
if(rootDirectory[i + 0x0B] != 0x08 &&
rootDirectory[i + 0x0B] != 0x28)
if(rootDirectory[i + 0x0B] != 0x08 && rootDirectory[i + 0x0B] != 0x28)
continue;
DirectoryEntry entry = Marshal.ByteArrayToStructureLittleEndian<DirectoryEntry>(rootDirectory, i, 32);
@@ -1088,7 +1117,8 @@ public sealed partial class FAT
if(entry.adate > 0)
{
sb.AppendFormat(Localization.Volume_last_accessed_on_0_d,
DateHandlers.DosToDateTime(entry.adate, 0)).AppendLine();
DateHandlers.DosToDateTime(entry.adate, 0)).
AppendLine();
}
break;

View File

@@ -128,9 +128,8 @@ public sealed partial class FAT
uint sectorsForRootDirectory = 0;
uint rootDirectoryCluster = 0;
_encoding = encoding ?? (bpbKind == BpbKind.Human
? Encoding.GetEncoding("shift_jis")
: Encoding.GetEncoding("IBM437"));
_encoding = encoding ??
(bpbKind == BpbKind.Human ? Encoding.GetEncoding("shift_jis") : Encoding.GetEncoding("IBM437"));
switch(bpbKind)
{
@@ -208,7 +207,8 @@ public sealed partial class FAT
// This will mean that the volume will boot, even if just to say "this is not bootable change disk"......
Metadata.Bootable =
fat32Bpb.jump[0] == 0xEB && fat32Bpb.jump[1] >= minBootNearJump && fat32Bpb.jump[1] < 0x80 ||
fat32Bpb.jump[0] == 0xE9 && fat32Bpb.jump.Length >= 3 &&
fat32Bpb.jump[0] == 0xE9 &&
fat32Bpb.jump.Length >= 3 &&
BitConverter.ToUInt16(fat32Bpb.jump, 1) >= minBootNearJump &&
BitConverter.ToUInt16(fat32Bpb.jump, 1) <= 0x1FC;
@@ -294,8 +294,9 @@ public sealed partial class FAT
if(bpbKind != BpbKind.Human)
{
int reservedSectors = fakeBpb.rsectors + fakeBpb.fats_no * fakeBpb.spfat +
fakeBpb.root_ent * 32 / fakeBpb.bps;
int reservedSectors = fakeBpb.rsectors +
fakeBpb.fats_no * fakeBpb.spfat +
fakeBpb.root_ent * 32 / fakeBpb.bps;
if(fakeBpb.sectors == 0)
{
@@ -316,8 +317,7 @@ public sealed partial class FAT
// This will walk all the FAT entries and check if they're valid FAT12 or FAT16 entries.
// If the whole table is valid in both senses, it considers the type entry in the BPB.
// BeOS is known to set the type as FAT16 but treat it as FAT12.
if(!_fat12 &&
!_fat16)
if(!_fat12 && !_fat16)
{
if(clusters < 4089)
{
@@ -360,8 +360,7 @@ public sealed partial class FAT
_fat16 = fat16Valid;
// Check BPB type
if(_fat12 == _fat16 &&
fakeBpb.fs_type != null)
if(_fat12 == _fat16 && fakeBpb.fs_type != null)
{
_fat12 = Encoding.ASCII.GetString(fakeBpb.fs_type) == "FAT12 ";
_fat16 = Encoding.ASCII.GetString(fakeBpb.fs_type) == "FAT16 ";
@@ -385,9 +384,7 @@ public sealed partial class FAT
if(bpbKind == BpbKind.Atari)
{
if(atariBpb.serial_no[0] != 0x49 ||
atariBpb.serial_no[1] != 0x48 ||
atariBpb.serial_no[2] != 0x43)
if(atariBpb.serial_no[0] != 0x49 || atariBpb.serial_no[1] != 0x48 || atariBpb.serial_no[2] != 0x43)
{
Metadata.VolumeSerial = $"{atariBpb.serial_no[0]:X2}{atariBpb.serial_no[1]:X2}{atariBpb.serial_no[2]
:X2}";
@@ -395,7 +392,8 @@ public sealed partial class FAT
_statfs.Id = new FileSystemId
{
IsInt = true,
Serial32 = (uint)((atariBpb.serial_no[0] << 16) + (atariBpb.serial_no[1] << 8) +
Serial32 = (uint)((atariBpb.serial_no[0] << 16) +
(atariBpb.serial_no[1] << 8) +
atariBpb.serial_no[2])
};
}
@@ -407,9 +405,7 @@ public sealed partial class FAT
}
else if(fakeBpb.oem_name != null)
{
if(fakeBpb.oem_name[5] != 0x49 ||
fakeBpb.oem_name[6] != 0x48 ||
fakeBpb.oem_name[7] != 0x43)
if(fakeBpb.oem_name[5] != 0x49 || fakeBpb.oem_name[6] != 0x48 || fakeBpb.oem_name[7] != 0x43)
{
Metadata.SystemIdentifier = fakeBpb.oem_name[0] switch
{
@@ -443,9 +439,8 @@ public sealed partial class FAT
fakeBpb.oem_name[6] >= 0x20 &&
fakeBpb.oem_name[6] <= 0x7F &&
fakeBpb.oem_name[7] >= 0x20 &&
fakeBpb.oem_name[7] <= 0x7F => StringHandlers.CToString(
fakeBpb.oem_name, _encoding,
start: 1),
fakeBpb.oem_name[7] <= 0x7F =>
StringHandlers.CToString(fakeBpb.oem_name, _encoding, start: 1),
_ => Metadata.SystemIdentifier
};
}
@@ -489,12 +484,12 @@ 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"......
if(Metadata.Bootable == false &&
fakeBpb.jump != null)
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 &&
fakeBpb.jump[0] == 0xE9 &&
fakeBpb.jump.Length >= 3 &&
BitConverter.ToUInt16(fakeBpb.jump, 1) >= minBootNearJump &&
BitConverter.ToUInt16(fakeBpb.jump, 1) <= 0x1FC;
}
@@ -537,7 +532,10 @@ public sealed partial class FAT
{
var rootMs = new MemoryStream();
foreach(ulong rootSector in new ulong[] { 0x17, 0x19, 0x1B, 0x1D, 0x1E, 0x20 })
foreach(ulong rootSector in new ulong[]
{
0x17, 0x19, 0x1B, 0x1D, 0x1E, 0x20
})
{
errno = imagePlugin.ReadSector(rootSector, out byte[] tmp);
@@ -560,8 +558,8 @@ public sealed partial class FAT
foreach(uint cluster in rootDirectoryClusters)
{
errno = imagePlugin.ReadSectors(_firstClusterSector + cluster * _sectorsPerCluster,
_sectorsPerCluster, out byte[] buffer);
errno = imagePlugin.ReadSectors(_firstClusterSector + cluster * _sectorsPerCluster, _sectorsPerCluster,
out byte[] buffer);
if(errno != ErrorNumber.NoError)
return errno;
@@ -593,8 +591,7 @@ public sealed partial class FAT
if(entry.attributes.HasFlag(FatAttributes.LFN))
{
if(_namespace != Namespace.Lfn &&
_namespace != Namespace.Ecs)
if(_namespace != Namespace.Lfn && _namespace != Namespace.Ecs)
continue;
LfnEntry lfnEntry =
@@ -627,8 +624,7 @@ public sealed partial class FAT
}
// Not a correct entry
if(entry.filename[0] < DIRENT_MIN &&
entry.filename[0] != DIRENT_E5)
if(entry.filename[0] < DIRENT_MIN && entry.filename[0] != DIRENT_E5)
continue;
// Self
@@ -680,8 +676,7 @@ public sealed partial class FAT
Dirent = entry
};
if(_namespace is Namespace.Lfn or Namespace.Ecs &&
lastLfnName != null)
if(_namespace is Namespace.Lfn or Namespace.Ecs && lastLfnName != null)
{
byte calculatedLfnChecksum = LfnChecksum(entry.filename, entry.extension);
@@ -715,13 +710,11 @@ public sealed partial class FAT
else
filename = name;
if(name == "" &&
extension == "")
if(name == "" && extension == "")
{
AaruConsole.DebugWriteLine(MODULE_NAME, Localization.Found_empty_filename_in_root_directory);
if(!_debug ||
entry is { size: > 0, start_cluster: 0 })
if(!_debug || entry is { size: > 0, start_cluster: 0 })
continue; // Skip invalid name
// If debug, add it
@@ -766,8 +759,7 @@ public sealed partial class FAT
completeEntry.HumanName = filename;
}
if(!_fat32 &&
filename == "EA DATA. SF")
if(!_fat32 && filename == "EA DATA. SF")
{
_eaDirEntry = entry;
lastLfnName = null;
@@ -917,12 +909,9 @@ public sealed partial class FAT
_eaCache = new Dictionary<string, Dictionary<string, byte[]>>();
// Check OS/2 .LONGNAME
if(_eaCache != null &&
_namespace is Namespace.Os2 or Namespace.Ecs &&
!_fat32)
if(_eaCache != null && _namespace is Namespace.Os2 or Namespace.Ecs && !_fat32)
{
var rootFilesWithEas =
_rootDirectoryCache.Where(t => t.Value.Dirent.ea_handle != 0).ToList();
var rootFilesWithEas = _rootDirectoryCache.Where(t => t.Value.Dirent.ea_handle != 0).ToList();
foreach(KeyValuePair<string, CompleteDirectoryEntry> fileWithEa in rootFilesWithEas)
{
@@ -963,8 +952,8 @@ public sealed partial class FAT
// Check FAT32.IFS EAs
if(_fat32 || _debug)
{
var fat32EaSidecars =
_rootDirectoryCache.Where(t => t.Key.EndsWith(FAT32_EA_TAIL, true, _cultureInfo)).ToList();
var fat32EaSidecars = _rootDirectoryCache.Where(t => t.Key.EndsWith(FAT32_EA_TAIL, true, _cultureInfo)).
ToList();
foreach(KeyValuePair<string, CompleteDirectoryEntry> sidecar in fat32EaSidecars)
{

View File

@@ -51,8 +51,7 @@ public sealed partial class FAT
return ErrorNumber.AccessDenied;
// No other xattr recognized yet
if(_cachedEaData is null &&
!_fat32)
if(_cachedEaData is null && !_fat32)
return ErrorNumber.NotSupported;
if(path[0] == '/')
@@ -67,8 +66,7 @@ public sealed partial class FAT
ErrorNumber err = GetFileEntry(path, out CompleteDirectoryEntry entry);
if(err != ErrorNumber.NoError ||
entry is null)
if(err != ErrorNumber.NoError || entry is null)
return err;
xattrs = new List<string>();
@@ -187,8 +185,7 @@ public sealed partial class FAT
Dictionary<string, byte[]> GetEas(byte[] eaData)
{
if(eaData is null ||
eaData.Length < 4)
if(eaData is null || eaData.Length < 4)
return null;
Dictionary<string, byte[]> eas = new();