2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2016-08-26 01:43:15 +01:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Super.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
2016-08-26 01:45:58 +01:00
|
|
|
// Component : CP/M filesystem plugin.
|
2016-08-26 01:43:15 +01:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-08-26 01:45:58 +01:00
|
|
|
// Handles mounting and umounting the CP/M filesystem.
|
|
|
|
|
// Caches the whole volume on mounting (shouldn't be a problem, maximum
|
|
|
|
|
// volume size for CP/M is 8 MiB).
|
2016-08-26 01:43:15 +01:00
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// This library is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
// published by the Free Software Foundation; either version 2.1 of the
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This library is distributed in the hope that it will be useful, but
|
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2016-08-26 01:43:15 +01:00
|
|
|
// ****************************************************************************/
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2016-08-26 01:43:15 +01:00
|
|
|
using System;
|
2016-08-26 01:45:58 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2017-12-21 07:08:26 +00:00
|
|
|
using System.Linq;
|
2016-08-26 01:45:58 +01:00
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using DiscImageChef.Console;
|
|
|
|
|
|
2016-08-26 01:43:15 +01:00
|
|
|
namespace DiscImageChef.Filesystems.CPM
|
|
|
|
|
{
|
2016-08-26 01:45:58 +01:00
|
|
|
partial class CPM : Filesystem
|
2016-08-26 01:43:15 +01:00
|
|
|
{
|
2016-08-26 01:45:58 +01:00
|
|
|
public override Errno Mount()
|
|
|
|
|
{
|
|
|
|
|
return Mount(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Errno Mount(bool debug)
|
|
|
|
|
{
|
|
|
|
|
// As the identification is so complex, just call Identify() and relay on its findings
|
2017-07-19 16:31:08 +01:00
|
|
|
if(!Identify(device, partition) || !cpmFound || workingDefinition == null || dpb == null)
|
2016-08-26 01:45:58 +01:00
|
|
|
return Errno.InvalidArgument;
|
|
|
|
|
|
|
|
|
|
// Build the software interleaving sector mask
|
|
|
|
|
if(workingDefinition.sides == 1)
|
|
|
|
|
{
|
|
|
|
|
sectorMask = new int[workingDefinition.side1.sectorIds.Length];
|
|
|
|
|
for(int m = 0; m < sectorMask.Length; m++)
|
|
|
|
|
sectorMask[m] = workingDefinition.side1.sectorIds[m] - workingDefinition.side1.sectorIds[0];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Head changes after every track
|
|
|
|
|
if(string.Compare(workingDefinition.order, "SIDES", StringComparison.InvariantCultureIgnoreCase) == 0)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
sectorMask = new int[workingDefinition.side1.sectorIds.Length +
|
|
|
|
|
workingDefinition.side2.sectorIds.Length];
|
2016-08-26 01:45:58 +01:00
|
|
|
for(int m = 0; m < workingDefinition.side1.sectorIds.Length; m++)
|
|
|
|
|
sectorMask[m] = workingDefinition.side1.sectorIds[m] - workingDefinition.side1.sectorIds[0];
|
|
|
|
|
// Skip first track (first side)
|
|
|
|
|
for(int m = 0; m < workingDefinition.side2.sectorIds.Length; m++)
|
2017-12-19 20:33:03 +00:00
|
|
|
sectorMask[m + workingDefinition.side1.sectorIds.Length] =
|
2017-12-20 17:26:28 +00:00
|
|
|
workingDefinition.side2.sectorIds[m] - workingDefinition.side2.sectorIds[0] +
|
2017-12-19 20:33:03 +00:00
|
|
|
workingDefinition.side1.sectorIds.Length;
|
2016-08-26 01:45:58 +01:00
|
|
|
}
|
|
|
|
|
// Head changes after whole side
|
2017-12-19 20:33:03 +00:00
|
|
|
else if(string.Compare(workingDefinition.order, "CYLINDERS",
|
|
|
|
|
StringComparison.InvariantCultureIgnoreCase) == 0)
|
2016-08-26 01:45:58 +01:00
|
|
|
{
|
|
|
|
|
for(int m = 0; m < workingDefinition.side1.sectorIds.Length; m++)
|
|
|
|
|
sectorMask[m] = workingDefinition.side1.sectorIds[m] - workingDefinition.side1.sectorIds[0];
|
|
|
|
|
// Skip first track (first side) and first track (second side)
|
|
|
|
|
for(int m = 0; m < workingDefinition.side1.sectorIds.Length; m++)
|
2017-12-19 20:33:03 +00:00
|
|
|
sectorMask[m + workingDefinition.side1.sectorIds.Length] =
|
2017-12-20 17:26:28 +00:00
|
|
|
workingDefinition.side1.sectorIds[m] - workingDefinition.side1.sectorIds[0] +
|
2017-12-19 20:33:03 +00:00
|
|
|
workingDefinition.side1.sectorIds.Length + workingDefinition.side2.sectorIds.Length;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
// TODO: Implement CYLINDERS ordering
|
|
|
|
|
DicConsole.DebugWriteLine("CP/M Plugin", "CYLINDERS ordering not yet implemented.");
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
}
|
|
|
|
|
// TODO: Implement COLUMBIA ordering
|
2017-12-19 20:33:03 +00:00
|
|
|
else if(
|
|
|
|
|
string.Compare(workingDefinition.order, "COLUMBIA", StringComparison.InvariantCultureIgnoreCase) ==
|
|
|
|
|
0)
|
2016-08-26 01:45:58 +01:00
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("CP/M Plugin",
|
|
|
|
|
"Don't know how to handle COLUMBIA ordering, not proceeding with this definition.");
|
2016-08-26 01:45:58 +01:00
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
}
|
|
|
|
|
// TODO: Implement EAGLE ordering
|
2017-12-19 20:33:03 +00:00
|
|
|
else if(string.Compare(workingDefinition.order, "EAGLE", StringComparison.InvariantCultureIgnoreCase) ==
|
|
|
|
|
0)
|
2016-08-26 01:45:58 +01:00
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("CP/M Plugin",
|
|
|
|
|
"Don't know how to handle EAGLE ordering, not proceeding with this definition.");
|
2016-08-26 01:45:58 +01:00
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("CP/M Plugin",
|
|
|
|
|
"Unknown order type \"{0}\", not proceeding with this definition.",
|
|
|
|
|
workingDefinition.order);
|
2016-08-26 01:45:58 +01:00
|
|
|
return Errno.NotSupported;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Deinterleave whole volume
|
|
|
|
|
Dictionary<ulong, byte[]> deinterleavedSectors = new Dictionary<ulong, byte[]>();
|
2017-12-19 20:33:03 +00:00
|
|
|
if(workingDefinition.sides == 1 ||
|
|
|
|
|
string.Compare(workingDefinition.order, "SIDES", StringComparison.InvariantCultureIgnoreCase) == 0)
|
2016-08-26 01:45:58 +01:00
|
|
|
{
|
|
|
|
|
DicConsole.DebugWriteLine("CP/M Plugin", "Deinterleaving whole volume.");
|
|
|
|
|
|
2017-07-19 16:37:11 +01:00
|
|
|
for(int p = 0; p <= (int)(partition.End - partition.Start); p++)
|
2016-08-26 01:45:58 +01:00
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
byte[] readSector =
|
2017-12-20 17:26:28 +00:00
|
|
|
device.ReadSector((ulong)((int)partition.Start + p / sectorMask.Length * sectorMask.Length +
|
2017-12-19 20:33:03 +00:00
|
|
|
sectorMask[p % sectorMask.Length]));
|
2017-12-20 23:07:46 +00:00
|
|
|
if(workingDefinition.complement) for(int b = 0; b < readSector.Length; b++) readSector[b] = (byte)(~readSector[b] & 0xFF);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2016-08-26 01:45:58 +01:00
|
|
|
deinterleavedSectors.Add((ulong)p, readSector);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int blockSize = 128 << dpb.bsh;
|
|
|
|
|
MemoryStream blockMs = new MemoryStream();
|
|
|
|
|
ulong blockNo = 0;
|
|
|
|
|
int sectorsPerBlock = 0;
|
|
|
|
|
Dictionary<ulong, byte[]> allocationBlocks = new Dictionary<ulong, byte[]>();
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("CP/M Plugin", "Creating allocation blocks.");
|
|
|
|
|
|
|
|
|
|
// For each volume sector
|
|
|
|
|
for(ulong a = 0; a < (ulong)deinterleavedSectors.Count; a++)
|
|
|
|
|
{
|
|
|
|
|
byte[] sector;
|
|
|
|
|
deinterleavedSectors.TryGetValue(a, out sector);
|
|
|
|
|
|
|
|
|
|
// May it happen? Just in case, CP/M blocks are smaller than physical sectors
|
|
|
|
|
if(sector.Length > blockSize)
|
2017-12-20 17:26:28 +00:00
|
|
|
for(int i = 0; i < sector.Length / blockSize; i++)
|
2016-08-26 01:45:58 +01:00
|
|
|
{
|
|
|
|
|
byte[] tmp = new byte[blockSize];
|
|
|
|
|
Array.Copy(sector, blockSize * i, tmp, 0, blockSize);
|
|
|
|
|
allocationBlocks.Add(blockNo++, tmp);
|
|
|
|
|
}
|
|
|
|
|
// CP/M blocks are larger than physical sectors
|
|
|
|
|
else if(sector.Length < blockSize)
|
|
|
|
|
{
|
|
|
|
|
blockMs.Write(sector, 0, sector.Length);
|
|
|
|
|
sectorsPerBlock++;
|
|
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
if(sectorsPerBlock != blockSize / sector.Length) continue;
|
|
|
|
|
|
|
|
|
|
allocationBlocks.Add(blockNo++, blockMs.ToArray());
|
|
|
|
|
sectorsPerBlock = 0;
|
|
|
|
|
blockMs = new MemoryStream();
|
2016-08-26 01:45:58 +01:00
|
|
|
}
|
|
|
|
|
// CP/M blocks are same size than physical sectors
|
2017-12-19 20:33:03 +00:00
|
|
|
else allocationBlocks.Add(blockNo++, sector);
|
2016-08-26 01:45:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("CP/M Plugin", "Reading directory.");
|
|
|
|
|
|
|
|
|
|
int dirOff;
|
2017-12-20 17:26:28 +00:00
|
|
|
int dirSectors = (dpb.drm + 1) * 32 / workingDefinition.bytesPerSector;
|
2017-12-19 20:33:03 +00:00
|
|
|
if(workingDefinition.sofs > 0) dirOff = workingDefinition.sofs;
|
|
|
|
|
else dirOff = workingDefinition.ofs * workingDefinition.sectorsPerTrack;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
// Read the whole directory blocks
|
|
|
|
|
MemoryStream dirMs = new MemoryStream();
|
|
|
|
|
for(int d = 0; d < dirSectors; d++)
|
|
|
|
|
{
|
|
|
|
|
byte[] sector;
|
|
|
|
|
deinterleavedSectors.TryGetValue((ulong)(d + dirOff), out sector);
|
|
|
|
|
dirMs.Write(sector, 0, sector.Length);
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2016-08-26 01:45:58 +01:00
|
|
|
byte[] directory = dirMs.ToArray();
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(directory == null) return Errno.InvalidArgument;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
int dirCnt = 0;
|
|
|
|
|
string file1 = null;
|
|
|
|
|
string file2 = null;
|
|
|
|
|
string file3 = null;
|
2017-12-19 20:33:03 +00:00
|
|
|
Dictionary<string, Dictionary<int, List<ushort>>> fileExtents =
|
|
|
|
|
new Dictionary<string, Dictionary<int, List<ushort>>>();
|
2016-08-26 01:45:58 +01:00
|
|
|
statCache = new Dictionary<string, FileEntryInfo>();
|
|
|
|
|
cpmStat = new FileSystemInfo();
|
|
|
|
|
bool atime = false;
|
|
|
|
|
dirList = new List<string>();
|
|
|
|
|
labelCreationDate = null;
|
|
|
|
|
labelUpdateDate = null;
|
|
|
|
|
passwordCache = new Dictionary<string, byte[]>();
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("CP/M Plugin", "Traversing directory.");
|
2017-12-21 04:43:29 +00:00
|
|
|
IntPtr dirPtr;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
// For each directory entry
|
|
|
|
|
for(int dOff = 0; dOff < directory.Length; dOff += 32)
|
2017-12-20 23:07:46 +00:00
|
|
|
// Describes a file (does not support PDOS entries with user >= 16, because they're identical to password entries
|
2016-08-26 01:45:58 +01:00
|
|
|
if((directory[dOff] & 0x7F) < 0x10)
|
|
|
|
|
if(allocationBlocks.Count > 256)
|
|
|
|
|
{
|
|
|
|
|
DirectoryEntry16 entry = new DirectoryEntry16();
|
2017-12-21 04:43:29 +00:00
|
|
|
dirPtr = Marshal.AllocHGlobal(32);
|
2016-08-26 01:45:58 +01:00
|
|
|
Marshal.Copy(directory, dOff, dirPtr, 32);
|
|
|
|
|
entry = (DirectoryEntry16)Marshal.PtrToStructure(dirPtr, typeof(DirectoryEntry16));
|
|
|
|
|
Marshal.FreeHGlobal(dirPtr);
|
|
|
|
|
|
|
|
|
|
bool hidden = (entry.statusUser & 0x80) == 0x80;
|
|
|
|
|
bool rdOnly = (entry.filename[0] & 0x80) == 0x80 || (entry.extension[0] & 0x80) == 0x80;
|
|
|
|
|
bool system = (entry.filename[1] & 0x80) == 0x80 || (entry.extension[2] & 0x80) == 0x80;
|
|
|
|
|
//bool backed = (entry.filename[3] & 0x80) == 0x80 || (entry.extension[3] & 0x80) == 0x80;
|
2017-12-20 17:26:28 +00:00
|
|
|
int user = entry.statusUser & 0x0F;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
bool validEntry = true;
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < 8; i++)
|
|
|
|
|
{
|
|
|
|
|
entry.filename[i] &= 0x7F;
|
|
|
|
|
validEntry &= entry.filename[i] >= 0x20;
|
|
|
|
|
}
|
|
|
|
|
for(int i = 0; i < 3; i++)
|
|
|
|
|
{
|
|
|
|
|
entry.extension[i] &= 0x7F;
|
|
|
|
|
validEntry &= entry.extension[i] >= 0x20;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(!validEntry) continue;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
string filename = Encoding.ASCII.GetString(entry.filename).Trim();
|
|
|
|
|
string extension = Encoding.ASCII.GetString(entry.extension).Trim();
|
|
|
|
|
|
|
|
|
|
// If user is != 0, append user to name to have identical filenames
|
2017-12-19 20:33:03 +00:00
|
|
|
if(user > 0) filename = string.Format("{0:X1}:{1}", user, filename);
|
|
|
|
|
if(!string.IsNullOrEmpty(extension)) filename = filename + "." + extension;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-20 17:26:28 +00:00
|
|
|
int entryNo = (32 * entry.extentCounter + entry.extentCounterHigh) / (dpb.exm + 1);
|
2016-08-26 01:45:58 +01:00
|
|
|
List<ushort> blocks;
|
|
|
|
|
Dictionary<int, List<ushort>> extentBlocks;
|
|
|
|
|
FileEntryInfo fInfo;
|
|
|
|
|
|
|
|
|
|
// Do we have a stat for the file already?
|
2017-12-19 20:33:03 +00:00
|
|
|
if(statCache.TryGetValue(filename, out fInfo)) statCache.Remove(filename);
|
2016-08-26 01:45:58 +01:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fInfo = new FileEntryInfo();
|
|
|
|
|
fInfo.Attributes = new FileAttributes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// And any extent?
|
2017-12-19 20:33:03 +00:00
|
|
|
if(fileExtents.TryGetValue(filename, out extentBlocks)) fileExtents.Remove(filename);
|
|
|
|
|
else extentBlocks = new Dictionary<int, List<ushort>>();
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
// Do we already have this extent? Should never happen
|
2017-12-19 20:33:03 +00:00
|
|
|
if(extentBlocks.TryGetValue(entryNo, out blocks)) extentBlocks.Remove(entryNo);
|
|
|
|
|
else blocks = new List<ushort>();
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
// Attributes
|
2017-12-19 20:33:03 +00:00
|
|
|
if(hidden) fInfo.Attributes |= FileAttributes.Hidden;
|
|
|
|
|
if(rdOnly) fInfo.Attributes |= FileAttributes.ReadOnly;
|
|
|
|
|
if(system) fInfo.Attributes |= FileAttributes.System;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
// Supposedly there is a value in the directory entry telling how many blocks are designated in this entry
|
|
|
|
|
// However some implementations tend to do whatever they wish, but none will ever allocate block 0 for a file
|
|
|
|
|
// 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.
|
2017-12-21 07:08:26 +00:00
|
|
|
foreach(ushort blk in entry.allocations.Where(blk => !blocks.Contains(blk) && blk != 0)) blocks.Add(blk);
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
// Save the file
|
|
|
|
|
fInfo.UID = (ulong)user;
|
|
|
|
|
extentBlocks.Add(entryNo, blocks);
|
|
|
|
|
fileExtents.Add(filename, extentBlocks);
|
|
|
|
|
statCache.Add(filename, fInfo);
|
|
|
|
|
|
|
|
|
|
// Add the file to the directory listing
|
2017-12-19 20:33:03 +00:00
|
|
|
if(!dirList.Contains(filename)) dirList.Add(filename);
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
// Count entries 3 by 3 for timestamps
|
|
|
|
|
switch(dirCnt % 3)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
file1 = filename;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
file2 = filename;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
file3 = filename;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2016-08-26 01:45:58 +01:00
|
|
|
dirCnt++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DirectoryEntry entry = new DirectoryEntry();
|
2017-12-21 04:43:29 +00:00
|
|
|
dirPtr = Marshal.AllocHGlobal(32);
|
2016-08-26 01:45:58 +01:00
|
|
|
Marshal.Copy(directory, dOff, dirPtr, 32);
|
|
|
|
|
entry = (DirectoryEntry)Marshal.PtrToStructure(dirPtr, typeof(DirectoryEntry));
|
|
|
|
|
Marshal.FreeHGlobal(dirPtr);
|
|
|
|
|
|
|
|
|
|
bool hidden = (entry.statusUser & 0x80) == 0x80;
|
|
|
|
|
bool rdOnly = (entry.filename[0] & 0x80) == 0x80 || (entry.extension[0] & 0x80) == 0x80;
|
|
|
|
|
bool system = (entry.filename[1] & 0x80) == 0x80 || (entry.extension[2] & 0x80) == 0x80;
|
|
|
|
|
//bool backed = (entry.filename[3] & 0x80) == 0x80 || (entry.extension[3] & 0x80) == 0x80;
|
2017-12-20 17:26:28 +00:00
|
|
|
int user = entry.statusUser & 0x0F;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
bool validEntry = true;
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < 8; i++)
|
|
|
|
|
{
|
|
|
|
|
entry.filename[i] &= 0x7F;
|
|
|
|
|
validEntry &= entry.filename[i] >= 0x20;
|
|
|
|
|
}
|
|
|
|
|
for(int i = 0; i < 3; i++)
|
|
|
|
|
{
|
|
|
|
|
entry.extension[i] &= 0x7F;
|
|
|
|
|
validEntry &= entry.extension[i] >= 0x20;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(!validEntry) continue;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
string filename = Encoding.ASCII.GetString(entry.filename).Trim();
|
|
|
|
|
string extension = Encoding.ASCII.GetString(entry.extension).Trim();
|
|
|
|
|
|
|
|
|
|
// If user is != 0, append user to name to have identical filenames
|
2017-12-19 20:33:03 +00:00
|
|
|
if(user > 0) filename = string.Format("{0:X1}:{1}", user, filename);
|
|
|
|
|
if(!string.IsNullOrEmpty(extension)) filename = filename + "." + extension;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-20 17:26:28 +00:00
|
|
|
int entryNo = (32 * entry.extentCounterHigh + entry.extentCounter) / (dpb.exm + 1);
|
2016-08-26 01:45:58 +01:00
|
|
|
List<ushort> blocks;
|
|
|
|
|
Dictionary<int, List<ushort>> extentBlocks;
|
|
|
|
|
FileEntryInfo fInfo;
|
|
|
|
|
|
|
|
|
|
// Do we have a stat for the file already?
|
2017-12-19 20:33:03 +00:00
|
|
|
if(statCache.TryGetValue(filename, out fInfo)) statCache.Remove(filename);
|
2016-08-26 01:45:58 +01:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fInfo = new FileEntryInfo();
|
|
|
|
|
fInfo.Attributes = new FileAttributes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// And any extent?
|
2017-12-19 20:33:03 +00:00
|
|
|
if(fileExtents.TryGetValue(filename, out extentBlocks)) fileExtents.Remove(filename);
|
|
|
|
|
else extentBlocks = new Dictionary<int, List<ushort>>();
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
// Do we already have this extent? Should never happen
|
2017-12-19 20:33:03 +00:00
|
|
|
if(extentBlocks.TryGetValue(entryNo, out blocks)) extentBlocks.Remove(entryNo);
|
|
|
|
|
else blocks = new List<ushort>();
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
// Attributes
|
2017-12-19 20:33:03 +00:00
|
|
|
if(hidden) fInfo.Attributes |= FileAttributes.Hidden;
|
|
|
|
|
if(rdOnly) fInfo.Attributes |= FileAttributes.ReadOnly;
|
|
|
|
|
if(system) fInfo.Attributes |= FileAttributes.System;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
// Supposedly there is a value in the directory entry telling how many blocks are designated in this entry
|
|
|
|
|
// However some implementations tend to do whatever they wish, but none will ever allocate block 0 for a file
|
|
|
|
|
// 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.
|
2017-12-21 07:08:26 +00:00
|
|
|
foreach(ushort blk in entry.allocations.Cast<ushort>().Where(blk => !blocks.Contains(blk) && blk != 0)) blocks.Add(blk);
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
// Save the file
|
|
|
|
|
fInfo.UID = (ulong)user;
|
|
|
|
|
extentBlocks.Add(entryNo, blocks);
|
|
|
|
|
fileExtents.Add(filename, extentBlocks);
|
|
|
|
|
statCache.Add(filename, fInfo);
|
|
|
|
|
|
|
|
|
|
// Add the file to the directory listing
|
2017-12-19 20:33:03 +00:00
|
|
|
if(!dirList.Contains(filename)) dirList.Add(filename);
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
// Count entries 3 by 3 for timestamps
|
|
|
|
|
switch(dirCnt % 3)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
file1 = filename;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
file2 = filename;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
file3 = filename;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2016-08-26 01:45:58 +01:00
|
|
|
dirCnt++;
|
|
|
|
|
}
|
|
|
|
|
// A password entry (or a file entry in PDOS, but this does not handle that case)
|
|
|
|
|
else if((directory[dOff] & 0x7F) >= 0x10 && (directory[dOff] & 0x7F) < 0x20)
|
|
|
|
|
{
|
|
|
|
|
PasswordEntry entry = new PasswordEntry();
|
2017-12-21 04:43:29 +00:00
|
|
|
dirPtr = Marshal.AllocHGlobal(32);
|
2016-08-26 01:45:58 +01:00
|
|
|
Marshal.Copy(directory, dOff, dirPtr, 32);
|
|
|
|
|
entry = (PasswordEntry)Marshal.PtrToStructure(dirPtr, typeof(PasswordEntry));
|
|
|
|
|
Marshal.FreeHGlobal(dirPtr);
|
|
|
|
|
|
2017-12-20 17:26:28 +00:00
|
|
|
int user = entry.userNumber & 0x0F;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
for(int i = 0; i < 8; i++) entry.filename[i] &= 0x7F;
|
|
|
|
|
for(int i = 0; i < 3; i++) entry.extension[i] &= 0x7F;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
string filename = Encoding.ASCII.GetString(entry.filename).Trim();
|
|
|
|
|
string extension = Encoding.ASCII.GetString(entry.extension).Trim();
|
|
|
|
|
|
|
|
|
|
// If user is != 0, append user to name to have identical filenames
|
2017-12-19 20:33:03 +00:00
|
|
|
if(user > 0) filename = string.Format("{0:X1}:{1}", user, filename);
|
|
|
|
|
if(!string.IsNullOrEmpty(extension)) filename = filename + "." + extension;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
// Do not repeat passwords
|
2017-12-19 20:33:03 +00:00
|
|
|
if(passwordCache.ContainsKey(filename)) passwordCache.Remove(filename);
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
// Copy whole password entry
|
|
|
|
|
byte[] tmp = new byte[32];
|
|
|
|
|
Array.Copy(directory, dOff, tmp, 0, 32);
|
|
|
|
|
passwordCache.Add(filename, tmp);
|
|
|
|
|
|
|
|
|
|
// Count entries 3 by 3 for timestamps
|
|
|
|
|
switch(dirCnt % 3)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
file1 = filename;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
file2 = filename;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
file3 = filename;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2016-08-26 01:45:58 +01:00
|
|
|
dirCnt++;
|
|
|
|
|
}
|
|
|
|
|
// Volume label and password entry. Volume password is ignored.
|
2017-12-21 04:43:29 +00:00
|
|
|
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);
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
// 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;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
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);
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
// 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;
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
dirCnt++;
|
|
|
|
|
break;
|
|
|
|
|
case 0x21:
|
|
|
|
|
if(directory[dOff + 10] == 0x00 && directory[dOff + 20] == 0x00 && directory[dOff + 30] == 0x00 &&
|
|
|
|
|
directory[dOff + 31] == 0x00)
|
|
|
|
|
{
|
|
|
|
|
DateEntry dateEntry;
|
|
|
|
|
dirPtr = Marshal.AllocHGlobal(32);
|
|
|
|
|
Marshal.Copy(directory, dOff, dirPtr, 32);
|
|
|
|
|
dateEntry = (DateEntry)Marshal.PtrToStructure(dirPtr, typeof(DateEntry));
|
|
|
|
|
Marshal.FreeHGlobal(dirPtr);
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
FileEntryInfo fInfo;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
// 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();
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
if(atime) fInfo.AccessTime = DateHandlers.CPMToDateTime(dateEntry.date1);
|
|
|
|
|
else fInfo.CreationTime = DateHandlers.CPMToDateTime(dateEntry.date1);
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
fInfo.LastWriteTime = DateHandlers.CPMToDateTime(dateEntry.date2);
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
statCache.Add(file1, fInfo);
|
|
|
|
|
}
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
if(!string.IsNullOrEmpty(file2))
|
|
|
|
|
{
|
|
|
|
|
if(statCache.TryGetValue(file2, out fInfo)) statCache.Remove(file2);
|
|
|
|
|
else fInfo = new FileEntryInfo();
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
if(atime) fInfo.AccessTime = DateHandlers.CPMToDateTime(dateEntry.date3);
|
|
|
|
|
else fInfo.CreationTime = DateHandlers.CPMToDateTime(dateEntry.date3);
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
fInfo.LastWriteTime = DateHandlers.CPMToDateTime(dateEntry.date4);
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
statCache.Add(file2, fInfo);
|
|
|
|
|
}
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
if(!string.IsNullOrEmpty(file3))
|
|
|
|
|
{
|
|
|
|
|
if(statCache.TryGetValue(file3, out fInfo)) statCache.Remove(file3);
|
|
|
|
|
else fInfo = new FileEntryInfo();
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
if(atime) fInfo.AccessTime = DateHandlers.CPMToDateTime(dateEntry.date5);
|
|
|
|
|
else fInfo.CreationTime = DateHandlers.CPMToDateTime(dateEntry.date5);
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
fInfo.LastWriteTime = DateHandlers.CPMToDateTime(dateEntry.date6);
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
statCache.Add(file3, fInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file1 = null;
|
|
|
|
|
file2 = null;
|
|
|
|
|
file3 = null;
|
|
|
|
|
dirCnt = 0;
|
2016-08-26 01:45:58 +01:00
|
|
|
}
|
2017-12-21 04:43:29 +00:00
|
|
|
// However, if this byte is 0, timestamp is in Z80DOS or DOS+ format
|
|
|
|
|
else if(directory[dOff + 1] == 0x00)
|
|
|
|
|
{
|
|
|
|
|
TrdPartyDateEntry trdPartyDateEntry;
|
|
|
|
|
dirPtr = Marshal.AllocHGlobal(32);
|
|
|
|
|
Marshal.Copy(directory, dOff, dirPtr, 32);
|
|
|
|
|
trdPartyDateEntry = (TrdPartyDateEntry)Marshal.PtrToStructure(dirPtr, typeof(TrdPartyDateEntry));
|
|
|
|
|
Marshal.FreeHGlobal(dirPtr);
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
FileEntryInfo fInfo;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
// 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();
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
byte[] ctime = new byte[4];
|
|
|
|
|
ctime[0] = trdPartyDateEntry.create1[0];
|
|
|
|
|
ctime[1] = trdPartyDateEntry.create1[1];
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
fInfo.AccessTime = DateHandlers.CPMToDateTime(trdPartyDateEntry.access1);
|
|
|
|
|
fInfo.CreationTime = DateHandlers.CPMToDateTime(ctime);
|
|
|
|
|
fInfo.LastWriteTime = DateHandlers.CPMToDateTime(trdPartyDateEntry.modify1);
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
statCache.Add(file1, fInfo);
|
|
|
|
|
}
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
if(!string.IsNullOrEmpty(file2))
|
|
|
|
|
{
|
|
|
|
|
if(statCache.TryGetValue(file2, out fInfo)) statCache.Remove(file2);
|
|
|
|
|
else fInfo = new FileEntryInfo();
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
byte[] ctime = new byte[4];
|
|
|
|
|
ctime[0] = trdPartyDateEntry.create2[0];
|
|
|
|
|
ctime[1] = trdPartyDateEntry.create2[1];
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
fInfo.AccessTime = DateHandlers.CPMToDateTime(trdPartyDateEntry.access2);
|
|
|
|
|
fInfo.CreationTime = DateHandlers.CPMToDateTime(ctime);
|
|
|
|
|
fInfo.LastWriteTime = DateHandlers.CPMToDateTime(trdPartyDateEntry.modify2);
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
statCache.Add(file2, fInfo);
|
|
|
|
|
}
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
if(!string.IsNullOrEmpty(file3))
|
|
|
|
|
{
|
|
|
|
|
if(statCache.TryGetValue(file1, out fInfo)) statCache.Remove(file3);
|
|
|
|
|
else fInfo = new FileEntryInfo();
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
byte[] ctime = new byte[4];
|
|
|
|
|
ctime[0] = trdPartyDateEntry.create3[0];
|
|
|
|
|
ctime[1] = trdPartyDateEntry.create3[1];
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
fInfo.AccessTime = DateHandlers.CPMToDateTime(trdPartyDateEntry.access3);
|
|
|
|
|
fInfo.CreationTime = DateHandlers.CPMToDateTime(ctime);
|
|
|
|
|
fInfo.LastWriteTime = DateHandlers.CPMToDateTime(trdPartyDateEntry.modify3);
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
statCache.Add(file3, fInfo);
|
|
|
|
|
}
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
file1 = null;
|
|
|
|
|
file2 = null;
|
|
|
|
|
file3 = null;
|
|
|
|
|
dirCnt = 0;
|
2016-08-26 01:45:58 +01:00
|
|
|
}
|
2017-12-21 04:43:29 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
// Cache all files. As CP/M maximum volume size is 8 Mib
|
|
|
|
|
// this should not be a problem
|
|
|
|
|
DicConsole.DebugWriteLine("CP/M Plugin", "Reading files.");
|
|
|
|
|
long usedBlocks = 0;
|
|
|
|
|
fileCache = new Dictionary<string, byte[]>();
|
|
|
|
|
foreach(string filename in dirList)
|
|
|
|
|
{
|
|
|
|
|
MemoryStream fileMs = new MemoryStream();
|
|
|
|
|
FileEntryInfo fInfo = new FileEntryInfo();
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(statCache.TryGetValue(filename, out fInfo)) statCache.Remove(filename);
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
fInfo.Blocks = 0;
|
|
|
|
|
|
|
|
|
|
Dictionary<int, List<ushort>> extents;
|
|
|
|
|
if(fileExtents.TryGetValue(filename, out extents))
|
|
|
|
|
for(int ex = 0; ex < extents.Count; ex++)
|
|
|
|
|
{
|
|
|
|
|
List<ushort> alBlks;
|
|
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
if(!extents.TryGetValue(ex, out alBlks)) continue;
|
|
|
|
|
|
|
|
|
|
foreach(ushort alBlk in alBlks)
|
|
|
|
|
{
|
|
|
|
|
byte[] blk = new byte[blockSize];
|
|
|
|
|
allocationBlocks.TryGetValue(alBlk, out blk);
|
|
|
|
|
fileMs.Write(blk, 0, blk.Length);
|
|
|
|
|
fInfo.Blocks++;
|
|
|
|
|
}
|
2016-08-26 01:45:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If you insist to call CP/M "extent based"
|
|
|
|
|
fInfo.Attributes |= FileAttributes.Extents;
|
|
|
|
|
fInfo.BlockSize = blockSize;
|
|
|
|
|
fInfo.Length = fileMs.Length;
|
|
|
|
|
cpmStat.Files++;
|
|
|
|
|
usedBlocks += fInfo.Blocks;
|
|
|
|
|
|
|
|
|
|
statCache.Add(filename, fInfo);
|
|
|
|
|
fileCache.Add(filename, fileMs.ToArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
decodedPasswordCache = new Dictionary<string, byte[]>();
|
|
|
|
|
// For each stored password, store a decoded version of it
|
|
|
|
|
if(passwordCache.Count > 0)
|
|
|
|
|
foreach(KeyValuePair<string, byte[]> kvp in passwordCache)
|
|
|
|
|
{
|
|
|
|
|
byte[] tmp = new byte[8];
|
|
|
|
|
Array.Copy(kvp.Value, 16, tmp, 0, 8);
|
2017-12-19 20:33:03 +00:00
|
|
|
for(int t = 0; t < 8; t++) tmp[t] ^= kvp.Value[13];
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
decodedPasswordCache.Add(kvp.Key, tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Generate statfs.
|
|
|
|
|
cpmStat.Blocks = dpb.dsm + 1;
|
|
|
|
|
cpmStat.FilenameLength = 11;
|
|
|
|
|
cpmStat.Files = (ulong)fileCache.Count;
|
|
|
|
|
cpmStat.FreeBlocks = cpmStat.Blocks - usedBlocks;
|
|
|
|
|
cpmStat.PluginId = PluginUUID;
|
|
|
|
|
cpmStat.Type = "CP/M filesystem";
|
|
|
|
|
|
|
|
|
|
// Generate XML info
|
|
|
|
|
xmlFSType = new Schemas.FileSystemType();
|
|
|
|
|
xmlFSType.Clusters = cpmStat.Blocks;
|
|
|
|
|
xmlFSType.ClusterSize = blockSize;
|
|
|
|
|
if(labelCreationDate != null)
|
|
|
|
|
{
|
|
|
|
|
xmlFSType.CreationDate = DateHandlers.CPMToDateTime(labelCreationDate);
|
|
|
|
|
xmlFSType.CreationDateSpecified = true;
|
|
|
|
|
}
|
|
|
|
|
if(labelUpdateDate != null)
|
|
|
|
|
{
|
|
|
|
|
xmlFSType.ModificationDate = DateHandlers.CPMToDateTime(labelUpdateDate);
|
|
|
|
|
xmlFSType.ModificationDateSpecified = true;
|
|
|
|
|
}
|
|
|
|
|
xmlFSType.Files = fileCache.Count;
|
|
|
|
|
xmlFSType.FilesSpecified = true;
|
|
|
|
|
xmlFSType.FreeClusters = cpmStat.FreeBlocks;
|
|
|
|
|
xmlFSType.FreeClustersSpecified = true;
|
|
|
|
|
xmlFSType.Type = "CP/M filesystem";
|
2017-12-19 20:33:03 +00:00
|
|
|
if(!string.IsNullOrEmpty(label)) xmlFSType.VolumeName = label;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
mounted = true;
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets information about the mounted volume.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="stat">Information about the mounted volume.</param>
|
|
|
|
|
public override Errno StatFs(ref FileSystemInfo stat)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(!mounted) return Errno.AccessDenied;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
stat = cpmStat;
|
|
|
|
|
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Errno Unmount()
|
2016-08-26 01:43:15 +01:00
|
|
|
{
|
2016-08-26 01:45:58 +01:00
|
|
|
mounted = false;
|
|
|
|
|
definitions = null;
|
|
|
|
|
cpmFound = false;
|
|
|
|
|
workingDefinition = null;
|
2017-12-19 20:33:03 +00:00
|
|
|
dpb = null;
|
2016-08-26 01:45:58 +01:00
|
|
|
sectorMask = null;
|
|
|
|
|
label = null;
|
|
|
|
|
thirdPartyTimestamps = false;
|
|
|
|
|
standardTimestamps = false;
|
|
|
|
|
labelCreationDate = null;
|
|
|
|
|
labelUpdateDate = null;
|
|
|
|
|
return Errno.NoError;
|
2016-08-26 01:43:15 +01:00
|
|
|
}
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|