2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2016-08-01 00:41:02 +01:00
|
|
|
|
// Filename : Info.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2016-08-01 00:41:02 +01:00
|
|
|
|
// Component : Apple Macintosh File System plugin.
|
2016-07-28 18:13:49 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Identifies the Apple Macintosh File System and shows information.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-01-03 17:51:30 +00:00
|
|
|
|
// Copyright © 2011-2020 Natalia Portillo
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// ****************************************************************************/
|
2014-04-17 19:58:14 +00:00
|
|
|
|
|
2011-03-03 18:34:33 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Text;
|
2017-12-28 05:52:39 +00:00
|
|
|
|
using Claunia.Encoding;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes;
|
|
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using Schemas;
|
2017-12-28 05:52:39 +00:00
|
|
|
|
using Encoding = System.Text.Encoding;
|
2011-03-03 18:34:33 +00:00
|
|
|
|
|
2020-02-27 00:33:26 +00:00
|
|
|
|
namespace Aaru.Filesystems.AppleMFS
|
2011-03-03 18:34:33 +00:00
|
|
|
|
{
|
2016-08-01 00:41:02 +01:00
|
|
|
|
// Information from Inside Macintosh Volume II
|
2017-12-21 16:27:09 +00:00
|
|
|
|
public partial class AppleMFS
|
2014-04-14 02:29:13 +00:00
|
|
|
|
{
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
2014-04-14 02:29:13 +00:00
|
|
|
|
{
|
2020-02-18 23:52:30 +00:00
|
|
|
|
if(2 + partition.Start >= partition.End)
|
|
|
|
|
|
return false;
|
2014-07-09 19:49:14 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
byte[] mdbSector = imagePlugin.ReadSector(2 + partition.Start);
|
2014-04-14 02:29:13 +00:00
|
|
|
|
|
2018-06-20 22:22:21 +01:00
|
|
|
|
ushort drSigWord = BigEndianBitConverter.ToUInt16(mdbSector, 0x000);
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
|
return drSigWord == MFS_MAGIC;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
|
2020-02-18 23:52:30 +00:00
|
|
|
|
Encoding encoding)
|
2014-04-14 02:29:13 +00:00
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
Encoding = encoding ?? new MacRoman();
|
2014-04-14 02:29:13 +00:00
|
|
|
|
information = "";
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2020-02-18 23:52:30 +00:00
|
|
|
|
var sb = new StringBuilder();
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2020-02-19 03:44:44 +00:00
|
|
|
|
var mdb = new MasterDirectoryBlock();
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
|
byte[] pString = new byte[16];
|
|
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
byte[] mdbSector = imagePlugin.ReadSector(2 + partition.Start);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
byte[] bbSector = imagePlugin.ReadSector(0 + partition.Start);
|
2012-08-05 00:43:49 +00:00
|
|
|
|
|
2018-06-20 22:22:21 +01:00
|
|
|
|
mdb.drSigWord = BigEndianBitConverter.ToUInt16(mdbSector, 0x000);
|
2020-02-18 23:52:30 +00:00
|
|
|
|
|
|
|
|
|
|
if(mdb.drSigWord != MFS_MAGIC)
|
|
|
|
|
|
return;
|
2018-06-20 22:22:21 +01:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
mdb.drCrDate = BigEndianBitConverter.ToUInt32(mdbSector, 0x002);
|
|
|
|
|
|
mdb.drLsBkUp = BigEndianBitConverter.ToUInt32(mdbSector, 0x006);
|
2020-02-19 01:57:39 +00:00
|
|
|
|
mdb.drAtrb = (AppleCommon.VolumeAttributes)BigEndianBitConverter.ToUInt16(mdbSector, 0x00A);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
mdb.drNmFls = BigEndianBitConverter.ToUInt16(mdbSector, 0x00C);
|
|
|
|
|
|
mdb.drDirSt = BigEndianBitConverter.ToUInt16(mdbSector, 0x00E);
|
|
|
|
|
|
mdb.drBlLen = BigEndianBitConverter.ToUInt16(mdbSector, 0x010);
|
2018-06-20 22:22:21 +01:00
|
|
|
|
mdb.drNmAlBlks = BigEndianBitConverter.ToUInt16(mdbSector, 0x012);
|
|
|
|
|
|
mdb.drAlBlkSiz = BigEndianBitConverter.ToUInt32(mdbSector, 0x014);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
mdb.drClpSiz = BigEndianBitConverter.ToUInt32(mdbSector, 0x018);
|
|
|
|
|
|
mdb.drAlBlSt = BigEndianBitConverter.ToUInt16(mdbSector, 0x01C);
|
|
|
|
|
|
mdb.drNxtFNum = BigEndianBitConverter.ToUInt32(mdbSector, 0x01E);
|
|
|
|
|
|
mdb.drFreeBks = BigEndianBitConverter.ToUInt16(mdbSector, 0x022);
|
|
|
|
|
|
mdb.drVNSiz = mdbSector[0x024];
|
2018-06-20 22:22:21 +01:00
|
|
|
|
byte[] variableSize = new byte[mdb.drVNSiz + 1];
|
|
|
|
|
|
Array.Copy(mdbSector, 0x024, variableSize, 0, mdb.drVNSiz + 1);
|
|
|
|
|
|
mdb.drVN = StringHandlers.PascalToString(variableSize, Encoding);
|
|
|
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
|
sb.AppendLine("Apple Macintosh File System");
|
|
|
|
|
|
sb.AppendLine();
|
|
|
|
|
|
sb.AppendLine("Master Directory Block:");
|
2018-06-20 22:22:21 +01:00
|
|
|
|
sb.AppendFormat("Creation date: {0}", DateHandlers.MacToDateTime(mdb.drCrDate)).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Last backup date: {0}", DateHandlers.MacToDateTime(mdb.drLsBkUp)).AppendLine();
|
2020-02-18 23:52:30 +00:00
|
|
|
|
|
2020-02-19 01:57:39 +00:00
|
|
|
|
if(mdb.drAtrb.HasFlag(AppleCommon.VolumeAttributes.HardwareLock))
|
2020-02-18 23:52:30 +00:00
|
|
|
|
sb.AppendLine("Volume is locked by hardware.");
|
|
|
|
|
|
|
2020-02-19 01:57:39 +00:00
|
|
|
|
sb.AppendLine(mdb.drAtrb.HasFlag(AppleCommon.VolumeAttributes.Unmounted) ? "Volume was unmonted."
|
|
|
|
|
|
: "Volume is mounted.");
|
|
|
|
|
|
|
|
|
|
|
|
if(mdb.drAtrb.HasFlag(AppleCommon.VolumeAttributes.SparedBadBlocks))
|
|
|
|
|
|
sb.AppendLine("Volume has spared bad blocks.");
|
|
|
|
|
|
|
|
|
|
|
|
if(mdb.drAtrb.HasFlag(AppleCommon.VolumeAttributes.DoesNotNeedCache))
|
|
|
|
|
|
sb.AppendLine("Volume does not need cache.");
|
|
|
|
|
|
|
|
|
|
|
|
if(mdb.drAtrb.HasFlag(AppleCommon.VolumeAttributes.BootInconsistent))
|
|
|
|
|
|
sb.AppendLine("Boot volume is inconsistent.");
|
|
|
|
|
|
|
|
|
|
|
|
if(mdb.drAtrb.HasFlag(AppleCommon.VolumeAttributes.ReusedIds))
|
|
|
|
|
|
sb.AppendLine("There are reused CNIDs.");
|
|
|
|
|
|
|
|
|
|
|
|
if(mdb.drAtrb.HasFlag(AppleCommon.VolumeAttributes.Inconsistent))
|
|
|
|
|
|
sb.AppendLine("Volume is seriously inconsistent.");
|
|
|
|
|
|
|
|
|
|
|
|
if(mdb.drAtrb.HasFlag(AppleCommon.VolumeAttributes.SoftwareLock))
|
2020-02-18 23:52:30 +00:00
|
|
|
|
sb.AppendLine("Volume is locked by software.");
|
|
|
|
|
|
|
2018-06-20 22:22:21 +01:00
|
|
|
|
sb.AppendFormat("{0} files on volume", mdb.drNmFls).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("First directory sector: {0}", mdb.drDirSt).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("{0} sectors in directory.", mdb.drBlLen).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("{0} volume allocation blocks.", mdb.drNmAlBlks + 1).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Size of allocation blocks: {0} bytes", mdb.drAlBlkSiz).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("{0} bytes to allocate.", mdb.drClpSiz).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("First allocation block (#2) starts in sector {0}.", mdb.drAlBlSt).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Next unused file number: {0}", mdb.drNxtFNum).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("{0} unused allocation blocks.", mdb.drFreeBks).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Volume name: {0}", mdb.drVN).AppendLine();
|
|
|
|
|
|
|
2020-02-19 00:12:15 +00:00
|
|
|
|
string bootBlockInfo = AppleCommon.GetBootBlockInformation(bbSector, Encoding);
|
|
|
|
|
|
|
|
|
|
|
|
if(bootBlockInfo != null)
|
2014-04-14 02:29:13 +00:00
|
|
|
|
{
|
|
|
|
|
|
sb.AppendLine("Volume is bootable.");
|
|
|
|
|
|
sb.AppendLine();
|
2020-02-19 00:12:15 +00:00
|
|
|
|
sb.AppendLine(bootBlockInfo);
|
2014-04-14 02:29:13 +00:00
|
|
|
|
}
|
2020-02-18 23:52:30 +00:00
|
|
|
|
else
|
|
|
|
|
|
sb.AppendLine("Volume is not bootable.");
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
|
information = sb.ToString();
|
2015-12-05 17:10:27 +00:00
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType = new FileSystemType();
|
2020-02-18 23:52:30 +00:00
|
|
|
|
|
2018-06-20 22:22:21 +01:00
|
|
|
|
if(mdb.drLsBkUp > 0)
|
2015-12-06 05:09:31 +00:00
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
XmlFsType.BackupDate = DateHandlers.MacToDateTime(mdb.drLsBkUp);
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.BackupDateSpecified = true;
|
2015-12-06 05:09:31 +00:00
|
|
|
|
}
|
2018-06-22 08:08:38 +01:00
|
|
|
|
|
2020-02-19 00:12:15 +00:00
|
|
|
|
XmlFsType.Bootable = bootBlockInfo != null;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
XmlFsType.Clusters = mdb.drNmAlBlks;
|
2019-04-23 01:38:33 +01:00
|
|
|
|
XmlFsType.ClusterSize = mdb.drAlBlkSiz;
|
2020-02-18 23:52:30 +00:00
|
|
|
|
|
2018-06-20 22:22:21 +01:00
|
|
|
|
if(mdb.drCrDate > 0)
|
2015-12-06 05:09:31 +00:00
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
XmlFsType.CreationDate = DateHandlers.MacToDateTime(mdb.drCrDate);
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.CreationDateSpecified = true;
|
2015-12-06 05:09:31 +00:00
|
|
|
|
}
|
2018-06-22 08:08:38 +01:00
|
|
|
|
|
|
|
|
|
|
XmlFsType.Files = mdb.drNmFls;
|
|
|
|
|
|
XmlFsType.FilesSpecified = true;
|
|
|
|
|
|
XmlFsType.FreeClusters = mdb.drFreeBks;
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.FreeClustersSpecified = true;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
XmlFsType.Type = "MFS";
|
|
|
|
|
|
XmlFsType.VolumeName = mdb.drVN;
|
2014-04-14 02:29:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|