REFACTOR: Final cleanup of DiscImageChef.Filesystems.

This commit is contained in:
2017-12-24 02:37:41 +00:00
parent ec73a6cdc3
commit 4115698ac8
94 changed files with 5196 additions and 5116 deletions

View File

@@ -40,75 +40,75 @@ namespace DiscImageChef.Filesystems.CPM
{
partial class CPM : Filesystem
{
bool mounted;
readonly ImagePlugin device;
Partition partition;
/// <summary>
/// Stores all known CP/M disk definitions
/// </summary>
CpmDefinitions definitions;
/// <summary>
/// True if <see cref="Identify"/> thinks this is a CP/M filesystem
/// True if <see cref="Identify" /> thinks this is a CP/M filesystem
/// </summary>
bool cpmFound;
/// <summary>
/// If <see cref="Identify"/> thinks this is a CP/M filesystem, this is the definition for it
/// </summary>
CpmDefinition workingDefinition;
/// <summary>
/// CP/M disc parameter block (on-memory)
/// </summary>
DiscParameterBlock dpb;
/// <summary>
/// Sector deinterleaving mask
/// </summary>
int[] sectorMask;
/// <summary>
/// The volume label, if the CP/M filesystem contains one
/// </summary>
string label;
/// <summary>
/// True if there are timestamps in Z80DOS or DOS+ format
/// </summary>
bool thirdPartyTimestamps;
/// <summary>
/// True if there are CP/M 3 timestamps
/// </summary>
bool standardTimestamps;
/// <summary>
/// Timestamp in volume label for creation
/// </summary>
byte[] labelCreationDate;
/// <summary>
/// Timestamp in volume label for update
/// </summary>
byte[] labelUpdateDate;
/// <summary>
/// Cached <see cref="FileSystemInfo"/>
/// Cached <see cref="FileSystemInfo" />
/// </summary>
FileSystemInfo cpmStat;
/// <summary>
/// Cached directory listing
/// Cached file passwords, decoded
/// </summary>
Dictionary<string, byte[]> decodedPasswordCache;
/// <summary>
/// Stores all known CP/M disk definitions
/// </summary>
CpmDefinitions definitions;
/// <summary>
/// Cached directory listing
/// </summary>
List<string> dirList;
/// <summary>
/// Cached file data
/// CP/M disc parameter block (on-memory)
/// </summary>
DiscParameterBlock dpb;
/// <summary>
/// Cached file data
/// </summary>
Dictionary<string, byte[]> fileCache;
/// <summary>
/// Cached file <see cref="FileEntryInfo"/>
/// The volume label, if the CP/M filesystem contains one
/// </summary>
Dictionary<string, FileEntryInfo> statCache;
string label;
/// <summary>
/// Cached file passwords
/// Timestamp in volume label for creation
/// </summary>
byte[] labelCreationDate;
/// <summary>
/// Timestamp in volume label for update
/// </summary>
byte[] labelUpdateDate;
bool mounted;
Partition partition;
/// <summary>
/// Cached file passwords
/// </summary>
Dictionary<string, byte[]> passwordCache;
/// <summary>
/// Cached file passwords, decoded
/// Sector deinterleaving mask
/// </summary>
Dictionary<string, byte[]> decodedPasswordCache;
int[] sectorMask;
/// <summary>
/// True if there are CP/M 3 timestamps
/// </summary>
bool standardTimestamps;
/// <summary>
/// Cached file <see cref="FileEntryInfo" />
/// </summary>
Dictionary<string, FileEntryInfo> statCache;
/// <summary>
/// True if there are timestamps in Z80DOS or DOS+ format
/// </summary>
bool thirdPartyTimestamps;
/// <summary>
/// If <see cref="Identify" /> thinks this is a CP/M filesystem, this is the definition for it
/// </summary>
CpmDefinition workingDefinition;
public CPM()
{

View File

@@ -35,48 +35,48 @@ namespace DiscImageChef.Filesystems.CPM
partial class CPM
{
/// <summary>
/// Enumerates the format identification byte used by CP/M-86
/// Enumerates the format identification byte used by CP/M-86
/// </summary>
enum FormatByte : byte
{
/// <summary>
/// 5.25" double-density single-side 8 sectors/track
/// 5.25" double-density single-side 8 sectors/track
/// </summary>
k160 = 0,
/// <summary>
/// 5.25" double-density double-side 8 sectors/track
/// 5.25" double-density double-side 8 sectors/track
/// </summary>
k320 = 1,
/// <summary>
/// 5.25" double-density double-side 9 sectors/track
/// 5.25" double-density double-side 9 sectors/track
/// </summary>
k360 = 0x10,
/// <summary>
/// 5.25" double-density double-side 9 sectors/track
/// 5.25" double-density double-side 9 sectors/track
/// </summary>
k360Alt = 0x40,
/// <summary>
/// 3.5" double-density double-side 9 sectors/track
/// 3.5" double-density double-side 9 sectors/track
/// </summary>
k720 = 0x11,
/// <summary>
/// 3.5" double-density double-side 9 sectors/track using FEAT144
/// 3.5" double-density double-side 9 sectors/track using FEAT144
/// </summary>
f720 = 0x48,
/// <summary>
/// 5.25" high-density double-side 15 sectors/track using FEAT144
/// 5.25" high-density double-side 15 sectors/track using FEAT144
/// </summary>
f1200 = 0x0C,
/// <summary>
/// 3.5" high-density double-side 18 sectors/track using FEAT144
/// 3.5" high-density double-side 18 sectors/track using FEAT144
/// </summary>
f1440 = 0x90,
/// <summary>
/// 5.25" double-density double-side 9 sectors/track
/// 5.25" double-density double-side 9 sectors/track
/// </summary>
k360Alt2 = 0x26,
/// <summary>
/// 3.5" double-density double-side 9 sectors/track
/// 3.5" double-density double-side 9 sectors/track
/// </summary>
k720Alt = 0x94
}

View File

@@ -41,7 +41,7 @@ namespace DiscImageChef.Filesystems.CPM
partial class CPM
{
/// <summary>
/// Loads all the known CP/M disk definitions from an XML stored as an embedded resource.
/// Loads all the known CP/M disk definitions from an XML stored as an embedded resource.
/// </summary>
/// <returns>The definitions.</returns>
bool LoadDefinitions()
@@ -50,7 +50,8 @@ namespace DiscImageChef.Filesystems.CPM
{
XmlReader defsReader =
XmlReader.Create(Assembly.GetExecutingAssembly()
.GetManifestResourceStream("DiscImageChef.Filesystems.CPM.cpmdefs.xml") ?? throw new InvalidOperationException());
.GetManifestResourceStream("DiscImageChef.Filesystems.CPM.cpmdefs.xml") ??
throw new InvalidOperationException());
XmlSerializer defsSerializer = new XmlSerializer(typeof(CpmDefinitions));
definitions = (CpmDefinitions)defsSerializer.Deserialize(defsReader);
@@ -78,131 +79,132 @@ namespace DiscImageChef.Filesystems.CPM
}
/// <summary>
/// CP/M disk definitions
/// CP/M disk definitions
/// </summary>
class CpmDefinitions
{
/// <summary>
/// List of all CP/M disk definitions
/// </summary>
public List<CpmDefinition> definitions;
/// <summary>
/// Timestamp of creation of the CP/M disk definitions list
/// Timestamp of creation of the CP/M disk definitions list
/// </summary>
public DateTime creation;
/// <summary>
/// List of all CP/M disk definitions
/// </summary>
public List<CpmDefinition> definitions;
}
/// <summary>
/// CP/M disk definition
/// CP/M disk definition
/// </summary>
class CpmDefinition
{
/// <summary>
/// Comment and description
/// </summary>
public string comment;
/// <summary>
/// Encoding, "FM", "MFM", "GCR"
/// </summary>
public string encoding;
/// <summary>
/// Controller bitrate
/// </summary>
public string bitrate;
/// <summary>
/// Total cylinders
/// </summary>
public int cylinders;
/// <summary>
/// Total sides
/// </summary>
public int sides;
/// <summary>
/// Physical sectors per side
/// </summary>
public int sectorsPerTrack;
/// <summary>
/// Physical bytes per sector
/// </summary>
public int bytesPerSector;
/// <summary>
/// Physical sector interleaving
/// </summary>
public int skew;
/// <summary>
/// Description of controller's side 0 (usually, upper side)
/// </summary>
public Side side1;
/// <summary>
/// Description of controller's side 1 (usually, lower side)
/// </summary>
public Side side2;
/// <summary>
/// Cylinder/side ordering. SIDES = change side after each track, CYLINDERS = change side after whole side, EAGLE and COLUMBIA unknown
/// </summary>
public string order;
/// <summary>
/// Disk definition label
/// </summary>
public string label;
/// <summary>
/// Left shifts needed to translate allocation block number to lba
/// </summary>
public int bsh;
/// <summary>
/// Block mask for <see cref="bsh"/>
/// </summary>
public int blm;
/// <summary>
/// Extent mask
/// </summary>
public int exm;
/// <summary>
/// Total number of 128 byte records on disk
/// </summary>
public int dsm;
/// <summary>
/// Total number of available directory entries
/// </summary>
public int drm;
/// <summary>
/// Maps the first 16 allocation blocks for reservation, high byte
/// Maps the first 16 allocation blocks for reservation, high byte
/// </summary>
public int al0;
/// <summary>
/// Maps the first 16 allocation blocks for reservation, low byte
/// Maps the first 16 allocation blocks for reservation, low byte
/// </summary>
public int al1;
/// <summary>
/// Tracks at the beginning of disk reserved for BIOS/BDOS
/// Controller bitrate
/// </summary>
public int ofs;
public string bitrate;
/// <summary>
/// Sectors at the beginning of disk reserved for BIOS/BDOS
/// Block mask for <see cref="bsh" />
/// </summary>
public int sofs;
public int blm;
/// <summary>
/// If true, all bytes written on disk are negated
/// Left shifts needed to translate allocation block number to lba
/// </summary>
public int bsh;
/// <summary>
/// Physical bytes per sector
/// </summary>
public int bytesPerSector;
/// <summary>
/// Comment and description
/// </summary>
public string comment;
/// <summary>
/// If true, all bytes written on disk are negated
/// </summary>
public bool complement;
/// <summary>
/// Absolutely unknown?
/// Total cylinders
/// </summary>
public int cylinders;
/// <summary>
/// Total number of available directory entries
/// </summary>
public int drm;
/// <summary>
/// Total number of 128 byte records on disk
/// </summary>
public int dsm;
/// <summary>
/// Encoding, "FM", "MFM", "GCR"
/// </summary>
public string encoding;
/// <summary>
/// Absolutely unknown?
/// </summary>
public bool evenOdd;
/// <summary>
/// Extent mask
/// </summary>
public int exm;
/// <summary>
/// Disk definition label
/// </summary>
public string label;
/// <summary>
/// Tracks at the beginning of disk reserved for BIOS/BDOS
/// </summary>
public int ofs;
/// <summary>
/// Cylinder/side ordering. SIDES = change side after each track, CYLINDERS = change side after whole side, EAGLE and
/// COLUMBIA unknown
/// </summary>
public string order;
/// <summary>
/// Physical sectors per side
/// </summary>
public int sectorsPerTrack;
/// <summary>
/// Description of controller's side 0 (usually, upper side)
/// </summary>
public Side side1;
/// <summary>
/// Description of controller's side 1 (usually, lower side)
/// </summary>
public Side side2;
/// <summary>
/// Total sides
/// </summary>
public int sides;
/// <summary>
/// Physical sector interleaving
/// </summary>
public int skew;
/// <summary>
/// Sectors at the beginning of disk reserved for BIOS/BDOS
/// </summary>
public int sofs;
}
/// <summary>
/// Side descriptions
/// Side descriptions
/// </summary>
class Side
{
/// <summary>
/// Side ID as found in each sector address mark
/// </summary>
public int sideId;
/// <summary>
/// Software interleaving mask, [1,3,0,2] means CP/M LBA 0 is physical sector 1, LBA 1 = 3, so on
/// Software interleaving mask, [1,3,0,2] means CP/M LBA 0 is physical sector 1, LBA 1 = 3, so on
/// </summary>
public int[] sectorIds;
/// <summary>
/// Side ID as found in each sector address mark
/// </summary>
public int sideId;
}
}

View File

@@ -52,10 +52,10 @@ namespace DiscImageChef.Filesystems.CPM
}
/// <summary>
/// Checks that the given directory blocks follow the CP/M filesystem directory specification
/// Corrupted directories will fail.
/// FAT firectories will false positive if all files start with 0x05, and do not use full extentions, for example:
/// "σAFILE.GZ" (using code page 437)
/// Checks that the given directory blocks follow the CP/M filesystem directory specification
/// Corrupted directories will fail.
/// FAT firectories will false positive if all files start with 0x05, and do not use full extentions, 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>
@@ -76,17 +76,21 @@ namespace DiscImageChef.Filesystems.CPM
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 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;
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 if(entry.statusUser == 0x20)
{
for(int f = 0; f < 8; f++) if(entry.filename[f] < 0x20 && entry.filename[f] != 0x00) return false;
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;
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];

View File

@@ -51,7 +51,8 @@ namespace DiscImageChef.Filesystems.CPM
return Errno.NoError;
}
if(!statCache.TryGetValue(pathElements[0].ToUpperInvariant(), out FileEntryInfo fInfo)) return Errno.NoSuchFile;
if(!statCache.TryGetValue(pathElements[0].ToUpperInvariant(), out FileEntryInfo fInfo))
return Errno.NoSuchFile;
attributes = fInfo.Attributes;
return Errno.NoError;
@@ -91,9 +92,7 @@ namespace DiscImageChef.Filesystems.CPM
public override Errno ReadLink(string path, ref string dest)
{
if(!mounted) return Errno.AccessDenied;
return Errno.NotSupported;
return !mounted ? Errno.AccessDenied : Errno.NotSupported;
}
public override Errno Stat(string path, ref FileEntryInfo stat)
@@ -112,9 +111,9 @@ namespace DiscImageChef.Filesystems.CPM
return Errno.NoError;
}
if(statCache.TryGetValue(pathElements[0].ToUpperInvariant(), out stat)) return Errno.NoError;
return Errno.NoSuchFile;
return statCache.TryGetValue(pathElements[0].ToUpperInvariant(), out stat)
? Errno.NoError
: Errno.NoSuchFile;
}
}
}

View File

@@ -264,12 +264,16 @@ namespace DiscImageChef.Filesystems.CPM
if(amsSb.format == 2)
{
switch(amsSb.sidedness & 0x02) {
case 1: workingDefinition.order = "SIDES";
switch(amsSb.sidedness & 0x02)
{
case 1:
workingDefinition.order = "SIDES";
break;
case 2: workingDefinition.order = "CYLINDERS";
case 2:
workingDefinition.order = "CYLINDERS";
break;
default: workingDefinition.order = null;
default:
workingDefinition.order = null;
break;
}
@@ -373,7 +377,6 @@ namespace DiscImageChef.Filesystems.CPM
for(int si = 0; si < hddSb.sectorsPerTrack; si++)
workingDefinition.side1.sectorIds[si] = si + 1;
for(int si = 0; si < hddSb.spt; si++) workingDefinition.side2.sectorIds[si] = si + 1;
}
}
}
@@ -787,7 +790,13 @@ namespace DiscImageChef.Filesystems.CPM
if(LoadDefinitions() && definitions?.definitions != null && definitions.definitions.Count > 0)
{
DicConsole.DebugWriteLine("CP/M Plugin", "Trying all known definitions.");
foreach(CpmDefinition def in from def in definitions.definitions let sectors = (ulong)(def.cylinders * def.sides * def.sectorsPerTrack) where sectors == imagePlugin.GetSectors() && def.bytesPerSector == imagePlugin.GetSectorSize() select def) {
foreach(CpmDefinition def in from def in definitions.definitions
let sectors =
(ulong)(def.cylinders * def.sides * def.sectorsPerTrack)
where sectors == imagePlugin.GetSectors() &&
def.bytesPerSector == imagePlugin.GetSectorSize()
select def)
{
// Definition seems to describe current disk, at least, same number of volume sectors and bytes per sector
DicConsole.DebugWriteLine("CP/M Plugin", "Trying definition \"{0}\"", def.comment);
ulong offset;
@@ -805,8 +814,7 @@ namespace DiscImageChef.Filesystems.CPM
else
{
// Head changes after every track
if(string.Compare(def.order, "SIDES",
StringComparison.InvariantCultureIgnoreCase) == 0)
if(string.Compare(def.order, "SIDES", StringComparison.InvariantCultureIgnoreCase) == 0)
{
sectorMask = new int[def.side1.sectorIds.Length + def.side2.sectorIds.Length];
for(int m = 0; m < def.side1.sectorIds.Length; m++)
@@ -838,8 +846,9 @@ namespace DiscImageChef.Filesystems.CPM
continue;
}
// TODO: Implement EAGLE ordering
else if(string.Compare(def.order, "EAGLE",
StringComparison.InvariantCultureIgnoreCase) == 0)
else if(
string.Compare(def.order, "EAGLE", StringComparison.InvariantCultureIgnoreCase) == 0
)
{
DicConsole.DebugWriteLine("CP/M Plugin",
"Don't know how to handle EAGLE ordering, not proceeding with this definition.");
@@ -873,14 +882,12 @@ namespace DiscImageChef.Filesystems.CPM
// Complement of the directory bytes if needed
if(def.complement)
for(int b = 0; b < directory.Length; b++)
directory[b] = (byte)(~directory[b] & 0xFF);
for(int b = 0; b < directory.Length; b++) directory[b] = (byte)(~directory[b] & 0xFF);
// Check the directory
if(CheckDir(directory))
{
DicConsole.DebugWriteLine("CP/M Plugin",
"Definition \"{0}\" has a correct directory",
DicConsole.DebugWriteLine("CP/M Plugin", "Definition \"{0}\" has a correct directory",
def.comment);
// Build a Disc Parameter Block

View File

@@ -37,496 +37,499 @@ namespace DiscImageChef.Filesystems.CPM
partial class CPM
{
/// <summary>
/// Most of the times this structure is hard wired or generated by CP/M, not stored on disk
/// Most of the times this structure is hard wired or generated by CP/M, not stored on disk
/// </summary>
class DiscParameterBlock
{
/// <summary>
/// Sectors per track
/// </summary>
public ushort spt;
/// <summary>
/// Block shift
/// </summary>
public byte bsh;
/// <summary>
/// Block mask
/// </summary>
public byte blm;
/// <summary>
/// Extent mask
/// </summary>
public byte exm;
/// <summary>
/// Blocks on disk - 1
/// </summary>
public ushort dsm;
/// <summary>
/// Directory entries - 1
/// </summary>
public ushort drm;
/// <summary>
/// First byte of allocation bitmap
/// First byte of allocation bitmap
/// </summary>
public byte al0;
/// <summary>
/// Second byte of allocation bitmap
/// Second byte of allocation bitmap
/// </summary>
public byte al1;
/// <summary>
/// Checksum vector size
/// Block mask
/// </summary>
public byte blm;
/// <summary>
/// Block shift
/// </summary>
public byte bsh;
/// <summary>
/// Checksum vector size
/// </summary>
public ushort cks;
/// <summary>
/// Reserved tracks
/// Directory entries - 1
/// </summary>
public ushort drm;
/// <summary>
/// Blocks on disk - 1
/// </summary>
public ushort dsm;
/// <summary>
/// Extent mask
/// </summary>
public byte exm;
/// <summary>
/// Reserved tracks
/// </summary>
public ushort off;
/// <summary>
/// Physical sector shift
/// Physical sector mask
/// </summary>
public byte phm;
/// <summary>
/// Physical sector shift
/// </summary>
public byte psh;
/// <summary>
/// Physical sector mask
/// Sectors per track
/// </summary>
public byte phm;
public ushort spt;
}
/// <summary>
/// Amstrad superblock, for PCW
/// Amstrad superblock, for PCW
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct AmstradSuperBlock
{
/// <summary>
/// Format ID. 0 single-side, 3 double-side. 1 and 2 are for CPC but they don't use the superblock
/// Format ID. 0 single-side, 3 double-side. 1 and 2 are for CPC but they don't use the superblock
/// </summary>
public byte format;
/// <summary>
/// Gives information about side ordering
/// Gives information about side ordering
/// </summary>
public byte sidedness;
/// <summary>
/// Tracks per side, aka, cylinders
/// Tracks per side, aka, cylinders
/// </summary>
public byte tps;
/// <summary>
/// Sectors per track
/// Sectors per track
/// </summary>
public byte spt;
/// <summary>
/// Physical sector shift
/// Physical sector shift
/// </summary>
public byte psh;
/// <summary>
/// Reserved tracks
/// Reserved tracks
/// </summary>
public byte off;
/// <summary>
/// Block size shift
/// Block size shift
/// </summary>
public byte bsh;
/// <summary>
/// How many blocks does the directory take
/// How many blocks does the directory take
/// </summary>
public byte dirBlocks;
/// <summary>
/// GAP#3 length (intersector)
/// GAP#3 length (intersector)
/// </summary>
public byte gapLen;
/// <summary>
/// GAP#4 length (end-of-track)
/// GAP#4 length (end-of-track)
/// </summary>
public byte formatGap;
/// <summary>
/// Must be 0
/// Must be 0
/// </summary>
public byte zero1;
/// <summary>
/// Must be 0
/// Must be 0
/// </summary>
public byte zero2;
/// <summary>
/// Must be 0
/// Must be 0
/// </summary>
public byte zero3;
/// <summary>
/// Must be 0
/// Must be 0
/// </summary>
public byte zero4;
/// <summary>
/// Must be 0
/// Must be 0
/// </summary>
public byte zero5;
/// <summary>
/// Indicates machine the boot code following the superblock is designed to boot
/// Indicates machine the boot code following the superblock is designed to boot
/// </summary>
public byte fiddle;
}
/// <summary>
/// Superblock found on CP/M-86 hard disk volumes
/// Superblock found on CP/M-86 hard disk volumes
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct HardDiskSuperBlock
{
/// <summary>
/// Value so the sum of all the superblock's sector bytes taken as 16-bit values gives 0
/// Value so the sum of all the superblock's sector bytes taken as 16-bit values gives 0
/// </summary>
public ushort checksum;
/// <summary>
/// Copyright string
/// Copyright string
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 0x1F)] public byte[] copyright;
/// <summary>
/// First cylinder of disk where this volume resides
/// First cylinder of disk where this volume resides
/// </summary>
public ushort firstCylinder;
/// <summary>
/// How many cylinders does this volume span
/// How many cylinders does this volume span
/// </summary>
public ushort cylinders;
/// <summary>
/// Heads on hard disk
/// Heads on hard disk
/// </summary>
public byte heads;
/// <summary>
/// Sectors per track
/// Sectors per track
/// </summary>
public byte sectorsPerTrack;
/// <summary>
/// Flags, only use by CCP/M where bit 0 equals verify on write
/// Flags, only use by CCP/M where bit 0 equals verify on write
/// </summary>
public byte flags;
/// <summary>
/// Sector size / 128
/// Sector size / 128
/// </summary>
public byte recordsPerSector;
/// <summary>
/// <see cref="DiscParameterBlock.spt"/>
/// <see cref="DiscParameterBlock.spt" />
/// </summary>
public ushort spt;
/// <summary>
/// <see cref="DiscParameterBlock.bsh"/>
/// <see cref="DiscParameterBlock.bsh" />
/// </summary>
public byte bsh;
/// <summary>
/// <see cref="DiscParameterBlock.blm"/>
/// <see cref="DiscParameterBlock.blm" />
/// </summary>
public byte blm;
/// <summary>
/// <see cref="DiscParameterBlock.exm"/>
/// <see cref="DiscParameterBlock.exm" />
/// </summary>
public byte exm;
/// <summary>
/// <see cref="DiscParameterBlock.dsm"/>
/// <see cref="DiscParameterBlock.dsm" />
/// </summary>
public ushort dsm;
/// <summary>
/// <see cref="DiscParameterBlock.drm"/>
/// <see cref="DiscParameterBlock.drm" />
/// </summary>
public ushort drm;
/// <summary>
/// <see cref="DiscParameterBlock.al0"/>
/// <see cref="DiscParameterBlock.al0" />
/// </summary>
public ushort al0;
/// <summary>
/// <see cref="DiscParameterBlock.al1"/>
/// <see cref="DiscParameterBlock.al1" />
/// </summary>
public ushort al1;
/// <summary>
/// <see cref="DiscParameterBlock.cks"/>
/// <see cref="DiscParameterBlock.cks" />
/// </summary>
public ushort cks;
/// <summary>
/// <see cref="DiscParameterBlock.off"/>
/// <see cref="DiscParameterBlock.off" />
/// </summary>
public ushort off;
/// <summary>
/// Must be zero
/// Must be zero
/// </summary>
public ushort zero1;
/// <summary>
/// Must be zero
/// Must be zero
/// </summary>
public ushort zero2;
/// <summary>
/// Must be zero
/// Must be zero
/// </summary>
public ushort zero3;
/// <summary>
/// Must be zero
/// Must be zero
/// </summary>
public ushort zero4;
/// <summary>
/// How many 128 bytes are in a block
/// How many 128 bytes are in a block
/// </summary>
public ushort recordsPerBlock;
/// <summary>
/// Maximum number of bad blocks in the bad block list
/// Maximum number of bad blocks in the bad block list
/// </summary>
public ushort badBlockWordsMax;
/// <summary>
/// Used number of bad blocks in the bad block list
/// Used number of bad blocks in the bad block list
/// </summary>
public ushort badBlockWords;
/// <summary>
/// First block after the blocks reserved for bad block substitution
/// First block after the blocks reserved for bad block substitution
/// </summary>
public ushort firstSub;
}
/// <summary>
/// Volume label entry
/// Volume label entry
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct LabelEntry
{
/// <summary>
/// Must be 0x20
/// Must be 0x20
/// </summary>
public byte signature;
/// <summary>
/// Label in ASCII
/// Label in ASCII
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 11)] public byte[] label;
/// <summary>
/// Label flags. Bit 0 = label exists, bit 4 = creation timestamp, bit 5 = modification timestamp, bit 6 = access timestamp, bit 7 = password enabled
/// Label flags. Bit 0 = label exists, bit 4 = creation timestamp, bit 5 = modification timestamp, bit 6 = access
/// timestamp, bit 7 = password enabled
/// </summary>
public byte flags;
/// <summary>
/// Password decoder byte
/// Password decoder byte
/// </summary>
public byte passwordDecoder;
/// <summary>
/// Must be 0
/// Must be 0
/// </summary>
public ushort reserved;
/// <summary>
/// Password XOR'ed with <see cref="passwordDecoder"/>
/// Password XOR'ed with <see cref="passwordDecoder" />
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] password;
/// <summary>
/// Label creation time
/// Label creation time
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public byte[] ctime;
/// <summary>
/// Label modification time
/// Label modification time
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public byte[] mtime;
}
/// <summary>
/// CP/M 3 timestamp entry
/// CP/M 3 timestamp entry
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct DateEntry
{
/// <summary>
/// Must be 0x21
/// Must be 0x21
/// </summary>
public byte signature;
/// <summary>
/// File 1 create/access timestamp
/// File 1 create/access timestamp
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public byte[] date1;
/// <summary>
/// File 1 modification timestamp
/// File 1 modification timestamp
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public byte[] date2;
/// <summary>
/// File 1 password mode
/// File 1 password mode
/// </summary>
public byte mode1;
public byte zero1;
/// <summary>
/// File 2 create/access timestamp
/// File 2 create/access timestamp
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public byte[] date3;
/// <summary>
/// File 2 modification timestamp
/// File 2 modification timestamp
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public byte[] date4;
/// <summary>
/// File 2 password mode
/// File 2 password mode
/// </summary>
public byte mode2;
public byte zero2;
/// <summary>
/// File 3 create/access timestamp
/// File 3 create/access timestamp
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public byte[] date5;
/// <summary>
/// File 3 modification timestamp
/// File 3 modification timestamp
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public byte[] date6;
/// <summary>
/// File 3 password mode
/// File 3 password mode
/// </summary>
public byte mode3;
public ushort zero3;
}
/// <summary>
/// Password entry
/// Password entry
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct PasswordEntry
{
/// <summary>
/// 16 + user number
/// 16 + user number
/// </summary>
public byte userNumber;
/// <summary>
/// Filename
/// Filename
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] filename;
/// <summary>
/// Extension
/// Extension
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public byte[] extension;
/// <summary>
/// Password mode. Bit 7 = required for read, bit 6 = required for write, bit 5 = required for delete
/// Password mode. Bit 7 = required for read, bit 6 = required for write, bit 5 = required for delete
/// </summary>
public byte mode;
/// <summary>
/// Password decoder byte
/// Password decoder byte
/// </summary>
public byte passwordDecoder;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public byte[] reserved;
/// <summary>
/// Password XOR'ed with <see cref="passwordDecoder"/>
/// Password XOR'ed with <see cref="passwordDecoder" />
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] password;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] reserved2;
}
/// <summary>
/// Timestamp for Z80DOS or DOS+
/// Timestamp for Z80DOS or DOS+
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct TrdPartyDateEntry
{
/// <summary>
/// Must be 0x21
/// Must be 0x21
/// </summary>
public byte signature;
public byte zero;
/// <summary>
/// Creation year for file 1
/// Creation year for file 1
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public byte[] create1;
/// <summary>
/// Modification time for file 1
/// Modification time for file 1
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public byte[] modify1;
/// <summary>
/// Access time for file 1
/// Access time for file 1
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public byte[] access1;
/// <summary>
/// Creation year for file 2
/// Creation year for file 2
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public byte[] create2;
/// <summary>
/// Modification time for file 2
/// Modification time for file 2
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public byte[] modify2;
/// <summary>
/// Access time for file 2
/// Access time for file 2
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public byte[] access2;
/// <summary>
/// Creation year for file 3
/// Creation year for file 3
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public byte[] create3;
/// <summary>
/// Modification time for file 3
/// Modification time for file 3
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public byte[] modify3;
/// <summary>
/// Access time for file 3
/// Access time for file 3
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public byte[] access3;
}
/// <summary>
/// Directory entry for &lt;256 allocation blocks
/// Directory entry for &lt;256 allocation blocks
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct DirectoryEntry
{
/// <summary>
/// User number. Bit 7 set in CP/M 1 means hidden
/// User number. Bit 7 set in CP/M 1 means hidden
/// </summary>
public byte statusUser;
/// <summary>
/// Filename and bit 7 as flags
/// Filename and bit 7 as flags
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] filename;
/// <summary>
/// Extension and bit 7 as flags
/// Extension and bit 7 as flags
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public byte[] extension;
/// <summary>
/// Low byte of extent number
/// Low byte of extent number
/// </summary>
public byte extentCounter;
/// <summary>
/// Last record bytes. In some implementations it means how many bytes are used in the last record, in others how many bytes are free.
/// It always refer to 128 byte records even if blocks are way bigger, so it's mostly useless.
/// Last record bytes. In some implementations it means how many bytes are used in the last record, in others how many
/// bytes are free.
/// It always refer to 128 byte records even if blocks are way bigger, so it's mostly useless.
/// </summary>
public byte lastRecordBytes;
/// <summary>
/// High byte of extent number
/// High byte of extent number
/// </summary>
public byte extentCounterHigh;
/// <summary>
/// How many records are used in this entry. 0x80 if all are used.
/// How many records are used in this entry. 0x80 if all are used.
/// </summary>
public byte records;
/// <summary>
/// Allocation blocks
/// Allocation blocks
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] allocations;
}
/// <summary>
/// Directory entry for &gt;256 allocation blocks
/// Directory entry for &gt;256 allocation blocks
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct DirectoryEntry16
{
/// <summary>
/// User number. Bit 7 set in CP/M 1 means hidden
/// User number. Bit 7 set in CP/M 1 means hidden
/// </summary>
public byte statusUser;
/// <summary>
/// Filename and bit 7 as flags
/// Filename and bit 7 as flags
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] filename;
/// <summary>
/// Extension and bit 7 as flags
/// Extension and bit 7 as flags
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public byte[] extension;
/// <summary>
/// Low byte of extent number
/// Low byte of extent number
/// </summary>
public byte extentCounter;
/// <summary>
/// Last record bytes. In some implementations it means how many bytes are used in the last record, in others how many bytes are free.
/// It always refer to 128 byte records even if blocks are way bigger, so it's mostly useless.
/// Last record bytes. In some implementations it means how many bytes are used in the last record, in others how many
/// bytes are free.
/// It always refer to 128 byte records even if blocks are way bigger, so it's mostly useless.
/// </summary>
public byte lastRecordBytes;
/// <summary>
/// High byte of extent number
/// High byte of extent number
/// </summary>
public byte extentCounterHigh;
/// <summary>
/// How many records are used in this entry. 0x80 if all are used.
/// How many records are used in this entry. 0x80 if all are used.
/// </summary>
public byte records;
/// <summary>
/// Allocation blocks
/// Allocation blocks
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public ushort[] allocations;
}

View File

@@ -132,7 +132,8 @@ namespace DiscImageChef.Filesystems.CPM
byte[] readSector =
device.ReadSector((ulong)((int)partition.Start + p / sectorMask.Length * sectorMask.Length +
sectorMask[p % sectorMask.Length]));
if(workingDefinition.complement) for(int b = 0; b < readSector.Length; b++) readSector[b] = (byte)(~readSector[b] & 0xFF);
if(workingDefinition.complement)
for(int b = 0; b < readSector.Length; b++) readSector[b] = (byte)(~readSector[b] & 0xFF);
deinterleavedSectors.Add((ulong)p, readSector);
}
@@ -213,13 +214,14 @@ namespace DiscImageChef.Filesystems.CPM
// For each directory entry
for(int dOff = 0; dOff < directory.Length; dOff += 32)
// Describes a file (does not support PDOS entries with user >= 16, because they're identical to password entries
// Describes a file (does not support PDOS entries with user >= 16, because they're identical to password entries
if((directory[dOff] & 0x7F) < 0x10)
if(allocationBlocks.Count > 256)
{
dirPtr = Marshal.AllocHGlobal(32);
Marshal.Copy(directory, dOff, dirPtr, 32);
DirectoryEntry16 entry = (DirectoryEntry16)Marshal.PtrToStructure(dirPtr, typeof(DirectoryEntry16));
DirectoryEntry16 entry =
(DirectoryEntry16)Marshal.PtrToStructure(dirPtr, typeof(DirectoryEntry16));
Marshal.FreeHGlobal(dirPtr);
bool hidden = (entry.statusUser & 0x80) == 0x80;
@@ -254,11 +256,11 @@ namespace DiscImageChef.Filesystems.CPM
// Do we have a stat for the file already?
if(statCache.TryGetValue(filename, out FileEntryInfo fInfo)) statCache.Remove(filename);
else
{ fInfo = new FileEntryInfo {Attributes = new FileAttributes()}; }
else fInfo = new FileEntryInfo {Attributes = new FileAttributes()};
// And any extent?
if(fileExtents.TryGetValue(filename, out Dictionary<int, List<ushort>> extentBlocks)) fileExtents.Remove(filename);
if(fileExtents.TryGetValue(filename, out Dictionary<int, List<ushort>> extentBlocks))
fileExtents.Remove(filename);
else extentBlocks = new Dictionary<int, List<ushort>>();
// Do we already have this extent? Should never happen
@@ -275,7 +277,8 @@ namespace DiscImageChef.Filesystems.CPM
// because that's where the directory resides.
// There is also a field telling how many bytes are used in the last block, but its meaning is non-standard so
// we must ignore it.
foreach(ushort blk in entry.allocations.Where(blk => !blocks.Contains(blk) && blk != 0)) blocks.Add(blk);
foreach(ushort blk in entry.allocations.Where(blk => !blocks.Contains(blk) && blk != 0))
blocks.Add(blk);
// Save the file
fInfo.UID = (ulong)user;
@@ -341,11 +344,11 @@ namespace DiscImageChef.Filesystems.CPM
// Do we have a stat for the file already?
if(statCache.TryGetValue(filename, out FileEntryInfo fInfo)) statCache.Remove(filename);
else
{ fInfo = new FileEntryInfo {Attributes = new FileAttributes()}; }
else fInfo = new FileEntryInfo {Attributes = new FileAttributes()};
// And any extent?
if(fileExtents.TryGetValue(filename, out Dictionary<int, List<ushort>> extentBlocks)) fileExtents.Remove(filename);
if(fileExtents.TryGetValue(filename, out Dictionary<int, List<ushort>> extentBlocks))
fileExtents.Remove(filename);
else extentBlocks = new Dictionary<int, List<ushort>>();
// Do we already have this extent? Should never happen
@@ -362,7 +365,8 @@ namespace DiscImageChef.Filesystems.CPM
// because that's where the directory resides.
// There is also a field telling how many bytes are used in the last block, but its meaning is non-standard so
// we must ignore it.
foreach(ushort blk in entry.allocations.Cast<ushort>().Where(blk => !blocks.Contains(blk) && blk != 0)) blocks.Add(blk);
foreach(ushort blk in entry.allocations.Cast<ushort>()
.Where(blk => !blocks.Contains(blk) && blk != 0)) blocks.Add(blk);
// Save the file
fInfo.UID = (ulong)user;
@@ -434,161 +438,164 @@ namespace DiscImageChef.Filesystems.CPM
dirCnt++;
}
// Volume label and password entry. Volume password is ignored.
else switch(directory[dOff] & 0x7F) {
case 0x20:
LabelEntry labelEntry;
dirPtr = Marshal.AllocHGlobal(32);
Marshal.Copy(directory, dOff, dirPtr, 32);
labelEntry = (LabelEntry)Marshal.PtrToStructure(dirPtr, typeof(LabelEntry));
Marshal.FreeHGlobal(dirPtr);
else
switch(directory[dOff] & 0x7F)
{
case 0x20:
LabelEntry labelEntry;
dirPtr = Marshal.AllocHGlobal(32);
Marshal.Copy(directory, dOff, dirPtr, 32);
labelEntry = (LabelEntry)Marshal.PtrToStructure(dirPtr, typeof(LabelEntry));
Marshal.FreeHGlobal(dirPtr);
// The volume label defines if one of the fields in CP/M 3 timestamp is a creation or an access time
atime |= (labelEntry.flags & 0x40) == 0x40;
// The volume label defines if one of the fields in CP/M 3 timestamp is a creation or an access time
atime |= (labelEntry.flags & 0x40) == 0x40;
label = Encoding.ASCII.GetString(directory, dOff + 1, 11).Trim();
labelCreationDate = new byte[4];
labelUpdateDate = new byte[4];
Array.Copy(directory, dOff + 24, labelCreationDate, 0, 4);
Array.Copy(directory, dOff + 28, labelUpdateDate, 0, 4);
label = Encoding.ASCII.GetString(directory, dOff + 1, 11).Trim();
labelCreationDate = new byte[4];
labelUpdateDate = new byte[4];
Array.Copy(directory, dOff + 24, labelCreationDate, 0, 4);
Array.Copy(directory, dOff + 28, labelUpdateDate, 0, 4);
// Count entries 3 by 3 for timestamps
switch(dirCnt % 3)
{
case 0:
file1 = null;
break;
case 1:
file2 = null;
break;
case 2:
file3 = null;
break;
}
dirCnt++;
break;
case 0x21:
if(directory[dOff + 10] == 0x00 && directory[dOff + 20] == 0x00 &&
directory[dOff + 30] == 0x00 && directory[dOff + 31] == 0x00)
{
dirPtr = Marshal.AllocHGlobal(32);
Marshal.Copy(directory, dOff, dirPtr, 32);
DateEntry dateEntry = (DateEntry)Marshal.PtrToStructure(dirPtr, typeof(DateEntry));
Marshal.FreeHGlobal(dirPtr);
FileEntryInfo fInfo;
// Entry contains timestamps for last 3 entries, whatever the kind they are.
if(!string.IsNullOrEmpty(file1))
{
if(statCache.TryGetValue(file1, out fInfo)) statCache.Remove(file1);
else fInfo = new FileEntryInfo();
if(atime) fInfo.AccessTime = DateHandlers.CpmToDateTime(dateEntry.date1);
else fInfo.CreationTime = DateHandlers.CpmToDateTime(dateEntry.date1);
fInfo.LastWriteTime = DateHandlers.CpmToDateTime(dateEntry.date2);
statCache.Add(file1, fInfo);
}
if(!string.IsNullOrEmpty(file2))
{
if(statCache.TryGetValue(file2, out fInfo)) statCache.Remove(file2);
else fInfo = new FileEntryInfo();
if(atime) fInfo.AccessTime = DateHandlers.CpmToDateTime(dateEntry.date3);
else fInfo.CreationTime = DateHandlers.CpmToDateTime(dateEntry.date3);
fInfo.LastWriteTime = DateHandlers.CpmToDateTime(dateEntry.date4);
statCache.Add(file2, fInfo);
}
if(!string.IsNullOrEmpty(file3))
{
if(statCache.TryGetValue(file3, out fInfo)) statCache.Remove(file3);
else fInfo = new FileEntryInfo();
if(atime) fInfo.AccessTime = DateHandlers.CpmToDateTime(dateEntry.date5);
else fInfo.CreationTime = DateHandlers.CpmToDateTime(dateEntry.date5);
fInfo.LastWriteTime = DateHandlers.CpmToDateTime(dateEntry.date6);
statCache.Add(file3, fInfo);
}
// Count entries 3 by 3 for timestamps
switch(dirCnt % 3)
{
case 0:
file1 = null;
break;
case 1:
file2 = null;
break;
case 2:
file3 = null;
break;
}
dirCnt++;
break;
case 0x21:
if(directory[dOff + 10] == 0x00 && directory[dOff + 20] == 0x00 && directory[dOff + 30] == 0x00 &&
directory[dOff + 31] == 0x00)
{
dirPtr = Marshal.AllocHGlobal(32);
Marshal.Copy(directory, dOff, dirPtr, 32);
DateEntry dateEntry = (DateEntry)Marshal.PtrToStructure(dirPtr, typeof(DateEntry));
Marshal.FreeHGlobal(dirPtr);
FileEntryInfo fInfo;
// Entry contains timestamps for last 3 entries, whatever the kind they are.
if(!string.IsNullOrEmpty(file1))
{
if(statCache.TryGetValue(file1, out fInfo)) statCache.Remove(file1);
else fInfo = new FileEntryInfo();
if(atime) fInfo.AccessTime = DateHandlers.CpmToDateTime(dateEntry.date1);
else fInfo.CreationTime = DateHandlers.CpmToDateTime(dateEntry.date1);
fInfo.LastWriteTime = DateHandlers.CpmToDateTime(dateEntry.date2);
statCache.Add(file1, fInfo);
dirCnt = 0;
}
if(!string.IsNullOrEmpty(file2))
// However, if this byte is 0, timestamp is in Z80DOS or DOS+ format
else if(directory[dOff + 1] == 0x00)
{
if(statCache.TryGetValue(file2, out fInfo)) statCache.Remove(file2);
else fInfo = new FileEntryInfo();
dirPtr = Marshal.AllocHGlobal(32);
Marshal.Copy(directory, dOff, dirPtr, 32);
TrdPartyDateEntry trdPartyDateEntry =
(TrdPartyDateEntry)Marshal.PtrToStructure(dirPtr, typeof(TrdPartyDateEntry));
Marshal.FreeHGlobal(dirPtr);
if(atime) fInfo.AccessTime = DateHandlers.CpmToDateTime(dateEntry.date3);
else fInfo.CreationTime = DateHandlers.CpmToDateTime(dateEntry.date3);
FileEntryInfo fInfo;
fInfo.LastWriteTime = DateHandlers.CpmToDateTime(dateEntry.date4);
// Entry contains timestamps for last 3 entries, whatever the kind they are.
if(!string.IsNullOrEmpty(file1))
{
if(statCache.TryGetValue(file1, out fInfo)) statCache.Remove(file1);
else fInfo = new FileEntryInfo();
statCache.Add(file2, fInfo);
byte[] ctime = new byte[4];
ctime[0] = trdPartyDateEntry.create1[0];
ctime[1] = trdPartyDateEntry.create1[1];
fInfo.AccessTime = DateHandlers.CpmToDateTime(trdPartyDateEntry.access1);
fInfo.CreationTime = DateHandlers.CpmToDateTime(ctime);
fInfo.LastWriteTime = DateHandlers.CpmToDateTime(trdPartyDateEntry.modify1);
statCache.Add(file1, fInfo);
}
if(!string.IsNullOrEmpty(file2))
{
if(statCache.TryGetValue(file2, out fInfo)) statCache.Remove(file2);
else fInfo = new FileEntryInfo();
byte[] ctime = new byte[4];
ctime[0] = trdPartyDateEntry.create2[0];
ctime[1] = trdPartyDateEntry.create2[1];
fInfo.AccessTime = DateHandlers.CpmToDateTime(trdPartyDateEntry.access2);
fInfo.CreationTime = DateHandlers.CpmToDateTime(ctime);
fInfo.LastWriteTime = DateHandlers.CpmToDateTime(trdPartyDateEntry.modify2);
statCache.Add(file2, fInfo);
}
if(!string.IsNullOrEmpty(file3))
{
if(statCache.TryGetValue(file1, out fInfo)) statCache.Remove(file3);
else fInfo = new FileEntryInfo();
byte[] ctime = new byte[4];
ctime[0] = trdPartyDateEntry.create3[0];
ctime[1] = trdPartyDateEntry.create3[1];
fInfo.AccessTime = DateHandlers.CpmToDateTime(trdPartyDateEntry.access3);
fInfo.CreationTime = DateHandlers.CpmToDateTime(ctime);
fInfo.LastWriteTime = DateHandlers.CpmToDateTime(trdPartyDateEntry.modify3);
statCache.Add(file3, fInfo);
}
file1 = null;
file2 = null;
file3 = null;
dirCnt = 0;
}
if(!string.IsNullOrEmpty(file3))
{
if(statCache.TryGetValue(file3, out fInfo)) statCache.Remove(file3);
else fInfo = new FileEntryInfo();
if(atime) fInfo.AccessTime = DateHandlers.CpmToDateTime(dateEntry.date5);
else fInfo.CreationTime = DateHandlers.CpmToDateTime(dateEntry.date5);
fInfo.LastWriteTime = DateHandlers.CpmToDateTime(dateEntry.date6);
statCache.Add(file3, fInfo);
}
file1 = null;
file2 = null;
file3 = null;
dirCnt = 0;
}
// However, if this byte is 0, timestamp is in Z80DOS or DOS+ format
else if(directory[dOff + 1] == 0x00)
{
dirPtr = Marshal.AllocHGlobal(32);
Marshal.Copy(directory, dOff, dirPtr, 32);
TrdPartyDateEntry trdPartyDateEntry = (TrdPartyDateEntry)Marshal.PtrToStructure(dirPtr, typeof(TrdPartyDateEntry));
Marshal.FreeHGlobal(dirPtr);
FileEntryInfo fInfo;
// Entry contains timestamps for last 3 entries, whatever the kind they are.
if(!string.IsNullOrEmpty(file1))
{
if(statCache.TryGetValue(file1, out fInfo)) statCache.Remove(file1);
else fInfo = new FileEntryInfo();
byte[] ctime = new byte[4];
ctime[0] = trdPartyDateEntry.create1[0];
ctime[1] = trdPartyDateEntry.create1[1];
fInfo.AccessTime = DateHandlers.CpmToDateTime(trdPartyDateEntry.access1);
fInfo.CreationTime = DateHandlers.CpmToDateTime(ctime);
fInfo.LastWriteTime = DateHandlers.CpmToDateTime(trdPartyDateEntry.modify1);
statCache.Add(file1, fInfo);
}
if(!string.IsNullOrEmpty(file2))
{
if(statCache.TryGetValue(file2, out fInfo)) statCache.Remove(file2);
else fInfo = new FileEntryInfo();
byte[] ctime = new byte[4];
ctime[0] = trdPartyDateEntry.create2[0];
ctime[1] = trdPartyDateEntry.create2[1];
fInfo.AccessTime = DateHandlers.CpmToDateTime(trdPartyDateEntry.access2);
fInfo.CreationTime = DateHandlers.CpmToDateTime(ctime);
fInfo.LastWriteTime = DateHandlers.CpmToDateTime(trdPartyDateEntry.modify2);
statCache.Add(file2, fInfo);
}
if(!string.IsNullOrEmpty(file3))
{
if(statCache.TryGetValue(file1, out fInfo)) statCache.Remove(file3);
else fInfo = new FileEntryInfo();
byte[] ctime = new byte[4];
ctime[0] = trdPartyDateEntry.create3[0];
ctime[1] = trdPartyDateEntry.create3[1];
fInfo.AccessTime = DateHandlers.CpmToDateTime(trdPartyDateEntry.access3);
fInfo.CreationTime = DateHandlers.CpmToDateTime(ctime);
fInfo.LastWriteTime = DateHandlers.CpmToDateTime(trdPartyDateEntry.modify3);
statCache.Add(file3, fInfo);
}
file1 = null;
file2 = null;
file3 = null;
dirCnt = 0;
}
break;
}
break;
}
// Cache all files. As CP/M maximum volume size is 8 Mib
// this should not be a problem
@@ -675,7 +682,7 @@ namespace DiscImageChef.Filesystems.CPM
}
/// <summary>
/// Gets information about the mounted volume.
/// Gets information about the mounted volume.
/// </summary>
/// <param name="stat">Information about the mounted volume.</param>
public override Errno StatFs(ref FileSystemInfo stat)

View File

@@ -38,7 +38,7 @@ namespace DiscImageChef.Filesystems.CPM
partial class CPM
{
/// <summary>
/// Reads an extended attribute, alternate data stream or fork from the given file.
/// Reads an extended attribute, alternate data stream or fork from the given file.
/// </summary>
/// <returns>Error number.</returns>
/// <param name="path">File path.</param>
@@ -53,16 +53,19 @@ namespace DiscImageChef.Filesystems.CPM
if(!fileCache.ContainsKey(pathElements[0].ToUpperInvariant())) return Errno.NoSuchFile;
if(string.Compare(xattr, "com.caldera.cpm.password", StringComparison.InvariantCulture) == 0) if(!passwordCache.TryGetValue(pathElements[0].ToUpperInvariant(), out buf)) return Errno.NoError;
if(string.Compare(xattr, "com.caldera.cpm.password", StringComparison.InvariantCulture) == 0)
if(!passwordCache.TryGetValue(pathElements[0].ToUpperInvariant(), out buf)) return Errno.NoError;
if(string.Compare(xattr, "com.caldera.cpm.password.text", StringComparison.InvariantCulture) != 0)
return Errno.NoSuchExtendedAttribute;
return !passwordCache.TryGetValue(pathElements[0].ToUpperInvariant(), out buf) ? Errno.NoError : Errno.NoSuchExtendedAttribute;
return !passwordCache.TryGetValue(pathElements[0].ToUpperInvariant(), out buf)
? Errno.NoError
: Errno.NoSuchExtendedAttribute;
}
/// <summary>
/// Lists all extended attributes, alternate data streams and forks of the given file.
/// Lists all extended attributes, alternate data streams and forks of the given file.
/// </summary>
/// <returns>Error number.</returns>
/// <param name="path">Path.</param>