2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2016-08-01 00:41:02 +01:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Dir.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : Apple Macintosh File System plugin.
|
|
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-08-01 00:43:31 +01:00
|
|
|
// Methods to handle the Apple Macintosh File System directory.
|
2016-08-01 00:41:02 +01:00
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// This library is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
// published by the Free Software Foundation; either version 2.1 of the
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This library is distributed in the hope that it will be useful, but
|
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2025-08-14 02:49:52 +01:00
|
|
|
// Copyright © 2011-2025 Natalia Portillo
|
2016-08-01 00:41:02 +01:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
2016-08-01 17:59:22 +01:00
|
|
|
using System;
|
2017-12-19 19:33:46 +00:00
|
|
|
using System.Collections.Generic;
|
2017-12-21 07:08:26 +00:00
|
|
|
using System.Linq;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.CommonTypes.Structs;
|
|
|
|
|
using Aaru.Console;
|
|
|
|
|
using Aaru.Helpers;
|
2016-08-01 00:41:02 +01:00
|
|
|
|
2020-07-20 15:43:52 +01:00
|
|
|
namespace Aaru.Filesystems
|
2016-08-01 00:41:02 +01:00
|
|
|
{
|
|
|
|
|
// Information from Inside Macintosh Volume II
|
2020-07-22 13:20:25 +01:00
|
|
|
public sealed partial class AppleMFS
|
2016-08-01 00:41:02 +01:00
|
|
|
{
|
2021-08-17 13:56:05 +01:00
|
|
|
/// <inheritdoc />
|
2017-12-26 08:17:28 +00:00
|
|
|
public Errno ReadDir(string path, out List<string> contents)
|
2016-08-01 00:41:02 +01:00
|
|
|
{
|
2017-12-26 08:17:28 +00:00
|
|
|
contents = null;
|
2016-08-01 17:59:22 +01:00
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
if(!_mounted)
|
2020-02-19 03:37:51 +00:00
|
|
|
return Errno.AccessDenied;
|
|
|
|
|
|
|
|
|
|
if(!string.IsNullOrEmpty(path) &&
|
|
|
|
|
string.Compare(path, "/", StringComparison.OrdinalIgnoreCase) != 0)
|
2016-08-01 17:59:22 +01:00
|
|
|
return Errno.NotSupported;
|
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
contents = _idToFilename.Select(kvp => kvp.Value).ToList();
|
2016-08-01 17:59:22 +01:00
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
if(_debug)
|
2016-08-01 17:59:22 +01:00
|
|
|
{
|
|
|
|
|
contents.Add("$");
|
|
|
|
|
contents.Add("$Bitmap");
|
|
|
|
|
contents.Add("$MDB");
|
2020-02-19 03:37:51 +00:00
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
if(_bootBlocks != null)
|
2020-02-19 03:37:51 +00:00
|
|
|
contents.Add("$Boot");
|
2016-08-01 17:59:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contents.Sort();
|
2020-02-19 03:37:51 +00:00
|
|
|
|
2016-08-01 17:59:22 +01:00
|
|
|
return Errno.NoError;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
bool FillDirectory()
|
2016-08-01 17:59:22 +01:00
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
_idToFilename = new Dictionary<uint, string>();
|
|
|
|
|
_idToEntry = new Dictionary<uint, FileEntry>();
|
|
|
|
|
_filenameToId = new Dictionary<string, uint>();
|
2016-08-01 17:59:22 +01:00
|
|
|
|
|
|
|
|
int offset = 0;
|
2020-02-19 03:37:51 +00:00
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
while(offset + 51 < _directoryBlocks.Length)
|
2016-08-01 17:59:22 +01:00
|
|
|
{
|
2020-02-19 03:44:44 +00:00
|
|
|
var entry = new FileEntry
|
2017-12-22 08:43:22 +00:00
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
flFlags = (FileFlags)_directoryBlocks[offset + 0]
|
2017-12-22 08:43:22 +00:00
|
|
|
};
|
2016-08-01 17:59:22 +01:00
|
|
|
|
2020-02-19 03:44:44 +00:00
|
|
|
if(!entry.flFlags.HasFlag(FileFlags.Used))
|
2020-02-19 03:37:51 +00:00
|
|
|
break;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
entry.flTyp = _directoryBlocks[offset + 1];
|
2020-02-19 03:37:51 +00:00
|
|
|
|
|
|
|
|
entry.flUsrWds =
|
2020-07-20 21:11:32 +01:00
|
|
|
Marshal.ByteArrayToStructureBigEndian<AppleCommon.FInfo>(_directoryBlocks, offset + 2, 16);
|
|
|
|
|
|
|
|
|
|
entry.flFlNum = BigEndianBitConverter.ToUInt32(_directoryBlocks, offset + 18);
|
|
|
|
|
entry.flStBlk = BigEndianBitConverter.ToUInt16(_directoryBlocks, offset + 22);
|
|
|
|
|
entry.flLgLen = BigEndianBitConverter.ToUInt32(_directoryBlocks, offset + 24);
|
|
|
|
|
entry.flPyLen = BigEndianBitConverter.ToUInt32(_directoryBlocks, offset + 28);
|
|
|
|
|
entry.flRStBlk = BigEndianBitConverter.ToUInt16(_directoryBlocks, offset + 32);
|
|
|
|
|
entry.flRLgLen = BigEndianBitConverter.ToUInt32(_directoryBlocks, offset + 34);
|
|
|
|
|
entry.flRPyLen = BigEndianBitConverter.ToUInt32(_directoryBlocks, offset + 38);
|
|
|
|
|
entry.flCrDat = BigEndianBitConverter.ToUInt32(_directoryBlocks, offset + 42);
|
|
|
|
|
entry.flMdDat = BigEndianBitConverter.ToUInt32(_directoryBlocks, offset + 46);
|
|
|
|
|
entry.flNam = new byte[_directoryBlocks[offset + 50] + 1];
|
|
|
|
|
Array.Copy(_directoryBlocks, offset + 50, entry.flNam, 0, entry.flNam.Length);
|
2016-08-01 17:59:22 +01:00
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
string lowerFilename = StringHandlers.PascalToString(entry.flNam, Encoding).ToLowerInvariant().
|
|
|
|
|
Replace('/', ':');
|
2020-02-19 03:37:51 +00:00
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
if(entry.flFlags.HasFlag(FileFlags.Used) &&
|
|
|
|
|
!_idToFilename.ContainsKey(entry.flFlNum) &&
|
|
|
|
|
!_idToEntry.ContainsKey(entry.flFlNum) &&
|
|
|
|
|
!_filenameToId.ContainsKey(lowerFilename) &&
|
2016-08-01 17:59:22 +01:00
|
|
|
entry.flFlNum > 0)
|
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
_idToEntry.Add(entry.flFlNum, entry);
|
2020-02-19 03:37:51 +00:00
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
_idToFilename.Add(entry.flFlNum,
|
|
|
|
|
StringHandlers.PascalToString(entry.flNam, Encoding).Replace('/', ':'));
|
2020-02-19 03:37:51 +00:00
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
_filenameToId.Add(lowerFilename, entry.flFlNum);
|
2016-08-01 17:59:22 +01:00
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
AaruConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flFlags = {0}", entry.flFlags);
|
|
|
|
|
AaruConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flTyp = {0}", entry.flTyp);
|
|
|
|
|
AaruConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flFlNum = {0}", entry.flFlNum);
|
|
|
|
|
AaruConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flStBlk = {0}", entry.flStBlk);
|
|
|
|
|
AaruConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flLgLen = {0}", entry.flLgLen);
|
|
|
|
|
AaruConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flPyLen = {0}", entry.flPyLen);
|
|
|
|
|
AaruConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flRStBlk = {0}", entry.flRStBlk);
|
|
|
|
|
AaruConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flRLgLen = {0}", entry.flRLgLen);
|
|
|
|
|
AaruConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flRPyLen = {0}", entry.flRPyLen);
|
|
|
|
|
|
|
|
|
|
AaruConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flCrDat = {0}",
|
2020-02-29 18:03:35 +00:00
|
|
|
DateHandlers.MacToDateTime(entry.flCrDat));
|
2020-02-19 03:37:51 +00:00
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
AaruConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flMdDat = {0}",
|
2020-02-29 18:03:35 +00:00
|
|
|
DateHandlers.MacToDateTime(entry.flMdDat));
|
2020-02-19 03:37:51 +00:00
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
AaruConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flNam0 = {0}",
|
2020-02-29 18:03:35 +00:00
|
|
|
StringHandlers.PascalToString(entry.flNam, Encoding));
|
2016-08-01 17:59:22 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:26:28 +00:00
|
|
|
offset += 50 + entry.flNam.Length;
|
2016-08-01 18:52:34 +01:00
|
|
|
|
|
|
|
|
// "Entries are always an integral number of words"
|
2020-02-19 03:37:51 +00:00
|
|
|
if(offset % 2 != 0)
|
|
|
|
|
offset++;
|
2016-08-01 18:52:34 +01:00
|
|
|
|
|
|
|
|
// TODO: "Entries don't cross logical block boundaries"
|
2016-08-01 17:59:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2016-08-01 00:41:02 +01:00
|
|
|
}
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|