mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[Refactor] General reformat and clean-up.
This commit is contained in:
@@ -34,7 +34,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Claunia.Encoding"/>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection"/>
|
||||
<PackageReference Include="Sentry" />
|
||||
<PackageReference Include="Sentry"/>
|
||||
<PackageReference Include="System.ValueTuple"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -241,8 +241,9 @@ public sealed partial class CBM
|
||||
_statfs.FreeFiles--;
|
||||
|
||||
for(var i = 0; i < dirEntry.name.Length; i++)
|
||||
if(dirEntry.name[i] == 0xA0)
|
||||
dirEntry.name[i] = 0;
|
||||
{
|
||||
if(dirEntry.name[i] == 0xA0) dirEntry.name[i] = 0;
|
||||
}
|
||||
|
||||
string name = StringHandlers.CToString(dirEntry.name, encoding);
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ public sealed partial class CPM
|
||||
sectorIds = new int[def.sectorsPerTrack]
|
||||
};
|
||||
|
||||
for(int i = 0; i < def.sectorsPerTrack; i++) def.side1.sectorIds[i] = i + 1;
|
||||
for(var i = 0; i < def.sectorsPerTrack; i++) def.side1.sectorIds[i] = i + 1;
|
||||
}
|
||||
|
||||
if(def.sides != 2 || def.side2 != null) continue;
|
||||
@@ -81,7 +81,7 @@ public sealed partial class CPM
|
||||
sectorIds = new int[def.sectorsPerTrack]
|
||||
};
|
||||
|
||||
for(int i = 0; i < def.sectorsPerTrack; i++) def.side2.sectorIds[i] = i + 1;
|
||||
for(var i = 0; i < def.sectorsPerTrack; i++) def.side2.sectorIds[i] = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,85 @@ namespace Aaru.Filesystems;
|
||||
|
||||
public sealed partial class CPM
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks that the given directory blocks follow the CP/M filesystem directory specification Corrupted
|
||||
/// directories will fail. FAT directories will false positive if all files start with 0x05, and do not use full
|
||||
/// extensions, for example: "σAFILE.GZ" (using code page 437)
|
||||
/// </summary>
|
||||
/// <returns>False if the directory does not follow the directory specification</returns>
|
||||
/// <param name="directory">Directory blocks.</param>
|
||||
bool CheckDir(byte[] directory)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(directory == null) return false;
|
||||
|
||||
var fileCount = 0;
|
||||
|
||||
for(var off = 0; off < directory.Length; off += 32)
|
||||
{
|
||||
DirectoryEntry entry = Marshal.ByteArrayToStructureLittleEndian<DirectoryEntry>(directory, off, 32);
|
||||
|
||||
if((entry.statusUser & 0x7F) < 0x20)
|
||||
{
|
||||
for(var f = 0; f < 8; f++)
|
||||
{
|
||||
if(entry.filename[f] < 0x20 && entry.filename[f] != 0x00) return false;
|
||||
}
|
||||
|
||||
for(var e = 0; e < 3; e++)
|
||||
{
|
||||
if(entry.extension[e] < 0x20 && entry.extension[e] != 0x00) return false;
|
||||
}
|
||||
|
||||
if(!ArrayHelpers.ArrayIsNullOrWhiteSpace(entry.filename)) fileCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(entry.statusUser)
|
||||
{
|
||||
case 0x20:
|
||||
{
|
||||
for(var f = 0; f < 8; f++)
|
||||
{
|
||||
if(entry.filename[f] < 0x20 && entry.filename[f] != 0x00) return false;
|
||||
}
|
||||
|
||||
for(var e = 0; e < 3; e++)
|
||||
{
|
||||
if(entry.extension[e] < 0x20 && entry.extension[e] != 0x00) return false;
|
||||
}
|
||||
|
||||
_label = Encoding.ASCII.GetString(directory, off + 1, 11).Trim();
|
||||
_labelCreationDate = new byte[4];
|
||||
_labelUpdateDate = new byte[4];
|
||||
Array.Copy(directory, off + 24, _labelCreationDate, 0, 4);
|
||||
Array.Copy(directory, off + 28, _labelUpdateDate, 0, 4);
|
||||
|
||||
break;
|
||||
}
|
||||
case 0x21 when directory[off + 1] == 0x00:
|
||||
_thirdPartyTimestamps = true;
|
||||
|
||||
break;
|
||||
case 0x21:
|
||||
_standardTimestamps |= directory[off + 21] == 0x00 && directory[off + 31] == 0x00;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fileCount > 0;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SentrySdk.CaptureException(ex);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#region IReadOnlyFilesystem Members
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -93,79 +172,4 @@ public sealed partial class CPM
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Checks that the given directory blocks follow the CP/M filesystem directory specification Corrupted
|
||||
/// directories will fail. FAT directories will false positive if all files start with 0x05, and do not use full
|
||||
/// extensions, for example: "σAFILE.GZ" (using code page 437)
|
||||
/// </summary>
|
||||
/// <returns>False if the directory does not follow the directory specification</returns>
|
||||
/// <param name="directory">Directory blocks.</param>
|
||||
bool CheckDir(byte[] directory)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(directory == null) return false;
|
||||
|
||||
int fileCount = 0;
|
||||
|
||||
for(int off = 0; off < directory.Length; off += 32)
|
||||
{
|
||||
DirectoryEntry entry = Marshal.ByteArrayToStructureLittleEndian<DirectoryEntry>(directory, off, 32);
|
||||
|
||||
if((entry.statusUser & 0x7F) < 0x20)
|
||||
{
|
||||
for(int f = 0; f < 8; f++)
|
||||
if(entry.filename[f] < 0x20 && entry.filename[f] != 0x00)
|
||||
return false;
|
||||
|
||||
for(int e = 0; e < 3; e++)
|
||||
if(entry.extension[e] < 0x20 && entry.extension[e] != 0x00)
|
||||
return false;
|
||||
|
||||
if(!ArrayHelpers.ArrayIsNullOrWhiteSpace(entry.filename)) fileCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(entry.statusUser)
|
||||
{
|
||||
case 0x20:
|
||||
{
|
||||
for(int f = 0; f < 8; f++)
|
||||
if(entry.filename[f] < 0x20 && entry.filename[f] != 0x00)
|
||||
return false;
|
||||
|
||||
for(int e = 0; e < 3; e++)
|
||||
if(entry.extension[e] < 0x20 && entry.extension[e] != 0x00)
|
||||
return false;
|
||||
|
||||
_label = Encoding.ASCII.GetString(directory, off + 1, 11).Trim();
|
||||
_labelCreationDate = new byte[4];
|
||||
_labelUpdateDate = new byte[4];
|
||||
Array.Copy(directory, off + 24, _labelCreationDate, 0, 4);
|
||||
Array.Copy(directory, off + 28, _labelUpdateDate, 0, 4);
|
||||
|
||||
break;
|
||||
}
|
||||
case 0x21 when directory[off + 1] == 0x00:
|
||||
_thirdPartyTimestamps = true;
|
||||
|
||||
break;
|
||||
case 0x21:
|
||||
_standardTimestamps |= directory[off + 21] == 0x00 && directory[off + 31] == 0x00;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fileCount > 0;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SentrySdk.CaptureException(ex);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1033,9 +1033,8 @@ public sealed partial class CPM
|
||||
|
||||
// Complement of the directory bytes if needed
|
||||
if(def.complement)
|
||||
{
|
||||
for(var b = 0; b < directory.Length; b++) directory[b] = (byte)(~directory[b] & 0xFF);
|
||||
}
|
||||
for(var b = 0; b < directory.Length; b++)
|
||||
directory[b] = (byte)(~directory[b] & 0xFF);
|
||||
|
||||
// Check the directory
|
||||
if(CheckDir(directory))
|
||||
|
||||
@@ -169,9 +169,8 @@ public sealed partial class CPM
|
||||
if(errno != ErrorNumber.NoError) return errno;
|
||||
|
||||
if(_workingDefinition.complement)
|
||||
{
|
||||
for(var b = 0; b < readSector.Length; b++) readSector[b] = (byte)(~readSector[b] & 0xFF);
|
||||
}
|
||||
for(var b = 0; b < readSector.Length; b++)
|
||||
readSector[b] = (byte)(~readSector[b] & 0xFF);
|
||||
|
||||
deinterleavedSectors.Add((ulong)p, readSector);
|
||||
}
|
||||
|
||||
@@ -52,9 +52,8 @@ public sealed partial class CPM
|
||||
if(!_fileCache.ContainsKey(pathElements[0].ToUpperInvariant())) return ErrorNumber.NoSuchFile;
|
||||
|
||||
if(string.Compare(xattr, "com.caldera.cpm.password", StringComparison.InvariantCulture) == 0)
|
||||
{
|
||||
if(!_passwordCache.TryGetValue(pathElements[0].ToUpperInvariant(), out buf)) return ErrorNumber.NoError;
|
||||
}
|
||||
if(!_passwordCache.TryGetValue(pathElements[0].ToUpperInvariant(), out buf))
|
||||
return ErrorNumber.NoError;
|
||||
|
||||
if(string.Compare(xattr, "com.caldera.cpm.password.text", StringComparison.InvariantCulture) != 0)
|
||||
return ErrorNumber.NoSuchExtendedAttribute;
|
||||
|
||||
@@ -194,8 +194,9 @@ public sealed partial class FAT
|
||||
};
|
||||
|
||||
if((fat32Bpb.flags & 0xF8) == 0x00)
|
||||
if((fat32Bpb.flags & 0x01) == 0x01)
|
||||
Metadata.Dirty = true;
|
||||
{
|
||||
if((fat32Bpb.flags & 0x01) == 0x01) Metadata.Dirty = true;
|
||||
}
|
||||
|
||||
if((fat32Bpb.mirror_flags & 0x80) == 0x80) _useFirstFat = (fat32Bpb.mirror_flags & 0xF) != 1;
|
||||
|
||||
@@ -460,8 +461,9 @@ public sealed partial class FAT
|
||||
if(fakeBpb.signature is 0x28 or 0x29 || andosOemCorrect)
|
||||
{
|
||||
if((fakeBpb.flags & 0xF8) == 0x00)
|
||||
if((fakeBpb.flags & 0x01) == 0x01)
|
||||
Metadata.Dirty = true;
|
||||
{
|
||||
if((fakeBpb.flags & 0x01) == 0x01) Metadata.Dirty = true;
|
||||
}
|
||||
|
||||
if(fakeBpb.signature == 0x29 || andosOemCorrect)
|
||||
{
|
||||
|
||||
@@ -154,8 +154,9 @@ public sealed partial class XboxFatPlugin
|
||||
_fat32 = MemoryMarshal.Cast<byte, uint>(buffer).ToArray();
|
||||
|
||||
if(!_littleEndian)
|
||||
for(var i = 0; i < _fat32.Length; i++)
|
||||
_fat32[i] = Swapping.Swap(_fat32[i]);
|
||||
{
|
||||
for(var i = 0; i < _fat32.Length; i++) _fat32[i] = Swapping.Swap(_fat32[i]);
|
||||
}
|
||||
|
||||
AaruLogging.Debug(MODULE_NAME, "fat32[0] == FATX32_ID = {0}", _fat32[0] == FATX32_ID);
|
||||
|
||||
@@ -185,8 +186,9 @@ public sealed partial class XboxFatPlugin
|
||||
_fat16 = MemoryMarshal.Cast<byte, ushort>(buffer).ToArray();
|
||||
|
||||
if(!_littleEndian)
|
||||
for(var i = 0; i < _fat16.Length; i++)
|
||||
_fat16[i] = Swapping.Swap(_fat16[i]);
|
||||
{
|
||||
for(var i = 0; i < _fat16.Length; i++) _fat16[i] = Swapping.Swap(_fat16[i]);
|
||||
}
|
||||
|
||||
AaruLogging.Debug(MODULE_NAME, "fat16[0] == FATX16_ID = {0}", _fat16[0] == FATX16_ID);
|
||||
|
||||
|
||||
@@ -105,8 +105,9 @@ public sealed partial class LisaFS
|
||||
if(!_mounted || !_debug) return ErrorNumber.AccessDenied;
|
||||
|
||||
if(fileId is > 4 or <= 0)
|
||||
if(fileId != FILEID_BOOT_SIGNED && fileId != FILEID_LOADER_SIGNED)
|
||||
return ErrorNumber.InvalidArgument;
|
||||
{
|
||||
if(fileId != FILEID_BOOT_SIGNED && fileId != FILEID_LOADER_SIGNED) return ErrorNumber.InvalidArgument;
|
||||
}
|
||||
|
||||
if(_systemFileCache.TryGetValue(fileId, out buf) && !tags) return ErrorNumber.NoError;
|
||||
|
||||
@@ -329,8 +330,9 @@ public sealed partial class LisaFS
|
||||
if(!tags)
|
||||
{
|
||||
if(_fileSizeCache.TryGetValue(fileId, out int realSize))
|
||||
if(realSize > temp.Length)
|
||||
AaruLogging.Error(Localization.File_0_gets_truncated, fileId);
|
||||
{
|
||||
if(realSize > temp.Length) AaruLogging.Error(Localization.File_0_gets_truncated, fileId);
|
||||
}
|
||||
|
||||
buf = temp;
|
||||
|
||||
|
||||
@@ -42,31 +42,6 @@ namespace Aaru.Filesystems;
|
||||
|
||||
public sealed partial class LisaFS
|
||||
{
|
||||
#region IReadOnlyFilesystem Members
|
||||
|
||||
/// <inheritdoc />
|
||||
public ErrorNumber ListXAttr(string path, out List<string> xattrs)
|
||||
{
|
||||
xattrs = null;
|
||||
ErrorNumber error = LookupFileId(path, out short fileId, out bool isDir);
|
||||
|
||||
if(error != ErrorNumber.NoError) return error;
|
||||
|
||||
return isDir ? ErrorNumber.InvalidArgument : ListXAttr(fileId, out xattrs);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ErrorNumber GetXattr(string path, string xattr, ref byte[] buf)
|
||||
{
|
||||
ErrorNumber error = LookupFileId(path, out short fileId, out bool isDir);
|
||||
|
||||
if(error != ErrorNumber.NoError) return error;
|
||||
|
||||
return isDir ? ErrorNumber.InvalidArgument : GetXattr(fileId, xattr, out buf);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>Lists special Apple Lisa filesystem features as extended attributes</summary>
|
||||
/// <returns>Error number.</returns>
|
||||
/// <param name="fileId">File identifier.</param>
|
||||
@@ -199,4 +174,29 @@ public sealed partial class LisaFS
|
||||
|
||||
return ErrorNumber.NoError;
|
||||
}
|
||||
|
||||
#region IReadOnlyFilesystem Members
|
||||
|
||||
/// <inheritdoc />
|
||||
public ErrorNumber ListXAttr(string path, out List<string> xattrs)
|
||||
{
|
||||
xattrs = null;
|
||||
ErrorNumber error = LookupFileId(path, out short fileId, out bool isDir);
|
||||
|
||||
if(error != ErrorNumber.NoError) return error;
|
||||
|
||||
return isDir ? ErrorNumber.InvalidArgument : ListXAttr(fileId, out xattrs);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ErrorNumber GetXattr(string path, string xattr, ref byte[] buf)
|
||||
{
|
||||
ErrorNumber error = LookupFileId(path, out short fileId, out bool isDir);
|
||||
|
||||
if(error != ErrorNumber.NoError) return error;
|
||||
|
||||
return isDir ? ErrorNumber.InvalidArgument : GetXattr(fileId, xattr, out buf);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -150,7 +150,7 @@ public sealed partial class Locus
|
||||
|
||||
public ino_t s_isize; /* size in blocks of i-list */
|
||||
public short s_nfree; /* number of addresses in s_free */
|
||||
public Flags s_flags; /* filsys flags, defined below */
|
||||
public Flags s_flags; /* filsys flags, defined below */
|
||||
public ino_t s_tinode; /* total free inodes */
|
||||
public ino_t s_lasti; /* start place for circular search */
|
||||
public ino_t s_nbehind; /* est # free inodes before s_lasti */
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Aaru.CommonTypes.AaruMetadata;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Aaru.CommonTypes.AaruMetadata;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
|
||||
Reference in New Issue
Block a user