Added support for subcatalogs.

This commit is contained in:
2016-07-31 01:53:47 +01:00
parent e4850ea473
commit 5ba711cf76
8 changed files with 164 additions and 108 deletions

View File

@@ -1,3 +1,13 @@
2016-07-31 Natalia Portillo <claunia@claunia.com>
* Dir.cs:
* File.cs:
* Super.cs:
* Xattr.cs:
* Consts.cs:
* LisaFS.cs:
* Structs.cs: Added support for subcatalogs.
2016-07-29 Natalia Portillo <claunia@claunia.com> 2016-07-29 Natalia Portillo <claunia@claunia.com>
* DiscImageChef.Filesystems.csproj: Bump to version 3.1.0. * DiscImageChef.Filesystems.csproj: Bump to version 3.1.0.

View File

@@ -80,7 +80,7 @@ namespace DiscImageChef.Filesystems.LisaFS
/// </summary> /// </summary>
const ushort FILEID_SRECORD = 0x0003; const ushort FILEID_SRECORD = 0x0003;
/// <summary>The root catalog</summary> /// <summary>The root catalog</summary>
const ushort FILEID_ROOTCATALOG = 0x0004; const ushort FILEID_CATALOG = 0x0004;
const short FILEID_BOOT_SIGNED = -21846; const short FILEID_BOOT_SIGNED = -21846;
const short FILEID_LOADER_SIGNED = -17477; const short FILEID_LOADER_SIGNED = -17477;
/// <summary> /// <summary>
@@ -89,6 +89,9 @@ namespace DiscImageChef.Filesystems.LisaFS
const ushort FILEID_ERASED = 0x7FFF; const ushort FILEID_ERASED = 0x7FFF;
const ushort FILEID_MAX = FILEID_ERASED; const ushort FILEID_MAX = FILEID_ERASED;
/// <summary>Root directory ID</summary>
const short DIRID_ROOT = 0;
enum FileType : byte enum FileType : byte
{ {
/// <summary> /// <summary>

View File

@@ -65,17 +65,16 @@ namespace DiscImageChef.Filesystems.LisaFS
if(!isDir) if(!isDir)
return Errno.NotDirectory; return Errno.NotDirectory;
List<CatalogEntry> catalog; /*List<CatalogEntry> catalog;
ReadCatalog(fileId, out catalog); error = ReadCatalog(fileId, out catalog);
if(error != Errno.NoError)
return error;*/
// Do same trick as Mac OS X, replace filesystem '/' with ':' ReadDir(fileId, ref contents);
// Maybe as ':' is the path separator in Lisa OS I should do that
foreach(CatalogEntry entry in catalog)
contents.Add(GetString(entry.filename).Replace('/', ':'));
// On debug add system files as readable files // On debug add system files as readable files
// Syntax similar to NTFS // Syntax similar to NTFS
if(debug && fileId == FILEID_ROOTCATALOG) if(debug && fileId == DIRID_ROOT)
{ {
contents.Add("$MDDF"); contents.Add("$MDDF");
contents.Add("$Boot"); contents.Add("$Boot");
@@ -89,41 +88,37 @@ namespace DiscImageChef.Filesystems.LisaFS
return Errno.NoError; return Errno.NoError;
} }
/// <summary> Errno ReadDir(short dirId, ref List<string> contents)
/// Lists contents from a catalog.
/// </summary>
/// <param name="fileId">Catalog id.</param>
/// <param name="catalog">Catalog contents.</param>
Errno ReadCatalog(short fileId, out List<CatalogEntry> catalog)
{ {
catalog = null; contents = new List<string>();
foreach(CatalogEntry entry in catalogCache)
{
if(entry.parentID == dirId)
// Do same trick as Mac OS X, replace filesystem '/' with ':'
// Maybe as '-' is the path separator in Lisa OS I should do that
contents.Add(GetString(entry.filename).Replace('/', ':'));
}
return Errno.NoError;
}
/// <summary>
/// Reads, interprets and caches the Catalog File
/// </summary>
Errno ReadCatalog()
{
if(!mounted) if(!mounted)
return Errno.AccessDenied; return Errno.AccessDenied;
if(fileId < 4) catalogCache = new List<CatalogEntry>();
return Errno.InvalidArgument;
if(catalogCache.TryGetValue(fileId, out catalog))
return Errno.NoError;
Errno error; Errno error;
// Do differently for V1 and V2 // Do differently for V1 and V2
if(mddf.fsversion == LisaFSv2 || mddf.fsversion == LisaFSv1) if(mddf.fsversion == LisaFSv2 || mddf.fsversion == LisaFSv1)
{ {
// V1 and V2 can only contain the root catalog
if(fileId != FILEID_ROOTCATALOG)
{
ExtentFile ext;
// Check if it's a file to return correct error
error = ReadExtentsFile(fileId, out ext);
if(error == Errno.NoError)
return Errno.NotDirectory;
}
byte[] buf; byte[] buf;
error = ReadFile(4, out buf); error = ReadFile((short)FILEID_CATALOG, out buf);
int offset = 0; int offset = 0;
List<CatalogEntryV2> catalogV2 = new List<CatalogEntryV2>(); List<CatalogEntryV2> catalogV2 = new List<CatalogEntryV2>();
@@ -149,8 +144,6 @@ namespace DiscImageChef.Filesystems.LisaFS
catalogV2.Add(entV2); catalogV2.Add(entV2);
} }
catalog = new List<CatalogEntry>();
// Convert entries to V3 format // Convert entries to V3 format
foreach(CatalogEntryV2 entV2 in catalogV2) foreach(CatalogEntryV2 entV2 in catalogV2)
{ {
@@ -167,11 +160,10 @@ namespace DiscImageChef.Filesystems.LisaFS
entV3.dtc = ext.dtc; entV3.dtc = ext.dtc;
entV3.dtm = ext.dtm; entV3.dtm = ext.dtm;
catalog.Add(entV3); catalogCache.Add(entV3);
} }
} }
catalogCache.Add(fileId, catalog);
return Errno.NoError; return Errno.NoError;
} }
@@ -185,15 +177,11 @@ namespace DiscImageChef.Filesystems.LisaFS
Tag catTag; Tag catTag;
DecodeTag(device.ReadSectorTag(i, SectorTagType.AppleSectorTag), out catTag); DecodeTag(device.ReadSectorTag(i, SectorTagType.AppleSectorTag), out catTag);
if(catTag.fileID == fileId && catTag.relBlock == 0) if(catTag.fileID == FILEID_CATALOG && catTag.relBlock == 0)
{ {
firstCatalogBlock = device.ReadSectors(i, 4); firstCatalogBlock = device.ReadSectors(i, 4);
break; break;
} }
// Found Extents File for a catalog, not allowable in V3, at least for root catalog
if(catTag.fileID == -fileId)
return Errno.NotDirectory;
} }
// Catalog not found // Catalog not found
@@ -209,7 +197,7 @@ namespace DiscImageChef.Filesystems.LisaFS
Tag prevTag; Tag prevTag;
DecodeTag(device.ReadSectorTag(prevCatalogPointer + mddf.mddf_block + volumePrefix, SectorTagType.AppleSectorTag), out prevTag); DecodeTag(device.ReadSectorTag(prevCatalogPointer + mddf.mddf_block + volumePrefix, SectorTagType.AppleSectorTag), out prevTag);
if(prevTag.fileID != fileId) if(prevTag.fileID != FILEID_CATALOG)
return Errno.InvalidArgument; return Errno.InvalidArgument;
firstCatalogBlock = device.ReadSectors(prevCatalogPointer + mddf.mddf_block + volumePrefix, 4); firstCatalogBlock = device.ReadSectors(prevCatalogPointer + mddf.mddf_block + volumePrefix, 4);
@@ -228,7 +216,7 @@ namespace DiscImageChef.Filesystems.LisaFS
Tag nextTag; Tag nextTag;
DecodeTag(device.ReadSectorTag(nextCatalogPointer + mddf.mddf_block + volumePrefix, SectorTagType.AppleSectorTag), out nextTag); DecodeTag(device.ReadSectorTag(nextCatalogPointer + mddf.mddf_block + volumePrefix, SectorTagType.AppleSectorTag), out nextTag);
if(nextTag.fileID != fileId) if(nextTag.fileID != FILEID_CATALOG)
return Errno.InvalidArgument; return Errno.InvalidArgument;
byte[] nextCatalogBlock = device.ReadSectors(nextCatalogPointer + mddf.mddf_block + volumePrefix, 4); byte[] nextCatalogBlock = device.ReadSectors(nextCatalogPointer + mddf.mddf_block + volumePrefix, 4);
@@ -236,8 +224,6 @@ namespace DiscImageChef.Filesystems.LisaFS
catalogBlocks.Add(nextCatalogBlock); catalogBlocks.Add(nextCatalogBlock);
} }
catalog = new List<CatalogEntry>();
// Foreach catalog block // Foreach catalog block
foreach(byte[] buf in catalogBlocks) foreach(byte[] buf in catalogBlocks)
{ {
@@ -260,7 +246,7 @@ namespace DiscImageChef.Filesystems.LisaFS
{ {
CatalogEntry entry = new CatalogEntry(); CatalogEntry entry = new CatalogEntry();
entry.marker = buf[offset]; entry.marker = buf[offset];
entry.zero = BigEndianBitConverter.ToUInt16(buf, offset + 0x01); entry.parentID = BigEndianBitConverter.ToUInt16(buf, offset + 0x01);
entry.filename = new byte[E_NAME]; entry.filename = new byte[E_NAME];
Array.Copy(buf, offset + 0x03, entry.filename, 0, E_NAME); Array.Copy(buf, offset + 0x03, entry.filename, 0, E_NAME);
entry.terminator = buf[offset + 0x23]; entry.terminator = buf[offset + 0x23];
@@ -274,27 +260,75 @@ namespace DiscImageChef.Filesystems.LisaFS
entry.tail = new byte[8]; entry.tail = new byte[8];
Array.Copy(buf, offset + 0x38, entry.tail, 0, 8); Array.Copy(buf, offset + 0x38, entry.tail, 0, 8);
// This is as Pascal Workshop does, if there is no extents file it simply ignores it.
ExtentFile ext; ExtentFile ext;
if(ReadExtentsFile(entry.fileID, out ext) == Errno.NoError) if(ReadExtentsFile(entry.fileID, out ext) == Errno.NoError)
{ {
if(!fileSizeCache.ContainsKey(entry.fileID)) if(!fileSizeCache.ContainsKey(entry.fileID))
{ {
catalog.Add(entry); catalogCache.Add(entry);
fileSizeCache.Add(entry.fileID, entry.length); fileSizeCache.Add(entry.fileID, entry.length);
} }
} }
offset += 64; offset += 64;
} }
// Subdirectory entry
else if(buf[offset + 0x24] == 0x01 && buf[offset] == 0x24)
{
CatalogEntry entry = new CatalogEntry();
entry.marker = buf[offset];
entry.parentID = BigEndianBitConverter.ToUInt16(buf, offset + 0x01);
entry.filename = new byte[E_NAME];
Array.Copy(buf, offset + 0x03, entry.filename, 0, E_NAME);
entry.terminator = buf[offset + 0x23];
entry.fileType = buf[offset + 0x24];
entry.unknown = buf[offset + 0x25];
entry.fileID = BigEndianBitConverter.ToInt16(buf, offset + 0x26);
entry.dtc = BigEndianBitConverter.ToUInt32(buf, offset + 0x28);
entry.dtm = BigEndianBitConverter.ToUInt32(buf, offset + 0x2C);
entry.length = 0;
entry.wasted = 0;
entry.tail = null;
if(!directoryDTCCache.ContainsKey(entry.fileID))
directoryDTCCache.Add(entry.fileID, DateHandlers.LisaToDateTime(entry.dtc));
catalogCache.Add(entry);
offset += 48;
}
else else
break; break;
} }
} }
catalogCache.Add(fileId, catalog); return Errno.NoError;
}
Errno StatDir(short dirId, out FileEntryInfo stat)
{
stat = null;
if(!mounted)
return Errno.AccessDenied;
stat = new FileEntryInfo();
stat.Attributes = new FileAttributes();
DateTime tmp = new DateTime();
directoryDTCCache.TryGetValue(dirId, out tmp);
stat.CreationTime = tmp;
stat.Inode = FILEID_CATALOG;
stat.Mode = 0x16D;
stat.Links = 0;
stat.UID = 0;
stat.GID = 0;
stat.DeviceNo = 0;
stat.Length = 0;
stat.BlockSize = mddf.datasize;
stat.Blocks = 0;
return Errno.NoError; return Errno.NoError;
} }
} }
} }

View File

@@ -42,11 +42,18 @@ namespace DiscImageChef.Filesystems.LisaFS
public override Errno GetAttributes(string path, ref FileAttributes attributes) public override Errno GetAttributes(string path, ref FileAttributes attributes)
{ {
short fileId; short fileId;
Errno error = LookupFileId(path, out fileId); bool isDir;
Errno error = LookupFileId(path, out fileId, out isDir);
if(error != Errno.NoError) if(error != Errno.NoError)
return error; return error;
if(!isDir)
return GetAttributes(fileId, ref attributes); return GetAttributes(fileId, ref attributes);
attributes = new FileAttributes();
attributes = FileAttributes.Directory;
return Errno.NoError;
} }
public override Errno Read(string path, long offset, long size, ref byte[] buf) public override Errno Read(string path, long offset, long size, ref byte[] buf)
@@ -76,7 +83,7 @@ namespace DiscImageChef.Filesystems.LisaFS
case (short)FILEID_MDDF: case (short)FILEID_MDDF:
case (short)FILEID_BITMAP: case (short)FILEID_BITMAP:
case (short)FILEID_SRECORD: case (short)FILEID_SRECORD:
case (short)FILEID_ROOTCATALOG: case (short)FILEID_CATALOG:
error = ReadSystemFile(fileId, out tmp); error = ReadSystemFile(fileId, out tmp);
break; break;
default: default:
@@ -104,11 +111,12 @@ namespace DiscImageChef.Filesystems.LisaFS
public override Errno Stat(string path, ref FileEntryInfo stat) public override Errno Stat(string path, ref FileEntryInfo stat)
{ {
short fileId; short fileId;
Errno error = LookupFileId(path, out fileId); bool isDir;
Errno error = LookupFileId(path, out fileId, out isDir);
if(error != Errno.NoError) if(error != Errno.NoError)
return error; return error;
return Stat(fileId, out stat); return isDir ? StatDir(fileId, out stat) : Stat(fileId, out stat);
} }
Errno GetAttributes(short fileId, ref FileAttributes attributes) Errno GetAttributes(short fileId, ref FileAttributes attributes)
@@ -116,24 +124,19 @@ namespace DiscImageChef.Filesystems.LisaFS
if(!mounted) if(!mounted)
return Errno.AccessDenied; return Errno.AccessDenied;
if(fileId <= 4) if(fileId < 4)
{ {
if(!debug || fileId == 0) if(!debug)
return Errno.NoSuchFile; return Errno.NoSuchFile;
else
{
attributes = new FileAttributes(); attributes = new FileAttributes();
attributes = FileAttributes.System; attributes = FileAttributes.System;
attributes |= FileAttributes.Hidden; attributes |= FileAttributes.Hidden;
if(fileId == 4)
attributes |= FileAttributes.Directory;
else
attributes |= FileAttributes.File; attributes |= FileAttributes.File;
return Errno.NoError; return Errno.NoError;
} }
}
ExtentFile extFile; ExtentFile extFile;
Errno error = ReadExtentsFile(fileId, out extFile); Errno error = ReadExtentsFile(fileId, out extFile);
@@ -159,7 +162,6 @@ namespace DiscImageChef.Filesystems.LisaFS
break; break;
default: default:
attributes |= FileAttributes.File; attributes |= FileAttributes.File;
// Subcatalogs use extents?
attributes |= FileAttributes.Extents; attributes |= FileAttributes.Extents;
break; break;
} }
@@ -435,12 +437,6 @@ namespace DiscImageChef.Filesystems.LisaFS
return Errno.NoError; return Errno.NoError;
} }
Errno LookupFileId(string path, out short fileId)
{
bool temp;
return LookupFileId(path, out fileId, out temp);
}
Errno LookupFileId(string path, out short fileId, out bool isDir) Errno LookupFileId(string path, out short fileId, out bool isDir)
{ {
fileId = 0; fileId = 0;
@@ -453,16 +449,16 @@ namespace DiscImageChef.Filesystems.LisaFS
if(pathElements.Length == 0) if(pathElements.Length == 0)
{ {
fileId = (short)FILEID_ROOTCATALOG; fileId = DIRID_ROOT;
isDir = true; isDir = true;
return Errno.NoError; return Errno.NoError;
} }
// TODO: Subcatalogs // Only V3 supports subdirectories
if(pathElements.Length > 1) if(pathElements.Length > 1 && mddf.fsversion != LisaFSv3)
return Errno.NotImplemented; return Errno.NotSupported;
if(debug) if(debug && pathElements.Length == 1)
{ {
if(string.Compare(pathElements[0], "$MDDF", StringComparison.InvariantCulture) == 0) if(string.Compare(pathElements[0], "$MDDF", StringComparison.InvariantCulture) == 0)
{ {
@@ -496,31 +492,37 @@ namespace DiscImageChef.Filesystems.LisaFS
if(string.Compare(pathElements[0], "$", StringComparison.InvariantCulture) == 0) if(string.Compare(pathElements[0], "$", StringComparison.InvariantCulture) == 0)
{ {
fileId = (short)FILEID_ROOTCATALOG; fileId = DIRID_ROOT;
isDir = true; isDir = true;
return Errno.NoError; return Errno.NoError;
} }
} }
List<CatalogEntry> catalog; for(int lvl = 0; lvl < pathElements.Length; lvl++)
{
Errno error = ReadCatalog((short)FILEID_ROOTCATALOG, out catalog);
if(error != Errno.NoError)
return error;
string wantedFilename = pathElements[0].Replace(':', '/'); string wantedFilename = pathElements[0].Replace(':', '/');
foreach(CatalogEntry entry in catalog) foreach(CatalogEntry entry in catalogCache)
{ {
string filename = GetString(entry.filename); string filename = GetString(entry.filename);
// Should they be case sensitive?
if(string.Compare(wantedFilename, filename, StringComparison.InvariantCultureIgnoreCase) == 0) // LisaOS is case insensitive
if(string.Compare(wantedFilename, filename, StringComparison.InvariantCultureIgnoreCase) == 0
&& entry.parentID == fileId)
{ {
fileId = entry.fileID; fileId = entry.fileID;
isDir |= entry.fileType != 0x03; isDir = entry.fileType == 0x01;
// Not last path element, and it's not a directory
if(lvl != pathElements.Length - 1 && !isDir)
return Errno.NotDirectory;
// Arrived last path element
if(lvl == pathElements.Length - 1)
return Errno.NoError; return Errno.NoError;
} }
} }
}
return Errno.NoSuchFile; return Errno.NoSuchFile;
} }

View File

@@ -58,11 +58,13 @@ namespace DiscImageChef.Filesystems.LisaFS
/// <summary>Caches user files files</summary> /// <summary>Caches user files files</summary>
Dictionary<short, byte[]> fileCache; Dictionary<short, byte[]> fileCache;
/// <summary>Caches catalogs</summary> /// <summary>Caches catalogs</summary>
Dictionary<short, List<CatalogEntry>> catalogCache; List<CatalogEntry> catalogCache;
/// <summary>Caches file size</summary> /// <summary>Caches file size</summary>
Dictionary<short, int> fileSizeCache; Dictionary<short, int> fileSizeCache;
/// <summary>Lists Extents Files already printed in debug mode to not repeat them</summary> /// <summary>Lists Extents Files already printed in debug mode to not repeat them</summary>
List<short> printedExtents; List<short> printedExtents;
/// <summary>Caches the creation times for subdirectories as to not have to traverse the Catalog File on each stat</summary>
Dictionary<short, DateTime> directoryDTCCache;
#endregion Caches #endregion Caches
public LisaFS() public LisaFS()

View File

@@ -259,14 +259,15 @@ namespace DiscImageChef.Filesystems.LisaFS
{ {
/// <summary>0x00, seems to be 0x24 when the entry is valid</summary> /// <summary>0x00, seems to be 0x24 when the entry is valid</summary>
public byte marker; public byte marker;
/// <summary>0x01, must be zero otherwise LisaOS gives an error</summary> /// <summary>0x01, parent directory ID for this file, 0 for root directory</summary>
public ushort zero; public ushort parentID;
/// <summary>0x03, filename, 32-bytes, null-padded</summary> /// <summary>0x03, filename, 32-bytes, null-padded</summary>
public byte[] filename; public byte[] filename;
/// <summary>0x23, null-termination</summary> /// <summary>0x23, null-termination</summary>
public byte terminator; public byte terminator;
/// <summary> /// <summary>
/// At 0x24 /// At 0x24
/// 0x01 here for subdirectories, entries 48 bytes long
/// 0x03 here for entries 64 bytes long /// 0x03 here for entries 64 bytes long
/// 0x08 here for entries 78 bytes long /// 0x08 here for entries 78 bytes long
/// This is incomplete, may fail, mostly works... /// This is incomplete, may fail, mostly works...

View File

@@ -213,7 +213,7 @@ namespace DiscImageChef.Filesystems.LisaFS
extentCache = new Dictionary<short, ExtentFile>(); extentCache = new Dictionary<short, ExtentFile>();
systemFileCache = new Dictionary<short, byte[]>(); systemFileCache = new Dictionary<short, byte[]>();
fileCache = new Dictionary<short, byte[]>(); fileCache = new Dictionary<short, byte[]>();
catalogCache = new Dictionary<short, List<CatalogEntry>>(); //catalogCache = new Dictionary<short, List<CatalogEntry>>();
fileSizeCache = new Dictionary<short, int>(); fileSizeCache = new Dictionary<short, int>();
Errno error; Errno error;
@@ -234,13 +234,15 @@ namespace DiscImageChef.Filesystems.LisaFS
return error; return error;
} }
// Read the root catalog directoryDTCCache = new Dictionary<short, DateTime>();
List<CatalogEntry> tempCat; directoryDTCCache.Add(DIRID_ROOT, mddf.dtcc);
error = ReadCatalog((short)FILEID_ROOTCATALOG, out tempCat);
// Read the Catalog File
error = ReadCatalog();
if(error != Errno.NoError) if(error != Errno.NoError)
{ {
DicConsole.DebugWriteLine("LisaFS plugin", "Cannot read root catalog, error {0}", error.ToString()); DicConsole.DebugWriteLine("LisaFS plugin", "Cannot read Catalog File, error {0}", error.ToString());
mounted = false; mounted = false;
return error; return error;
} }

View File

@@ -48,11 +48,12 @@ namespace DiscImageChef.Filesystems.LisaFS
public override Errno ListXAttr(string path, ref List<string> xattrs) public override Errno ListXAttr(string path, ref List<string> xattrs)
{ {
short fileId; short fileId;
Errno error = LookupFileId(path, out fileId); bool isDir;
Errno error = LookupFileId(path, out fileId, out isDir);
if(error != Errno.NoError) if(error != Errno.NoError)
return error; return error;
return ListXAttr(fileId, ref xattrs); return isDir ? Errno.InvalidArgument : ListXAttr(fileId, ref xattrs);
} }
/// <summary> /// <summary>
@@ -65,11 +66,12 @@ namespace DiscImageChef.Filesystems.LisaFS
public override Errno GetXattr(string path, string xattr, ref byte[] buf) public override Errno GetXattr(string path, string xattr, ref byte[] buf)
{ {
short fileId; short fileId;
Errno error = LookupFileId(path, out fileId); bool isDir;
Errno error = LookupFileId(path, out fileId, out isDir);
if(error != Errno.NoError) if(error != Errno.NoError)
return error; return error;
return GetXattr(fileId, xattr, out buf); return isDir ? Errno.InvalidArgument : GetXattr(fileId, xattr, out buf);
} }
/// <summary> /// <summary>