mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Added support for subcatalogs.
This commit is contained in:
@@ -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>
|
||||
|
||||
* DiscImageChef.Filesystems.csproj: Bump to version 3.1.0.
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
/// </summary>
|
||||
const ushort FILEID_SRECORD = 0x0003;
|
||||
/// <summary>The root catalog</summary>
|
||||
const ushort FILEID_ROOTCATALOG = 0x0004;
|
||||
const ushort FILEID_CATALOG = 0x0004;
|
||||
const short FILEID_BOOT_SIGNED = -21846;
|
||||
const short FILEID_LOADER_SIGNED = -17477;
|
||||
/// <summary>
|
||||
@@ -89,6 +89,9 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
const ushort FILEID_ERASED = 0x7FFF;
|
||||
const ushort FILEID_MAX = FILEID_ERASED;
|
||||
|
||||
/// <summary>Root directory ID</summary>
|
||||
const short DIRID_ROOT = 0;
|
||||
|
||||
enum FileType : byte
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -65,17 +65,16 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
if(!isDir)
|
||||
return Errno.NotDirectory;
|
||||
|
||||
List<CatalogEntry> catalog;
|
||||
ReadCatalog(fileId, out catalog);
|
||||
/*List<CatalogEntry> catalog;
|
||||
error = ReadCatalog(fileId, out catalog);
|
||||
if(error != Errno.NoError)
|
||||
return error;*/
|
||||
|
||||
// Do same trick as Mac OS X, replace filesystem '/' with ':'
|
||||
// Maybe as ':' is the path separator in Lisa OS I should do that
|
||||
foreach(CatalogEntry entry in catalog)
|
||||
contents.Add(GetString(entry.filename).Replace('/', ':'));
|
||||
ReadDir(fileId, ref contents);
|
||||
|
||||
// On debug add system files as readable files
|
||||
// Syntax similar to NTFS
|
||||
if(debug && fileId == FILEID_ROOTCATALOG)
|
||||
if(debug && fileId == DIRID_ROOT)
|
||||
{
|
||||
contents.Add("$MDDF");
|
||||
contents.Add("$Boot");
|
||||
@@ -89,41 +88,37 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
Errno ReadDir(short dirId, ref List<string> contents)
|
||||
{
|
||||
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)
|
||||
return Errno.AccessDenied;
|
||||
|
||||
if(fileId < 4)
|
||||
return Errno.InvalidArgument;
|
||||
|
||||
if(catalogCache.TryGetValue(fileId, out catalog))
|
||||
return Errno.NoError;
|
||||
catalogCache = new List<CatalogEntry>();
|
||||
|
||||
Errno error;
|
||||
|
||||
// Do differently for V1 and V2
|
||||
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;
|
||||
error = ReadFile(4, out buf);
|
||||
error = ReadFile((short)FILEID_CATALOG, out buf);
|
||||
|
||||
int offset = 0;
|
||||
List<CatalogEntryV2> catalogV2 = new List<CatalogEntryV2>();
|
||||
@@ -149,8 +144,6 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
catalogV2.Add(entV2);
|
||||
}
|
||||
|
||||
catalog = new List<CatalogEntry>();
|
||||
|
||||
// Convert entries to V3 format
|
||||
foreach(CatalogEntryV2 entV2 in catalogV2)
|
||||
{
|
||||
@@ -167,11 +160,10 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
entV3.dtc = ext.dtc;
|
||||
entV3.dtm = ext.dtm;
|
||||
|
||||
catalog.Add(entV3);
|
||||
catalogCache.Add(entV3);
|
||||
}
|
||||
}
|
||||
|
||||
catalogCache.Add(fileId, catalog);
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
@@ -185,15 +177,11 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
Tag 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);
|
||||
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
|
||||
@@ -209,7 +197,7 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
Tag 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;
|
||||
|
||||
firstCatalogBlock = device.ReadSectors(prevCatalogPointer + mddf.mddf_block + volumePrefix, 4);
|
||||
@@ -228,7 +216,7 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
Tag 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;
|
||||
|
||||
byte[] nextCatalogBlock = device.ReadSectors(nextCatalogPointer + mddf.mddf_block + volumePrefix, 4);
|
||||
@@ -236,8 +224,6 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
catalogBlocks.Add(nextCatalogBlock);
|
||||
}
|
||||
|
||||
catalog = new List<CatalogEntry>();
|
||||
|
||||
// Foreach catalog block
|
||||
foreach(byte[] buf in catalogBlocks)
|
||||
{
|
||||
@@ -260,7 +246,7 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
{
|
||||
CatalogEntry entry = new CatalogEntry();
|
||||
entry.marker = buf[offset];
|
||||
entry.zero = BigEndianBitConverter.ToUInt16(buf, offset + 0x01);
|
||||
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];
|
||||
@@ -274,27 +260,75 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
entry.tail = new byte[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;
|
||||
if(ReadExtentsFile(entry.fileID, out ext) == Errno.NoError)
|
||||
{
|
||||
if(!fileSizeCache.ContainsKey(entry.fileID))
|
||||
{
|
||||
catalog.Add(entry);
|
||||
catalogCache.Add(entry);
|
||||
fileSizeCache.Add(entry.fileID, entry.length);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,11 +42,18 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
public override Errno GetAttributes(string path, ref FileAttributes attributes)
|
||||
{
|
||||
short fileId;
|
||||
Errno error = LookupFileId(path, out fileId);
|
||||
bool isDir;
|
||||
Errno error = LookupFileId(path, out fileId, out isDir);
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
if(!isDir)
|
||||
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)
|
||||
@@ -76,7 +83,7 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
case (short)FILEID_MDDF:
|
||||
case (short)FILEID_BITMAP:
|
||||
case (short)FILEID_SRECORD:
|
||||
case (short)FILEID_ROOTCATALOG:
|
||||
case (short)FILEID_CATALOG:
|
||||
error = ReadSystemFile(fileId, out tmp);
|
||||
break;
|
||||
default:
|
||||
@@ -104,11 +111,12 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
public override Errno Stat(string path, ref FileEntryInfo stat)
|
||||
{
|
||||
short fileId;
|
||||
Errno error = LookupFileId(path, out fileId);
|
||||
bool isDir;
|
||||
Errno error = LookupFileId(path, out fileId, out isDir);
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
return Stat(fileId, out stat);
|
||||
return isDir ? StatDir(fileId, out stat) : Stat(fileId, out stat);
|
||||
}
|
||||
|
||||
Errno GetAttributes(short fileId, ref FileAttributes attributes)
|
||||
@@ -116,24 +124,19 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
if(!mounted)
|
||||
return Errno.AccessDenied;
|
||||
|
||||
if(fileId <= 4)
|
||||
if(fileId < 4)
|
||||
{
|
||||
if(!debug || fileId == 0)
|
||||
if(!debug)
|
||||
return Errno.NoSuchFile;
|
||||
else
|
||||
{
|
||||
|
||||
attributes = new FileAttributes();
|
||||
attributes = FileAttributes.System;
|
||||
attributes |= FileAttributes.Hidden;
|
||||
|
||||
if(fileId == 4)
|
||||
attributes |= FileAttributes.Directory;
|
||||
else
|
||||
attributes |= FileAttributes.File;
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
}
|
||||
|
||||
ExtentFile extFile;
|
||||
Errno error = ReadExtentsFile(fileId, out extFile);
|
||||
@@ -159,7 +162,6 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
break;
|
||||
default:
|
||||
attributes |= FileAttributes.File;
|
||||
// Subcatalogs use extents?
|
||||
attributes |= FileAttributes.Extents;
|
||||
break;
|
||||
}
|
||||
@@ -435,12 +437,6 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
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)
|
||||
{
|
||||
fileId = 0;
|
||||
@@ -453,16 +449,16 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
|
||||
if(pathElements.Length == 0)
|
||||
{
|
||||
fileId = (short)FILEID_ROOTCATALOG;
|
||||
fileId = DIRID_ROOT;
|
||||
isDir = true;
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
// TODO: Subcatalogs
|
||||
if(pathElements.Length > 1)
|
||||
return Errno.NotImplemented;
|
||||
// Only V3 supports subdirectories
|
||||
if(pathElements.Length > 1 && mddf.fsversion != LisaFSv3)
|
||||
return Errno.NotSupported;
|
||||
|
||||
if(debug)
|
||||
if(debug && pathElements.Length == 1)
|
||||
{
|
||||
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)
|
||||
{
|
||||
fileId = (short)FILEID_ROOTCATALOG;
|
||||
fileId = DIRID_ROOT;
|
||||
isDir = true;
|
||||
return Errno.NoError;
|
||||
}
|
||||
}
|
||||
|
||||
List<CatalogEntry> catalog;
|
||||
|
||||
Errno error = ReadCatalog((short)FILEID_ROOTCATALOG, out catalog);
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
for(int lvl = 0; lvl < pathElements.Length; lvl++)
|
||||
{
|
||||
string wantedFilename = pathElements[0].Replace(':', '/');
|
||||
|
||||
foreach(CatalogEntry entry in catalog)
|
||||
foreach(CatalogEntry entry in catalogCache)
|
||||
{
|
||||
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;
|
||||
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.NoSuchFile;
|
||||
}
|
||||
|
||||
@@ -58,11 +58,13 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
/// <summary>Caches user files files</summary>
|
||||
Dictionary<short, byte[]> fileCache;
|
||||
/// <summary>Caches catalogs</summary>
|
||||
Dictionary<short, List<CatalogEntry>> catalogCache;
|
||||
List<CatalogEntry> catalogCache;
|
||||
/// <summary>Caches file size</summary>
|
||||
Dictionary<short, int> fileSizeCache;
|
||||
/// <summary>Lists Extents Files already printed in debug mode to not repeat them</summary>
|
||||
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
|
||||
|
||||
public LisaFS()
|
||||
|
||||
@@ -259,14 +259,15 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
{
|
||||
/// <summary>0x00, seems to be 0x24 when the entry is valid</summary>
|
||||
public byte marker;
|
||||
/// <summary>0x01, must be zero otherwise LisaOS gives an error</summary>
|
||||
public ushort zero;
|
||||
/// <summary>0x01, parent directory ID for this file, 0 for root directory</summary>
|
||||
public ushort parentID;
|
||||
/// <summary>0x03, filename, 32-bytes, null-padded</summary>
|
||||
public byte[] filename;
|
||||
/// <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...
|
||||
|
||||
@@ -213,7 +213,7 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
extentCache = new Dictionary<short, ExtentFile>();
|
||||
systemFileCache = 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>();
|
||||
|
||||
Errno error;
|
||||
@@ -234,13 +234,15 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
return error;
|
||||
}
|
||||
|
||||
// Read the root catalog
|
||||
List<CatalogEntry> tempCat;
|
||||
error = ReadCatalog((short)FILEID_ROOTCATALOG, out tempCat);
|
||||
directoryDTCCache = new Dictionary<short, DateTime>();
|
||||
directoryDTCCache.Add(DIRID_ROOT, mddf.dtcc);
|
||||
|
||||
// Read the Catalog File
|
||||
error = ReadCatalog();
|
||||
|
||||
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;
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -48,11 +48,12 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
public override Errno ListXAttr(string path, ref List<string> xattrs)
|
||||
{
|
||||
short fileId;
|
||||
Errno error = LookupFileId(path, out fileId);
|
||||
bool isDir;
|
||||
Errno error = LookupFileId(path, out fileId, out isDir);
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
return ListXAttr(fileId, ref xattrs);
|
||||
return isDir ? Errno.InvalidArgument : ListXAttr(fileId, ref xattrs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -65,11 +66,12 @@ namespace DiscImageChef.Filesystems.LisaFS
|
||||
public override Errno GetXattr(string path, string xattr, ref byte[] buf)
|
||||
{
|
||||
short fileId;
|
||||
Errno error = LookupFileId(path, out fileId);
|
||||
bool isDir;
|
||||
Errno error = LookupFileId(path, out fileId, out isDir);
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
return GetXattr(fileId, xattr, out buf);
|
||||
return isDir ? Errno.InvalidArgument : GetXattr(fileId, xattr, out buf);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user