mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Code cleanup.
This commit is contained in:
@@ -58,7 +58,7 @@ namespace DiscImageChef.Filesystems.AppleDOS
|
||||
public Guid Id => new Guid("8658A1E9-B2E7-4BCC-9638-157A31B0A700\n");
|
||||
|
||||
public IEnumerable<(string name, Type type, string description)> SupportedOptions =>
|
||||
new(string name, Type type, string description)[] { };
|
||||
new (string name, Type type, string description)[] { };
|
||||
|
||||
static Dictionary<string, string> GetDefaultOptions()
|
||||
{
|
||||
|
||||
@@ -80,12 +80,12 @@ namespace DiscImageChef.Filesystems.AppleDOS
|
||||
Errno ReadCatalog()
|
||||
{
|
||||
MemoryStream catalogMs = new MemoryStream();
|
||||
ulong lba = (ulong)(vtoc.catalogTrack * sectorsPerTrack + vtoc.catalogSector);
|
||||
ulong lba = (ulong)(vtoc.catalogTrack * sectorsPerTrack + vtoc.catalogSector);
|
||||
totalFileEntries = 0;
|
||||
catalogCache = new Dictionary<string, ushort>();
|
||||
fileTypeCache = new Dictionary<string, byte>();
|
||||
fileSizeCache = new Dictionary<string, int>();
|
||||
lockedFiles = new List<string>();
|
||||
catalogCache = new Dictionary<string, ushort>();
|
||||
fileTypeCache = new Dictionary<string, byte>();
|
||||
fileSizeCache = new Dictionary<string, int>();
|
||||
lockedFiles = new List<string>();
|
||||
|
||||
if(lba == 0 || lba > device.Info.Sectors) return Errno.InvalidArgument;
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace DiscImageChef.Filesystems.AppleDOS
|
||||
track2UsedByFiles |= entry.extentTrack == 2;
|
||||
|
||||
byte[] filenameB = new byte[30];
|
||||
ushort ts = (ushort)((entry.extentTrack << 8) | entry.extentSector);
|
||||
ushort ts = (ushort)((entry.extentTrack << 8) | entry.extentSector);
|
||||
|
||||
// Apple DOS has high byte set over ASCII.
|
||||
for(int i = 0; i < 30; i++) filenameB[i] = (byte)(entry.filename[i] & 0x7F);
|
||||
|
||||
@@ -52,11 +52,11 @@ namespace DiscImageChef.Filesystems.AppleDOS
|
||||
|
||||
if(!fileCache.ContainsKey(filename)) return Errno.NoSuchFile;
|
||||
|
||||
attributes = FileAttributes.Extents;
|
||||
attributes = FileAttributes.Extents;
|
||||
attributes |= FileAttributes.File;
|
||||
if(lockedFiles.Contains(filename)) attributes |= FileAttributes.ReadOnly;
|
||||
|
||||
if(debug && (string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
|
||||
if(debug && (string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
|
||||
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 ||
|
||||
string.Compare(path, "$Vtoc", StringComparison.InvariantCulture) == 0))
|
||||
attributes |= FileAttributes.System;
|
||||
@@ -75,12 +75,13 @@ namespace DiscImageChef.Filesystems.AppleDOS
|
||||
string filename = pathElements[0].ToUpperInvariant();
|
||||
if(filename.Length > 30) return Errno.NameTooLong;
|
||||
|
||||
if(debug && (string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
|
||||
if(debug && (string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
|
||||
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 ||
|
||||
string.Compare(path, "$Vtoc", StringComparison.InvariantCulture) == 0))
|
||||
if(string.Compare(path, "$", StringComparison.InvariantCulture) == 0) file = catalogBlocks;
|
||||
if(string.Compare(path, "$", StringComparison.InvariantCulture) == 0)
|
||||
file = catalogBlocks;
|
||||
else if(string.Compare(path, "$Vtoc", StringComparison.InvariantCulture) == 0) file = vtocBlocks;
|
||||
else file = bootBlocks;
|
||||
else file = bootBlocks;
|
||||
else
|
||||
{
|
||||
if(!fileCache.TryGetValue(filename, out file))
|
||||
@@ -121,7 +122,7 @@ namespace DiscImageChef.Filesystems.AppleDOS
|
||||
fileSizeCache.TryGetValue(filename, out int filesize);
|
||||
GetAttributes(path, out FileAttributes attrs);
|
||||
|
||||
if(debug && (string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
|
||||
if(debug && (string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
|
||||
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 ||
|
||||
string.Compare(path, "$Vtoc", StringComparison.InvariantCulture) == 0))
|
||||
{
|
||||
@@ -141,8 +142,8 @@ namespace DiscImageChef.Filesystems.AppleDOS
|
||||
}
|
||||
|
||||
stat.Attributes = attrs;
|
||||
stat.BlockSize = vtoc.bytesPerSector;
|
||||
stat.Links = 1;
|
||||
stat.BlockSize = vtoc.bytesPerSector;
|
||||
stat.Links = 1;
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
@@ -164,10 +165,10 @@ namespace DiscImageChef.Filesystems.AppleDOS
|
||||
|
||||
if(!catalogCache.TryGetValue(filename, out ushort ts)) return Errno.NoSuchFile;
|
||||
|
||||
ulong lba = (ulong)(((ts & 0xFF00) >> 8) * sectorsPerTrack + (ts & 0xFF));
|
||||
MemoryStream fileMs = new MemoryStream();
|
||||
MemoryStream tsListMs = new MemoryStream();
|
||||
ushort expectedBlock = 0;
|
||||
ulong lba = (ulong)(((ts & 0xFF00) >> 8) * sectorsPerTrack + (ts & 0xFF));
|
||||
MemoryStream fileMs = new MemoryStream();
|
||||
MemoryStream tsListMs = new MemoryStream();
|
||||
ushort expectedBlock = 0;
|
||||
|
||||
while(lba != 0)
|
||||
{
|
||||
@@ -216,7 +217,7 @@ namespace DiscImageChef.Filesystems.AppleDOS
|
||||
|
||||
Errno CacheAllFiles()
|
||||
{
|
||||
fileCache = new Dictionary<string, byte[]>();
|
||||
fileCache = new Dictionary<string, byte[]>();
|
||||
extentCache = new Dictionary<string, byte[]>();
|
||||
|
||||
foreach(Errno error in catalogCache.Keys.Select(CacheFile).Where(error => error != Errno.NoError))
|
||||
@@ -226,7 +227,7 @@ namespace DiscImageChef.Filesystems.AppleDOS
|
||||
if(!track1UsedByFiles) tracksOnBoot++;
|
||||
if(!track2UsedByFiles) tracksOnBoot++;
|
||||
|
||||
bootBlocks = device.ReadSectors(0, (uint)(tracksOnBoot * sectorsPerTrack));
|
||||
bootBlocks = device.ReadSectors(0, (uint)(tracksOnBoot * sectorsPerTrack));
|
||||
usedSectors += bootBlocks.Length / vtoc.bytesPerSector;
|
||||
|
||||
return Errno.NoError;
|
||||
|
||||
@@ -58,14 +58,14 @@ namespace DiscImageChef.Filesystems.AppleDOS
|
||||
vtoc = (Vtoc)Marshal.PtrToStructure(vtocPtr, typeof(Vtoc));
|
||||
Marshal.FreeHGlobal(vtocPtr);
|
||||
|
||||
return vtoc.catalogSector < spt && vtoc.maxTrackSectorPairsPerSector <= 122 &&
|
||||
vtoc.sectorsPerTrack == spt && vtoc.bytesPerSector == 256;
|
||||
return vtoc.catalogSector < spt && vtoc.maxTrackSectorPairsPerSector <= 122 &&
|
||||
vtoc.sectorsPerTrack == spt && vtoc.bytesPerSector == 256;
|
||||
}
|
||||
|
||||
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
|
||||
Encoding encoding)
|
||||
Encoding encoding)
|
||||
{
|
||||
Encoding = encoding ?? new Apple2();
|
||||
Encoding = encoding ?? new Apple2();
|
||||
information = "";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
@@ -96,10 +96,10 @@ namespace DiscImageChef.Filesystems.AppleDOS
|
||||
|
||||
XmlFsType = new FileSystemType
|
||||
{
|
||||
Bootable = true,
|
||||
Clusters = (long)imagePlugin.Info.Sectors,
|
||||
Bootable = true,
|
||||
Clusters = (long)imagePlugin.Info.Sectors,
|
||||
ClusterSize = (int)imagePlugin.Info.SectorSize,
|
||||
Type = "Apple DOS"
|
||||
Type = "Apple DOS"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,18 +43,23 @@ namespace DiscImageChef.Filesystems.AppleDOS
|
||||
public byte catalogTrack;
|
||||
public byte catalogSector;
|
||||
public byte dosRelease;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public byte[] unused2;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
|
||||
public byte[] unused2;
|
||||
public byte volumeNumber;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] public byte[] unused3;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
|
||||
public byte[] unused3;
|
||||
public byte maxTrackSectorPairsPerSector;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] unused4;
|
||||
public byte lastAllocatedSector;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
|
||||
public byte[] unused4;
|
||||
public byte lastAllocatedSector;
|
||||
public sbyte allocationDirection;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public byte[] unused5;
|
||||
public byte tracks;
|
||||
public byte sectorsPerTrack;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
|
||||
public byte[] unused5;
|
||||
public byte tracks;
|
||||
public byte sectorsPerTrack;
|
||||
public ushort bytesPerSector;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 200)] public byte[] bitmap;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 200)]
|
||||
public byte[] bitmap;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
@@ -63,8 +68,10 @@ namespace DiscImageChef.Filesystems.AppleDOS
|
||||
public byte unused1;
|
||||
public byte trackOfNext;
|
||||
public byte sectorOfNext;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] unused2;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 7)] public FileEntry[] entries;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
|
||||
public byte[] unused2;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 7)]
|
||||
public FileEntry[] entries;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
@@ -73,7 +80,8 @@ namespace DiscImageChef.Filesystems.AppleDOS
|
||||
public byte extentTrack;
|
||||
public byte extentSector;
|
||||
public byte typeAndFlags;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 30)] public byte[] filename;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 30)]
|
||||
public byte[] filename;
|
||||
public ushort length;
|
||||
}
|
||||
|
||||
@@ -83,10 +91,13 @@ namespace DiscImageChef.Filesystems.AppleDOS
|
||||
public byte unused1;
|
||||
public byte nextListTrack;
|
||||
public byte nextListSector;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public byte[] unused2;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
|
||||
public byte[] unused2;
|
||||
public ushort sectorOffset;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)] public byte[] unused3;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 122)] public TrackSectorListEntry[] entries;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
|
||||
public byte[] unused3;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 122)]
|
||||
public TrackSectorListEntry[] entries;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
|
||||
@@ -75,8 +75,8 @@ namespace DiscImageChef.Filesystems.AppleDOS
|
||||
sectorsPerTrack = device.Info.Sectors == 455 ? 13 : 16;
|
||||
|
||||
// Read the VTOC
|
||||
vtocBlocks = device.ReadSector((ulong)(17 * sectorsPerTrack));
|
||||
vtoc = new Vtoc();
|
||||
vtocBlocks = device.ReadSector((ulong)(17 * sectorsPerTrack));
|
||||
vtoc = new Vtoc();
|
||||
IntPtr vtocPtr = Marshal.AllocHGlobal(256);
|
||||
Marshal.Copy(vtocBlocks, 0, vtocPtr, 256);
|
||||
vtoc = (Vtoc)Marshal.PtrToStructure(vtocPtr, typeof(Vtoc));
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace DiscImageChef.Filesystems.AppleDOS
|
||||
|
||||
xattrs = new List<string>();
|
||||
|
||||
if(debug && (string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
|
||||
if(debug && (string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
|
||||
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 ||
|
||||
string.Compare(path, "$Vtoc", StringComparison.InvariantCulture) == 0)) { }
|
||||
else
|
||||
@@ -88,7 +88,7 @@ namespace DiscImageChef.Filesystems.AppleDOS
|
||||
string filename = pathElements[0].ToUpperInvariant();
|
||||
if(filename.Length > 30) return Errno.NameTooLong;
|
||||
|
||||
if(debug && (string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
|
||||
if(debug && (string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
|
||||
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 ||
|
||||
string.Compare(path, "$Vtoc", StringComparison.InvariantCulture) == 0))
|
||||
return Errno.NoSuchExtendedAttribute;
|
||||
@@ -99,7 +99,7 @@ namespace DiscImageChef.Filesystems.AppleDOS
|
||||
{
|
||||
if(!fileTypeCache.TryGetValue(filename, out byte type)) return Errno.InvalidArgument;
|
||||
|
||||
buf = new byte[1];
|
||||
buf = new byte[1];
|
||||
buf[0] = type;
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user