mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Code restyling.
This commit is contained in:
@@ -34,58 +34,38 @@ namespace Aaru.Filesystems.LisaFS
|
||||
{
|
||||
public partial class LisaFS
|
||||
{
|
||||
/// <summary>
|
||||
/// Lisa FS v1, from Lisa OS 1.0 (Workshop or Office)
|
||||
/// Never seen on Sony floppies.
|
||||
/// </summary>
|
||||
/// <summary>Lisa FS v1, from Lisa OS 1.0 (Workshop or Office) Never seen on Sony floppies.</summary>
|
||||
const byte LISA_V1 = 0x0E;
|
||||
/// <summary>
|
||||
/// Lisa FS v2, from Lisa OS 2.0 (Workshop or Office)
|
||||
/// Contrary to what most information online says the only difference with V1
|
||||
/// is the Extents File size. Catalog format is the same
|
||||
/// Lisa FS v2, from Lisa OS 2.0 (Workshop or Office) Contrary to what most information online says the only
|
||||
/// difference with V1 is the Extents File size. Catalog format is the same
|
||||
/// </summary>
|
||||
const byte LISA_V2 = 0x0F;
|
||||
/// <summary>
|
||||
/// Lisa FS v3, from Lisa OS 3.0 (Workshop or Office)
|
||||
/// Adds support for user catalogs (aka subdirectories),
|
||||
/// and changes the catalog format from extents to double-linked list.
|
||||
/// Uses '-' as path separator (so people that created Lisa/FILE.TEXT just
|
||||
/// created a file named like that :p)
|
||||
/// Lisa FS v3, from Lisa OS 3.0 (Workshop or Office) Adds support for user catalogs (aka subdirectories), and
|
||||
/// changes the catalog format from extents to double-linked list. Uses '-' as path separator (so people that created
|
||||
/// Lisa/FILE.TEXT just created a file named like that :p)
|
||||
/// </summary>
|
||||
const byte LISA_V3 = 0x11;
|
||||
/// <summary>Maximum string size in LisaFS</summary>
|
||||
const uint E_NAME = 32;
|
||||
/// <summary>
|
||||
/// Unused file ID
|
||||
/// </summary>
|
||||
/// <summary>Unused file ID</summary>
|
||||
const ushort FILEID_FREE = 0x0000;
|
||||
/// <summary>
|
||||
/// Used by the boot blocks
|
||||
/// </summary>
|
||||
/// <summary>Used by the boot blocks</summary>
|
||||
const ushort FILEID_BOOT = 0xAAAA;
|
||||
/// <summary>
|
||||
/// Used by the operating system loader blocks
|
||||
/// </summary>
|
||||
/// <summary>Used by the operating system loader blocks</summary>
|
||||
const ushort FILEID_LOADER = 0xBBBB;
|
||||
/// <summary>
|
||||
/// Used by the MDDF
|
||||
/// </summary>
|
||||
/// <summary>Used by the MDDF</summary>
|
||||
const ushort FILEID_MDDF = 0x0001;
|
||||
/// <summary>
|
||||
/// Used by the volume bitmap, sits between MDDF and S-Records file.
|
||||
/// </summary>
|
||||
/// <summary>Used by the volume bitmap, sits between MDDF and S-Records file.</summary>
|
||||
const ushort FILEID_BITMAP = 0x0002;
|
||||
/// <summary>
|
||||
/// S-Records file
|
||||
/// </summary>
|
||||
/// <summary>S-Records file</summary>
|
||||
const ushort FILEID_SRECORD = 0x0003;
|
||||
/// <summary>The root catalog</summary>
|
||||
const ushort FILEID_CATALOG = 0x0004;
|
||||
const short FILEID_BOOT_SIGNED = -21846;
|
||||
const short FILEID_LOADER_SIGNED = -17477;
|
||||
/// <summary>
|
||||
/// A file that has been erased
|
||||
/// </summary>
|
||||
/// <summary>A file that has been erased</summary>
|
||||
const ushort FILEID_ERASED = 0x7FFF;
|
||||
const ushort FILEID_MAX = FILEID_ERASED;
|
||||
|
||||
@@ -94,69 +74,37 @@ namespace Aaru.Filesystems.LisaFS
|
||||
|
||||
enum FileType : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// Undefined file type
|
||||
/// </summary>
|
||||
/// <summary>Undefined file type</summary>
|
||||
Undefined = 0,
|
||||
/// <summary>
|
||||
/// MDDF
|
||||
/// </summary>
|
||||
/// <summary>MDDF</summary>
|
||||
MDDFile = 1,
|
||||
/// <summary>
|
||||
/// Root catalog
|
||||
/// </summary>
|
||||
/// <summary>Root catalog</summary>
|
||||
RootCat = 2,
|
||||
/// <summary>
|
||||
/// Bitmap
|
||||
/// </summary>
|
||||
/// <summary>Bitmap</summary>
|
||||
FreeList = 3,
|
||||
/// <summary>
|
||||
/// Unknown, maybe refers to the S-Records File?
|
||||
/// </summary>
|
||||
/// <summary>Unknown, maybe refers to the S-Records File?</summary>
|
||||
BadBlocks = 4,
|
||||
/// <summary>
|
||||
/// System data
|
||||
/// </summary>
|
||||
/// <summary>System data</summary>
|
||||
SysData = 5,
|
||||
/// <summary>
|
||||
/// Printer spool
|
||||
/// </summary>
|
||||
/// <summary>Printer spool</summary>
|
||||
Spool = 6,
|
||||
/// <summary>
|
||||
/// Executable. Yet application files don't use it
|
||||
/// </summary>
|
||||
/// <summary>Executable. Yet application files don't use it</summary>
|
||||
Exec = 7,
|
||||
/// <summary>
|
||||
/// User catalog
|
||||
/// </summary>
|
||||
/// <summary>User catalog</summary>
|
||||
UserCat = 8,
|
||||
/// <summary>
|
||||
/// Pipe. Not seen on disk.
|
||||
/// </summary>
|
||||
/// <summary>Pipe. Not seen on disk.</summary>
|
||||
Pipe = 9,
|
||||
/// <summary>
|
||||
/// Boot file?
|
||||
/// </summary>
|
||||
/// <summary>Boot file?</summary>
|
||||
BootFile = 10,
|
||||
/// <summary>
|
||||
/// Swap for data
|
||||
/// </summary>
|
||||
/// <summary>Swap for data</summary>
|
||||
SwapData = 11,
|
||||
/// <summary>
|
||||
/// Swap for code
|
||||
/// </summary>
|
||||
/// <summary>Swap for code</summary>
|
||||
SwapCode = 12,
|
||||
/// <summary>
|
||||
/// Unknown
|
||||
/// </summary>
|
||||
/// <summary>Unknown</summary>
|
||||
RamAP = 13,
|
||||
/// <summary>
|
||||
/// Any file
|
||||
/// </summary>
|
||||
/// <summary>Any file</summary>
|
||||
UserFile = 14,
|
||||
/// <summary>
|
||||
/// Erased?
|
||||
/// </summary>
|
||||
/// <summary>Erased?</summary>
|
||||
KilledObject = 15
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,30 +41,30 @@ namespace Aaru.Filesystems.LisaFS
|
||||
{
|
||||
public partial class LisaFS
|
||||
{
|
||||
/// <summary>
|
||||
/// Solves a symbolic link.
|
||||
/// </summary>
|
||||
/// <summary>Solves a symbolic link.</summary>
|
||||
/// <param name="path">Link path.</param>
|
||||
/// <param name="dest">Link destination.</param>
|
||||
public Errno ReadLink(string path, out string dest)
|
||||
{
|
||||
dest = null;
|
||||
|
||||
// LisaFS does not support symbolic links (afaik)
|
||||
return Errno.NotSupported;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lists contents from a directory.
|
||||
/// </summary>
|
||||
/// <summary>Lists contents from a directory.</summary>
|
||||
/// <param name="path">Directory path.</param>
|
||||
/// <param name="contents">Directory contents.</param>
|
||||
public Errno ReadDir(string path, out List<string> contents)
|
||||
{
|
||||
contents = null;
|
||||
Errno error = LookupFileId(path, out short fileId, out bool isDir);
|
||||
if(error != Errno.NoError) return error;
|
||||
|
||||
if(!isDir) return Errno.NotDirectory;
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
if(!isDir)
|
||||
return Errno.NotDirectory;
|
||||
|
||||
/*List<CatalogEntry> catalog;
|
||||
error = ReadCatalog(fileId, out catalog);
|
||||
@@ -86,6 +86,7 @@ namespace Aaru.Filesystems.LisaFS
|
||||
}
|
||||
|
||||
contents.Sort();
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
@@ -93,27 +94,28 @@ namespace Aaru.Filesystems.LisaFS
|
||||
{
|
||||
// Do same trick as Mac OS X, replace filesystem '/' with '-',
|
||||
// as '-' is the path separator in Lisa OS
|
||||
contents = (from entry in catalogCache
|
||||
where entry.parentID == dirId
|
||||
contents = (from entry in catalogCache where entry.parentID == dirId
|
||||
select StringHandlers.CToString(entry.filename, Encoding).Replace('/', '-')).ToList();
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads, interprets and caches the Catalog File
|
||||
/// </summary>
|
||||
/// <summary>Reads, interprets and caches the Catalog File</summary>
|
||||
Errno ReadCatalog()
|
||||
{
|
||||
if(!mounted) return Errno.AccessDenied;
|
||||
if(!mounted)
|
||||
return Errno.AccessDenied;
|
||||
|
||||
catalogCache = new List<CatalogEntry>();
|
||||
|
||||
// Do differently for V1 and V2
|
||||
if(mddf.fsversion == LISA_V2 || mddf.fsversion == LISA_V1)
|
||||
if(mddf.fsversion == LISA_V2 ||
|
||||
mddf.fsversion == LISA_V1)
|
||||
{
|
||||
Errno error = ReadFile((short)FILEID_CATALOG, out byte[] buf);
|
||||
if(error != Errno.NoError) return error;
|
||||
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
int offset = 0;
|
||||
List<CatalogEntryV2> catalogV2 = new List<CatalogEntryV2>();
|
||||
@@ -121,23 +123,25 @@ namespace Aaru.Filesystems.LisaFS
|
||||
// For each entry on the catalog
|
||||
while(offset + 54 < buf.Length)
|
||||
{
|
||||
CatalogEntryV2 entV2 = new CatalogEntryV2
|
||||
var entV2 = new CatalogEntryV2
|
||||
{
|
||||
filenameLen = buf[offset],
|
||||
filename = new byte[E_NAME],
|
||||
unknown1 = buf[offset + 0x21],
|
||||
fileType = buf[offset + 0x22],
|
||||
unknown2 = buf[offset + 0x23],
|
||||
fileID = BigEndianBitConverter.ToInt16(buf, offset + 0x24),
|
||||
filenameLen = buf[offset], filename = new byte[E_NAME], unknown1 = buf[offset + 0x21],
|
||||
fileType = buf[offset + 0x22],
|
||||
unknown2 = buf[offset + 0x23],
|
||||
fileID = BigEndianBitConverter.ToInt16(buf, offset + 0x24),
|
||||
unknown3 = new byte[16]
|
||||
};
|
||||
|
||||
Array.Copy(buf, offset + 0x01, entV2.filename, 0, E_NAME);
|
||||
Array.Copy(buf, offset + 0x26, entV2.unknown3, 0, 16);
|
||||
|
||||
offset += 54;
|
||||
|
||||
// Check that the entry is correct, not empty or garbage
|
||||
if(entV2.filenameLen != 0 && entV2.filenameLen <= E_NAME && entV2.fileType != 0 && entV2.fileID > 0)
|
||||
if(entV2.filenameLen != 0 &&
|
||||
entV2.filenameLen <= E_NAME &&
|
||||
entV2.fileType != 0 &&
|
||||
entV2.fileID > 0)
|
||||
catalogV2.Add(entV2);
|
||||
}
|
||||
|
||||
@@ -145,17 +149,16 @@ namespace Aaru.Filesystems.LisaFS
|
||||
foreach(CatalogEntryV2 entV2 in catalogV2)
|
||||
{
|
||||
error = ReadExtentsFile(entV2.fileID, out ExtentFile ext);
|
||||
if(error != Errno.NoError) continue;
|
||||
|
||||
CatalogEntry entV3 = new CatalogEntry
|
||||
if(error != Errno.NoError)
|
||||
continue;
|
||||
|
||||
var entV3 = new CatalogEntry
|
||||
{
|
||||
fileID = entV2.fileID,
|
||||
filename = new byte[32],
|
||||
fileType = entV2.fileType,
|
||||
length = (int)srecords[entV2.fileID].filesize,
|
||||
dtc = ext.dtc,
|
||||
dtm = ext.dtm
|
||||
fileID = entV2.fileID, filename = new byte[32], fileType = entV2.fileType,
|
||||
length = (int)srecords[entV2.fileID].filesize, dtc = ext.dtc, dtm = ext.dtm
|
||||
};
|
||||
|
||||
Array.Copy(entV2.filename, 0, entV3.filename, 0, entV2.filenameLen);
|
||||
|
||||
catalogCache.Add(entV3);
|
||||
@@ -173,14 +176,18 @@ namespace Aaru.Filesystems.LisaFS
|
||||
{
|
||||
DecodeTag(device.ReadSectorTag(i, SectorTagType.AppleSectorTag), out LisaTag.PriamTag catTag);
|
||||
|
||||
if(catTag.FileId != FILEID_CATALOG || catTag.RelPage != 0) continue;
|
||||
if(catTag.FileId != FILEID_CATALOG ||
|
||||
catTag.RelPage != 0)
|
||||
continue;
|
||||
|
||||
firstCatalogBlock = device.ReadSectors(i, 4);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Catalog not found
|
||||
if(firstCatalogBlock == null) return Errno.NoSuchFile;
|
||||
if(firstCatalogBlock == null)
|
||||
return Errno.NoSuchFile;
|
||||
|
||||
ulong prevCatalogPointer;
|
||||
prevCatalogPointer = BigEndianBitConverter.ToUInt32(firstCatalogBlock, 0x7F6);
|
||||
@@ -191,7 +198,8 @@ namespace Aaru.Filesystems.LisaFS
|
||||
DecodeTag(device.ReadSectorTag(prevCatalogPointer + mddf.mddf_block + volumePrefix, SectorTagType.AppleSectorTag),
|
||||
out LisaTag.PriamTag prevTag);
|
||||
|
||||
if(prevTag.FileId != FILEID_CATALOG) return Errno.InvalidArgument;
|
||||
if(prevTag.FileId != FILEID_CATALOG)
|
||||
return Errno.InvalidArgument;
|
||||
|
||||
firstCatalogBlock = device.ReadSectors(prevCatalogPointer + mddf.mddf_block + volumePrefix, 4);
|
||||
prevCatalogPointer = BigEndianBitConverter.ToUInt32(firstCatalogBlock, 0x7F6);
|
||||
@@ -200,7 +208,10 @@ namespace Aaru.Filesystems.LisaFS
|
||||
ulong nextCatalogPointer;
|
||||
nextCatalogPointer = BigEndianBitConverter.ToUInt32(firstCatalogBlock, 0x7FA);
|
||||
|
||||
List<byte[]> catalogBlocks = new List<byte[]> {firstCatalogBlock};
|
||||
List<byte[]> catalogBlocks = new List<byte[]>
|
||||
{
|
||||
firstCatalogBlock
|
||||
};
|
||||
|
||||
// Traverse double-linked list to read full catalog
|
||||
while(nextCatalogPointer != 0xFFFFFFFF)
|
||||
@@ -208,7 +219,8 @@ namespace Aaru.Filesystems.LisaFS
|
||||
DecodeTag(device.ReadSectorTag(nextCatalogPointer + mddf.mddf_block + volumePrefix, SectorTagType.AppleSectorTag),
|
||||
out LisaTag.PriamTag nextTag);
|
||||
|
||||
if(nextTag.FileId != FILEID_CATALOG) return Errno.InvalidArgument;
|
||||
if(nextTag.FileId != FILEID_CATALOG)
|
||||
return Errno.InvalidArgument;
|
||||
|
||||
byte[] nextCatalogBlock = device.ReadSectors(nextCatalogPointer + mddf.mddf_block + volumePrefix, 4);
|
||||
nextCatalogPointer = BigEndianBitConverter.ToUInt32(nextCatalogBlock, 0x7FA);
|
||||
@@ -222,33 +234,46 @@ namespace Aaru.Filesystems.LisaFS
|
||||
|
||||
// Traverse all entries
|
||||
while(offset + 64 <= buf.Length)
|
||||
|
||||
// Catalog block header
|
||||
if(buf[offset + 0x24] == 0x08)
|
||||
offset += 78;
|
||||
|
||||
// Maybe just garbage? Found in more than 1 disk
|
||||
else if(buf[offset + 0x24] == 0x7C) offset += 50;
|
||||
else if(buf[offset + 0x24] == 0x7C)
|
||||
offset += 50;
|
||||
|
||||
// Apparently reserved to indicate end of catalog?
|
||||
else if(buf[offset + 0x24] == 0xFF) break;
|
||||
else if(buf[offset + 0x24] == 0xFF)
|
||||
break;
|
||||
|
||||
// Normal entry
|
||||
else if(buf[offset + 0x24] == 0x03 && buf[offset] == 0x24)
|
||||
else if(buf[offset + 0x24] == 0x03 &&
|
||||
buf[offset] == 0x24)
|
||||
{
|
||||
CatalogEntry entry = new CatalogEntry
|
||||
var entry = new CatalogEntry
|
||||
{
|
||||
marker = buf[offset],
|
||||
parentID = BigEndianBitConverter.ToUInt16(buf, offset + 0x01),
|
||||
filename = new byte[E_NAME],
|
||||
terminator = buf[offset + 0x23],
|
||||
fileType = buf[offset + 0x24],
|
||||
unknown = buf[offset + 0x25],
|
||||
fileID = BigEndianBitConverter.ToInt16(buf, offset + 0x26),
|
||||
dtc = BigEndianBitConverter.ToUInt32(buf, offset + 0x28),
|
||||
dtm = BigEndianBitConverter.ToUInt32(buf, offset + 0x2C),
|
||||
length = BigEndianBitConverter.ToInt32(buf, offset + 0x30),
|
||||
wasted = BigEndianBitConverter.ToInt32(buf, offset + 0x34),
|
||||
tail = new byte[8]
|
||||
terminator = buf[offset + 0x23],
|
||||
fileType = buf[offset + 0x24],
|
||||
unknown =
|
||||
buf[offset + 0x25],
|
||||
fileID = BigEndianBitConverter.ToInt16(buf, offset + 0x26),
|
||||
dtc =
|
||||
BigEndianBitConverter.ToUInt32(buf, offset + 0x28),
|
||||
dtm =
|
||||
BigEndianBitConverter.ToUInt32(buf, offset + 0x2C),
|
||||
length =
|
||||
BigEndianBitConverter.ToInt32(buf, offset + 0x30),
|
||||
wasted =
|
||||
BigEndianBitConverter.ToInt32(buf, offset + 0x34),
|
||||
tail = new byte[8]
|
||||
};
|
||||
|
||||
Array.Copy(buf, offset + 0x03, entry.filename, 0, E_NAME);
|
||||
Array.Copy(buf, offset + 0x38, entry.tail, 0, 8);
|
||||
Array.Copy(buf, offset + 0x38, entry.tail, 0, 8);
|
||||
|
||||
if(ReadExtentsFile(entry.fileID, out _) == Errno.NoError)
|
||||
if(!fileSizeCache.ContainsKey(entry.fileID))
|
||||
@@ -259,24 +284,29 @@ namespace Aaru.Filesystems.LisaFS
|
||||
|
||||
offset += 64;
|
||||
}
|
||||
|
||||
// Subdirectory entry
|
||||
else if(buf[offset + 0x24] == 0x01 && buf[offset] == 0x24)
|
||||
else if(buf[offset + 0x24] == 0x01 &&
|
||||
buf[offset] == 0x24)
|
||||
{
|
||||
CatalogEntry entry = new CatalogEntry
|
||||
var entry = new CatalogEntry
|
||||
{
|
||||
marker = buf[offset],
|
||||
parentID = BigEndianBitConverter.ToUInt16(buf, offset + 0x01),
|
||||
filename = new byte[E_NAME],
|
||||
terminator = buf[offset + 0x23],
|
||||
fileType = buf[offset + 0x24],
|
||||
unknown = buf[offset + 0x25],
|
||||
fileID = BigEndianBitConverter.ToInt16(buf, offset + 0x26),
|
||||
dtc = BigEndianBitConverter.ToUInt32(buf, offset + 0x28),
|
||||
dtm = BigEndianBitConverter.ToUInt32(buf, offset + 0x2C),
|
||||
length = 0,
|
||||
wasted = 0,
|
||||
tail = null
|
||||
terminator = buf[offset + 0x23],
|
||||
fileType = buf[offset + 0x24],
|
||||
unknown =
|
||||
buf[offset + 0x25],
|
||||
fileID = BigEndianBitConverter.ToInt16(buf, offset + 0x26),
|
||||
dtc =
|
||||
BigEndianBitConverter.ToUInt32(buf, offset + 0x28),
|
||||
dtm =
|
||||
BigEndianBitConverter.ToUInt32(buf, offset + 0x2C),
|
||||
length = 0, wasted = 0,
|
||||
tail = null
|
||||
};
|
||||
|
||||
Array.Copy(buf, offset + 0x03, entry.filename, 0, E_NAME);
|
||||
|
||||
if(!directoryDtcCache.ContainsKey(entry.fileID))
|
||||
@@ -286,7 +316,8 @@ namespace Aaru.Filesystems.LisaFS
|
||||
|
||||
offset += 48;
|
||||
}
|
||||
else break;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return Errno.NoError;
|
||||
@@ -296,20 +327,14 @@ namespace Aaru.Filesystems.LisaFS
|
||||
{
|
||||
stat = null;
|
||||
|
||||
if(!mounted) return Errno.AccessDenied;
|
||||
if(!mounted)
|
||||
return Errno.AccessDenied;
|
||||
|
||||
stat = new FileEntryInfo
|
||||
{
|
||||
Attributes = new FileAttributes(),
|
||||
Inode = FILEID_CATALOG,
|
||||
Mode = 0x16D,
|
||||
Links = 0,
|
||||
UID = 0,
|
||||
GID = 0,
|
||||
DeviceNo = 0,
|
||||
Length = 0,
|
||||
BlockSize = mddf.datasize,
|
||||
Blocks = 0
|
||||
Attributes = new FileAttributes(), Inode = FILEID_CATALOG, Mode = 0x16D, Links = 0,
|
||||
UID = 0, GID = 0, DeviceNo = 0, Length = 0,
|
||||
BlockSize = mddf.datasize, Blocks = 0
|
||||
};
|
||||
|
||||
directoryDtcCache.TryGetValue(dirId, out DateTime tmp);
|
||||
|
||||
@@ -43,13 +43,12 @@ namespace Aaru.Filesystems.LisaFS
|
||||
public Errno MapBlock(string path, long fileBlock, out long deviceBlock)
|
||||
{
|
||||
deviceBlock = 0;
|
||||
|
||||
// TODO: Not really important.
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Searches the disk for an extents file (or gets it from cache)
|
||||
/// </summary>
|
||||
/// <summary>Searches the disk for an extents file (or gets it from cache)</summary>
|
||||
/// <returns>Error.</returns>
|
||||
/// <param name="fileId">File identifier.</param>
|
||||
/// <param name="file">Extents file.</param>
|
||||
@@ -57,20 +56,26 @@ namespace Aaru.Filesystems.LisaFS
|
||||
{
|
||||
file = new ExtentFile();
|
||||
|
||||
if(!mounted) return Errno.AccessDenied;
|
||||
if(!mounted)
|
||||
return Errno.AccessDenied;
|
||||
|
||||
if(fileId < 4 || fileId == 4 && mddf.fsversion != LISA_V2 && mddf.fsversion != LISA_V1)
|
||||
if(fileId < 4 ||
|
||||
(fileId == 4 && mddf.fsversion != LISA_V2 && mddf.fsversion != LISA_V1))
|
||||
return Errno.InvalidArgument;
|
||||
|
||||
if(extentCache.TryGetValue(fileId, out file)) return Errno.NoError;
|
||||
if(extentCache.TryGetValue(fileId, out file))
|
||||
return Errno.NoError;
|
||||
|
||||
// A file ID that cannot be stored in the S-Records File
|
||||
if(fileId >= srecords.Length) return Errno.InvalidArgument;
|
||||
if(fileId >= srecords.Length)
|
||||
return Errno.InvalidArgument;
|
||||
|
||||
ulong ptr = srecords[fileId].extent_ptr;
|
||||
|
||||
// An invalid pointer denotes file does not exist
|
||||
if(ptr == 0xFFFFFFFF || ptr == 0x00000000) return Errno.NoSuchFile;
|
||||
if(ptr == 0xFFFFFFFF ||
|
||||
ptr == 0x00000000)
|
||||
return Errno.NoSuchFile;
|
||||
|
||||
// Pointers are relative to MDDF
|
||||
ptr += mddf.mddf_block + volumePrefix;
|
||||
@@ -87,24 +92,31 @@ namespace Aaru.Filesystems.LisaFS
|
||||
for(ulong i = 0; i < device.Info.Sectors; i++)
|
||||
{
|
||||
DecodeTag(device.ReadSectorTag(i, SectorTagType.AppleSectorTag), out extTag);
|
||||
if(extTag.FileId != fileId * -1) continue;
|
||||
|
||||
if(extTag.FileId != fileId * -1)
|
||||
continue;
|
||||
|
||||
ptr = i;
|
||||
found = true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if(!found) return Errno.InvalidArgument;
|
||||
if(!found)
|
||||
return Errno.InvalidArgument;
|
||||
}
|
||||
|
||||
// Checks that the sector tag indicates its the Extents File we are searching for
|
||||
DecodeTag(device.ReadSectorTag(ptr, SectorTagType.AppleSectorTag), out extTag);
|
||||
|
||||
if(extTag.FileId != (short)(-1 * fileId)) return Errno.NoSuchFile;
|
||||
if(extTag.FileId != (short)(-1 * fileId))
|
||||
return Errno.NoSuchFile;
|
||||
|
||||
byte[] sector = mddf.fsversion == LISA_V1 ? device.ReadSectors(ptr, 2) : device.ReadSector(ptr);
|
||||
|
||||
if(sector[0] >= 32 || sector[0] == 0) return Errno.InvalidArgument;
|
||||
if(sector[0] >= 32 ||
|
||||
sector[0] == 0)
|
||||
return Errno.InvalidArgument;
|
||||
|
||||
file.filenameLen = sector[0];
|
||||
file.filename = new byte[file.filenameLen];
|
||||
@@ -165,7 +177,8 @@ namespace Aaru.Filesystems.LisaFS
|
||||
|
||||
for(int j = 0; j < 41; j++)
|
||||
{
|
||||
if(BigEndianBitConverter.ToInt16(sector, extentsOffset + j * 6 + 4) == 0) break;
|
||||
if(BigEndianBitConverter.ToInt16(sector, extentsOffset + (j * 6) + 4) == 0)
|
||||
break;
|
||||
|
||||
extentsCount++;
|
||||
}
|
||||
@@ -175,77 +188,87 @@ namespace Aaru.Filesystems.LisaFS
|
||||
for(int j = 0; j < extentsCount; j++)
|
||||
file.extents[j] = new Extent
|
||||
{
|
||||
start = BigEndianBitConverter.ToInt32(sector, extentsOffset + j * 6),
|
||||
length = BigEndianBitConverter.ToInt16(sector, extentsOffset + j * 6 + 4)
|
||||
start = BigEndianBitConverter.ToInt32(sector, extentsOffset + (j * 6)),
|
||||
length = BigEndianBitConverter.ToInt16(sector, extentsOffset + (j * 6) + 4)
|
||||
};
|
||||
|
||||
extentCache.Add(fileId, file);
|
||||
|
||||
if(!debug) return Errno.NoError;
|
||||
if(!debug)
|
||||
return Errno.NoError;
|
||||
|
||||
if(printedExtents.Contains(fileId)) return Errno.NoError;
|
||||
if(printedExtents.Contains(fileId))
|
||||
return Errno.NoError;
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].filenameLen = {1}", fileId, file.filenameLen);
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].filename = {1}", fileId,
|
||||
StringHandlers.CToString(file.filename, Encoding));
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown1 = 0x{1:X4}", fileId, file.unknown1);
|
||||
StringHandlers.CToString(file.filename, Encoding));
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown1 = 0x{1:X4}", fileId, file.unknown1);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].file_uid = 0x{1:X16}", fileId, file.file_uid);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown2 = 0x{1:X2}", fileId, file.unknown2);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].etype = 0x{1:X2}", fileId, file.etype);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].ftype = {1}", fileId, file.ftype);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown3 = 0x{1:X2}", fileId, file.unknown3);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dtc = {1}", fileId, file.dtc);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dta = {1}", fileId, file.dta);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dtm = {1}", fileId, file.dtm);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dtb = {1}", fileId, file.dtb);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dts = {1}", fileId, file.dts);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].serial = {1}", fileId, file.serial);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown4 = 0x{1:X2}", fileId, file.unknown4);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].locked = {1}", fileId,
|
||||
file.locked > 0);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].protect = {1}", fileId,
|
||||
file.protect > 0);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].master = {1}", fileId,
|
||||
file.master > 0);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].scavenged = {1}", fileId,
|
||||
file.scavenged > 0);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].closed = {1}", fileId,
|
||||
file.closed > 0);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].open = {1}", fileId,
|
||||
file.open > 0);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown2 = 0x{1:X2}", fileId, file.unknown2);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].etype = 0x{1:X2}", fileId, file.etype);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].ftype = {1}", fileId, file.ftype);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown3 = 0x{1:X2}", fileId, file.unknown3);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dtc = {1}", fileId, file.dtc);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dta = {1}", fileId, file.dta);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dtm = {1}", fileId, file.dtm);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dtb = {1}", fileId, file.dtb);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dts = {1}", fileId, file.dts);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].serial = {1}", fileId, file.serial);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown4 = 0x{1:X2}", fileId, file.unknown4);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].locked = {1}", fileId, file.locked > 0);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].protect = {1}", fileId, file.protect > 0);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].master = {1}", fileId, file.master > 0);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].scavenged = {1}", fileId, file.scavenged > 0);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].closed = {1}", fileId, file.closed > 0);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].open = {1}", fileId, file.open > 0);
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin",
|
||||
"ExtentFile[{0}].unknown5 = 0x{1:X2}{2:X2}{3:X2}{4:X2}{5:X2}{6:X2}{7:X2}{8:X2}{9:X2}" +
|
||||
"{10:X2}{11:X2}", fileId, file.unknown5[0], file.unknown5[1], file.unknown5[2],
|
||||
file.unknown5[3], file.unknown5[4], file.unknown5[5], file.unknown5[6],
|
||||
file.unknown5[7], file.unknown5[8], file.unknown5[9], file.unknown5[10]);
|
||||
"ExtentFile[{0}].unknown5 = 0x{1:X2}{2:X2}{3:X2}{4:X2}{5:X2}{6:X2}{7:X2}{8:X2}{9:X2}" +
|
||||
"{10:X2}{11:X2}", fileId, file.unknown5[0], file.unknown5[1], file.unknown5[2],
|
||||
file.unknown5[3], file.unknown5[4], file.unknown5[5], file.unknown5[6],
|
||||
file.unknown5[7], file.unknown5[8], file.unknown5[9], file.unknown5[10]);
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].release = {1}", fileId, file.release);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].build = {1}", fileId, file.build);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].build = {1}", fileId, file.build);
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].compatibility = {1}", fileId,
|
||||
file.compatibility);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].revision = {1}", fileId, file.revision);
|
||||
file.compatibility);
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].revision = {1}", fileId, file.revision);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown6 = 0x{1:X4}", fileId, file.unknown6);
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].password_valid = {1}", fileId,
|
||||
file.password_valid > 0);
|
||||
file.password_valid > 0);
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].password = {1}", fileId,
|
||||
Encoding.GetString(file.password));
|
||||
Encoding.GetString(file.password));
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown7 = 0x{1:X2}{2:X2}{3:X2}", fileId,
|
||||
file.unknown7[0], file.unknown7[1], file.unknown7[2]);
|
||||
file.unknown7[0], file.unknown7[1], file.unknown7[2]);
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].overhead = {1}", fileId, file.overhead);
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin",
|
||||
"ExtentFile[{0}].unknown8 = 0x{1:X2}{2:X2}{3:X2}{4:X2}{5:X2}{6:X2}{7:X2}{8:X2}{9:X2}" +
|
||||
"{10:X2}{11:X2}{12:X2}{13:X2}{14:X2}{15:X2}{16:X2}", fileId, file.unknown8[0],
|
||||
file.unknown8[1], file.unknown8[2], file.unknown8[3], file.unknown8[4],
|
||||
file.unknown8[5], file.unknown8[6], file.unknown8[7], file.unknown8[8],
|
||||
file.unknown8[9], file.unknown8[10], file.unknown8[11], file.unknown8[12],
|
||||
file.unknown8[13], file.unknown8[14], file.unknown8[15]);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].length = {1}", fileId, file.length);
|
||||
"ExtentFile[{0}].unknown8 = 0x{1:X2}{2:X2}{3:X2}{4:X2}{5:X2}{6:X2}{7:X2}{8:X2}{9:X2}" +
|
||||
"{10:X2}{11:X2}{12:X2}{13:X2}{14:X2}{15:X2}{16:X2}", fileId, file.unknown8[0],
|
||||
file.unknown8[1], file.unknown8[2], file.unknown8[3], file.unknown8[4],
|
||||
file.unknown8[5], file.unknown8[6], file.unknown8[7], file.unknown8[8],
|
||||
file.unknown8[9], file.unknown8[10], file.unknown8[11], file.unknown8[12],
|
||||
file.unknown8[13], file.unknown8[14], file.unknown8[15]);
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].length = {1}", fileId, file.length);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown9 = 0x{1:X8}", fileId, file.unknown9);
|
||||
|
||||
for(int ext = 0; ext < file.extents.Length; ext++)
|
||||
{
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].extents[{1}].start = {2}", fileId, ext,
|
||||
file.extents[ext].start);
|
||||
file.extents[ext].start);
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].extents[{1}].length = {2}", fileId, ext,
|
||||
file.extents[ext].length);
|
||||
file.extents[ext].length);
|
||||
}
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown10 = 0x{1:X4}", fileId, file.unknown10);
|
||||
@@ -255,12 +278,11 @@ namespace Aaru.Filesystems.LisaFS
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads all the S-Records and caches it
|
||||
/// </summary>
|
||||
/// <summary>Reads all the S-Records and caches it</summary>
|
||||
Errno ReadSRecords()
|
||||
{
|
||||
if(!mounted) return Errno.AccessDenied;
|
||||
if(!mounted)
|
||||
return Errno.AccessDenied;
|
||||
|
||||
// Searches the S-Records place using MDDF pointers
|
||||
byte[] sectors = device.ReadSectors(mddf.srec_ptr + mddf.mddf_block + volumePrefix, mddf.srec_len);
|
||||
@@ -271,10 +293,10 @@ namespace Aaru.Filesystems.LisaFS
|
||||
for(int s = 0; s < srecords.Length; s++)
|
||||
srecords[s] = new SRecord
|
||||
{
|
||||
extent_ptr = BigEndianBitConverter.ToUInt32(sectors, 0x00 + 14 * s),
|
||||
unknown = BigEndianBitConverter.ToUInt32(sectors, 0x04 + 14 * s),
|
||||
filesize = BigEndianBitConverter.ToUInt32(sectors, 0x08 + 14 * s),
|
||||
flags = BigEndianBitConverter.ToUInt16(sectors, 0x0C + 14 * s)
|
||||
extent_ptr = BigEndianBitConverter.ToUInt32(sectors, 0x00 + (14 * s)),
|
||||
unknown = BigEndianBitConverter.ToUInt32(sectors, 0x04 + (14 * s)),
|
||||
filesize = BigEndianBitConverter.ToUInt32(sectors, 0x08 + (14 * s)),
|
||||
flags = BigEndianBitConverter.ToUInt16(sectors, 0x0C + (14 * s))
|
||||
};
|
||||
|
||||
return Errno.NoError;
|
||||
|
||||
@@ -45,9 +45,12 @@ namespace Aaru.Filesystems.LisaFS
|
||||
attributes = new FileAttributes();
|
||||
|
||||
Errno error = LookupFileId(path, out short fileId, out bool isDir);
|
||||
if(error != Errno.NoError) return error;
|
||||
|
||||
if(!isDir) return GetAttributes(fileId, out attributes);
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
if(!isDir)
|
||||
return GetAttributes(fileId, out attributes);
|
||||
|
||||
attributes = FileAttributes.Directory;
|
||||
|
||||
@@ -59,15 +62,20 @@ namespace Aaru.Filesystems.LisaFS
|
||||
if(size == 0)
|
||||
{
|
||||
buf = new byte[0];
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
if(offset < 0) return Errno.InvalidArgument;
|
||||
if(offset < 0)
|
||||
return Errno.InvalidArgument;
|
||||
|
||||
Errno error = LookupFileId(path, out short fileId, out _);
|
||||
if(error != Errno.NoError) return error;
|
||||
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
byte[] tmp;
|
||||
|
||||
if(debug)
|
||||
switch(fileId)
|
||||
{
|
||||
@@ -78,21 +86,28 @@ namespace Aaru.Filesystems.LisaFS
|
||||
case (short)FILEID_SRECORD:
|
||||
case (short)FILEID_CATALOG:
|
||||
error = ReadSystemFile(fileId, out tmp);
|
||||
|
||||
break;
|
||||
default:
|
||||
error = ReadFile(fileId, out tmp);
|
||||
|
||||
break;
|
||||
}
|
||||
else error = ReadFile(fileId, out tmp);
|
||||
else
|
||||
error = ReadFile(fileId, out tmp);
|
||||
|
||||
if(error != Errno.NoError) return error;
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
if(offset >= tmp.Length) return Errno.EINVAL;
|
||||
if(offset >= tmp.Length)
|
||||
return Errno.EINVAL;
|
||||
|
||||
if(size + offset >= tmp.Length) size = tmp.Length - offset;
|
||||
if(size + offset >= tmp.Length)
|
||||
size = tmp.Length - offset;
|
||||
|
||||
buf = new byte[size];
|
||||
Array.Copy(tmp, offset, buf, 0, size);
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
@@ -100,7 +115,9 @@ namespace Aaru.Filesystems.LisaFS
|
||||
{
|
||||
stat = null;
|
||||
Errno error = LookupFileId(path, out short fileId, out bool isDir);
|
||||
if(error != Errno.NoError) return error;
|
||||
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
return isDir ? StatDir(fileId, out stat) : Stat(fileId, out stat);
|
||||
}
|
||||
@@ -108,11 +125,14 @@ namespace Aaru.Filesystems.LisaFS
|
||||
Errno GetAttributes(short fileId, out FileAttributes attributes)
|
||||
{
|
||||
attributes = new FileAttributes();
|
||||
if(!mounted) return Errno.AccessDenied;
|
||||
|
||||
if(!mounted)
|
||||
return Errno.AccessDenied;
|
||||
|
||||
if(fileId < 4)
|
||||
{
|
||||
if(!debug) return Errno.NoSuchFile;
|
||||
if(!debug)
|
||||
return Errno.NoSuchFile;
|
||||
|
||||
attributes = new FileAttributes();
|
||||
attributes = FileAttributes.System;
|
||||
@@ -125,30 +145,40 @@ namespace Aaru.Filesystems.LisaFS
|
||||
|
||||
Errno error = ReadExtentsFile(fileId, out ExtentFile extFile);
|
||||
|
||||
if(error != Errno.NoError) return error;
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
switch(extFile.ftype)
|
||||
{
|
||||
case FileType.Spool:
|
||||
attributes |= FileAttributes.CharDevice;
|
||||
|
||||
break;
|
||||
case FileType.UserCat:
|
||||
case FileType.RootCat:
|
||||
attributes |= FileAttributes.Directory;
|
||||
|
||||
break;
|
||||
case FileType.Pipe:
|
||||
attributes |= FileAttributes.Pipe;
|
||||
|
||||
break;
|
||||
case FileType.Undefined: break;
|
||||
default:
|
||||
attributes |= FileAttributes.File;
|
||||
attributes |= FileAttributes.Extents;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if(extFile.protect > 0) attributes |= FileAttributes.Immutable;
|
||||
if(extFile.locked > 0) attributes |= FileAttributes.ReadOnly;
|
||||
if(extFile.password_valid > 0) attributes |= FileAttributes.Password;
|
||||
if(extFile.protect > 0)
|
||||
attributes |= FileAttributes.Immutable;
|
||||
|
||||
if(extFile.locked > 0)
|
||||
attributes |= FileAttributes.ReadOnly;
|
||||
|
||||
if(extFile.password_valid > 0)
|
||||
attributes |= FileAttributes.Password;
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
@@ -158,13 +188,20 @@ namespace Aaru.Filesystems.LisaFS
|
||||
Errno ReadSystemFile(short fileId, out byte[] buf, bool tags)
|
||||
{
|
||||
buf = null;
|
||||
if(!mounted || !debug) return Errno.AccessDenied;
|
||||
|
||||
if(fileId > 4 || fileId <= 0)
|
||||
if(fileId != FILEID_BOOT_SIGNED && fileId != FILEID_LOADER_SIGNED)
|
||||
if(!mounted ||
|
||||
!debug)
|
||||
return Errno.AccessDenied;
|
||||
|
||||
if(fileId > 4 ||
|
||||
fileId <= 0)
|
||||
if(fileId != FILEID_BOOT_SIGNED &&
|
||||
fileId != FILEID_LOADER_SIGNED)
|
||||
return Errno.InvalidArgument;
|
||||
|
||||
if(systemFileCache.TryGetValue(fileId, out buf) && !tags) return Errno.NoError;
|
||||
if(systemFileCache.TryGetValue(fileId, out buf) &&
|
||||
!tags)
|
||||
return Errno.NoError;
|
||||
|
||||
int count = 0;
|
||||
|
||||
@@ -173,12 +210,14 @@ namespace Aaru.Filesystems.LisaFS
|
||||
{
|
||||
buf = device.ReadSectors(mddf.mddf_block + volumePrefix + mddf.srec_ptr, mddf.srec_len);
|
||||
systemFileCache.Add(fileId, buf);
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
else
|
||||
{
|
||||
buf = device.ReadSectorsTag(mddf.mddf_block + volumePrefix + mddf.srec_ptr, mddf.srec_len,
|
||||
SectorTagType.AppleSectorTag);
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
@@ -189,10 +228,12 @@ namespace Aaru.Filesystems.LisaFS
|
||||
{
|
||||
DecodeTag(device.ReadSectorTag(i, SectorTagType.AppleSectorTag), out sysTag);
|
||||
|
||||
if(sysTag.FileId == fileId) count++;
|
||||
if(sysTag.FileId == fileId)
|
||||
count++;
|
||||
}
|
||||
|
||||
if(count == 0) return Errno.NoSuchFile;
|
||||
if(count == 0)
|
||||
return Errno.NoSuchFile;
|
||||
|
||||
buf = !tags ? new byte[count * device.Info.SectorSize] : new byte[count * devTagSize];
|
||||
|
||||
@@ -201,17 +242,20 @@ namespace Aaru.Filesystems.LisaFS
|
||||
{
|
||||
DecodeTag(device.ReadSectorTag(i, SectorTagType.AppleSectorTag), out sysTag);
|
||||
|
||||
if(sysTag.FileId != fileId) continue;
|
||||
if(sysTag.FileId != fileId)
|
||||
continue;
|
||||
|
||||
byte[] sector = !tags ? device.ReadSector(i) : device.ReadSectorTag(i, SectorTagType.AppleSectorTag);
|
||||
|
||||
// Relative block for $Loader starts at $Boot block
|
||||
if(sysTag.FileId == FILEID_LOADER_SIGNED) sysTag.RelPage--;
|
||||
if(sysTag.FileId == FILEID_LOADER_SIGNED)
|
||||
sysTag.RelPage--;
|
||||
|
||||
Array.Copy(sector, 0, buf, sector.Length * sysTag.RelPage, sector.Length);
|
||||
}
|
||||
|
||||
if(!tags) systemFileCache.Add(fileId, buf);
|
||||
if(!tags)
|
||||
systemFileCache.Add(fileId, buf);
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
@@ -220,24 +264,36 @@ namespace Aaru.Filesystems.LisaFS
|
||||
{
|
||||
stat = null;
|
||||
|
||||
if(!mounted) return Errno.AccessDenied;
|
||||
if(!mounted)
|
||||
return Errno.AccessDenied;
|
||||
|
||||
Errno error;
|
||||
ExtentFile file;
|
||||
|
||||
if(fileId <= 4)
|
||||
if(!debug || fileId == 0) return Errno.NoSuchFile;
|
||||
if(!debug ||
|
||||
fileId == 0)
|
||||
return Errno.NoSuchFile;
|
||||
else
|
||||
{
|
||||
stat = new FileEntryInfo {Attributes = new FileAttributes()};
|
||||
stat = new FileEntryInfo
|
||||
{
|
||||
Attributes = new FileAttributes()
|
||||
};
|
||||
|
||||
error = GetAttributes(fileId, out stat.Attributes);
|
||||
if(error != Errno.NoError) return error;
|
||||
|
||||
if(fileId < 0 && fileId != FILEID_BOOT_SIGNED && fileId != FILEID_LOADER_SIGNED)
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
if(fileId < 0 &&
|
||||
fileId != FILEID_BOOT_SIGNED &&
|
||||
fileId != FILEID_LOADER_SIGNED)
|
||||
{
|
||||
error = ReadExtentsFile((short)(fileId * -1), out file);
|
||||
if(error != Errno.NoError) return error;
|
||||
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
stat.CreationTime = DateHandlers.LisaToDateTime(file.dtc);
|
||||
stat.AccessTime = DateHandlers.LisaToDateTime(file.dta);
|
||||
@@ -253,7 +309,9 @@ namespace Aaru.Filesystems.LisaFS
|
||||
else
|
||||
{
|
||||
error = ReadSystemFile(fileId, out byte[] buf);
|
||||
if(error != Errno.NoError) return error;
|
||||
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
stat.CreationTime = fileId != 4 ? mddf.dtvc : mddf.dtcc;
|
||||
|
||||
@@ -269,12 +327,20 @@ namespace Aaru.Filesystems.LisaFS
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
stat = new FileEntryInfo {Attributes = new FileAttributes()};
|
||||
stat = new FileEntryInfo
|
||||
{
|
||||
Attributes = new FileAttributes()
|
||||
};
|
||||
|
||||
error = GetAttributes(fileId, out stat.Attributes);
|
||||
if(error != Errno.NoError) return error;
|
||||
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
error = ReadExtentsFile(fileId, out file);
|
||||
if(error != Errno.NoError) return error;
|
||||
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
stat.CreationTime = DateHandlers.LisaToDateTime(file.dtc);
|
||||
stat.AccessTime = DateHandlers.LisaToDateTime(file.dta);
|
||||
@@ -283,8 +349,12 @@ namespace Aaru.Filesystems.LisaFS
|
||||
|
||||
stat.Inode = (ulong)fileId;
|
||||
stat.Links = 1;
|
||||
if(!fileSizeCache.TryGetValue(fileId, out int len)) stat.Length = srecords[fileId].filesize;
|
||||
else stat.Length = len;
|
||||
|
||||
if(!fileSizeCache.TryGetValue(fileId, out int len))
|
||||
stat.Length = srecords[fileId].filesize;
|
||||
else
|
||||
stat.Length = len;
|
||||
|
||||
stat.BlockSize = mddf.datasize;
|
||||
stat.Blocks = file.length;
|
||||
|
||||
@@ -296,25 +366,36 @@ namespace Aaru.Filesystems.LisaFS
|
||||
Errno ReadFile(short fileId, out byte[] buf, bool tags)
|
||||
{
|
||||
buf = null;
|
||||
if(!mounted) return Errno.AccessDenied;
|
||||
|
||||
if(!mounted)
|
||||
return Errno.AccessDenied;
|
||||
|
||||
tags &= debug;
|
||||
|
||||
if(fileId < 4 || fileId == 4 && mddf.fsversion != LISA_V2 && mddf.fsversion != LISA_V1)
|
||||
if(fileId < 4 ||
|
||||
(fileId == 4 && mddf.fsversion != LISA_V2 && mddf.fsversion != LISA_V1))
|
||||
return Errno.InvalidArgument;
|
||||
|
||||
if(!tags && fileCache.TryGetValue(fileId, out buf)) return Errno.NoError;
|
||||
if(!tags &&
|
||||
fileCache.TryGetValue(fileId, out buf))
|
||||
return Errno.NoError;
|
||||
|
||||
Errno error = ReadExtentsFile(fileId, out ExtentFile file);
|
||||
if(error != Errno.NoError) return error;
|
||||
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
int sectorSize;
|
||||
if(tags) sectorSize = devTagSize;
|
||||
else sectorSize = (int)device.Info.SectorSize;
|
||||
|
||||
if(tags)
|
||||
sectorSize = devTagSize;
|
||||
else
|
||||
sectorSize = (int)device.Info.SectorSize;
|
||||
|
||||
byte[] temp = new byte[file.length * sectorSize];
|
||||
|
||||
int offset = 0;
|
||||
|
||||
for(int i = 0; i < file.extents.Length; i++)
|
||||
{
|
||||
byte[] sector;
|
||||
@@ -335,11 +416,13 @@ namespace Aaru.Filesystems.LisaFS
|
||||
if(fileSizeCache.TryGetValue(fileId, out int realSize))
|
||||
if(realSize > temp.Length)
|
||||
AaruConsole.ErrorWriteLine("File {0} gets truncated.", fileId);
|
||||
|
||||
buf = temp;
|
||||
|
||||
fileCache.Add(fileId, buf);
|
||||
}
|
||||
else buf = temp;
|
||||
else
|
||||
buf = temp;
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
@@ -349,49 +432,61 @@ namespace Aaru.Filesystems.LisaFS
|
||||
fileId = 0;
|
||||
isDir = false;
|
||||
|
||||
if(!mounted) return Errno.AccessDenied;
|
||||
if(!mounted)
|
||||
return Errno.AccessDenied;
|
||||
|
||||
string[] pathElements = path.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] pathElements = path.Split(new[]
|
||||
{
|
||||
'/'
|
||||
}, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if(pathElements.Length == 0)
|
||||
{
|
||||
fileId = DIRID_ROOT;
|
||||
isDir = true;
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
// Only V3 supports subdirectories
|
||||
if(pathElements.Length > 1 && mddf.fsversion != LISA_V3) return Errno.NotSupported;
|
||||
if(pathElements.Length > 1 &&
|
||||
mddf.fsversion != LISA_V3)
|
||||
return Errno.NotSupported;
|
||||
|
||||
if(debug && pathElements.Length == 1)
|
||||
{
|
||||
if(string.Compare(pathElements[0], "$MDDF", StringComparison.InvariantCulture) == 0)
|
||||
{
|
||||
fileId = (short)FILEID_MDDF;
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
if(string.Compare(pathElements[0], "$Boot", StringComparison.InvariantCulture) == 0)
|
||||
{
|
||||
fileId = FILEID_BOOT_SIGNED;
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
if(string.Compare(pathElements[0], "$Loader", StringComparison.InvariantCulture) == 0)
|
||||
{
|
||||
fileId = FILEID_LOADER_SIGNED;
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
if(string.Compare(pathElements[0], "$Bitmap", StringComparison.InvariantCulture) == 0)
|
||||
{
|
||||
fileId = (short)FILEID_BITMAP;
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
if(string.Compare(pathElements[0], "$S-Record", StringComparison.InvariantCulture) == 0)
|
||||
{
|
||||
fileId = (short)FILEID_SRECORD;
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
@@ -399,6 +494,7 @@ namespace Aaru.Filesystems.LisaFS
|
||||
{
|
||||
fileId = DIRID_ROOT;
|
||||
isDir = true;
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
}
|
||||
@@ -413,17 +509,20 @@ namespace Aaru.Filesystems.LisaFS
|
||||
|
||||
// LisaOS is case insensitive
|
||||
if(string.Compare(wantedFilename, filename, StringComparison.InvariantCultureIgnoreCase) != 0 ||
|
||||
entry.parentID !=
|
||||
fileId) continue;
|
||||
entry.parentID != fileId)
|
||||
continue;
|
||||
|
||||
fileId = entry.fileID;
|
||||
isDir = entry.fileType == 0x01;
|
||||
|
||||
// Not last path element, and it's not a directory
|
||||
if(lvl != pathElements.Length - 1 && !isDir) return Errno.NotDirectory;
|
||||
if(lvl != pathElements.Length - 1 &&
|
||||
!isDir)
|
||||
return Errno.NotDirectory;
|
||||
|
||||
// Arrived last path element
|
||||
if(lvl == pathElements.Length - 1) return Errno.NoError;
|
||||
if(lvl == pathElements.Length - 1)
|
||||
return Errno.NoError;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,12 +32,12 @@
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
using Claunia.Encoding;
|
||||
using Aaru.CommonTypes;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
using Aaru.CommonTypes.Interfaces;
|
||||
using Aaru.Console;
|
||||
using Aaru.Decoders;
|
||||
using Claunia.Encoding;
|
||||
using Schemas;
|
||||
using Encoding = System.Text.Encoding;
|
||||
|
||||
@@ -49,12 +49,15 @@ namespace Aaru.Filesystems.LisaFS
|
||||
{
|
||||
try
|
||||
{
|
||||
if(imagePlugin.Info.ReadableSectorTags == null) return false;
|
||||
if(imagePlugin.Info.ReadableSectorTags == null)
|
||||
return false;
|
||||
|
||||
if(!imagePlugin.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag)) return false;
|
||||
if(!imagePlugin.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag))
|
||||
return false;
|
||||
|
||||
// Minimal LisaOS disk is 3.5" single sided double density, 800 sectors
|
||||
if(imagePlugin.Info.Sectors < 800) return false;
|
||||
if(imagePlugin.Info.Sectors < 800)
|
||||
return false;
|
||||
|
||||
int beforeMddf = -1;
|
||||
|
||||
@@ -66,12 +69,16 @@ namespace Aaru.Filesystems.LisaFS
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "Sector {0}, file ID 0x{1:X4}", i, searchTag.FileId);
|
||||
|
||||
if(beforeMddf == -1 && searchTag.FileId == FILEID_LOADER_SIGNED) beforeMddf = i - 1;
|
||||
if(beforeMddf == -1 &&
|
||||
searchTag.FileId == FILEID_LOADER_SIGNED)
|
||||
beforeMddf = i - 1;
|
||||
|
||||
if(searchTag.FileId != FILEID_MDDF) continue;
|
||||
if(searchTag.FileId != FILEID_MDDF)
|
||||
continue;
|
||||
|
||||
byte[] sector = imagePlugin.ReadSector((ulong)i);
|
||||
MDDF infoMddf = new MDDF
|
||||
|
||||
var infoMddf = new MDDF
|
||||
{
|
||||
mddf_block = BigEndianBitConverter.ToUInt32(sector, 0x6C),
|
||||
volsize_minus_one = BigEndianBitConverter.ToUInt32(sector, 0x70),
|
||||
@@ -81,30 +88,36 @@ namespace Aaru.Filesystems.LisaFS
|
||||
datasize = BigEndianBitConverter.ToUInt16(sector, 0x7E)
|
||||
};
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "Current sector = {0}", i);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.mddf_block = {0}", infoMddf.mddf_block);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "Disk size = {0} sectors", imagePlugin.Info.Sectors);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "Current sector = {0}", i);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.mddf_block = {0}", infoMddf.mddf_block);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "Disk size = {0} sectors", imagePlugin.Info.Sectors);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.vol_size = {0} sectors", infoMddf.vol_size);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.vol_size - 1 = {0}",
|
||||
infoMddf.volsize_minus_one);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.vol_size - 1 = {0}", infoMddf.volsize_minus_one);
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.vol_size - mddf.mddf_block -1 = {0}",
|
||||
infoMddf.volsize_minus_mddf_minus_one);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "Disk sector = {0} bytes",
|
||||
imagePlugin.Info.SectorSize);
|
||||
infoMddf.volsize_minus_mddf_minus_one);
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "Disk sector = {0} bytes", imagePlugin.Info.SectorSize);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.blocksize = {0} bytes", infoMddf.blocksize);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.datasize = {0} bytes", infoMddf.datasize);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.datasize = {0} bytes", infoMddf.datasize);
|
||||
|
||||
if(infoMddf.mddf_block != i - beforeMddf) return false;
|
||||
if(infoMddf.mddf_block != i - beforeMddf)
|
||||
return false;
|
||||
|
||||
if(infoMddf.vol_size > imagePlugin.Info.Sectors) return false;
|
||||
if(infoMddf.vol_size > imagePlugin.Info.Sectors)
|
||||
return false;
|
||||
|
||||
if(infoMddf.vol_size - 1 != infoMddf.volsize_minus_one) return false;
|
||||
if(infoMddf.vol_size - 1 != infoMddf.volsize_minus_one)
|
||||
return false;
|
||||
|
||||
if(infoMddf.vol_size - i - 1 != infoMddf.volsize_minus_mddf_minus_one - beforeMddf) return false;
|
||||
if(infoMddf.vol_size - i - 1 != infoMddf.volsize_minus_mddf_minus_one - beforeMddf)
|
||||
return false;
|
||||
|
||||
if(infoMddf.datasize > infoMddf.blocksize) return false;
|
||||
if(infoMddf.datasize > infoMddf.blocksize)
|
||||
return false;
|
||||
|
||||
if(infoMddf.blocksize < imagePlugin.Info.SectorSize) return false;
|
||||
if(infoMddf.blocksize < imagePlugin.Info.SectorSize)
|
||||
return false;
|
||||
|
||||
return infoMddf.datasize == imagePlugin.Info.SectorSize;
|
||||
}
|
||||
@@ -114,25 +127,29 @@ namespace Aaru.Filesystems.LisaFS
|
||||
catch(Exception ex)
|
||||
{
|
||||
AaruConsole.ErrorWriteLine("Exception {0}, {1}, {2}", ex.Message, ex.InnerException, ex.StackTrace);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
|
||||
Encoding encoding)
|
||||
Encoding encoding)
|
||||
{
|
||||
Encoding = new LisaRoman();
|
||||
information = "";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var sb = new StringBuilder();
|
||||
|
||||
try
|
||||
{
|
||||
if(imagePlugin.Info.ReadableSectorTags == null) return;
|
||||
if(imagePlugin.Info.ReadableSectorTags == null)
|
||||
return;
|
||||
|
||||
if(!imagePlugin.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag)) return;
|
||||
if(!imagePlugin.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag))
|
||||
return;
|
||||
|
||||
// Minimal LisaOS disk is 3.5" single sided double density, 800 sectors
|
||||
if(imagePlugin.Info.Sectors < 800) return;
|
||||
if(imagePlugin.Info.Sectors < 800)
|
||||
return;
|
||||
|
||||
int beforeMddf = -1;
|
||||
|
||||
@@ -144,12 +161,15 @@ namespace Aaru.Filesystems.LisaFS
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "Sector {0}, file ID 0x{1:X4}", i, searchTag.FileId);
|
||||
|
||||
if(beforeMddf == -1 && searchTag.FileId == FILEID_LOADER_SIGNED) beforeMddf = i - 1;
|
||||
if(beforeMddf == -1 &&
|
||||
searchTag.FileId == FILEID_LOADER_SIGNED)
|
||||
beforeMddf = i - 1;
|
||||
|
||||
if(searchTag.FileId != FILEID_MDDF) continue;
|
||||
if(searchTag.FileId != FILEID_MDDF)
|
||||
continue;
|
||||
|
||||
byte[] sector = imagePlugin.ReadSector((ulong)i);
|
||||
MDDF infoMddf = new MDDF();
|
||||
var infoMddf = new MDDF();
|
||||
byte[] pString = new byte[33];
|
||||
|
||||
infoMddf.fsversion = BigEndianBitConverter.ToUInt16(sector, 0x00);
|
||||
@@ -159,6 +179,7 @@ namespace Aaru.Filesystems.LisaFS
|
||||
infoMddf.volname = StringHandlers.PascalToString(pString, Encoding);
|
||||
infoMddf.unknown1 = sector[0x2D];
|
||||
Array.Copy(sector, 0x2E, pString, 0, 33);
|
||||
|
||||
// Prevent garbage
|
||||
infoMddf.password = pString[0] <= 32 ? StringHandlers.PascalToString(pString, Encoding) : "";
|
||||
infoMddf.unknown2 = sector[0x4F];
|
||||
@@ -231,14 +252,14 @@ namespace Aaru.Filesystems.LisaFS
|
||||
infoMddf.vol_sequence = BigEndianBitConverter.ToUInt16(sector, 0x136);
|
||||
infoMddf.vol_left_mounted = sector[0x138];
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown1 = 0x{0:X2} ({0})", infoMddf.unknown1);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown2 = 0x{0:X2} ({0})", infoMddf.unknown2);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown3 = 0x{0:X8} ({0})", infoMddf.unknown3);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown4 = 0x{0:X4} ({0})", infoMddf.unknown4);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown5 = 0x{0:X8} ({0})", infoMddf.unknown5);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown6 = 0x{0:X8} ({0})", infoMddf.unknown6);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown7 = 0x{0:X8} ({0})", infoMddf.unknown7);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown9 = 0x{0:X4} ({0})", infoMddf.unknown9);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown1 = 0x{0:X2} ({0})", infoMddf.unknown1);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown2 = 0x{0:X2} ({0})", infoMddf.unknown2);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown3 = 0x{0:X8} ({0})", infoMddf.unknown3);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown4 = 0x{0:X4} ({0})", infoMddf.unknown4);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown5 = 0x{0:X8} ({0})", infoMddf.unknown5);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown6 = 0x{0:X8} ({0})", infoMddf.unknown6);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown7 = 0x{0:X8} ({0})", infoMddf.unknown7);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown9 = 0x{0:X4} ({0})", infoMddf.unknown9);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown10 = 0x{0:X8} ({0})", infoMddf.unknown10);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown11 = 0x{0:X8} ({0})", infoMddf.unknown11);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown12 = 0x{0:X8} ({0})", infoMddf.unknown12);
|
||||
@@ -268,37 +289,49 @@ namespace Aaru.Filesystems.LisaFS
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown36 = 0x{0:X8} ({0})", infoMddf.unknown36);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown37 = 0x{0:X8} ({0})", infoMddf.unknown37);
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown38 = 0x{0:X8} ({0})", infoMddf.unknown38);
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown_timestamp = 0x{0:X8} ({0}, {1})",
|
||||
infoMddf.unknown_timestamp,
|
||||
DateHandlers.LisaToDateTime(infoMddf.unknown_timestamp));
|
||||
infoMddf.unknown_timestamp,
|
||||
DateHandlers.LisaToDateTime(infoMddf.unknown_timestamp));
|
||||
|
||||
if(infoMddf.mddf_block != i - beforeMddf) return;
|
||||
if(infoMddf.mddf_block != i - beforeMddf)
|
||||
return;
|
||||
|
||||
if(infoMddf.vol_size > imagePlugin.Info.Sectors) return;
|
||||
if(infoMddf.vol_size > imagePlugin.Info.Sectors)
|
||||
return;
|
||||
|
||||
if(infoMddf.vol_size - 1 != infoMddf.volsize_minus_one) return;
|
||||
if(infoMddf.vol_size - 1 != infoMddf.volsize_minus_one)
|
||||
return;
|
||||
|
||||
if(infoMddf.vol_size - i - 1 != infoMddf.volsize_minus_mddf_minus_one - beforeMddf) return;
|
||||
if(infoMddf.vol_size - i - 1 != infoMddf.volsize_minus_mddf_minus_one - beforeMddf)
|
||||
return;
|
||||
|
||||
if(infoMddf.datasize > infoMddf.blocksize) return;
|
||||
if(infoMddf.datasize > infoMddf.blocksize)
|
||||
return;
|
||||
|
||||
if(infoMddf.blocksize < imagePlugin.Info.SectorSize) return;
|
||||
if(infoMddf.blocksize < imagePlugin.Info.SectorSize)
|
||||
return;
|
||||
|
||||
if(infoMddf.datasize != imagePlugin.Info.SectorSize) return;
|
||||
if(infoMddf.datasize != imagePlugin.Info.SectorSize)
|
||||
return;
|
||||
|
||||
switch(infoMddf.fsversion)
|
||||
{
|
||||
case LISA_V1:
|
||||
sb.AppendLine("LisaFS v1");
|
||||
|
||||
break;
|
||||
case LISA_V2:
|
||||
sb.AppendLine("LisaFS v2");
|
||||
|
||||
break;
|
||||
case LISA_V3:
|
||||
sb.AppendLine("LisaFS v3");
|
||||
|
||||
break;
|
||||
default:
|
||||
sb.AppendFormat("Uknown LisaFS version {0}", infoMddf.fsversion).AppendLine();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -311,8 +344,9 @@ namespace Aaru.Filesystems.LisaFS
|
||||
|
||||
sb.AppendFormat("Volume is number {0} of {1}", infoMddf.volnum, infoMddf.vol_sequence).AppendLine();
|
||||
|
||||
sb.AppendFormat("Serial number of Lisa computer that created this volume: {0}", infoMddf.machine_id)
|
||||
.AppendLine();
|
||||
sb.AppendFormat("Serial number of Lisa computer that created this volume: {0}",
|
||||
infoMddf.machine_id).AppendLine();
|
||||
|
||||
sb.AppendFormat("Serial number of Lisa computer that can use this volume's software {0}",
|
||||
infoMddf.serialization).AppendLine();
|
||||
|
||||
@@ -323,8 +357,10 @@ namespace Aaru.Filesystems.LisaFS
|
||||
sb.AppendFormat("MDDF is in block {0}", infoMddf.mddf_block + beforeMddf).AppendLine();
|
||||
sb.AppendFormat("There are {0} reserved blocks before volume", beforeMddf).AppendLine();
|
||||
sb.AppendFormat("{0} blocks minus one", infoMddf.volsize_minus_one).AppendLine();
|
||||
sb.AppendFormat("{0} blocks minus one minus MDDF offset", infoMddf.volsize_minus_mddf_minus_one)
|
||||
.AppendLine();
|
||||
|
||||
sb.AppendFormat("{0} blocks minus one minus MDDF offset", infoMddf.volsize_minus_mddf_minus_one).
|
||||
AppendLine();
|
||||
|
||||
sb.AppendFormat("{0} blocks in volume", infoMddf.vol_size).AppendLine();
|
||||
sb.AppendFormat("{0} bytes per sector (uncooked)", infoMddf.blocksize).AppendLine();
|
||||
sb.AppendFormat("{0} bytes per sector", infoMddf.datasize).AppendLine();
|
||||
@@ -338,15 +374,17 @@ namespace Aaru.Filesystems.LisaFS
|
||||
sb.AppendFormat("Boot code: 0x{0:X8}", infoMddf.boot_code).AppendLine();
|
||||
sb.AppendFormat("Boot environment: 0x{0:X8}", infoMddf.boot_environ).AppendLine();
|
||||
sb.AppendFormat("Overmount stamp: 0x{0:X16}", infoMddf.overmount_stamp).AppendLine();
|
||||
|
||||
sb.AppendFormat("S-Records start at {0} and spans for {1} blocks",
|
||||
infoMddf.srec_ptr + infoMddf.mddf_block + beforeMddf, infoMddf.srec_len)
|
||||
.AppendLine();
|
||||
infoMddf.srec_ptr + infoMddf.mddf_block + beforeMddf, infoMddf.srec_len).
|
||||
AppendLine();
|
||||
|
||||
sb.AppendLine(infoMddf.vol_left_mounted == 0 ? "Volume is clean" : "Volume is dirty");
|
||||
|
||||
information = sb.ToString();
|
||||
|
||||
XmlFsType = new FileSystemType();
|
||||
|
||||
if(DateTime.Compare(infoMddf.dtvb, DateHandlers.LisaToDateTime(0)) > 0)
|
||||
{
|
||||
XmlFsType.BackupDate = infoMddf.dtvb;
|
||||
@@ -355,6 +393,7 @@ namespace Aaru.Filesystems.LisaFS
|
||||
|
||||
XmlFsType.Clusters = infoMddf.vol_size;
|
||||
XmlFsType.ClusterSize = (uint)(infoMddf.clustersize * infoMddf.datasize);
|
||||
|
||||
if(DateTime.Compare(infoMddf.dtvc, DateHandlers.LisaToDateTime(0)) > 0)
|
||||
{
|
||||
XmlFsType.CreationDate = infoMddf.dtvc;
|
||||
|
||||
@@ -59,17 +59,25 @@ namespace Aaru.Filesystems.LisaFS
|
||||
|
||||
// TODO: Implement Lisa 7/7 namespace (needs decoding {!CATALOG} file)
|
||||
public IEnumerable<(string name, Type type, string description)> SupportedOptions =>
|
||||
new (string name, Type type, string description)[] { };
|
||||
new (string name, Type type, string description)[]
|
||||
{};
|
||||
|
||||
public Dictionary<string, string> Namespaces =>
|
||||
new Dictionary<string, string>
|
||||
public Dictionary<string, string> Namespaces => new Dictionary<string, string>
|
||||
{
|
||||
{
|
||||
{"workshop", "Filenames as shown by the Lisa Pascal Workshop (default)"},
|
||||
{"office", "Filenames as shown by the Lisa Office System (not yet implemented)"}
|
||||
};
|
||||
"workshop", "Filenames as shown by the Lisa Pascal Workshop (default)"
|
||||
},
|
||||
{
|
||||
"office", "Filenames as shown by the Lisa Office System (not yet implemented)"
|
||||
}
|
||||
};
|
||||
|
||||
static Dictionary<string, string> GetDefaultOptions() =>
|
||||
new Dictionary<string, string> {{"debug", false.ToString()}};
|
||||
static Dictionary<string, string> GetDefaultOptions() => new Dictionary<string, string>
|
||||
{
|
||||
{
|
||||
"debug", false.ToString()
|
||||
}
|
||||
};
|
||||
|
||||
#region Caches
|
||||
/// <summary>Caches Extents Files</summary>
|
||||
|
||||
@@ -37,11 +37,9 @@ namespace Aaru.Filesystems.LisaFS
|
||||
public partial class LisaFS
|
||||
{
|
||||
/// <summary>
|
||||
/// The MDDF is the most import block on a Lisa FS volume.
|
||||
/// It describes the volume and its contents.
|
||||
/// On initialization the memory where it resides is not emptied
|
||||
/// so it tends to contain a lot of garbage. This has difficulted
|
||||
/// its reverse engineering.
|
||||
/// The MDDF is the most import block on a Lisa FS volume. It describes the volume and its contents. On
|
||||
/// initialization the memory where it resides is not emptied so it tends to contain a lot of garbage. This has
|
||||
/// difficulted its reverse engineering.
|
||||
/// </summary>
|
||||
struct MDDF
|
||||
{
|
||||
@@ -193,6 +191,7 @@ namespace Aaru.Filesystems.LisaFS
|
||||
public uint opencount;
|
||||
/// <summary>No idea (On-disk position unknown)</summary>
|
||||
public uint copy_thread;
|
||||
|
||||
// Flags are boolean, but Pascal seems to use them as full unsigned 8 bit values
|
||||
/// <summary>No idea (On-disk position unknown)</summary>
|
||||
public byte privileged;
|
||||
@@ -209,10 +208,10 @@ namespace Aaru.Filesystems.LisaFS
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An entry in the catalog from V3.
|
||||
/// The first entry is bigger than the rest, may be a header, I have not needed any of its values so I just ignored it.
|
||||
/// Each catalog is divided in 4-sector blocks, and if it needs more than a block there are previous and next block
|
||||
/// pointers, effectively making the V3 catalog a double-linked list. Garbage is not zeroed.
|
||||
/// An entry in the catalog from V3. The first entry is bigger than the rest, may be a header, I have not needed
|
||||
/// any of its values so I just ignored it. Each catalog is divided in 4-sector blocks, and if it needs more than a
|
||||
/// block there are previous and next block pointers, effectively making the V3 catalog a double-linked list. Garbage
|
||||
/// is not zeroed.
|
||||
/// </summary>
|
||||
struct CatalogEntry
|
||||
{
|
||||
@@ -225,11 +224,8 @@ namespace Aaru.Filesystems.LisaFS
|
||||
/// <summary>0x23, null-termination</summary>
|
||||
public byte terminator;
|
||||
/// <summary>
|
||||
/// At 0x24
|
||||
/// 0x01 here for subdirectories, entries 48 bytes long
|
||||
/// 0x03 here for entries 64 bytes long
|
||||
/// 0x08 here for entries 78 bytes long
|
||||
/// This is incomplete, may fail, mostly works...
|
||||
/// At 0x24 0x01 here for subdirectories, entries 48 bytes long 0x03 here for entries 64 bytes long 0x08 here for
|
||||
/// entries 78 bytes long This is incomplete, may fail, mostly works...
|
||||
/// </summary>
|
||||
public byte fileType;
|
||||
/// <summary>0x25, lot of values found here, unknown</summary>
|
||||
@@ -248,9 +244,7 @@ namespace Aaru.Filesystems.LisaFS
|
||||
public byte[] tail;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An extent indicating a start and a run of sectors.
|
||||
/// </summary>
|
||||
/// <summary>An extent indicating a start and a run of sectors.</summary>
|
||||
struct Extent
|
||||
{
|
||||
public int start;
|
||||
@@ -258,12 +252,10 @@ namespace Aaru.Filesystems.LisaFS
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Extents File. There is one Extents File per each file stored on disk.
|
||||
/// The file ID present on the sectors tags for the Extents File is the negated
|
||||
/// value of the file ID it represents. e.g. file = 5 (0x0005) extents = -5 (0xFFFB)
|
||||
/// It spans a single sector on V2 and V3 but 2 sectors on V1.
|
||||
/// It contains all information about a file, and is indexed in the S-Records file.
|
||||
/// It also contains the label. Garbage is zeroed.
|
||||
/// The Extents File. There is one Extents File per each file stored on disk. The file ID present on the sectors
|
||||
/// tags for the Extents File is the negated value of the file ID it represents. e.g. file = 5 (0x0005) extents = -5
|
||||
/// (0xFFFB) It spans a single sector on V2 and V3 but 2 sectors on V1. It contains all information about a file, and
|
||||
/// is indexed in the S-Records file. It also contains the label. Garbage is zeroed.
|
||||
/// </summary>
|
||||
struct ExtentFile
|
||||
{
|
||||
@@ -343,30 +335,23 @@ namespace Aaru.Filesystems.LisaFS
|
||||
/// <summary>0x17E, unknown, empty, padding?</summary>
|
||||
public short unknown10;
|
||||
/// <summary>
|
||||
/// At 0x180, this is the label.
|
||||
/// While 1982 pre-release documentation says the label can be up to 448 bytes, v1 onward only have space for a 128
|
||||
/// bytes one.
|
||||
/// Any application can write whatever they want in the label, however, Lisa Office uses it to store its own
|
||||
/// information, something
|
||||
/// that will effectively overwrite any information a user application wrote there.
|
||||
/// The information written here by Lisa Office is like the information Finder writes in the FinderInfo structures,
|
||||
/// plus
|
||||
/// the non-unique name that is shown on the GUI. For this reason I called it LisaInfo.
|
||||
/// I have not tried to reverse engineer it.
|
||||
/// At 0x180, this is the label. While 1982 pre-release documentation says the label can be up to 448 bytes, v1
|
||||
/// onward only have space for a 128 bytes one. Any application can write whatever they want in the label, however,
|
||||
/// Lisa Office uses it to store its own information, something that will effectively overwrite any information a user
|
||||
/// application wrote there. The information written here by Lisa Office is like the information Finder writes in the
|
||||
/// FinderInfo structures, plus the non-unique name that is shown on the GUI. For this reason I called it LisaInfo. I
|
||||
/// have not tried to reverse engineer it.
|
||||
/// </summary>
|
||||
public byte[] LisaInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The S-Records File is a hashtable of S-Records, where the hash is the file ID they belong to.
|
||||
/// The S-Records File cannot be fragmented or grown, and it can easily become full before the 32766 file IDs are
|
||||
/// exhausted.
|
||||
/// Each S-Record entry contains a block pointer to the Extents File that correspond to that file ID as well as the
|
||||
/// real file size,
|
||||
/// the only important information about a file that's not inside the Extents File.
|
||||
/// It also contains a low value (less than 0x200) variable field of unknown meaning and another one that seems to be
|
||||
/// flags,
|
||||
/// with values like 0, 1, 3 and 5.
|
||||
/// The S-Records File is a hashtable of S-Records, where the hash is the file ID they belong to. The S-Records
|
||||
/// File cannot be fragmented or grown, and it can easily become full before the 32766 file IDs are exhausted. Each
|
||||
/// S-Record entry contains a block pointer to the Extents File that correspond to that file ID as well as the real
|
||||
/// file size, the only important information about a file that's not inside the Extents File. It also contains a low
|
||||
/// value (less than 0x200) variable field of unknown meaning and another one that seems to be flags, with values like
|
||||
/// 0, 1, 3 and 5.
|
||||
/// </summary>
|
||||
struct SRecord
|
||||
{
|
||||
@@ -381,13 +366,12 @@ namespace Aaru.Filesystems.LisaFS
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The catalog entry for the V1 and V2 volume formats.
|
||||
/// It merely contains the file name, type and ID, plus a few (mostly empty) unknown fields.
|
||||
/// Contrary to V3, it has no header and instead of being a double-linked list it is fragmented using an Extents File.
|
||||
/// The Extents File position for the root catalog is then stored in the S-Records File.
|
||||
/// Its entries are not filed sequentially denoting some kind of in-memory structure while at the same time
|
||||
/// forcing LisaOS to read the whole catalog. That or I missed the pointers.
|
||||
/// Empty entries just contain a 0-len filename. Garbage is not zeroed.
|
||||
/// The catalog entry for the V1 and V2 volume formats. It merely contains the file name, type and ID, plus a few
|
||||
/// (mostly empty) unknown fields. Contrary to V3, it has no header and instead of being a double-linked list it is
|
||||
/// fragmented using an Extents File. The Extents File position for the root catalog is then stored in the S-Records
|
||||
/// File. Its entries are not filed sequentially denoting some kind of in-memory structure while at the same time
|
||||
/// forcing LisaOS to read the whole catalog. That or I missed the pointers. Empty entries just contain a 0-len
|
||||
/// filename. Garbage is not zeroed.
|
||||
/// </summary>
|
||||
struct CatalogEntryV2
|
||||
{
|
||||
|
||||
@@ -32,13 +32,13 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Claunia.Encoding;
|
||||
using Aaru.CommonTypes;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
using Aaru.CommonTypes.Interfaces;
|
||||
using Aaru.CommonTypes.Structs;
|
||||
using Aaru.Console;
|
||||
using Aaru.Decoders;
|
||||
using Claunia.Encoding;
|
||||
using Schemas;
|
||||
using Encoding = System.Text.Encoding;
|
||||
|
||||
@@ -46,11 +46,9 @@ namespace Aaru.Filesystems.LisaFS
|
||||
{
|
||||
public partial class LisaFS
|
||||
{
|
||||
/// <summary>
|
||||
/// Mounts an Apple Lisa filesystem
|
||||
/// </summary>
|
||||
public Errno Mount(IMediaImage imagePlugin, Partition partition, Encoding encoding,
|
||||
Dictionary<string, string> options, string @namespace)
|
||||
/// <summary>Mounts an Apple Lisa filesystem</summary>
|
||||
public Errno Mount(IMediaImage imagePlugin, Partition partition, Encoding encoding,
|
||||
Dictionary<string, string> options, string @namespace)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -64,6 +62,7 @@ namespace Aaru.Filesystems.LisaFS
|
||||
!device.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag))
|
||||
{
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "Underlying device does not support Lisa tags");
|
||||
|
||||
return Errno.InOutError;
|
||||
}
|
||||
|
||||
@@ -71,6 +70,7 @@ namespace Aaru.Filesystems.LisaFS
|
||||
if(device.Info.Sectors < 800)
|
||||
{
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "Device is too small");
|
||||
|
||||
return Errno.InOutError;
|
||||
}
|
||||
|
||||
@@ -84,10 +84,12 @@ namespace Aaru.Filesystems.LisaFS
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "Sector {0}, file ID 0x{1:X4}", i, searchTag.FileId);
|
||||
|
||||
if(volumePrefix == device.Info.Sectors && searchTag.FileId == FILEID_LOADER_SIGNED)
|
||||
if(volumePrefix == device.Info.Sectors &&
|
||||
searchTag.FileId == FILEID_LOADER_SIGNED)
|
||||
volumePrefix = i - 1;
|
||||
|
||||
if(searchTag.FileId != FILEID_MDDF) continue;
|
||||
if(searchTag.FileId != FILEID_MDDF)
|
||||
continue;
|
||||
|
||||
devTagSize = device.ReadSectorTag(i, SectorTagType.AppleSectorTag).Length;
|
||||
|
||||
@@ -102,6 +104,7 @@ namespace Aaru.Filesystems.LisaFS
|
||||
mddf.volname = StringHandlers.PascalToString(pString, Encoding);
|
||||
mddf.unknown1 = sector[0x2D];
|
||||
Array.Copy(sector, 0x2E, pString, 0, 33);
|
||||
|
||||
// Prevent garbage
|
||||
mddf.password = pString[0] <= 32 ? StringHandlers.PascalToString(pString, Encoding) : "";
|
||||
mddf.unknown2 = sector[0x4F];
|
||||
@@ -175,17 +178,16 @@ namespace Aaru.Filesystems.LisaFS
|
||||
mddf.vol_left_mounted = sector[0x138];
|
||||
|
||||
// Check that the MDDF is correct
|
||||
if(mddf.mddf_block != i - volumePrefix ||
|
||||
mddf.vol_size > device.Info.Sectors ||
|
||||
mddf.vol_size - 1 !=
|
||||
mddf.volsize_minus_one ||
|
||||
mddf.vol_size - i - 1 !=
|
||||
mddf.volsize_minus_mddf_minus_one - volumePrefix ||
|
||||
mddf.datasize >
|
||||
mddf.blocksize || mddf.blocksize < device.Info.SectorSize ||
|
||||
mddf.datasize != device.Info.SectorSize)
|
||||
if(mddf.mddf_block != i - volumePrefix ||
|
||||
mddf.vol_size > device.Info.Sectors ||
|
||||
mddf.vol_size - 1 != mddf.volsize_minus_one ||
|
||||
mddf.vol_size - i - 1 != mddf.volsize_minus_mddf_minus_one - volumePrefix ||
|
||||
mddf.datasize > mddf.blocksize ||
|
||||
mddf.blocksize < device.Info.SectorSize ||
|
||||
mddf.datasize != device.Info.SectorSize)
|
||||
{
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "Incorrect MDDF found");
|
||||
|
||||
return Errno.InvalidArgument;
|
||||
}
|
||||
|
||||
@@ -194,15 +196,19 @@ namespace Aaru.Filesystems.LisaFS
|
||||
{
|
||||
case LISA_V1:
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "Mounting LisaFS v1");
|
||||
|
||||
break;
|
||||
case LISA_V2:
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "Mounting LisaFS v2");
|
||||
|
||||
break;
|
||||
case LISA_V3:
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "Mounting LisaFS v3");
|
||||
|
||||
break;
|
||||
default:
|
||||
AaruConsole.ErrorWriteLine("Cannot mount LisaFS version {0}", mddf.fsversion.ToString());
|
||||
|
||||
return Errno.NotSupported;
|
||||
}
|
||||
|
||||
@@ -210,24 +216,37 @@ namespace Aaru.Filesystems.LisaFS
|
||||
extentCache = new Dictionary<short, ExtentFile>();
|
||||
systemFileCache = new Dictionary<short, byte[]>();
|
||||
fileCache = new Dictionary<short, byte[]>();
|
||||
|
||||
//catalogCache = new Dictionary<short, List<CatalogEntry>>();
|
||||
fileSizeCache = new Dictionary<short, int>();
|
||||
|
||||
mounted = true;
|
||||
if(options == null) options = GetDefaultOptions();
|
||||
if(options.TryGetValue("debug", out string debugString)) bool.TryParse(debugString, out debug);
|
||||
|
||||
if(debug) printedExtents = new List<short>();
|
||||
if(options == null)
|
||||
options = GetDefaultOptions();
|
||||
|
||||
if(options.TryGetValue("debug", out string debugString))
|
||||
bool.TryParse(debugString, out debug);
|
||||
|
||||
if(debug)
|
||||
printedExtents = new List<short>();
|
||||
|
||||
// Read the S-Records file
|
||||
Errno error = ReadSRecords();
|
||||
|
||||
if(error != Errno.NoError)
|
||||
{
|
||||
AaruConsole.ErrorWriteLine("Error {0} reading S-Records file.", error);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
directoryDtcCache = new Dictionary<short, DateTime> {{DIRID_ROOT, mddf.dtcc}};
|
||||
directoryDtcCache = new Dictionary<short, DateTime>
|
||||
{
|
||||
{
|
||||
DIRID_ROOT, mddf.dtcc
|
||||
}
|
||||
};
|
||||
|
||||
// Read the Catalog File
|
||||
error = ReadCatalog();
|
||||
@@ -235,8 +254,10 @@ namespace Aaru.Filesystems.LisaFS
|
||||
if(error != Errno.NoError)
|
||||
{
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "Cannot read Catalog File, error {0}",
|
||||
error.ToString());
|
||||
error.ToString());
|
||||
|
||||
mounted = false;
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -244,48 +265,59 @@ namespace Aaru.Filesystems.LisaFS
|
||||
if(debug)
|
||||
{
|
||||
error = ReadSystemFile(FILEID_BOOT_SIGNED, out _);
|
||||
|
||||
if(error != Errno.NoError)
|
||||
{
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "Unable to read boot blocks");
|
||||
mounted = false;
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
error = ReadSystemFile(FILEID_LOADER_SIGNED, out _);
|
||||
|
||||
if(error != Errno.NoError)
|
||||
{
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "Unable to read boot loader");
|
||||
mounted = false;
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
error = ReadSystemFile((short)FILEID_MDDF, out _);
|
||||
|
||||
if(error != Errno.NoError)
|
||||
{
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "Unable to read MDDF");
|
||||
mounted = false;
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
error = ReadSystemFile((short)FILEID_BITMAP, out _);
|
||||
|
||||
if(error != Errno.NoError)
|
||||
{
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "Unable to read volume bitmap");
|
||||
mounted = false;
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
error = ReadSystemFile((short)FILEID_SRECORD, out _);
|
||||
|
||||
if(error != Errno.NoError)
|
||||
{
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "Unable to read S-Records file");
|
||||
mounted = false;
|
||||
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
// Create XML metadata for mounted filesystem
|
||||
XmlFsType = new FileSystemType();
|
||||
|
||||
if(DateTime.Compare(mddf.dtvb, DateHandlers.LisaToDateTime(0)) > 0)
|
||||
{
|
||||
XmlFsType.BackupDate = mddf.dtvb;
|
||||
@@ -294,6 +326,7 @@ namespace Aaru.Filesystems.LisaFS
|
||||
|
||||
XmlFsType.Clusters = mddf.vol_size;
|
||||
XmlFsType.ClusterSize = (uint)(mddf.clustersize * mddf.datasize);
|
||||
|
||||
if(DateTime.Compare(mddf.dtvc, DateHandlers.LisaToDateTime(0)) > 0)
|
||||
{
|
||||
XmlFsType.CreationDate = mddf.dtvc;
|
||||
@@ -313,18 +346,18 @@ namespace Aaru.Filesystems.LisaFS
|
||||
}
|
||||
|
||||
AaruConsole.DebugWriteLine("LisaFS plugin", "Not a Lisa filesystem");
|
||||
|
||||
return Errno.NotSupported;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
AaruConsole.ErrorWriteLine("Exception {0}, {1}, {2}", ex.Message, ex.InnerException, ex.StackTrace);
|
||||
|
||||
return Errno.InOutError;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Umounts this Lisa filesystem
|
||||
/// </summary>
|
||||
/// <summary>Umounts this Lisa filesystem</summary>
|
||||
public Errno Unmount()
|
||||
{
|
||||
mounted = false;
|
||||
@@ -342,35 +375,40 @@ namespace Aaru.Filesystems.LisaFS
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets information about the mounted volume.
|
||||
/// </summary>
|
||||
/// <summary>Gets information about the mounted volume.</summary>
|
||||
/// <param name="stat">Information about the mounted volume.</param>
|
||||
public Errno StatFs(out FileSystemInfo stat)
|
||||
{
|
||||
stat = null;
|
||||
if(!mounted) return Errno.AccessDenied;
|
||||
|
||||
if(!mounted)
|
||||
return Errno.AccessDenied;
|
||||
|
||||
stat = new FileSystemInfo
|
||||
{
|
||||
Blocks = mddf.vol_size,
|
||||
FilenameLength = (ushort)E_NAME,
|
||||
Files = mddf.filecount,
|
||||
FreeBlocks = mddf.freecount,
|
||||
Id = {Serial64 = mddf.volid, IsLong = true},
|
||||
PluginId = Id
|
||||
Blocks = mddf.vol_size, FilenameLength = (ushort)E_NAME, Files = mddf.filecount,
|
||||
FreeBlocks = mddf.freecount, Id =
|
||||
{
|
||||
Serial64 = mddf.volid, IsLong = true
|
||||
},
|
||||
PluginId = Id
|
||||
};
|
||||
|
||||
stat.FreeFiles = FILEID_MAX - stat.Files;
|
||||
|
||||
switch(mddf.fsversion)
|
||||
{
|
||||
case LISA_V1:
|
||||
stat.Type = "LisaFS v1";
|
||||
|
||||
break;
|
||||
case LISA_V2:
|
||||
stat.Type = "LisaFS v2";
|
||||
|
||||
break;
|
||||
case LISA_V3:
|
||||
stat.Type = "LisaFS v3";
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,9 +41,7 @@ namespace Aaru.Filesystems.LisaFS
|
||||
{
|
||||
public partial class LisaFS
|
||||
{
|
||||
/// <summary>
|
||||
/// Lists all extended attributes, alternate data streams and forks of the given file.
|
||||
/// </summary>
|
||||
/// <summary>Lists all extended attributes, alternate data streams and forks of the given file.</summary>
|
||||
/// <returns>Error number.</returns>
|
||||
/// <param name="path">Path.</param>
|
||||
/// <param name="xattrs">List of extended attributes, alternate data streams and forks.</param>
|
||||
@@ -51,14 +49,14 @@ namespace Aaru.Filesystems.LisaFS
|
||||
{
|
||||
xattrs = null;
|
||||
Errno error = LookupFileId(path, out short fileId, out bool isDir);
|
||||
if(error != Errno.NoError) return error;
|
||||
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
return isDir ? Errno.InvalidArgument : ListXAttr(fileId, out xattrs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads an extended attribute, alternate data stream or fork from the given file.
|
||||
/// </summary>
|
||||
/// <summary>Reads an extended attribute, alternate data stream or fork from the given file.</summary>
|
||||
/// <returns>Error number.</returns>
|
||||
/// <param name="path">File path.</param>
|
||||
/// <param name="xattr">Extendad attribute, alternate data stream or fork name.</param>
|
||||
@@ -66,14 +64,14 @@ namespace Aaru.Filesystems.LisaFS
|
||||
public Errno GetXattr(string path, string xattr, ref byte[] buf)
|
||||
{
|
||||
Errno error = LookupFileId(path, out short fileId, out bool isDir);
|
||||
if(error != Errno.NoError) return error;
|
||||
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
return isDir ? Errno.InvalidArgument : GetXattr(fileId, xattr, out buf);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lists special Apple Lisa filesystem features as extended attributes
|
||||
/// </summary>
|
||||
/// <summary>Lists special Apple Lisa filesystem features as extended attributes</summary>
|
||||
/// <returns>Error number.</returns>
|
||||
/// <param name="fileId">File identifier.</param>
|
||||
/// <param name="xattrs">Extended attributes.</param>
|
||||
@@ -81,12 +79,15 @@ namespace Aaru.Filesystems.LisaFS
|
||||
{
|
||||
xattrs = null;
|
||||
|
||||
if(!mounted) return Errno.AccessDenied;
|
||||
if(!mounted)
|
||||
return Errno.AccessDenied;
|
||||
|
||||
// System files
|
||||
if(fileId < 4)
|
||||
{
|
||||
if(!debug || fileId == 0) return Errno.InvalidArgument;
|
||||
if(!debug ||
|
||||
fileId == 0)
|
||||
return Errno.InvalidArgument;
|
||||
|
||||
xattrs = new List<string>();
|
||||
|
||||
@@ -96,7 +97,8 @@ namespace Aaru.Filesystems.LisaFS
|
||||
byte[] buf = Encoding.ASCII.GetBytes(mddf.password);
|
||||
|
||||
// If the MDDF contains a password, show it
|
||||
if(buf.Length > 0) xattrs.Add("com.apple.lisa.password");
|
||||
if(buf.Length > 0)
|
||||
xattrs.Add("com.apple.lisa.password");
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -104,31 +106,34 @@ namespace Aaru.Filesystems.LisaFS
|
||||
// Search for the file
|
||||
Errno error = ReadExtentsFile(fileId, out ExtentFile file);
|
||||
|
||||
if(error != Errno.NoError) return error;
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
xattrs = new List<string>();
|
||||
|
||||
// Password field is never emptied, check if valid
|
||||
if(file.password_valid > 0) xattrs.Add("com.apple.lisa.password");
|
||||
if(file.password_valid > 0)
|
||||
xattrs.Add("com.apple.lisa.password");
|
||||
|
||||
// Check for a valid copy-protection serial number
|
||||
if(file.serial > 0) xattrs.Add("com.apple.lisa.serial");
|
||||
if(file.serial > 0)
|
||||
xattrs.Add("com.apple.lisa.serial");
|
||||
|
||||
// Check if the label contains something or is empty
|
||||
if(!ArrayHelpers.ArrayIsNullOrEmpty(file.LisaInfo)) xattrs.Add("com.apple.lisa.label");
|
||||
if(!ArrayHelpers.ArrayIsNullOrEmpty(file.LisaInfo))
|
||||
xattrs.Add("com.apple.lisa.label");
|
||||
}
|
||||
|
||||
// On debug mode allow sector tags to be accessed as an xattr
|
||||
if(debug) xattrs.Add("com.apple.lisa.tags");
|
||||
if(debug)
|
||||
xattrs.Add("com.apple.lisa.tags");
|
||||
|
||||
xattrs.Sort();
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lists special Apple Lisa filesystem features as extended attributes
|
||||
/// </summary>
|
||||
/// <summary>Lists special Apple Lisa filesystem features as extended attributes</summary>
|
||||
/// <returns>Error number.</returns>
|
||||
/// <param name="fileId">File identifier.</param>
|
||||
/// <param name="xattr">Extended attribute name.</param>
|
||||
@@ -137,23 +142,28 @@ namespace Aaru.Filesystems.LisaFS
|
||||
{
|
||||
buf = null;
|
||||
|
||||
if(!mounted) return Errno.AccessDenied;
|
||||
if(!mounted)
|
||||
return Errno.AccessDenied;
|
||||
|
||||
// System files
|
||||
if(fileId < 4)
|
||||
{
|
||||
if(!debug || fileId == 0) return Errno.InvalidArgument;
|
||||
if(!debug ||
|
||||
fileId == 0)
|
||||
return Errno.InvalidArgument;
|
||||
|
||||
// Only MDDF contains an extended attributes
|
||||
if(fileId == FILEID_MDDF)
|
||||
if(xattr == "com.apple.lisa.password")
|
||||
{
|
||||
buf = Encoding.ASCII.GetBytes(mddf.password);
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
// But on debug mode even system files contain tags
|
||||
if(debug && xattr == "com.apple.lisa.tags") return ReadSystemFile(fileId, out buf, true);
|
||||
if(debug && xattr == "com.apple.lisa.tags")
|
||||
return ReadSystemFile(fileId, out buf, true);
|
||||
|
||||
return Errno.NoSuchExtendedAttribute;
|
||||
}
|
||||
@@ -161,34 +171,38 @@ namespace Aaru.Filesystems.LisaFS
|
||||
// Search for the file
|
||||
Errno error = ReadExtentsFile(fileId, out ExtentFile file);
|
||||
|
||||
if(error != Errno.NoError) return error;
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
switch(xattr)
|
||||
{
|
||||
case "com.apple.lisa.password" when file.password_valid > 0:
|
||||
buf = new byte[8];
|
||||
Array.Copy(file.password, 0, buf, 0, 8);
|
||||
|
||||
return Errno.NoError;
|
||||
case "com.apple.lisa.serial" when file.serial > 0:
|
||||
buf = Encoding.ASCII.GetBytes(file.serial.ToString());
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
if(!ArrayHelpers.ArrayIsNullOrEmpty(file.LisaInfo) && xattr == "com.apple.lisa.label")
|
||||
if(!ArrayHelpers.ArrayIsNullOrEmpty(file.LisaInfo) &&
|
||||
xattr == "com.apple.lisa.label")
|
||||
{
|
||||
buf = new byte[128];
|
||||
Array.Copy(file.LisaInfo, 0, buf, 0, 128);
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
if(debug && xattr == "com.apple.lisa.tags") return ReadFile(fileId, out buf, true);
|
||||
if(debug && xattr == "com.apple.lisa.tags")
|
||||
return ReadFile(fileId, out buf, true);
|
||||
|
||||
return Errno.NoSuchExtendedAttribute;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a sector tag. Not tested with 24-byte tags.
|
||||
/// </summary>
|
||||
/// <summary>Decodes a sector tag. Not tested with 24-byte tags.</summary>
|
||||
/// <returns>Error number.</returns>
|
||||
/// <param name="tag">Sector tag.</param>
|
||||
/// <param name="decoded">Decoded sector tag.</param>
|
||||
@@ -197,9 +211,11 @@ namespace Aaru.Filesystems.LisaFS
|
||||
decoded = new LisaTag.PriamTag();
|
||||
LisaTag.PriamTag? pmTag = LisaTag.DecodeTag(tag);
|
||||
|
||||
if(!pmTag.HasValue) return Errno.InvalidArgument;
|
||||
if(!pmTag.HasValue)
|
||||
return Errno.InvalidArgument;
|
||||
|
||||
decoded = pmTag.Value;
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user