diff --git a/DiscImageChef/ChangeLog b/DiscImageChef/ChangeLog index bd0e6625..07091d05 100644 --- a/DiscImageChef/ChangeLog +++ b/DiscImageChef/ChangeLog @@ -1,3 +1,10 @@ +2015-04-20 Natalia Portillo + + * DateHandlers.cs: + * Plugins/AmigaDOS.cs: + * DiscImageChef.csproj: + Added support for AmigaDOS filesystems. + 2015-04-20 Natalia Portillo * PartPlugins/RDB.cs: diff --git a/DiscImageChef/DateHandlers.cs b/DiscImageChef/DateHandlers.cs index 8a8db44b..b186b9d3 100644 --- a/DiscImageChef/DateHandlers.cs +++ b/DiscImageChef/DateHandlers.cs @@ -47,6 +47,7 @@ namespace DiscImageChef static readonly DateTime UNIXEpoch = new DateTime(1970, 1, 1, 0, 0, 0); // Day 0 of Julian Date system static readonly DateTime JulianEpoch = new DateTime(1858, 11, 17, 0, 0, 0); + static readonly DateTime AmigaEpoch = new DateTime(1978, 1, 1, 0, 0, 0); public static DateTime MacToDateTime(ulong MacTimeStamp) { @@ -145,6 +146,13 @@ namespace DiscImageChef double delta = vmsDate * 0.0001; // Tenths of microseconds to milliseconds, will lose some detail return JulianEpoch.AddMilliseconds(delta); } + + public static DateTime AmigaToDateTime(UInt32 days, UInt32 minutes, UInt32 ticks) + { + DateTime temp = AmigaEpoch.AddDays(days); + temp = temp.AddMinutes(minutes); + return temp.AddMilliseconds(ticks * 20); + } } } diff --git a/DiscImageChef/DiscImageChef.csproj b/DiscImageChef/DiscImageChef.csproj index ff609baa..723219c4 100644 --- a/DiscImageChef/DiscImageChef.csproj +++ b/DiscImageChef/DiscImageChef.csproj @@ -111,6 +111,7 @@ + diff --git a/DiscImageChef/Plugins/AmigaDOS.cs b/DiscImageChef/Plugins/AmigaDOS.cs new file mode 100644 index 00000000..58ae6498 --- /dev/null +++ b/DiscImageChef/Plugins/AmigaDOS.cs @@ -0,0 +1,364 @@ +/*************************************************************************** +The Disc Image Chef +---------------------------------------------------------------------------- + +Filename : AmigaDOS.cs +Version : 1.0 +Author(s) : Natalia Portillo + +Component : Filesystem plugins + +Revision : $Revision$ +Last change by : $Author$ +Date : $Date$ + +--[ Description ] ---------------------------------------------------------- + +Identifies PC-Engine CDs. + +--[ License ] -------------------------------------------------------------- + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +---------------------------------------------------------------------------- +Copyright (C) 2011-2014 Claunia.com +****************************************************************************/ +//$Id$ + +using System; +using System.Text; +using DiscImageChef; +using DiscImageChef.PartPlugins; +using System.Collections.Generic; + +namespace DiscImageChef.Plugins +{ + class AmigaDOSPlugin : Plugin + { + public AmigaDOSPlugin(PluginBase Core) + { + Name = "Amiga DOS filesystem"; + PluginUUID = new Guid("3c882400-208c-427d-a086-9119852a1bc7"); + } + + /// + /// Boot block, first 2 sectors + /// + struct BootBlock + { + /// + /// Offset 0x00, "DOSx" disk type + /// + public UInt32 diskType; + /// + /// Offset 0x04, Checksum + /// + public UInt32 checksum; + /// + /// Offset 0x08, Pointer to root block, mostly invalid + /// + public UInt32 root_ptr; + /// + /// Offset 0x0C, Boot code, til completion + /// + public byte[] bootCode; + } + + struct RootBlock + { + /// + /// Offset 0x00, block type, value = T_HEADER (2) + /// + public UInt32 type; + /// + /// Offset 0x04, unused + /// + public UInt32 headerKey; + /// + /// Offset 0x08, unused + /// + public UInt32 highSeq; + /// + /// Offset 0x0C, longs used by hash table + /// + public UInt32 hashTableSize; + /// + /// Offset 0x10, unused + /// + public UInt32 firstData; + /// + /// Offset 0x14, Rootblock checksum + /// + public UInt32 checksum; + /// + /// Offset 0x18, Hashtable, size = (block size / 4) - 56 or size = hashTableSize + /// + public UInt32[] hashTable; + /// + /// Offset 0x18+hashTableSize*4+0, bitmap flag, 0xFFFFFFFF if valid + /// + public UInt32 bitmapFlag; + /// + /// Offset 0x18+hashTableSize*4+4, bitmap pages, 25 entries + /// + public UInt32[] bitmapPages; + /// + /// Offset 0x18+hashTableSize*4+104, pointer to bitmap extension block + /// + public UInt32 bitmapExtensionBlock; + /// + /// Offset 0x18+hashTableSize*4+108, last root alteration days since 1978/01/01 + /// + public UInt32 rDays; + /// + /// Offset 0x18+hashTableSize*4+112, last root alteration minutes past midnight + /// + public UInt32 rMins; + /// + /// Offset 0x18+hashTableSize*4+116, last root alteration ticks (1/50 secs) + /// + public UInt32 rTicks; + /// + /// Offset 0x18+hashTableSize*4+120, disk name, pascal string, 32 bytes + /// + public string diskName; + /// + /// Offset 0x18+hashTableSize*4+152, unused + /// + public UInt32 reserved1; + /// + /// Offset 0x18+hashTableSize*4+156, unused + /// + public UInt32 reserved2; + /// + /// Offset 0x18+hashTableSize*4+160, last disk alteration days since 1978/01/01 + /// + public UInt32 vDays; + /// + /// Offset 0x18+hashTableSize*4+164, last disk alteration minutes past midnight + /// + public UInt32 vMins; + /// + /// Offset 0x18+hashTableSize*4+168, last disk alteration ticks (1/50 secs) + /// + public UInt32 vTicks; + /// + /// Offset 0x18+hashTableSize*4+172, filesystem creation days since 1978/01/01 + /// + public UInt32 cDays; + /// + /// Offset 0x18+hashTableSize*4+176, filesystem creation minutes since 1978/01/01 + /// + public UInt32 cMins; + /// + /// Offset 0x18+hashTableSize*4+180, filesystem creation ticks since 1978/01/01 + /// + public UInt32 cTicks; + /// + /// Offset 0x18+hashTableSize*4+184, unused + /// + public UInt32 nextHash; + /// + /// Offset 0x18+hashTableSize*4+188, unused + /// + public UInt32 parentDir; + /// + /// Offset 0x18+hashTableSize*4+192, first directory cache block + /// + public UInt32 extension; + /// + /// Offset 0x18+hashTableSize*4+196, block secondary type = ST_ROOT (1) + /// + public UInt32 sec_type; + } + + public override bool Identify(ImagePlugins.ImagePlugin imagePlugin, ulong partitionStart, ulong partitionEnd) + { + if (partitionStart >= imagePlugin.GetSectors()) + return false; + + BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; + + byte[] sector = imagePlugin.ReadSector(0 + partitionStart); + + UInt32 magic = BigEndianBitConverter.ToUInt32(sector, 0x00); + + if ((magic & 0x6D754600) != 0x6D754600 && + (magic & 0x444F5300) != 0x444F5300) + return false; + + ulong root_ptr = BigEndianBitConverter.ToUInt32(sector, 0x08); + if (MainClass.isDebug) + Console.WriteLine("DEBUG (AmigaDOS plugin): Bootblock points to {0} as Rootblock", root_ptr); + + root_ptr = (partitionEnd - partitionStart) / 2 + partitionStart; + + if (MainClass.isDebug) + Console.WriteLine("DEBUG (AmigaDOS plugin): Nonetheless, going to block {0} for Rootblock", root_ptr); + + if (root_ptr >= imagePlugin.GetSectors()) + return false; + + sector = imagePlugin.ReadSector(root_ptr); + + UInt32 type = BigEndianBitConverter.ToUInt32(sector, 0x00); + UInt32 hashTableSize = BigEndianBitConverter.ToUInt32(sector, 0x0C); + + if ((0x18 + hashTableSize * 4 + 196) > sector.Length) + return false; + + UInt32 sec_type = BigEndianBitConverter.ToUInt32(sector, (int)(0x18 + hashTableSize * 4 + 196)); + + return type == 2 && sec_type == 1; + } + + public override void GetInformation(ImagePlugins.ImagePlugin imagePlugin, ulong partitionStart, ulong partitionEnd, out string information) + { + StringBuilder sbInformation = new StringBuilder(); + + byte[] BootBlockSectors = imagePlugin.ReadSectors(0 + partitionStart, 2); + byte[] RootBlockSector = imagePlugin.ReadSector((partitionEnd - partitionStart) / 2 + partitionStart); + byte[] diskName = new byte[32]; + + BootBlock bootBlk = new BootBlock(); + RootBlock rootBlk = new RootBlock(); + + BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; + + bootBlk.diskType = BigEndianBitConverter.ToUInt32(BootBlockSectors, 0x00); + bootBlk.checksum = BigEndianBitConverter.ToUInt32(BootBlockSectors, 0x04); + bootBlk.root_ptr = BigEndianBitConverter.ToUInt32(BootBlockSectors, 0x08); + bootBlk.bootCode = new byte[BootBlockSectors.Length - 0x0C]; + Array.Copy(BootBlockSectors, 0x0C, bootBlk.bootCode, 0, BootBlockSectors.Length - 0x0C); + + if (MainClass.isDebug) + { + Console.WriteLine("DEBUG (AmigaDOS plugin): Stored boot blocks checksum is 0x{0:X8}", bootBlk.checksum); + Console.WriteLine("DEBUG (AmigaDOS plugin): Probably incorrect calculated boot blocks checksum is 0x{0:X8}", AmigaChecksum(RootBlockSector)); + Checksums.SHA1Context sha1Ctx = new Checksums.SHA1Context(); + sha1Ctx.Init(); + sha1Ctx.Update(bootBlk.bootCode); + Console.WriteLine("DEBUG (AmigaDOS plugin): Boot code SHA1 is {0}", sha1Ctx.End()); + } + + rootBlk.type = BigEndianBitConverter.ToUInt32(RootBlockSector, 0x00); + rootBlk.headerKey = BigEndianBitConverter.ToUInt32(RootBlockSector, 0x04); + rootBlk.highSeq = BigEndianBitConverter.ToUInt32(RootBlockSector, 0x08); + rootBlk.hashTableSize = BigEndianBitConverter.ToUInt32(RootBlockSector, 0x0C); + rootBlk.firstData = BigEndianBitConverter.ToUInt32(RootBlockSector, 0x10); + rootBlk.checksum = BigEndianBitConverter.ToUInt32(RootBlockSector, 0x14); + rootBlk.hashTable = new uint[rootBlk.hashTableSize]; + + for (int i = 0; i < rootBlk.hashTableSize; i++) + rootBlk.hashTable[i] = BigEndianBitConverter.ToUInt32(RootBlockSector, 0x18 + i*4); + + rootBlk.bitmapFlag = BigEndianBitConverter.ToUInt32(RootBlockSector, (int)(0x18 + rootBlk.hashTableSize * 4 + 0)); + rootBlk.bitmapPages = new uint[25]; + + for (int i = 0; i < 25; i++) + rootBlk.bitmapPages[i] = BigEndianBitConverter.ToUInt32(RootBlockSector, (int)(0x18 + rootBlk.hashTableSize * 4 + 4 + i * 4)); + + rootBlk.bitmapExtensionBlock = BigEndianBitConverter.ToUInt32(RootBlockSector, (int)(0x18 + rootBlk.hashTableSize * 4 + 104)); + rootBlk.rDays = BigEndianBitConverter.ToUInt32(RootBlockSector, (int)(0x18 + rootBlk.hashTableSize * 4 + 108)); + rootBlk.rMins = BigEndianBitConverter.ToUInt32(RootBlockSector, (int)(0x18 + rootBlk.hashTableSize * 4 + 112)); + rootBlk.rTicks = BigEndianBitConverter.ToUInt32(RootBlockSector, (int)(0x18 + rootBlk.hashTableSize * 4 + 116)); + + Array.Copy(RootBlockSector, 0x18+rootBlk.hashTableSize*4+120, diskName, 0, 32); + rootBlk.diskName = StringHandlers.PascalToString(diskName); + + rootBlk.reserved1 = BigEndianBitConverter.ToUInt32(RootBlockSector, (int)(0x18 + rootBlk.hashTableSize * 4 + 152)); + rootBlk.reserved2 = BigEndianBitConverter.ToUInt32(RootBlockSector, (int)(0x18 + rootBlk.hashTableSize * 4 + 156)); + rootBlk.vDays = BigEndianBitConverter.ToUInt32(RootBlockSector, (int)(0x18 + rootBlk.hashTableSize * 4 + 160)); + rootBlk.vMins = BigEndianBitConverter.ToUInt32(RootBlockSector, (int)(0x18 + rootBlk.hashTableSize * 4 + 164)); + rootBlk.vTicks = BigEndianBitConverter.ToUInt32(RootBlockSector, (int)(0x18 + rootBlk.hashTableSize * 4 + 168)); + rootBlk.cDays = BigEndianBitConverter.ToUInt32(RootBlockSector, (int)(0x18 + rootBlk.hashTableSize * 4 + 172)); + rootBlk.cMins = BigEndianBitConverter.ToUInt32(RootBlockSector, (int)(0x18 + rootBlk.hashTableSize * 4 + 176)); + rootBlk.cTicks = BigEndianBitConverter.ToUInt32(RootBlockSector, (int)(0x18 + rootBlk.hashTableSize * 4 + 180)); + rootBlk.nextHash = BigEndianBitConverter.ToUInt32(RootBlockSector, (int)(0x18 + rootBlk.hashTableSize * 4 + 184)); + rootBlk.parentDir = BigEndianBitConverter.ToUInt32(RootBlockSector, (int)(0x18 + rootBlk.hashTableSize * 4 + 188)); + rootBlk.extension = BigEndianBitConverter.ToUInt32(RootBlockSector, (int)(0x18 + rootBlk.hashTableSize * 4 + 192)); + rootBlk.sec_type = BigEndianBitConverter.ToUInt32(RootBlockSector, (int)(0x18 + rootBlk.hashTableSize * 4 + 196)); + + if (MainClass.isDebug) + { + Console.WriteLine("DEBUG (AmigaDOS plugin): Stored root block checksum is 0x{0:X8}", rootBlk.checksum); + Console.WriteLine("DEBUG (AmigaDOS plugin): Probably incorrect calculated root block checksum is 0x{0:X8}", AmigaChecksum(RootBlockSector)); + } + + switch (bootBlk.diskType & 0xFF) + { + case 0: + sbInformation.Append("Amiga Original File System"); + break; + case 1: + sbInformation.Append("Amiga Fast File System"); + break; + case 2: + sbInformation.Append("Amiga Original File System with international characters"); + break; + case 3: + sbInformation.Append("Amiga Fast File System with international characters"); + break; + case 4: + sbInformation.Append("Amiga Original File System with directory cache"); + break; + case 5: + sbInformation.Append("Amiga Fast File System with directory cache"); + break; + case 6: + sbInformation.Append("Amiga Original File System with long filenames"); + break; + case 7: + sbInformation.Append("Amiga Fast File System with long filenames"); + break; + } + + if((bootBlk.diskType & 0x6D754600) == 0x6D754600) + sbInformation.Append(", with multi-user patches"); + + sbInformation.AppendLine(); + + if((bootBlk.diskType & 0xFF) == 6 || (bootBlk.diskType & 0xFF) == 7) + sbInformation.AppendLine("AFFS v2, following information may be completely incorrect or garbage."); + + sbInformation.AppendFormat("Volume name: {0}", rootBlk.diskName).AppendLine(); + + if (rootBlk.bitmapFlag == 0xFFFFFFFF) + sbInformation.AppendLine("Volume bitmap is valid"); + + if (rootBlk.bitmapExtensionBlock != 0x00000000 && rootBlk.bitmapExtensionBlock != 0xFFFFFFFF) + sbInformation.AppendFormat("Bitmap extension at block {0}", rootBlk.bitmapExtensionBlock).AppendLine(); + + if((bootBlk.diskType & 0xFF) == 4 || (bootBlk.diskType & 0xFF) == 5) + sbInformation.AppendFormat("Directory cache starts at block {0}", rootBlk.extension).AppendLine(); + + sbInformation.AppendFormat("Volume created on {0}", DateHandlers.AmigaToDateTime(rootBlk.cDays, rootBlk.cMins, rootBlk.cTicks)).AppendLine(); + sbInformation.AppendFormat("Volume last modified on {0}", DateHandlers.AmigaToDateTime(rootBlk.vDays, rootBlk.vMins, rootBlk.vTicks)).AppendLine(); + sbInformation.AppendFormat("Volume root directory last modified on on {0}", DateHandlers.AmigaToDateTime(rootBlk.rDays, rootBlk.rMins, rootBlk.rTicks)).AppendLine(); + + information = sbInformation.ToString(); + } + + static UInt32 AmigaChecksum(byte[] data) + { + BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; + UInt32 sum = 0; + + for (int i = 0; i < data.Length; i += 4) + sum += BigEndianBitConverter.ToUInt32(data, i); + + return sum; + } + } +} \ No newline at end of file diff --git a/README.md b/README.md index a5fec8aa..a949da35 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,9 @@ Supported file systems * Xenix file system * Coherent UNIX file system * UnixWare boot file system +* Amiga Original File System, with international characters, directory cache and multi-user patches +* Amiga Fast File System, with international characters, directory cache and multi-user patches +* Amiga Fast File System v2, untested Supported checksums =================== diff --git a/TODO b/TODO index 47000312..79d96e5f 100644 --- a/TODO +++ b/TODO @@ -19,7 +19,6 @@ --- Add support foe QEMU QED images Filesystem plugins: ---- Add support for AmigaOS filesystems --- Add support for SFS filesystem --- Add support for PFS3 filesystem --- Add support for Acorn filesystems