mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
🐛Correct UCSD Pascal filesystem on Apple II disks.
This commit is contained in:
@@ -47,7 +47,7 @@ namespace DiscImageChef.Filesystems.UCSDPascal
|
|||||||
if(!string.IsNullOrEmpty(path) && string.Compare(path, "/", StringComparison.OrdinalIgnoreCase) != 0)
|
if(!string.IsNullOrEmpty(path) && string.Compare(path, "/", StringComparison.OrdinalIgnoreCase) != 0)
|
||||||
return Errno.NotSupported;
|
return Errno.NotSupported;
|
||||||
|
|
||||||
contents = fileEntries.Select(ent => StringHandlers.PascalToString(ent.filename, Encoding)).ToList();
|
contents = fileEntries.Select(ent => StringHandlers.PascalToString(ent.Filename, Encoding)).ToList();
|
||||||
|
|
||||||
if(debug)
|
if(debug)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -70,17 +70,22 @@ namespace DiscImageChef.Filesystems.UCSDPascal
|
|||||||
|
|
||||||
byte[] file;
|
byte[] file;
|
||||||
|
|
||||||
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, "$Boot", StringComparison.InvariantCulture) == 0))
|
||||||
file = string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ? catalogBlocks : bootBlocks;
|
file = string.Compare(path, "$", StringComparison.InvariantCulture) == 0
|
||||||
|
? catalogBlocks
|
||||||
|
: bootBlocks;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Errno error = GetFileEntry(path, out PascalFileEntry entry);
|
Errno error = GetFileEntry(path, out PascalFileEntry entry);
|
||||||
|
|
||||||
if(error != Errno.NoError) return error;
|
if(error != Errno.NoError) return error;
|
||||||
|
|
||||||
byte[] tmp = device.ReadSectors((ulong)entry.firstBlock, (uint)(entry.lastBlock - entry.firstBlock));
|
byte[] tmp = device.ReadSectors((ulong)entry.FirstBlock * multiplier,
|
||||||
file = new byte[(entry.lastBlock - entry.firstBlock - 1) * device.Info.SectorSize + entry.lastBytes];
|
(uint)(entry.LastBlock - entry.FirstBlock) * multiplier);
|
||||||
|
file = new byte[(entry.LastBlock - entry.FirstBlock - 1) *
|
||||||
|
device.Info.SectorSize * multiplier +
|
||||||
|
entry.LastBytes];
|
||||||
Array.Copy(tmp, 0, file, 0, file.Length);
|
Array.Copy(tmp, 0, file, 0, file.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,19 +108,19 @@ namespace DiscImageChef.Filesystems.UCSDPascal
|
|||||||
if(pathElements.Length != 1) return Errno.NotSupported;
|
if(pathElements.Length != 1) return Errno.NotSupported;
|
||||||
|
|
||||||
if(debug)
|
if(debug)
|
||||||
if(string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
|
if(string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
|
||||||
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0)
|
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0)
|
||||||
{
|
{
|
||||||
stat = new FileEntryInfo
|
stat = new FileEntryInfo
|
||||||
{
|
{
|
||||||
Attributes = FileAttributes.System,
|
Attributes = FileAttributes.System,
|
||||||
BlockSize = device.Info.SectorSize,
|
BlockSize = device.Info.SectorSize * multiplier,
|
||||||
DeviceNo = 0,
|
DeviceNo = 0,
|
||||||
GID = 0,
|
GID = 0,
|
||||||
Inode = 0,
|
Inode = 0,
|
||||||
Links = 1,
|
Links = 1,
|
||||||
Mode = 0x124,
|
Mode = 0x124,
|
||||||
UID = 0
|
UID = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
if(string.Compare(path, "$", StringComparison.InvariantCulture) == 0)
|
if(string.Compare(path, "$", StringComparison.InvariantCulture) == 0)
|
||||||
@@ -138,17 +143,18 @@ namespace DiscImageChef.Filesystems.UCSDPascal
|
|||||||
|
|
||||||
stat = new FileEntryInfo
|
stat = new FileEntryInfo
|
||||||
{
|
{
|
||||||
Attributes = FileAttributes.File,
|
Attributes = FileAttributes.File,
|
||||||
Blocks = entry.lastBlock - entry.firstBlock,
|
Blocks = entry.LastBlock - entry.FirstBlock,
|
||||||
BlockSize = device.Info.SectorSize,
|
BlockSize = device.Info.SectorSize * multiplier,
|
||||||
DeviceNo = 0,
|
DeviceNo = 0,
|
||||||
GID = 0,
|
GID = 0,
|
||||||
Inode = 0,
|
Inode = 0,
|
||||||
LastWriteTimeUtc = DateHandlers.UcsdPascalToDateTime(entry.mtime),
|
LastWriteTimeUtc = DateHandlers.UcsdPascalToDateTime(entry.ModificationTime),
|
||||||
Length = (entry.lastBlock - entry.firstBlock) * device.Info.SectorSize + entry.lastBytes,
|
Length = (entry.LastBlock - entry.FirstBlock) * device.Info.SectorSize * multiplier +
|
||||||
|
entry.LastBytes,
|
||||||
Links = 1,
|
Links = 1,
|
||||||
Mode = 0x124,
|
Mode = 0x124,
|
||||||
UID = 0
|
UID = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
return Errno.NoError;
|
return Errno.NoError;
|
||||||
@@ -161,10 +167,10 @@ namespace DiscImageChef.Filesystems.UCSDPascal
|
|||||||
foreach(PascalFileEntry ent in fileEntries.Where(ent =>
|
foreach(PascalFileEntry ent in fileEntries.Where(ent =>
|
||||||
string.Compare(path,
|
string.Compare(path,
|
||||||
StringHandlers
|
StringHandlers
|
||||||
.PascalToString(ent.filename,
|
.PascalToString(ent.Filename,
|
||||||
Encoding),
|
Encoding),
|
||||||
StringComparison
|
StringComparison
|
||||||
.InvariantCultureIgnoreCase) == 0))
|
.InvariantCultureIgnoreCase) == 0))
|
||||||
{
|
{
|
||||||
entry = ent;
|
entry = ent;
|
||||||
return Errno.NoError;
|
return Errno.NoError;
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ using System;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Claunia.Encoding;
|
using Claunia.Encoding;
|
||||||
using DiscImageChef.CommonTypes;
|
using DiscImageChef.CommonTypes;
|
||||||
|
using DiscImageChef.Console;
|
||||||
using DiscImageChef.DiscImages;
|
using DiscImageChef.DiscImages;
|
||||||
using Schemas;
|
using Schemas;
|
||||||
using Encoding = System.Text.Encoding;
|
using Encoding = System.Text.Encoding;
|
||||||
@@ -47,111 +48,129 @@ namespace DiscImageChef.Filesystems.UCSDPascal
|
|||||||
{
|
{
|
||||||
if(partition.Length < 3) return false;
|
if(partition.Length < 3) return false;
|
||||||
|
|
||||||
|
multiplier = (uint)(imagePlugin.Info.SectorSize == 256 ? 2 : 1);
|
||||||
|
|
||||||
// Blocks 0 and 1 are boot code
|
// Blocks 0 and 1 are boot code
|
||||||
byte[] volBlock = imagePlugin.ReadSector(2 + partition.Start);
|
byte[] volBlock = imagePlugin.ReadSectors(multiplier * 2 + partition.Start, multiplier);
|
||||||
|
|
||||||
PascalVolumeEntry volEntry = new PascalVolumeEntry();
|
PascalVolumeEntry volEntry = new PascalVolumeEntry();
|
||||||
|
|
||||||
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
// On Apple II, it's little endian
|
||||||
|
BigEndianBitConverter.IsLittleEndian =
|
||||||
|
multiplier == 2 ? !BitConverter.IsLittleEndian : BitConverter.IsLittleEndian;
|
||||||
|
|
||||||
volEntry.firstBlock = BigEndianBitConverter.ToInt16(volBlock, 0x00);
|
volEntry.FirstBlock = BigEndianBitConverter.ToInt16(volBlock, 0x00);
|
||||||
volEntry.lastBlock = BigEndianBitConverter.ToInt16(volBlock, 0x02);
|
volEntry.LastBlock = BigEndianBitConverter.ToInt16(volBlock, 0x02);
|
||||||
volEntry.entryType = (PascalFileKind)BigEndianBitConverter.ToInt16(volBlock, 0x04);
|
volEntry.EntryType = (PascalFileKind)BigEndianBitConverter.ToInt16(volBlock, 0x04);
|
||||||
volEntry.volumeName = new byte[8];
|
volEntry.VolumeName = new byte[8];
|
||||||
Array.Copy(volBlock, 0x06, volEntry.volumeName, 0, 8);
|
Array.Copy(volBlock, 0x06, volEntry.VolumeName, 0, 8);
|
||||||
volEntry.blocks = BigEndianBitConverter.ToInt16(volBlock, 0x0E);
|
volEntry.Blocks = BigEndianBitConverter.ToInt16(volBlock, 0x0E);
|
||||||
volEntry.files = BigEndianBitConverter.ToInt16(volBlock, 0x10);
|
volEntry.Files = BigEndianBitConverter.ToInt16(volBlock, 0x10);
|
||||||
volEntry.dummy = BigEndianBitConverter.ToInt16(volBlock, 0x12);
|
volEntry.Dummy = BigEndianBitConverter.ToInt16(volBlock, 0x12);
|
||||||
volEntry.lastBoot = BigEndianBitConverter.ToInt16(volBlock, 0x14);
|
volEntry.LastBoot = BigEndianBitConverter.ToInt16(volBlock, 0x14);
|
||||||
volEntry.tail = BigEndianBitConverter.ToInt32(volBlock, 0x16);
|
volEntry.Tail = BigEndianBitConverter.ToInt32(volBlock, 0x16);
|
||||||
|
|
||||||
|
DicConsole.DebugWriteLine("UCSD Pascal Plugin", "volEntry.firstBlock = {0}", volEntry.FirstBlock);
|
||||||
|
DicConsole.DebugWriteLine("UCSD Pascal Plugin", "volEntry.lastBlock = {0}", volEntry.LastBlock);
|
||||||
|
DicConsole.DebugWriteLine("UCSD Pascal Plugin", "volEntry.entryType = {0}", volEntry.EntryType);
|
||||||
|
DicConsole.DebugWriteLine("UCSD Pascal Plugin", "volEntry.volumeName = {0}", volEntry.VolumeName);
|
||||||
|
DicConsole.DebugWriteLine("UCSD Pascal Plugin", "volEntry.blocks = {0}", volEntry.Blocks);
|
||||||
|
DicConsole.DebugWriteLine("UCSD Pascal Plugin", "volEntry.files = {0}", volEntry.Files);
|
||||||
|
DicConsole.DebugWriteLine("UCSD Pascal Plugin", "volEntry.dummy = {0}", volEntry.Dummy);
|
||||||
|
DicConsole.DebugWriteLine("UCSD Pascal Plugin", "volEntry.lastBoot = {0}", volEntry.LastBoot);
|
||||||
|
DicConsole.DebugWriteLine("UCSD Pascal Plugin", "volEntry.tail = {0}", volEntry.Tail);
|
||||||
|
|
||||||
// First block is always 0 (even is it's sector 2)
|
// First block is always 0 (even is it's sector 2)
|
||||||
if(volEntry.firstBlock != 0) return false;
|
if(volEntry.FirstBlock != 0) return false;
|
||||||
|
|
||||||
// Last volume record block must be after first block, and before end of device
|
// Last volume record block must be after first block, and before end of device
|
||||||
if(volEntry.lastBlock <= volEntry.firstBlock ||
|
if(volEntry.LastBlock <= volEntry.FirstBlock ||
|
||||||
(ulong)volEntry.lastBlock > imagePlugin.Info.Sectors - 2) return false;
|
(ulong)volEntry.LastBlock > imagePlugin.Info.Sectors / multiplier - 2) return false;
|
||||||
|
|
||||||
// Volume record entry type must be volume or secure
|
// Volume record entry type must be volume or secure
|
||||||
if(volEntry.entryType != PascalFileKind.Volume && volEntry.entryType != PascalFileKind.Secure) return false;
|
if(volEntry.EntryType != PascalFileKind.Volume && volEntry.EntryType != PascalFileKind.Secure) return false;
|
||||||
|
|
||||||
// Volume name is max 7 characters
|
// Volume name is max 7 characters
|
||||||
if(volEntry.volumeName[0] > 7) return false;
|
if(volEntry.VolumeName[0] > 7) return false;
|
||||||
|
|
||||||
// Volume blocks is equal to volume sectors
|
// Volume blocks is equal to volume sectors
|
||||||
if(volEntry.blocks < 0 || (ulong)volEntry.blocks != imagePlugin.Info.Sectors) return false;
|
if(volEntry.Blocks < 0 || (ulong)volEntry.Blocks != imagePlugin.Info.Sectors / multiplier) return false;
|
||||||
|
|
||||||
// There can be not less than zero files
|
// There can be not less than zero files
|
||||||
return volEntry.files >= 0;
|
return volEntry.Files >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
|
||||||
Encoding encoding)
|
Encoding encoding)
|
||||||
{
|
{
|
||||||
Encoding = encoding ?? new Apple2();
|
Encoding = encoding ?? new Apple2();
|
||||||
StringBuilder sbInformation = new StringBuilder();
|
StringBuilder sbInformation = new StringBuilder();
|
||||||
information = "";
|
information = "";
|
||||||
|
multiplier = (uint)(imagePlugin.Info.SectorSize == 256 ? 2 : 1);
|
||||||
|
|
||||||
if(imagePlugin.Info.Sectors < 3) return;
|
if(imagePlugin.Info.Sectors < 3) return;
|
||||||
|
|
||||||
// Blocks 0 and 1 are boot code
|
// Blocks 0 and 1 are boot code
|
||||||
byte[] volBlock = imagePlugin.ReadSector(2 + partition.Start);
|
byte[] volBlock = imagePlugin.ReadSectors(multiplier * 2 + partition.Start, multiplier);
|
||||||
|
|
||||||
PascalVolumeEntry volEntry = new PascalVolumeEntry();
|
PascalVolumeEntry volEntry = new PascalVolumeEntry();
|
||||||
|
|
||||||
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
// On Apple //, it's little endian
|
||||||
|
BigEndianBitConverter.IsLittleEndian =
|
||||||
|
multiplier == 2 ? !BitConverter.IsLittleEndian : BitConverter.IsLittleEndian;
|
||||||
|
|
||||||
volEntry.firstBlock = BigEndianBitConverter.ToInt16(volBlock, 0x00);
|
volEntry.FirstBlock = BigEndianBitConverter.ToInt16(volBlock, 0x00);
|
||||||
volEntry.lastBlock = BigEndianBitConverter.ToInt16(volBlock, 0x02);
|
volEntry.LastBlock = BigEndianBitConverter.ToInt16(volBlock, 0x02);
|
||||||
volEntry.entryType = (PascalFileKind)BigEndianBitConverter.ToInt16(volBlock, 0x04);
|
volEntry.EntryType = (PascalFileKind)BigEndianBitConverter.ToInt16(volBlock, 0x04);
|
||||||
volEntry.volumeName = new byte[8];
|
volEntry.VolumeName = new byte[8];
|
||||||
Array.Copy(volBlock, 0x06, volEntry.volumeName, 0, 8);
|
Array.Copy(volBlock, 0x06, volEntry.VolumeName, 0, 8);
|
||||||
volEntry.blocks = BigEndianBitConverter.ToInt16(volBlock, 0x0E);
|
volEntry.Blocks = BigEndianBitConverter.ToInt16(volBlock, 0x0E);
|
||||||
volEntry.files = BigEndianBitConverter.ToInt16(volBlock, 0x10);
|
volEntry.Files = BigEndianBitConverter.ToInt16(volBlock, 0x10);
|
||||||
volEntry.dummy = BigEndianBitConverter.ToInt16(volBlock, 0x12);
|
volEntry.Dummy = BigEndianBitConverter.ToInt16(volBlock, 0x12);
|
||||||
volEntry.lastBoot = BigEndianBitConverter.ToInt16(volBlock, 0x14);
|
volEntry.LastBoot = BigEndianBitConverter.ToInt16(volBlock, 0x14);
|
||||||
volEntry.tail = BigEndianBitConverter.ToInt32(volBlock, 0x16);
|
volEntry.Tail = BigEndianBitConverter.ToInt32(volBlock, 0x16);
|
||||||
|
|
||||||
// First block is always 0 (even is it's sector 2)
|
// First block is always 0 (even is it's sector 2)
|
||||||
if(volEntry.firstBlock != 0) return;
|
if(volEntry.FirstBlock != 0) return;
|
||||||
|
|
||||||
// Last volume record block must be after first block, and before end of device
|
// Last volume record block must be after first block, and before end of device
|
||||||
if(volEntry.lastBlock <= volEntry.firstBlock ||
|
if(volEntry.LastBlock <= volEntry.FirstBlock ||
|
||||||
(ulong)volEntry.lastBlock > imagePlugin.Info.Sectors - 2) return;
|
(ulong)volEntry.LastBlock > imagePlugin.Info.Sectors / multiplier - 2) return;
|
||||||
|
|
||||||
// Volume record entry type must be volume or secure
|
// Volume record entry type must be volume or secure
|
||||||
if(volEntry.entryType != PascalFileKind.Volume && volEntry.entryType != PascalFileKind.Secure) return;
|
if(volEntry.EntryType != PascalFileKind.Volume && volEntry.EntryType != PascalFileKind.Secure) return;
|
||||||
|
|
||||||
// Volume name is max 7 characters
|
// Volume name is max 7 characters
|
||||||
if(volEntry.volumeName[0] > 7) return;
|
if(volEntry.VolumeName[0] > 7) return;
|
||||||
|
|
||||||
// Volume blocks is equal to volume sectors
|
// Volume blocks is equal to volume sectors
|
||||||
if(volEntry.blocks < 0 || (ulong)volEntry.blocks != imagePlugin.Info.Sectors) return;
|
if(volEntry.Blocks < 0 || (ulong)volEntry.Blocks != imagePlugin.Info.Sectors / multiplier) return;
|
||||||
|
|
||||||
// There can be not less than zero files
|
// There can be not less than zero files
|
||||||
if(volEntry.files < 0) return;
|
if(volEntry.Files < 0) return;
|
||||||
|
|
||||||
sbInformation.AppendFormat("Volume record spans from block {0} to block {1}", volEntry.firstBlock,
|
sbInformation.AppendFormat("Volume record spans from block {0} to block {1}", volEntry.FirstBlock,
|
||||||
volEntry.lastBlock).AppendLine();
|
volEntry.LastBlock).AppendLine();
|
||||||
sbInformation.AppendFormat("Volume name: {0}", StringHandlers.PascalToString(volEntry.volumeName, Encoding))
|
sbInformation.AppendFormat("Volume name: {0}", StringHandlers.PascalToString(volEntry.VolumeName, Encoding))
|
||||||
.AppendLine();
|
.AppendLine();
|
||||||
sbInformation.AppendFormat("Volume has {0} blocks", volEntry.blocks).AppendLine();
|
sbInformation.AppendFormat("Volume has {0} blocks", volEntry.Blocks).AppendLine();
|
||||||
sbInformation.AppendFormat("Volume has {0} files", volEntry.files).AppendLine();
|
sbInformation.AppendFormat("Volume has {0} files", volEntry.Files).AppendLine();
|
||||||
sbInformation
|
sbInformation
|
||||||
.AppendFormat("Volume last booted at {0}", DateHandlers.UcsdPascalToDateTime(volEntry.lastBoot))
|
.AppendFormat("Volume last booted at {0}", DateHandlers.UcsdPascalToDateTime(volEntry.LastBoot))
|
||||||
.AppendLine();
|
.AppendLine();
|
||||||
|
|
||||||
information = sbInformation.ToString();
|
information = sbInformation.ToString();
|
||||||
|
|
||||||
XmlFsType = new FileSystemType
|
XmlFsType = new FileSystemType
|
||||||
{
|
{
|
||||||
Bootable = !ArrayHelpers.ArrayIsNullOrEmpty(imagePlugin.ReadSectors(partition.Start, 2)),
|
Bootable =
|
||||||
Clusters = volEntry.blocks,
|
!ArrayHelpers.ArrayIsNullOrEmpty(imagePlugin.ReadSectors(partition.Start, multiplier * 2)),
|
||||||
ClusterSize = (int)imagePlugin.Info.SectorSize,
|
Clusters = volEntry.Blocks,
|
||||||
Files = volEntry.files,
|
ClusterSize = (int)imagePlugin.Info.SectorSize,
|
||||||
|
Files = volEntry.Files,
|
||||||
FilesSpecified = true,
|
FilesSpecified = true,
|
||||||
Type = "UCSD Pascal",
|
Type = "UCSD Pascal",
|
||||||
VolumeName = StringHandlers.PascalToString(volEntry.volumeName, Encoding)
|
VolumeName = StringHandlers.PascalToString(volEntry.VolumeName, Encoding)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,39 +38,39 @@ namespace DiscImageChef.Filesystems.UCSDPascal
|
|||||||
struct PascalVolumeEntry
|
struct PascalVolumeEntry
|
||||||
{
|
{
|
||||||
/// <summary>0x00, first block of volume entry</summary>
|
/// <summary>0x00, first block of volume entry</summary>
|
||||||
public short firstBlock;
|
public short FirstBlock;
|
||||||
/// <summary>0x02, last block of volume entry</summary>
|
/// <summary>0x02, last block of volume entry</summary>
|
||||||
public short lastBlock;
|
public short LastBlock;
|
||||||
/// <summary>0x04, entry type</summary>
|
/// <summary>0x04, entry type</summary>
|
||||||
public PascalFileKind entryType;
|
public PascalFileKind EntryType;
|
||||||
/// <summary>0x06, volume name</summary>
|
/// <summary>0x06, volume name</summary>
|
||||||
public byte[] volumeName;
|
public byte[] VolumeName;
|
||||||
/// <summary>0x0E, block in volume</summary>
|
/// <summary>0x0E, block in volume</summary>
|
||||||
public short blocks;
|
public short Blocks;
|
||||||
/// <summary>0x10, files in volume</summary>
|
/// <summary>0x10, files in volume</summary>
|
||||||
public short files;
|
public short Files;
|
||||||
/// <summary>0x12, dummy</summary>
|
/// <summary>0x12, dummy</summary>
|
||||||
public short dummy;
|
public short Dummy;
|
||||||
/// <summary>0x14, last booted</summary>
|
/// <summary>0x14, last booted</summary>
|
||||||
public short lastBoot;
|
public short LastBoot;
|
||||||
/// <summary>0x16, tail to make record same size as <see cref="PascalFileEntry" /></summary>
|
/// <summary>0x16, tail to make record same size as <see cref="PascalFileEntry" /></summary>
|
||||||
public int tail;
|
public int Tail;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct PascalFileEntry
|
struct PascalFileEntry
|
||||||
{
|
{
|
||||||
/// <summary>0x00, first block of file</summary>
|
/// <summary>0x00, first block of file</summary>
|
||||||
public short firstBlock;
|
public short FirstBlock;
|
||||||
/// <summary>0x02, last block of file</summary>
|
/// <summary>0x02, last block of file</summary>
|
||||||
public short lastBlock;
|
public short LastBlock;
|
||||||
/// <summary>0x04, entry type</summary>
|
/// <summary>0x04, entry type</summary>
|
||||||
public PascalFileKind entryType;
|
public PascalFileKind EntryType;
|
||||||
/// <summary>0x06, file name</summary>
|
/// <summary>0x06, file name</summary>
|
||||||
public byte[] filename;
|
public byte[] Filename;
|
||||||
/// <summary>0x16, bytes used in last block</summary>
|
/// <summary>0x16, bytes used in last block</summary>
|
||||||
public short lastBytes;
|
public short LastBytes;
|
||||||
/// <summary>0x18, modification time</summary>
|
/// <summary>0x18, modification time</summary>
|
||||||
public short mtime;
|
public short ModificationTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,65 +52,71 @@ namespace DiscImageChef.Filesystems.UCSDPascal
|
|||||||
if(options.TryGetValue("debug", out string debugString)) bool.TryParse(debugString, out debug);
|
if(options.TryGetValue("debug", out string debugString)) bool.TryParse(debugString, out debug);
|
||||||
if(device.Info.Sectors < 3) return Errno.InvalidArgument;
|
if(device.Info.Sectors < 3) return Errno.InvalidArgument;
|
||||||
|
|
||||||
|
multiplier = (uint)(imagePlugin.Info.SectorSize == 256 ? 2 : 1);
|
||||||
|
|
||||||
// Blocks 0 and 1 are boot code
|
// Blocks 0 and 1 are boot code
|
||||||
catalogBlocks = device.ReadSector(2);
|
catalogBlocks = device.ReadSectors(multiplier * 2, multiplier);
|
||||||
|
|
||||||
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
// On Apple //, it's little endian
|
||||||
|
BigEndianBitConverter.IsLittleEndian =
|
||||||
|
multiplier == 2 ? !BitConverter.IsLittleEndian : BitConverter.IsLittleEndian;
|
||||||
|
|
||||||
mountedVolEntry.firstBlock = BigEndianBitConverter.ToInt16(catalogBlocks, 0x00);
|
mountedVolEntry.FirstBlock = BigEndianBitConverter.ToInt16(catalogBlocks, 0x00);
|
||||||
mountedVolEntry.lastBlock = BigEndianBitConverter.ToInt16(catalogBlocks, 0x02);
|
mountedVolEntry.LastBlock = BigEndianBitConverter.ToInt16(catalogBlocks, 0x02);
|
||||||
mountedVolEntry.entryType = (PascalFileKind)BigEndianBitConverter.ToInt16(catalogBlocks, 0x04);
|
mountedVolEntry.EntryType = (PascalFileKind)BigEndianBitConverter.ToInt16(catalogBlocks, 0x04);
|
||||||
mountedVolEntry.volumeName = new byte[8];
|
mountedVolEntry.VolumeName = new byte[8];
|
||||||
Array.Copy(catalogBlocks, 0x06, mountedVolEntry.volumeName, 0, 8);
|
Array.Copy(catalogBlocks, 0x06, mountedVolEntry.VolumeName, 0, 8);
|
||||||
mountedVolEntry.blocks = BigEndianBitConverter.ToInt16(catalogBlocks, 0x0E);
|
mountedVolEntry.Blocks = BigEndianBitConverter.ToInt16(catalogBlocks, 0x0E);
|
||||||
mountedVolEntry.files = BigEndianBitConverter.ToInt16(catalogBlocks, 0x10);
|
mountedVolEntry.Files = BigEndianBitConverter.ToInt16(catalogBlocks, 0x10);
|
||||||
mountedVolEntry.dummy = BigEndianBitConverter.ToInt16(catalogBlocks, 0x12);
|
mountedVolEntry.Dummy = BigEndianBitConverter.ToInt16(catalogBlocks, 0x12);
|
||||||
mountedVolEntry.lastBoot = BigEndianBitConverter.ToInt16(catalogBlocks, 0x14);
|
mountedVolEntry.LastBoot = BigEndianBitConverter.ToInt16(catalogBlocks, 0x14);
|
||||||
mountedVolEntry.tail = BigEndianBitConverter.ToInt32(catalogBlocks, 0x16);
|
mountedVolEntry.Tail = BigEndianBitConverter.ToInt32(catalogBlocks, 0x16);
|
||||||
|
|
||||||
if(mountedVolEntry.firstBlock != 0 ||
|
if(mountedVolEntry.FirstBlock != 0 ||
|
||||||
mountedVolEntry.lastBlock <= mountedVolEntry.firstBlock ||
|
mountedVolEntry.LastBlock <= mountedVolEntry.FirstBlock ||
|
||||||
(ulong)mountedVolEntry.lastBlock > device.Info.Sectors - 2 ||
|
(ulong)mountedVolEntry.LastBlock > device.Info.Sectors / multiplier - 2 ||
|
||||||
mountedVolEntry.entryType != PascalFileKind.Volume &&
|
mountedVolEntry.EntryType != PascalFileKind.Volume &&
|
||||||
mountedVolEntry.entryType != PascalFileKind.Secure ||
|
mountedVolEntry.EntryType != PascalFileKind.Secure ||
|
||||||
mountedVolEntry.volumeName[0] > 7 ||
|
mountedVolEntry.VolumeName[0] > 7 ||
|
||||||
mountedVolEntry.blocks < 0 ||
|
mountedVolEntry.Blocks < 0 ||
|
||||||
(ulong)mountedVolEntry.blocks != device.Info.Sectors ||
|
(ulong)mountedVolEntry.Blocks != device.Info.Sectors / multiplier ||
|
||||||
mountedVolEntry.files < 0) return Errno.InvalidArgument;
|
mountedVolEntry.Files < 0) return Errno.InvalidArgument;
|
||||||
|
|
||||||
catalogBlocks = device.ReadSectors(2, (uint)(mountedVolEntry.lastBlock - mountedVolEntry.firstBlock - 2));
|
catalogBlocks = device.ReadSectors(multiplier * 2,
|
||||||
int offset = 26;
|
(uint)(mountedVolEntry.LastBlock - mountedVolEntry.FirstBlock - 2) *
|
||||||
|
multiplier);
|
||||||
|
int offset = 26;
|
||||||
|
|
||||||
fileEntries = new List<PascalFileEntry>();
|
fileEntries = new List<PascalFileEntry>();
|
||||||
while(offset + 26 < catalogBlocks.Length)
|
while(offset + 26 < catalogBlocks.Length)
|
||||||
{
|
{
|
||||||
PascalFileEntry entry = new PascalFileEntry
|
PascalFileEntry entry = new PascalFileEntry
|
||||||
{
|
{
|
||||||
filename = new byte[16],
|
Filename = new byte[16],
|
||||||
firstBlock = BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x00),
|
FirstBlock = BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x00),
|
||||||
lastBlock = BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x02),
|
LastBlock = BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x02),
|
||||||
entryType = (PascalFileKind)BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x04),
|
EntryType = (PascalFileKind)BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x04),
|
||||||
lastBytes = BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x16),
|
LastBytes = BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x16),
|
||||||
mtime = BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x18)
|
ModificationTime = BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x18)
|
||||||
};
|
};
|
||||||
Array.Copy(catalogBlocks, offset + 0x06, entry.filename, 0, 16);
|
Array.Copy(catalogBlocks, offset + 0x06, entry.Filename, 0, 16);
|
||||||
|
|
||||||
if(entry.filename[0] <= 15 && entry.filename[0] > 0) fileEntries.Add(entry);
|
if(entry.Filename[0] <= 15 && entry.Filename[0] > 0) fileEntries.Add(entry);
|
||||||
|
|
||||||
offset += 26;
|
offset += 26;
|
||||||
}
|
}
|
||||||
|
|
||||||
bootBlocks = device.ReadSectors(0, 2);
|
bootBlocks = device.ReadSectors(0, 2 * multiplier);
|
||||||
|
|
||||||
XmlFsType = new FileSystemType
|
XmlFsType = new FileSystemType
|
||||||
{
|
{
|
||||||
Bootable = !ArrayHelpers.ArrayIsNullOrEmpty(bootBlocks),
|
Bootable = !ArrayHelpers.ArrayIsNullOrEmpty(bootBlocks),
|
||||||
Clusters = mountedVolEntry.blocks,
|
Clusters = mountedVolEntry.Blocks,
|
||||||
ClusterSize = (int)device.Info.SectorSize,
|
ClusterSize = (int)device.Info.SectorSize,
|
||||||
Files = mountedVolEntry.files,
|
Files = mountedVolEntry.Files,
|
||||||
FilesSpecified = true,
|
FilesSpecified = true,
|
||||||
Type = "UCSD Pascal",
|
Type = "UCSD Pascal",
|
||||||
VolumeName = StringHandlers.PascalToString(mountedVolEntry.volumeName, Encoding)
|
VolumeName = StringHandlers.PascalToString(mountedVolEntry.VolumeName, Encoding)
|
||||||
};
|
};
|
||||||
|
|
||||||
mounted = true;
|
mounted = true;
|
||||||
@@ -129,17 +135,17 @@ namespace DiscImageChef.Filesystems.UCSDPascal
|
|||||||
{
|
{
|
||||||
stat = new FileSystemInfo
|
stat = new FileSystemInfo
|
||||||
{
|
{
|
||||||
Blocks = mountedVolEntry.blocks,
|
Blocks = mountedVolEntry.Blocks,
|
||||||
FilenameLength = 16,
|
FilenameLength = 16,
|
||||||
Files = (ulong)mountedVolEntry.files,
|
Files = (ulong)mountedVolEntry.Files,
|
||||||
FreeBlocks = 0,
|
FreeBlocks = 0,
|
||||||
PluginId = Id,
|
PluginId = Id,
|
||||||
Type = "UCSD Pascal"
|
Type = "UCSD Pascal"
|
||||||
};
|
};
|
||||||
|
|
||||||
stat.FreeBlocks = mountedVolEntry.blocks - (mountedVolEntry.lastBlock - mountedVolEntry.firstBlock);
|
stat.FreeBlocks = mountedVolEntry.Blocks - (mountedVolEntry.LastBlock - mountedVolEntry.FirstBlock);
|
||||||
|
|
||||||
foreach(PascalFileEntry entry in fileEntries) stat.FreeBlocks -= entry.lastBlock - entry.firstBlock;
|
foreach(PascalFileEntry entry in fileEntries) stat.FreeBlocks -= entry.LastBlock - entry.FirstBlock;
|
||||||
|
|
||||||
return Errno.NotImplemented;
|
return Errno.NotImplemented;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ namespace DiscImageChef.Filesystems.UCSDPascal
|
|||||||
bool mounted;
|
bool mounted;
|
||||||
|
|
||||||
PascalVolumeEntry mountedVolEntry;
|
PascalVolumeEntry mountedVolEntry;
|
||||||
|
/// <summary>Apple II disks use 256 bytes / sector, but filesystem assumes it's 512 bytes / sector</summary>
|
||||||
|
uint multiplier;
|
||||||
|
|
||||||
public FileSystemType XmlFsType { get; private set; }
|
public FileSystemType XmlFsType { get; private set; }
|
||||||
public string Name => "U.C.S.D. Pascal filesystem";
|
public string Name => "U.C.S.D. Pascal filesystem";
|
||||||
|
|||||||
Reference in New Issue
Block a user