2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2019-04-25 01:25:13 +01:00
|
|
|
|
// Filename : Info.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// Component : Microsoft FAT filesystem plugin.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Identifies the Microsoft FAT filesystem 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2018-12-29 17:34:38 +00:00
|
|
|
|
// Copyright © 2011-2019 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;
|
2017-12-19 19:33:46 +00:00
|
|
|
|
using System.IO;
|
2017-12-21 07:08:26 +00:00
|
|
|
|
using System.Linq;
|
2017-07-19 16:31:08 +01:00
|
|
|
|
using System.Text;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using DiscImageChef.Checksums;
|
2017-07-19 16:31:08 +01:00
|
|
|
|
using DiscImageChef.CommonTypes;
|
2018-06-25 19:08:16 +01:00
|
|
|
|
using DiscImageChef.CommonTypes.Enums;
|
|
|
|
|
|
using DiscImageChef.CommonTypes.Interfaces;
|
2017-07-19 16:31:08 +01:00
|
|
|
|
using DiscImageChef.Console;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using DiscImageChef.Helpers;
|
|
|
|
|
|
using Schemas;
|
2015-10-18 22:04:03 +01:00
|
|
|
|
|
2019-04-25 01:25:13 +01:00
|
|
|
|
namespace DiscImageChef.Filesystems.FAT
|
2011-03-03 18:34:33 +00:00
|
|
|
|
{
|
2019-04-25 01:25:13 +01:00
|
|
|
|
public partial class FAT
|
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
|
|
|
|
{
|
2017-12-20 17:26:28 +00:00
|
|
|
|
if(2 + partition.Start >= partition.End) return false;
|
2014-07-09 19:49:14 +01:00
|
|
|
|
|
2017-07-10 21:39:12 +01:00
|
|
|
|
ushort bps;
|
2018-02-01 01:19:19 +00:00
|
|
|
|
byte spc;
|
|
|
|
|
|
byte numberOfFats;
|
2017-12-22 08:43:22 +00:00
|
|
|
|
ushort reservedSecs;
|
|
|
|
|
|
ushort rootEntries;
|
2017-07-10 21:39:12 +01:00
|
|
|
|
ushort sectors;
|
2018-02-01 01:19:19 +00:00
|
|
|
|
byte mediaDescriptor;
|
2017-12-22 08:43:22 +00:00
|
|
|
|
ushort fatSectors;
|
2018-02-01 01:19:19 +00:00
|
|
|
|
uint bigSectors;
|
|
|
|
|
|
byte bpbSignature;
|
|
|
|
|
|
byte fat32Signature;
|
|
|
|
|
|
ulong hugeSectors;
|
2017-12-22 08:43:22 +00:00
|
|
|
|
byte[] fat32Id = new byte[8];
|
2018-02-01 01:19:19 +00:00
|
|
|
|
byte[] msxId = new byte[6];
|
|
|
|
|
|
byte fatId;
|
|
|
|
|
|
byte[] dosOem = new byte[8];
|
2017-12-22 08:43:22 +00:00
|
|
|
|
byte[] atariOem = new byte[6];
|
2017-07-10 21:39:12 +01:00
|
|
|
|
ushort bootable = 0;
|
2014-04-14 02:29:13 +00:00
|
|
|
|
|
2018-04-09 18:47:29 +01:00
|
|
|
|
uint sectorsPerBpb = imagePlugin.Info.SectorSize < 512 ? 512 / imagePlugin.Info.SectorSize : 1;
|
|
|
|
|
|
|
|
|
|
|
|
byte[] bpbSector = imagePlugin.ReadSectors(0 + partition.Start, sectorsPerBpb);
|
|
|
|
|
|
byte[] fatSector = imagePlugin.ReadSector(sectorsPerBpb + partition.Start);
|
|
|
|
|
|
|
2019-02-27 08:49:42 +00:00
|
|
|
|
HumanParameterBlock humanBpb = Marshal.ByteArrayToStructureBigEndian<HumanParameterBlock>(bpbSector);
|
2018-04-09 18:47:29 +01:00
|
|
|
|
|
|
|
|
|
|
ulong expectedClusters = humanBpb.bpc > 0 ? partition.Size / humanBpb.bpc : 0;
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "Human bpc = {0}", humanBpb.bpc);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "Human clusters = {0}", humanBpb.clusters);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "Human big_clusters = {0}", humanBpb.big_clusters);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "Human expected clusters = {0}", expectedClusters);
|
|
|
|
|
|
|
|
|
|
|
|
// Check clusters for Human68k are correct
|
|
|
|
|
|
bool humanClustersCorrect = humanBpb.clusters == 0
|
|
|
|
|
|
? humanBpb.big_clusters == expectedClusters
|
|
|
|
|
|
: humanBpb.clusters == expectedClusters;
|
|
|
|
|
|
|
|
|
|
|
|
// Check OEM for Human68k is correct
|
|
|
|
|
|
bool humanOemCorrect = bpbSector[2] >= 0x20 && bpbSector[3] >= 0x20 && bpbSector[4] >= 0x20 &&
|
|
|
|
|
|
bpbSector[5] >= 0x20 && bpbSector[6] >= 0x20 && bpbSector[7] >= 0x20 &&
|
|
|
|
|
|
bpbSector[8] >= 0x20 && bpbSector[9] >= 0x20 && bpbSector[10] >= 0x20 &&
|
|
|
|
|
|
bpbSector[11] >= 0x20 && bpbSector[12] >= 0x20 && bpbSector[13] >= 0x20 &&
|
|
|
|
|
|
bpbSector[14] >= 0x20 && bpbSector[15] >= 0x20 && bpbSector[16] >= 0x20 &&
|
|
|
|
|
|
bpbSector[17] >= 0x20;
|
|
|
|
|
|
|
|
|
|
|
|
// Check correct branch for Human68k
|
|
|
|
|
|
bool humanBranchCorrect = bpbSector[0] == 0x60 && bpbSector[1] >= 0x20 && bpbSector[1] < 0xFE;
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "humanClustersCorrect = {0}", humanClustersCorrect);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "humanOemCorrect = {0}", humanOemCorrect);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "humanBranchCorrect = {0}", humanBranchCorrect);
|
|
|
|
|
|
|
|
|
|
|
|
// If all Human68k checks are correct, it is a Human68k FAT16
|
|
|
|
|
|
if(humanClustersCorrect && humanOemCorrect && humanBranchCorrect && expectedClusters > 0) return true;
|
2017-12-22 08:43:22 +00:00
|
|
|
|
|
|
|
|
|
|
Array.Copy(bpbSector, 0x02, atariOem, 0, 6);
|
2018-02-01 01:19:19 +00:00
|
|
|
|
Array.Copy(bpbSector, 0x03, dosOem, 0, 8);
|
|
|
|
|
|
bps = BitConverter.ToUInt16(bpbSector, 0x00B);
|
|
|
|
|
|
spc = bpbSector[0x00D];
|
|
|
|
|
|
reservedSecs = BitConverter.ToUInt16(bpbSector, 0x00E);
|
|
|
|
|
|
numberOfFats = bpbSector[0x010];
|
|
|
|
|
|
rootEntries = BitConverter.ToUInt16(bpbSector, 0x011);
|
|
|
|
|
|
sectors = BitConverter.ToUInt16(bpbSector, 0x013);
|
2017-12-22 08:43:22 +00:00
|
|
|
|
mediaDescriptor = bpbSector[0x015];
|
2018-02-01 01:19:19 +00:00
|
|
|
|
fatSectors = BitConverter.ToUInt16(bpbSector, 0x016);
|
2017-12-22 08:43:22 +00:00
|
|
|
|
Array.Copy(bpbSector, 0x052, msxId, 0, 6);
|
2018-02-01 01:19:19 +00:00
|
|
|
|
bigSectors = BitConverter.ToUInt32(bpbSector, 0x020);
|
|
|
|
|
|
bpbSignature = bpbSector[0x026];
|
2017-12-22 08:43:22 +00:00
|
|
|
|
fat32Signature = bpbSector[0x042];
|
|
|
|
|
|
Array.Copy(bpbSector, 0x052, fat32Id, 0, 8);
|
2018-04-09 18:47:29 +01:00
|
|
|
|
hugeSectors = BitConverter.ToUInt64(bpbSector, 0x052);
|
|
|
|
|
|
fatId = fatSector[0];
|
2018-02-01 01:19:19 +00:00
|
|
|
|
int bitsInBps = CountBits.Count(bps);
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize >= 512) bootable = BitConverter.ToUInt16(bpbSector, 0x1FE);
|
2017-12-22 08:43:22 +00:00
|
|
|
|
|
2018-04-09 18:47:29 +01:00
|
|
|
|
bool correctSpc = spc == 1 || spc == 2 || spc == 4 || spc == 8 || spc == 16 || spc == 32 || spc == 64;
|
|
|
|
|
|
string msxString = Encoding.ASCII.GetString(msxId);
|
|
|
|
|
|
string fat32String = Encoding.ASCII.GetString(fat32Id);
|
|
|
|
|
|
bool atariOemCorrect = atariOem[0] >= 0x20 && atariOem[1] >= 0x20 && atariOem[2] >= 0x20 &&
|
|
|
|
|
|
atariOem[3] >= 0x20 && atariOem[4] >= 0x20 && atariOem[5] >= 0x20;
|
|
|
|
|
|
bool dosOemCorrect = dosOem[0] >= 0x20 && dosOem[1] >= 0x20 && dosOem[2] >= 0x20 && dosOem[3] >= 0x20 &&
|
|
|
|
|
|
dosOem[4] >= 0x20 && dosOem[5] >= 0x20 && dosOem[6] >= 0x20 && dosOem[7] >= 0x20;
|
2017-12-22 08:43:22 +00:00
|
|
|
|
string atariString = Encoding.ASCII.GetString(atariOem);
|
2018-02-01 01:19:19 +00:00
|
|
|
|
string oemString = Encoding.ASCII.GetString(dosOem);
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "atari_oem_correct = {0}", atariOemCorrect);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "dos_oem_correct = {0}", dosOemCorrect);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "bps = {0}", bps);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "bits in bps = {0}", bitsInBps);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "spc = {0}", spc);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "correct_spc = {0}", correctSpc);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "reserved_secs = {0}", reservedSecs);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "fats_no = {0}", numberOfFats);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "root_entries = {0}", rootEntries);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "sectors = {0}", sectors);
|
2017-12-22 08:43:22 +00:00
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "media_descriptor = 0x{0:X2}", mediaDescriptor);
|
2018-02-01 01:19:19 +00:00
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "fat_sectors = {0}", fatSectors);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "msx_id = \"{0}\"", msxString);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "big_sectors = {0}", bigSectors);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "bpb_signature = 0x{0:X2}", bpbSignature);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "fat32_signature = 0x{0:X2}", fat32Signature);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "fat32_id = \"{0}\"", fat32String);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "huge_sectors = {0}", hugeSectors);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "fat_id = 0x{0:X2}", fatId);
|
|
|
|
|
|
|
|
|
|
|
|
ushort apricotBps = BitConverter.ToUInt16(bpbSector, 0x50);
|
|
|
|
|
|
byte apricotSpc = bpbSector[0x52];
|
|
|
|
|
|
ushort apricotReservedSecs = BitConverter.ToUInt16(bpbSector, 0x53);
|
|
|
|
|
|
byte apricotFatsNo = bpbSector[0x55];
|
|
|
|
|
|
ushort apricotRootEntries = BitConverter.ToUInt16(bpbSector, 0x56);
|
|
|
|
|
|
ushort apricotSectors = BitConverter.ToUInt16(bpbSector, 0x58);
|
|
|
|
|
|
byte apricotMediaDescriptor = bpbSector[0x5A];
|
|
|
|
|
|
ushort apricotFatSectors = BitConverter.ToUInt16(bpbSector, 0x5B);
|
2018-04-09 18:47:29 +01:00
|
|
|
|
bool apricotCorrectSpc = apricotSpc == 1 || apricotSpc == 2 || apricotSpc == 4 || apricotSpc == 8 ||
|
|
|
|
|
|
apricotSpc == 16 || apricotSpc == 32 || apricotSpc == 64;
|
2018-02-01 01:19:19 +00:00
|
|
|
|
int bitsInApricotBps = CountBits.Count(apricotBps);
|
2017-12-22 08:43:22 +00:00
|
|
|
|
byte apricotPartitions = bpbSector[0x0C];
|
|
|
|
|
|
|
2018-02-01 01:19:19 +00:00
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "apricot_bps = {0}", apricotBps);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "apricot_spc = {0}", apricotSpc);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "apricot_correct_spc = {0}", apricotCorrectSpc);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "apricot_reserved_secs = {0}", apricotReservedSecs);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "apricot_fats_no = {0}", apricotFatsNo);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "apricot_root_entries = {0}", apricotRootEntries);
|
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "apricot_sectors = {0}", apricotSectors);
|
2017-12-22 08:43:22 +00:00
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "apricot_media_descriptor = 0x{0:X2}", apricotMediaDescriptor);
|
2018-02-01 01:19:19 +00:00
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "apricot_fat_sectors = {0}", apricotFatSectors);
|
2017-09-22 23:57:53 +01:00
|
|
|
|
|
2017-07-25 00:27:46 +01:00
|
|
|
|
// This is to support FAT partitions on hybrid ISO/USB images
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imagePlugin.Info.XmlMediaType == XmlMediaType.OpticalDisc)
|
2017-07-25 00:27:46 +01:00
|
|
|
|
{
|
2018-02-01 01:19:19 +00:00
|
|
|
|
sectors /= 4;
|
|
|
|
|
|
bigSectors /= 4;
|
2017-12-22 08:43:22 +00:00
|
|
|
|
hugeSectors /= 4;
|
2017-07-25 00:27:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-24 02:37:41 +00:00
|
|
|
|
switch(oemString)
|
|
|
|
|
|
{
|
2017-12-21 04:43:29 +00:00
|
|
|
|
// exFAT
|
|
|
|
|
|
case "EXFAT ": return false;
|
|
|
|
|
|
// NTFS
|
2017-12-22 08:43:22 +00:00
|
|
|
|
case "NTFS " when bootable == 0xAA55 && numberOfFats == 0 && fatSectors == 0: return false;
|
2017-12-21 04:43:29 +00:00
|
|
|
|
// QNX4
|
|
|
|
|
|
case "FQNX4FS ": return false;
|
|
|
|
|
|
}
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
|
|
|
|
|
// HPFS
|
2017-07-23 19:58:11 +01:00
|
|
|
|
if(16 + partition.Start <= partition.End)
|
|
|
|
|
|
{
|
2017-12-22 08:43:22 +00:00
|
|
|
|
byte[] hpfsSbSector =
|
2017-12-19 20:33:03 +00:00
|
|
|
|
imagePlugin.ReadSector(16 + partition.Start); // Seek to superblock, on logical sector 16
|
2018-06-20 22:22:21 +01:00
|
|
|
|
uint hpfsMagic1 = BitConverter.ToUInt32(hpfsSbSector, 0x000);
|
|
|
|
|
|
uint hpfsMagic2 = BitConverter.ToUInt32(hpfsSbSector, 0x004);
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(hpfsMagic1 == 0xF995E849 && hpfsMagic2 == 0xFA53E9C5) return false;
|
2017-07-23 19:58:11 +01:00
|
|
|
|
}
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2017-12-24 02:37:41 +00:00
|
|
|
|
switch(bitsInBps)
|
|
|
|
|
|
{
|
2017-12-21 04:43:29 +00:00
|
|
|
|
// FAT32 for sure
|
2018-02-01 01:19:19 +00:00
|
|
|
|
case 1 when correctSpc && numberOfFats <= 2 && sectors == 0 && fatSectors == 0 &&
|
|
|
|
|
|
fat32Signature == 0x29 && fat32String == "FAT32 ": return true;
|
2017-12-21 04:43:29 +00:00
|
|
|
|
// short FAT32
|
2018-04-09 18:47:29 +01:00
|
|
|
|
case 1
|
|
|
|
|
|
when correctSpc && numberOfFats <= 2 && sectors == 0 && fatSectors == 0 && fat32Signature == 0x28:
|
2018-02-01 01:19:19 +00:00
|
|
|
|
return bigSectors == 0
|
2017-12-22 08:43:22 +00:00
|
|
|
|
? hugeSectors <= partition.End - partition.Start + 1
|
2018-02-01 01:19:19 +00:00
|
|
|
|
: bigSectors <= partition.End - partition.Start + 1;
|
2017-12-21 04:43:29 +00:00
|
|
|
|
// MSX-DOS FAT12
|
2018-02-01 01:19:19 +00:00
|
|
|
|
case 1 when correctSpc && numberOfFats <= 2 && rootEntries > 0 &&
|
|
|
|
|
|
sectors <= partition.End - partition.Start + 1 && fatSectors > 0 &&
|
|
|
|
|
|
msxString == "VOL_ID": return true;
|
2017-12-21 04:43:29 +00:00
|
|
|
|
// EBPB
|
2018-04-09 18:47:29 +01:00
|
|
|
|
case 1 when correctSpc && numberOfFats <= 2 && rootEntries > 0 && fatSectors > 0 &&
|
|
|
|
|
|
(bpbSignature == 0x28 || bpbSignature == 0x29):
|
|
|
|
|
|
return sectors == 0
|
|
|
|
|
|
? bigSectors <= partition.End - partition.Start + 1
|
|
|
|
|
|
: sectors <= partition.End - partition.Start + 1;
|
2017-12-21 04:43:29 +00:00
|
|
|
|
// BPB
|
2017-12-24 02:37:41 +00:00
|
|
|
|
case 1 when correctSpc && reservedSecs < partition.End - partition.Start && numberOfFats <= 2 &&
|
2018-02-01 01:19:19 +00:00
|
|
|
|
rootEntries > 0 && fatSectors > 0:
|
2018-04-09 18:47:29 +01:00
|
|
|
|
return sectors == 0
|
|
|
|
|
|
? bigSectors <= partition.End - partition.Start + 1
|
|
|
|
|
|
: sectors <= partition.End - partition.Start + 1;
|
2017-12-21 04:43:29 +00:00
|
|
|
|
}
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2017-09-22 23:57:53 +01:00
|
|
|
|
// Apricot BPB
|
2018-02-01 01:19:19 +00:00
|
|
|
|
if(bitsInApricotBps == 1 && apricotCorrectSpc &&
|
|
|
|
|
|
apricotReservedSecs < partition.End - partition.Start &&
|
|
|
|
|
|
apricotFatsNo <= 2 &&
|
|
|
|
|
|
apricotRootEntries > 0 && apricotFatSectors > 0 &&
|
|
|
|
|
|
apricotSectors <= partition.End - partition.Start + 1 &&
|
|
|
|
|
|
apricotPartitions == 0) return true;
|
2017-09-22 23:57:53 +01:00
|
|
|
|
|
2017-07-10 21:39:12 +01:00
|
|
|
|
// All FAT12 without BPB can only be used on floppies, without partitions.
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(partition.Start != 0) return false;
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2017-10-02 14:24:19 +01:00
|
|
|
|
// DEC Rainbow, lacks a BPB but has a very concrete structure...
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imagePlugin.Info.Sectors == 800 && imagePlugin.Info.SectorSize == 512)
|
2017-10-02 14:24:19 +01:00
|
|
|
|
{
|
|
|
|
|
|
// DEC Rainbow boots up with a Z80, first byte should be DI (disable interrupts)
|
2017-12-22 08:43:22 +00:00
|
|
|
|
byte z80Di = bpbSector[0];
|
2017-10-02 14:24:19 +01:00
|
|
|
|
// First FAT1 sector resides at LBA 0x14
|
2017-12-22 08:43:22 +00:00
|
|
|
|
byte[] fat1Sector0 = imagePlugin.ReadSector(0x14);
|
2017-10-02 14:24:19 +01:00
|
|
|
|
// First FAT2 sector resides at LBA 0x1A
|
2017-12-22 08:43:22 +00:00
|
|
|
|
byte[] fat2Sector0 = imagePlugin.ReadSector(0x1A);
|
2018-02-01 01:19:19 +00:00
|
|
|
|
bool equalFatIds = fat1Sector0[0] == fat2Sector0[0] && fat1Sector0[1] == fat2Sector0[1];
|
2017-10-02 14:24:19 +01:00
|
|
|
|
// Volume is software interleaved 2:1
|
|
|
|
|
|
MemoryStream rootMs = new MemoryStream();
|
2017-12-26 06:46:28 +00:00
|
|
|
|
foreach(byte[] tmp in from ulong rootSector in new ulong[] {0x17, 0x19, 0x1B, 0x1D, 0x1E, 0x20}
|
2017-12-24 02:37:41 +00:00
|
|
|
|
select imagePlugin.ReadSector(rootSector)) rootMs.Write(tmp, 0, tmp.Length);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2018-02-01 01:19:19 +00:00
|
|
|
|
byte[] rootDir = rootMs.ToArray();
|
|
|
|
|
|
bool validRootDir = true;
|
2017-10-02 14:24:19 +01:00
|
|
|
|
|
|
|
|
|
|
// Iterate all root directory
|
|
|
|
|
|
for(int e = 0; e < 96 * 32; e += 32)
|
|
|
|
|
|
{
|
2018-04-09 18:47:29 +01:00
|
|
|
|
for(int c = 0; c < 11; c++)
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(rootDir[c + e] < 0x20 && rootDir[c + e] != 0x00 && rootDir[c + e] != 0x05 ||
|
2018-02-01 01:19:19 +00:00
|
|
|
|
rootDir[c + e] == 0xFF ||
|
|
|
|
|
|
rootDir[c + e] == 0x2E)
|
2017-10-02 14:24:19 +01:00
|
|
|
|
{
|
2017-12-22 08:43:22 +00:00
|
|
|
|
validRootDir = false;
|
2017-10-02 14:24:19 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(!validRootDir) break;
|
2017-10-02 14:24:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(z80Di == 0xF3 && equalFatIds && (fat1Sector0[0] & 0xF0) == 0xF0 && fat1Sector0[1] == 0xFF &&
|
|
|
|
|
|
validRootDir) return true;
|
2017-10-02 14:24:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-01 01:19:19 +00:00
|
|
|
|
byte fat2 = fatSector[1];
|
|
|
|
|
|
byte fat3 = fatSector[2];
|
2017-12-22 08:43:22 +00:00
|
|
|
|
ushort fat2ndCluster = (ushort)(((fat2 << 8) + fat3) & 0xFFF);
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "1st fat cluster 1 = {0:X3}", fat2ndCluster);
|
|
|
|
|
|
if(fat2ndCluster < 0xFF0) return false;
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
ulong fat2SectorNo = 0;
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
switch(fatId)
|
2014-04-14 02:29:13 +00:00
|
|
|
|
{
|
2017-07-10 21:39:12 +01:00
|
|
|
|
case 0xE5:
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imagePlugin.Info.Sectors == 2002 && imagePlugin.Info.SectorSize == 128) fat2SectorNo = 2;
|
2017-07-10 21:39:12 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case 0xFD:
|
2018-02-01 01:19:19 +00:00
|
|
|
|
if(imagePlugin.Info.Sectors == 4004 && imagePlugin.Info.SectorSize == 128) fat2SectorNo = 7;
|
2018-04-09 18:47:29 +01:00
|
|
|
|
else if(imagePlugin.Info.Sectors == 2002 && imagePlugin.Info.SectorSize == 128) fat2SectorNo = 7;
|
2017-07-10 21:39:12 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case 0xFE:
|
2018-04-09 18:47:29 +01:00
|
|
|
|
if(imagePlugin.Info.Sectors == 320 && imagePlugin.Info.SectorSize == 512) fat2SectorNo = 2;
|
|
|
|
|
|
else if(imagePlugin.Info.Sectors == 2002 && imagePlugin.Info.SectorSize == 128) fat2SectorNo = 7;
|
|
|
|
|
|
else if(imagePlugin.Info.Sectors == 1232 && imagePlugin.Info.SectorSize == 1024) fat2SectorNo = 3;
|
|
|
|
|
|
else if(imagePlugin.Info.Sectors == 616 && imagePlugin.Info.SectorSize == 1024) fat2SectorNo = 2;
|
|
|
|
|
|
else if(imagePlugin.Info.Sectors == 720 && imagePlugin.Info.SectorSize == 128) fat2SectorNo = 5;
|
|
|
|
|
|
else if(imagePlugin.Info.Sectors == 640 && imagePlugin.Info.SectorSize == 512) fat2SectorNo = 2;
|
2017-07-10 21:39:12 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case 0xFF:
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imagePlugin.Info.Sectors == 640 && imagePlugin.Info.SectorSize == 512) fat2SectorNo = 2;
|
2017-07-10 21:39:12 +01:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(fatId < 0xE8) return false;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
fat2SectorNo = 2;
|
2017-07-10 21:39:12 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(fat2SectorNo > partition.End) return false;
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "2nd fat starts at = {0}", fat2SectorNo);
|
2014-06-07 17:21:40 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
byte[] fat2Sector = imagePlugin.ReadSector(fat2SectorNo);
|
2012-08-05 21:10:54 +00:00
|
|
|
|
|
2018-02-01 01:19:19 +00:00
|
|
|
|
fat2 = fat2Sector[1];
|
|
|
|
|
|
fat3 = fat2Sector[2];
|
2017-12-22 08:43:22 +00:00
|
|
|
|
fat2ndCluster = (ushort)(((fat2 << 8) + fat3) & 0xFFF);
|
|
|
|
|
|
if(fat2ndCluster < 0xFF0) return false;
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
return fatId == fat2Sector[0];
|
2017-07-10 21:39:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
|
2018-02-01 01:19:19 +00:00
|
|
|
|
Encoding encoding)
|
2017-07-10 21:39:12 +01:00
|
|
|
|
{
|
2018-02-01 01:19:19 +00:00
|
|
|
|
Encoding = encoding ?? Encoding.GetEncoding("IBM437");
|
2017-07-10 21:39:12 +01:00
|
|
|
|
information = "";
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
2018-04-09 18:47:29 +01:00
|
|
|
|
XmlFsType = new FileSystemType();
|
2018-02-01 01:19:19 +00:00
|
|
|
|
|
2018-04-09 18:47:29 +01:00
|
|
|
|
uint sectorsPerBpb = imagePlugin.Info.SectorSize < 512 ? 512 / imagePlugin.Info.SectorSize : 1;
|
|
|
|
|
|
|
|
|
|
|
|
byte[] bpbSector = imagePlugin.ReadSectors(0 + partition.Start, sectorsPerBpb);
|
|
|
|
|
|
|
2019-04-25 22:05:33 +01:00
|
|
|
|
BpbKind bpbKind = DetectBpbKind(bpbSector, imagePlugin, partition,
|
|
|
|
|
|
out BiosParameterBlockEbpb fakeBpb,
|
|
|
|
|
|
out HumanParameterBlock humanBpb, out AtariParameterBlock atariBpb,
|
|
|
|
|
|
out byte minBootNearJump, out bool andosOemCorrect,
|
|
|
|
|
|
out bool bootable);
|
2018-04-09 18:47:29 +01:00
|
|
|
|
|
2019-04-25 22:05:33 +01:00
|
|
|
|
bool isFat12 = false;
|
|
|
|
|
|
bool isFat16 = false;
|
|
|
|
|
|
bool isFat32 = false;
|
|
|
|
|
|
ulong rootDirectorySector = 0;
|
|
|
|
|
|
string extraInfo = null;
|
|
|
|
|
|
string bootChk = null;
|
|
|
|
|
|
XmlFsType.Bootable = bootable;
|
2018-04-09 18:47:29 +01:00
|
|
|
|
|
2019-04-25 22:05:33 +01:00
|
|
|
|
// This is needed because for FAT16, GEMDOS increases bytes per sector count instead of using big_sectors field.
|
|
|
|
|
|
uint sectorsPerRealSector;
|
|
|
|
|
|
// This is needed because some OSes don't put volume label as first entry in the root directory
|
|
|
|
|
|
uint sectorsForRootDirectory = 0;
|
2018-01-30 01:08:59 +00:00
|
|
|
|
|
2019-04-25 22:05:33 +01:00
|
|
|
|
switch(bpbKind)
|
2017-07-10 21:39:12 +01:00
|
|
|
|
{
|
2019-04-25 22:05:33 +01:00
|
|
|
|
case BpbKind.DecRainbow:
|
|
|
|
|
|
case BpbKind.Hardcoded:
|
|
|
|
|
|
case BpbKind.Msx:
|
|
|
|
|
|
case BpbKind.Apricot:
|
|
|
|
|
|
isFat12 = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case BpbKind.ShortFat32:
|
|
|
|
|
|
case BpbKind.LongFat32:
|
2014-06-07 17:21:40 +01:00
|
|
|
|
{
|
2019-04-25 22:05:33 +01:00
|
|
|
|
isFat32 = true;
|
|
|
|
|
|
Fat32ParameterBlock fat32Bpb =
|
|
|
|
|
|
Marshal.ByteArrayToStructureLittleEndian<Fat32ParameterBlock>(bpbSector);
|
|
|
|
|
|
Fat32ParameterBlockShort shortFat32Bpb =
|
|
|
|
|
|
Marshal.ByteArrayToStructureLittleEndian<Fat32ParameterBlockShort>(bpbSector);
|
|
|
|
|
|
|
|
|
|
|
|
// This is to support FAT partitions on hybrid ISO/USB images
|
|
|
|
|
|
if(imagePlugin.Info.XmlMediaType == XmlMediaType.OpticalDisc)
|
2014-06-07 17:21:40 +01:00
|
|
|
|
{
|
2019-04-25 22:05:33 +01:00
|
|
|
|
fat32Bpb.bps *= 4;
|
|
|
|
|
|
fat32Bpb.spc /= 4;
|
|
|
|
|
|
fat32Bpb.big_spfat /= 4;
|
|
|
|
|
|
fat32Bpb.hsectors /= 4;
|
|
|
|
|
|
fat32Bpb.sptrk /= 4;
|
2017-07-10 21:39:12 +01:00
|
|
|
|
}
|
2019-04-25 22:05:33 +01:00
|
|
|
|
|
|
|
|
|
|
if(fat32Bpb.version != 0)
|
2017-07-10 21:39:12 +01:00
|
|
|
|
{
|
2019-04-25 22:05:33 +01:00
|
|
|
|
sb.AppendLine("FAT+");
|
|
|
|
|
|
XmlFsType.Type = "FAT+";
|
2017-07-10 21:39:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-04-25 22:05:33 +01:00
|
|
|
|
sb.AppendLine("Microsoft FAT32");
|
|
|
|
|
|
XmlFsType.Type = "FAT32";
|
2014-06-07 17:21:40 +01:00
|
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2019-04-25 22:05:33 +01:00
|
|
|
|
if(fat32Bpb.oem_name != null)
|
|
|
|
|
|
if(fat32Bpb.oem_name[5] == 0x49 && fat32Bpb.oem_name[6] == 0x48 && fat32Bpb.oem_name[7] == 0x43)
|
|
|
|
|
|
sb.AppendLine("Volume has been modified by Windows 9x/Me Volume Tracker.");
|
|
|
|
|
|
else XmlFsType.SystemIdentifier = StringHandlers.CToString(fat32Bpb.oem_name);
|
|
|
|
|
|
|
|
|
|
|
|
if(!string.IsNullOrEmpty(XmlFsType.SystemIdentifier))
|
|
|
|
|
|
sb.AppendFormat("OEM Name: {0}", XmlFsType.SystemIdentifier.Trim()).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("{0} bytes per sector.", fat32Bpb.bps).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("{0} sectors per cluster.", fat32Bpb.spc).AppendLine();
|
|
|
|
|
|
XmlFsType.ClusterSize = (uint)(fat32Bpb.bps * fat32Bpb.spc);
|
|
|
|
|
|
sb.AppendFormat("{0} sectors reserved between BPB and FAT.", fat32Bpb.rsectors).AppendLine();
|
|
|
|
|
|
if(fat32Bpb.big_sectors == 0 && fat32Bpb.signature == 0x28)
|
|
|
|
|
|
{
|
|
|
|
|
|
sb.AppendFormat("{0} sectors on volume ({1} bytes).", shortFat32Bpb.huge_sectors,
|
|
|
|
|
|
shortFat32Bpb.huge_sectors * shortFat32Bpb.bps).AppendLine();
|
|
|
|
|
|
XmlFsType.Clusters = shortFat32Bpb.huge_sectors / shortFat32Bpb.spc;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
sb.AppendFormat("{0} sectors on volume ({1} bytes).", fat32Bpb.big_sectors,
|
|
|
|
|
|
fat32Bpb.big_sectors * fat32Bpb.bps).AppendLine();
|
|
|
|
|
|
XmlFsType.Clusters = fat32Bpb.big_sectors / fat32Bpb.spc;
|
|
|
|
|
|
}
|
2017-10-02 14:24:19 +01:00
|
|
|
|
|
2019-04-25 22:05:33 +01:00
|
|
|
|
sb.AppendFormat("{0} clusters on volume.", XmlFsType.Clusters).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Media descriptor: 0x{0:X2}", fat32Bpb.media).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("{0} sectors per FAT.", fat32Bpb.big_spfat).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("{0} sectors per track.", fat32Bpb.sptrk).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("{0} heads.", fat32Bpb.heads).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("{0} hidden sectors before BPB.", fat32Bpb.hsectors).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Cluster of root directory: {0}", fat32Bpb.root_cluster).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Sector of FSINFO structure: {0}", fat32Bpb.fsinfo_sector).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Sector of backup FAT32 parameter block: {0}", fat32Bpb.backup_sector).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Drive number: 0x{0:X2}", fat32Bpb.drive_no).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Volume Serial Number: 0x{0:X8}", fat32Bpb.serial_no).AppendLine();
|
|
|
|
|
|
XmlFsType.VolumeSerial = $"{fat32Bpb.serial_no:X8}";
|
|
|
|
|
|
|
|
|
|
|
|
if((fat32Bpb.flags & 0xF8) == 0x00)
|
|
|
|
|
|
{
|
|
|
|
|
|
if((fat32Bpb.flags & 0x01) == 0x01)
|
2017-10-02 14:24:19 +01:00
|
|
|
|
{
|
2019-04-25 22:05:33 +01:00
|
|
|
|
sb.AppendLine("Volume should be checked on next mount.");
|
|
|
|
|
|
XmlFsType.Dirty = true;
|
2017-10-02 14:24:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-25 22:05:33 +01:00
|
|
|
|
if((fat32Bpb.flags & 0x02) == 0x02) sb.AppendLine("Disk surface should be on next mount.");
|
|
|
|
|
|
}
|
2017-10-02 14:24:19 +01:00
|
|
|
|
|
2019-04-25 22:05:33 +01:00
|
|
|
|
if((fat32Bpb.mirror_flags & 0x80) == 0x80)
|
|
|
|
|
|
sb.AppendFormat("FATs are out of sync. FAT #{0} is in use.", fat32Bpb.mirror_flags & 0xF)
|
|
|
|
|
|
.AppendLine();
|
|
|
|
|
|
else sb.AppendLine("All copies of FAT are the same.");
|
2017-10-02 14:24:19 +01:00
|
|
|
|
|
2019-04-25 22:05:33 +01:00
|
|
|
|
if((fat32Bpb.mirror_flags & 0x6F20) == 0x6F20)
|
|
|
|
|
|
sb.AppendLine("DR-DOS will boot this FAT32 using CHS.");
|
|
|
|
|
|
else if((fat32Bpb.mirror_flags & 0x4F20) == 0x4F20)
|
|
|
|
|
|
sb.AppendLine("DR-DOS will boot this FAT32 using LBA.");
|
2018-02-01 01:19:19 +00:00
|
|
|
|
|
2019-04-25 22:05:33 +01:00
|
|
|
|
if(fat32Bpb.signature == 0x29)
|
|
|
|
|
|
{
|
|
|
|
|
|
XmlFsType.VolumeName = Encoding.ASCII.GetString(fat32Bpb.volume_label);
|
|
|
|
|
|
sb.AppendFormat("Filesystem type: {0}", Encoding.ASCII.GetString(fat32Bpb.fs_type))
|
|
|
|
|
|
.AppendLine();
|
|
|
|
|
|
bootChk = Sha1Context.Data(fat32Bpb.boot_code, out _);
|
|
|
|
|
|
}
|
|
|
|
|
|
else bootChk = Sha1Context.Data(shortFat32Bpb.boot_code, out _);
|
|
|
|
|
|
|
|
|
|
|
|
// Check that jumps to a correct boot code position and has boot signature set.
|
|
|
|
|
|
// This will mean that the volume will boot, even if just to say "this is not bootable change disk"......
|
|
|
|
|
|
XmlFsType.Bootable =
|
|
|
|
|
|
fat32Bpb.jump[0] == 0xEB && fat32Bpb.jump[1] >= minBootNearJump && fat32Bpb.jump[1] < 0x80 ||
|
|
|
|
|
|
fat32Bpb.jump[0] == 0xE9 && fat32Bpb.jump.Length >= 3 &&
|
|
|
|
|
|
BitConverter.ToUInt16(fat32Bpb.jump, 1) >= minBootNearJump &&
|
|
|
|
|
|
BitConverter.ToUInt16(fat32Bpb.jump, 1) <= 0x1FC;
|
|
|
|
|
|
|
|
|
|
|
|
sectorsPerRealSector = fat32Bpb.bps / imagePlugin.Info.SectorSize;
|
|
|
|
|
|
// First root directory sector
|
|
|
|
|
|
rootDirectorySector =
|
|
|
|
|
|
(ulong)((fat32Bpb.root_cluster - 2) * fat32Bpb.spc + fat32Bpb.big_spfat * fat32Bpb.fats_no +
|
|
|
|
|
|
fat32Bpb.rsectors) * sectorsPerRealSector;
|
|
|
|
|
|
sectorsForRootDirectory = 1;
|
|
|
|
|
|
|
|
|
|
|
|
if(fat32Bpb.fsinfo_sector + partition.Start <= partition.End)
|
|
|
|
|
|
{
|
|
|
|
|
|
byte[] fsinfoSector = imagePlugin.ReadSector(fat32Bpb.fsinfo_sector + partition.Start);
|
|
|
|
|
|
FsInfoSector fsInfo =
|
|
|
|
|
|
Marshal.ByteArrayToStructureLittleEndian<FsInfoSector>(fsinfoSector);
|
2018-02-01 01:19:19 +00:00
|
|
|
|
|
2019-04-25 22:05:33 +01:00
|
|
|
|
if(fsInfo.signature1 == FSINFO_SIGNATURE1 && fsInfo.signature2 == FSINFO_SIGNATURE2 &&
|
|
|
|
|
|
fsInfo.signature3 == FSINFO_SIGNATURE3)
|
2017-07-10 21:39:12 +01:00
|
|
|
|
{
|
2019-04-25 22:05:33 +01:00
|
|
|
|
if(fsInfo.free_clusters < 0xFFFFFFFF)
|
|
|
|
|
|
{
|
|
|
|
|
|
sb.AppendFormat("{0} free clusters", fsInfo.free_clusters).AppendLine();
|
|
|
|
|
|
XmlFsType.FreeClusters = fsInfo.free_clusters;
|
|
|
|
|
|
XmlFsType.FreeClustersSpecified = true;
|
|
|
|
|
|
}
|
2018-02-01 01:19:19 +00:00
|
|
|
|
|
2019-04-25 22:05:33 +01:00
|
|
|
|
if(fsInfo.last_cluster > 2 && fsInfo.last_cluster < 0xFFFFFFFF)
|
|
|
|
|
|
sb.AppendFormat("Last allocated cluster {0}", fsInfo.last_cluster).AppendLine();
|
2017-07-10 21:39:12 +01:00
|
|
|
|
}
|
2016-09-13 12:58:19 +01:00
|
|
|
|
}
|
2018-02-01 01:19:19 +00:00
|
|
|
|
|
2019-04-25 22:05:33 +01:00
|
|
|
|
break;
|
2017-07-10 21:39:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-25 22:05:33 +01:00
|
|
|
|
// Some fields could overflow fake BPB, those will be handled below
|
|
|
|
|
|
case BpbKind.Atari:
|
2017-07-10 21:39:12 +01:00
|
|
|
|
{
|
2019-05-11 20:49:32 +01:00
|
|
|
|
ushort sum = 0;
|
2019-04-25 22:05:33 +01:00
|
|
|
|
for(int i = 0; i < bpbSector.Length; i += 2) sum += BigEndianBitConverter.ToUInt16(bpbSector, i);
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2019-04-25 22:05:33 +01:00
|
|
|
|
// TODO: Check this
|
|
|
|
|
|
if(sum == 0x1234)
|
2016-09-13 12:58:19 +01:00
|
|
|
|
{
|
2019-04-25 22:05:33 +01:00
|
|
|
|
XmlFsType.Bootable = true;
|
|
|
|
|
|
StringBuilder atariSb = new StringBuilder();
|
|
|
|
|
|
atariSb.AppendFormat("cmdload will be loaded with value {0:X4}h",
|
|
|
|
|
|
BigEndianBitConverter.ToUInt16(bpbSector, 0x01E)).AppendLine();
|
|
|
|
|
|
atariSb.AppendFormat("Boot program will be loaded at address {0:X4}h", atariBpb.ldaaddr)
|
|
|
|
|
|
.AppendLine();
|
|
|
|
|
|
atariSb.AppendFormat("FAT and directory will be cached at address {0:X4}h", atariBpb.fatbuf)
|
|
|
|
|
|
.AppendLine();
|
|
|
|
|
|
if(atariBpb.ldmode == 0)
|
2017-07-10 21:39:12 +01:00
|
|
|
|
{
|
2019-04-25 22:05:33 +01:00
|
|
|
|
byte[] tmp = new byte[8];
|
|
|
|
|
|
Array.Copy(atariBpb.fname, 0, tmp, 0, 8);
|
|
|
|
|
|
string fname = Encoding.ASCII.GetString(tmp).Trim();
|
|
|
|
|
|
tmp = new byte[3];
|
|
|
|
|
|
Array.Copy(atariBpb.fname, 8, tmp, 0, 3);
|
|
|
|
|
|
string extension = Encoding.ASCII.GetString(tmp).Trim();
|
|
|
|
|
|
string filename;
|
|
|
|
|
|
|
|
|
|
|
|
if(string.IsNullOrEmpty(extension)) filename = fname;
|
|
|
|
|
|
else filename = fname + "." + extension;
|
|
|
|
|
|
|
|
|
|
|
|
atariSb.AppendFormat("Boot program resides in file \"{0}\"", filename).AppendLine();
|
2017-07-10 21:39:12 +01:00
|
|
|
|
}
|
2019-04-25 22:05:33 +01:00
|
|
|
|
else
|
|
|
|
|
|
atariSb
|
|
|
|
|
|
.AppendFormat("Boot program starts in sector {0} and is {1} sectors long ({2} bytes)",
|
2017-12-22 08:43:22 +00:00
|
|
|
|
atariBpb.ssect, atariBpb.sectcnt, atariBpb.sectcnt * atariBpb.bps)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
.AppendLine();
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2019-04-25 22:05:33 +01:00
|
|
|
|
extraInfo = atariSb.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
2017-07-10 21:39:12 +01:00
|
|
|
|
}
|
2019-04-25 22:05:33 +01:00
|
|
|
|
|
|
|
|
|
|
case BpbKind.Human:
|
|
|
|
|
|
XmlFsType.Bootable = true;
|
|
|
|
|
|
break;
|
2018-04-09 18:47:29 +01:00
|
|
|
|
}
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(!isFat32)
|
2017-07-10 21:39:12 +01:00
|
|
|
|
{
|
2017-07-25 00:27:46 +01:00
|
|
|
|
// This is to support FAT partitions on hybrid ISO/USB images
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imagePlugin.Info.XmlMediaType == XmlMediaType.OpticalDisc)
|
2017-07-25 00:27:46 +01:00
|
|
|
|
{
|
2018-02-01 01:19:19 +00:00
|
|
|
|
fakeBpb.bps *= 4;
|
|
|
|
|
|
fakeBpb.spc /= 4;
|
|
|
|
|
|
fakeBpb.spfat /= 4;
|
2017-12-22 08:43:22 +00:00
|
|
|
|
fakeBpb.hsectors /= 4;
|
2018-02-01 01:19:19 +00:00
|
|
|
|
fakeBpb.sptrk /= 4;
|
2017-12-22 08:43:22 +00:00
|
|
|
|
fakeBpb.rsectors /= 4;
|
|
|
|
|
|
|
|
|
|
|
|
if(fakeBpb.spc == 0) fakeBpb.spc = 1;
|
2017-07-25 00:27:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-07-10 21:39:12 +01:00
|
|
|
|
// This assumes no sane implementation will violate cluster size rules
|
|
|
|
|
|
// However nothing prevents this to happen
|
|
|
|
|
|
// If first file on disk uses only one cluster there is absolutely no way to differentiate between FAT12 and FAT16,
|
|
|
|
|
|
// so let's hope implementations use common sense?
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(!isFat12 && !isFat16)
|
2017-07-10 21:39:12 +01:00
|
|
|
|
{
|
|
|
|
|
|
ulong clusters;
|
2017-08-07 16:12:36 +01:00
|
|
|
|
|
2018-04-09 18:47:29 +01:00
|
|
|
|
if(fakeBpb.sectors == 0)
|
2018-02-01 01:19:19 +00:00
|
|
|
|
clusters = fakeBpb.spc == 0 ? fakeBpb.big_sectors : fakeBpb.big_sectors / fakeBpb.spc;
|
|
|
|
|
|
else clusters = fakeBpb.spc == 0 ? fakeBpb.sectors : (ulong)fakeBpb.sectors / fakeBpb.spc;
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(clusters < 4089) isFat12 = true;
|
2018-02-01 01:19:19 +00:00
|
|
|
|
else isFat16 = true;
|
2014-06-07 17:21:40 +01:00
|
|
|
|
}
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(isFat12)
|
2014-06-07 17:21:40 +01:00
|
|
|
|
{
|
2019-04-25 22:05:33 +01:00
|
|
|
|
switch(bpbKind)
|
|
|
|
|
|
{
|
|
|
|
|
|
case BpbKind.Atari:
|
|
|
|
|
|
sb.AppendLine("Atari FAT12");
|
|
|
|
|
|
break;
|
|
|
|
|
|
case BpbKind.Apricot:
|
|
|
|
|
|
sb.AppendLine("Apricot FAT12");
|
|
|
|
|
|
break;
|
2019-04-28 15:44:34 +01:00
|
|
|
|
case BpbKind.Human:
|
|
|
|
|
|
sb.AppendLine("Human68k FAT12");
|
|
|
|
|
|
break;
|
2019-04-25 22:05:33 +01:00
|
|
|
|
default:
|
|
|
|
|
|
sb.AppendLine("Microsoft FAT12");
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.Type = "FAT12";
|
2014-06-07 17:21:40 +01:00
|
|
|
|
}
|
2017-12-22 08:43:22 +00:00
|
|
|
|
else if(isFat16)
|
2014-04-14 02:29:13 +00:00
|
|
|
|
{
|
2019-04-25 22:05:33 +01:00
|
|
|
|
sb.AppendLine(bpbKind == BpbKind.Atari
|
2018-04-09 18:47:29 +01:00
|
|
|
|
? "Atari FAT16"
|
2019-04-25 22:05:33 +01:00
|
|
|
|
: bpbKind == BpbKind.Human
|
2018-04-09 18:47:29 +01:00
|
|
|
|
? "Human68k FAT16"
|
|
|
|
|
|
: "Microsoft FAT16");
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.Type = "FAT16";
|
2014-04-14 02:29:13 +00:00
|
|
|
|
}
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2019-04-25 22:05:33 +01:00
|
|
|
|
if(bpbKind == BpbKind.Atari)
|
2017-07-10 21:39:12 +01:00
|
|
|
|
{
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(atariBpb.serial_no[0] == 0x49 && atariBpb.serial_no[1] == 0x48 && atariBpb.serial_no[2] == 0x43)
|
2017-07-10 21:39:12 +01:00
|
|
|
|
sb.AppendLine("Volume has been modified by Windows 9x/Me Volume Tracker.");
|
|
|
|
|
|
else
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.VolumeSerial =
|
2017-12-22 08:43:22 +00:00
|
|
|
|
$"{atariBpb.serial_no[0]:X2}{atariBpb.serial_no[1]:X2}{atariBpb.serial_no[2]:X2}";
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2018-04-09 18:47:29 +01:00
|
|
|
|
XmlFsType.SystemIdentifier = StringHandlers.CToString(atariBpb.oem_name);
|
2017-12-26 08:01:40 +00:00
|
|
|
|
if(string.IsNullOrEmpty(XmlFsType.SystemIdentifier)) XmlFsType.SystemIdentifier = null;
|
2017-07-10 21:39:12 +01:00
|
|
|
|
}
|
2017-12-22 08:43:22 +00:00
|
|
|
|
else if(fakeBpb.oem_name != null)
|
2014-04-14 02:29:13 +00:00
|
|
|
|
{
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(fakeBpb.oem_name[5] == 0x49 && fakeBpb.oem_name[6] == 0x48 && fakeBpb.oem_name[7] == 0x43)
|
2017-07-10 21:39:12 +01:00
|
|
|
|
sb.AppendLine("Volume has been modified by Windows 9x/Me Volume Tracker.");
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// Later versions of Windows create a DOS 3 BPB without OEM name on 8 sectors/track floppies
|
|
|
|
|
|
// OEM ID should be ASCII, otherwise ignore it
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(fakeBpb.oem_name[0] >= 0x20 && fakeBpb.oem_name[0] <= 0x7F && fakeBpb.oem_name[1] >= 0x20 &&
|
|
|
|
|
|
fakeBpb.oem_name[1] <= 0x7F && fakeBpb.oem_name[2] >= 0x20 && fakeBpb.oem_name[2] <= 0x7F &&
|
|
|
|
|
|
fakeBpb.oem_name[3] >= 0x20 && fakeBpb.oem_name[3] <= 0x7F && fakeBpb.oem_name[4] >= 0x20 &&
|
|
|
|
|
|
fakeBpb.oem_name[4] <= 0x7F && fakeBpb.oem_name[5] >= 0x20 && fakeBpb.oem_name[5] <= 0x7F &&
|
|
|
|
|
|
fakeBpb.oem_name[6] >= 0x20 && fakeBpb.oem_name[6] <= 0x7F && fakeBpb.oem_name[7] >= 0x20 &&
|
|
|
|
|
|
fakeBpb.oem_name[7] <= 0x7F)
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.SystemIdentifier = StringHandlers.CToString(fakeBpb.oem_name);
|
2018-02-01 01:19:19 +00:00
|
|
|
|
else if(fakeBpb.oem_name[0] < 0x20 && fakeBpb.oem_name[1] >= 0x20 &&
|
2017-12-22 08:43:22 +00:00
|
|
|
|
fakeBpb.oem_name[1] <= 0x7F && fakeBpb.oem_name[2] >= 0x20 &&
|
|
|
|
|
|
fakeBpb.oem_name[2] <= 0x7F && fakeBpb.oem_name[3] >= 0x20 &&
|
|
|
|
|
|
fakeBpb.oem_name[3] <= 0x7F && fakeBpb.oem_name[4] >= 0x20 &&
|
|
|
|
|
|
fakeBpb.oem_name[4] <= 0x7F && fakeBpb.oem_name[5] >= 0x20 &&
|
|
|
|
|
|
fakeBpb.oem_name[5] <= 0x7F && fakeBpb.oem_name[6] >= 0x20 &&
|
|
|
|
|
|
fakeBpb.oem_name[6] <= 0x7F && fakeBpb.oem_name[7] >= 0x20 &&
|
|
|
|
|
|
fakeBpb.oem_name[7] <= 0x7F)
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.SystemIdentifier = StringHandlers.CToString(fakeBpb.oem_name, Encoding, start: 1);
|
2017-07-10 21:39:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(fakeBpb.signature == 0x28 || fakeBpb.signature == 0x29)
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.VolumeSerial = $"{fakeBpb.serial_no:X8}";
|
2014-06-07 17:21:40 +01:00
|
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
if(XmlFsType.SystemIdentifier != null)
|
|
|
|
|
|
sb.AppendFormat("OEM Name: {0}", XmlFsType.SystemIdentifier.Trim()).AppendLine();
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
sb.AppendFormat("{0} bytes per sector.", fakeBpb.bps).AppendLine();
|
2019-04-25 22:05:33 +01:00
|
|
|
|
if(bpbKind != BpbKind.Human)
|
2018-04-09 18:47:29 +01:00
|
|
|
|
if(fakeBpb.sectors == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
sb.AppendFormat("{0} sectors on volume ({1} bytes).", fakeBpb.big_sectors,
|
|
|
|
|
|
fakeBpb.big_sectors * fakeBpb.bps).AppendLine();
|
|
|
|
|
|
XmlFsType.Clusters = fakeBpb.spc == 0 ? fakeBpb.big_sectors : fakeBpb.big_sectors / fakeBpb.spc;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
sb.AppendFormat("{0} sectors on volume ({1} bytes).", fakeBpb.sectors,
|
|
|
|
|
|
fakeBpb.sectors * fakeBpb.bps).AppendLine();
|
2019-04-23 01:38:33 +01:00
|
|
|
|
XmlFsType.Clusters =
|
|
|
|
|
|
(ulong)(fakeBpb.spc == 0 ? fakeBpb.sectors : fakeBpb.sectors / fakeBpb.spc);
|
2018-04-09 18:47:29 +01:00
|
|
|
|
}
|
2014-06-07 17:21:40 +01:00
|
|
|
|
else
|
2015-12-05 17:10:27 +00:00
|
|
|
|
{
|
2018-04-09 18:47:29 +01:00
|
|
|
|
XmlFsType.Clusters = humanBpb.clusters == 0 ? humanBpb.big_clusters : humanBpb.clusters;
|
|
|
|
|
|
sb.AppendFormat("{0} sectors on volume ({1} bytes).",
|
|
|
|
|
|
XmlFsType.Clusters * humanBpb.bpc / imagePlugin.Info.SectorSize,
|
|
|
|
|
|
XmlFsType.Clusters * humanBpb.bpc).AppendLine();
|
2015-12-05 17:10:27 +00:00
|
|
|
|
}
|
2018-02-01 01:19:19 +00:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
sb.AppendFormat("{0} sectors per cluster.", fakeBpb.spc).AppendLine();
|
2018-04-09 18:47:29 +01:00
|
|
|
|
sb.AppendFormat("{0} clusters on volume.", XmlFsType.Clusters).AppendLine();
|
2019-04-23 01:38:33 +01:00
|
|
|
|
XmlFsType.ClusterSize = (uint)(fakeBpb.bps * fakeBpb.spc);
|
2017-12-22 08:43:22 +00:00
|
|
|
|
sb.AppendFormat("{0} sectors reserved between BPB and FAT.", fakeBpb.rsectors).AppendLine();
|
2018-04-09 18:47:29 +01:00
|
|
|
|
sb.AppendFormat("{0} FATs.", fakeBpb.fats_no).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("{0} entries on root directory.", fakeBpb.root_ent).AppendLine();
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(fakeBpb.media > 0) sb.AppendFormat("Media descriptor: 0x{0:X2}", fakeBpb.media).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
sb.AppendFormat("{0} sectors per FAT.", fakeBpb.spfat).AppendLine();
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(fakeBpb.sptrk > 0 && fakeBpb.sptrk < 64 && fakeBpb.heads > 0 && fakeBpb.heads < 256)
|
2017-07-10 21:39:12 +01:00
|
|
|
|
{
|
2017-12-22 08:43:22 +00:00
|
|
|
|
sb.AppendFormat("{0} sectors per track.", fakeBpb.sptrk).AppendLine();
|
2018-04-09 18:47:29 +01:00
|
|
|
|
sb.AppendFormat("{0} heads.", fakeBpb.heads).AppendLine();
|
2014-04-14 02:29:13 +00:00
|
|
|
|
}
|
2018-02-01 01:19:19 +00:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(fakeBpb.hsectors <= partition.Start)
|
|
|
|
|
|
sb.AppendFormat("{0} hidden sectors before BPB.", fakeBpb.hsectors).AppendLine();
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(fakeBpb.signature == 0x28 || fakeBpb.signature == 0x29 || andosOemCorrect)
|
2014-06-07 17:21:40 +01:00
|
|
|
|
{
|
2017-12-22 08:43:22 +00:00
|
|
|
|
sb.AppendFormat("Drive number: 0x{0:X2}", fakeBpb.drive_no).AppendLine();
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
if(XmlFsType.VolumeSerial != null)
|
|
|
|
|
|
sb.AppendFormat("Volume Serial Number: {0}", XmlFsType.VolumeSerial).AppendLine();
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if((fakeBpb.flags & 0xF8) == 0x00)
|
2014-06-07 17:21:40 +01:00
|
|
|
|
{
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if((fakeBpb.flags & 0x01) == 0x01)
|
2014-06-07 17:21:40 +01:00
|
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
|
sb.AppendLine("Volume should be checked on next mount.");
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.Dirty = true;
|
2014-06-07 17:21:40 +01:00
|
|
|
|
}
|
2018-02-01 01:19:19 +00:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if((fakeBpb.flags & 0x02) == 0x02) sb.AppendLine("Disk surface should be on next mount.");
|
2017-07-10 21:39:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(fakeBpb.signature == 0x29 || andosOemCorrect)
|
2017-07-10 21:39:12 +01:00
|
|
|
|
{
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.VolumeName = Encoding.ASCII.GetString(fakeBpb.volume_label);
|
2017-12-22 08:43:22 +00:00
|
|
|
|
sb.AppendFormat("Filesystem type: {0}", Encoding.ASCII.GetString(fakeBpb.fs_type)).AppendLine();
|
2017-07-10 21:39:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-04-25 22:05:33 +01:00
|
|
|
|
else if(bpbKind == BpbKind.Atari && XmlFsType.VolumeSerial != null)
|
2017-12-26 08:01:40 +00:00
|
|
|
|
sb.AppendFormat("Volume Serial Number: {0}", XmlFsType.VolumeSerial).AppendLine();
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2018-02-03 19:11:41 +00:00
|
|
|
|
bootChk = Sha1Context.Data(fakeBpb.boot_code, out _);
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2018-08-29 22:15:43 +01:00
|
|
|
|
// Workaround that PCExchange jumps into "FAT16 "...
|
2018-01-30 01:08:59 +00:00
|
|
|
|
if(XmlFsType.SystemIdentifier == "PCX 2.0 ") fakeBpb.jump[1] += 8;
|
2018-02-01 01:19:19 +00:00
|
|
|
|
|
2017-07-10 21:39:12 +01:00
|
|
|
|
// Check that jumps to a correct boot code position and has boot signature set.
|
|
|
|
|
|
// This will mean that the volume will boot, even if just to say "this is not bootable change disk"......
|
2017-12-26 08:01:40 +00:00
|
|
|
|
if(XmlFsType.Bootable == false && fakeBpb.jump != null)
|
2018-02-01 01:19:19 +00:00
|
|
|
|
XmlFsType.Bootable |=
|
2018-04-09 18:47:29 +01:00
|
|
|
|
fakeBpb.jump[0] == 0xEB && fakeBpb.jump[1] >= minBootNearJump && fakeBpb.jump[1] < 0x80 ||
|
|
|
|
|
|
fakeBpb.jump[0] == 0xE9 && fakeBpb.jump.Length >= 3 &&
|
2018-02-01 01:19:19 +00:00
|
|
|
|
BitConverter.ToUInt16(fakeBpb.jump, 1) >= minBootNearJump &&
|
|
|
|
|
|
BitConverter.ToUInt16(fakeBpb.jump, 1) <= 0x1FC;
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
sectorsPerRealSector = fakeBpb.bps / imagePlugin.Info.SectorSize;
|
2017-07-10 21:39:12 +01:00
|
|
|
|
// First root directory sector
|
2017-12-22 08:43:22 +00:00
|
|
|
|
rootDirectorySector =
|
2018-04-09 18:47:29 +01:00
|
|
|
|
(ulong)(fakeBpb.spfat * fakeBpb.fats_no + fakeBpb.rsectors) * sectorsPerRealSector;
|
|
|
|
|
|
sectorsForRootDirectory = (uint)(fakeBpb.root_ent * 32 / imagePlugin.Info.SectorSize);
|
2017-07-10 21:39:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(extraInfo != null) sb.Append(extraInfo);
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(rootDirectorySector + partition.Start < partition.End &&
|
2018-02-01 01:19:19 +00:00
|
|
|
|
imagePlugin.Info.XmlMediaType != XmlMediaType.OpticalDisc)
|
2017-07-10 21:39:12 +01:00
|
|
|
|
{
|
2017-12-22 08:43:22 +00:00
|
|
|
|
byte[] rootDirectory =
|
|
|
|
|
|
imagePlugin.ReadSectors(rootDirectorySector + partition.Start, sectorsForRootDirectory);
|
2017-10-02 14:24:19 +01:00
|
|
|
|
|
2019-04-25 22:05:33 +01:00
|
|
|
|
if(bpbKind == BpbKind.DecRainbow)
|
2017-10-02 14:24:19 +01:00
|
|
|
|
{
|
|
|
|
|
|
MemoryStream rootMs = new MemoryStream();
|
2017-12-24 02:37:41 +00:00
|
|
|
|
foreach(byte[] tmp in from ulong rootSector in new[] {0x17, 0x19, 0x1B, 0x1D, 0x1E, 0x20}
|
|
|
|
|
|
select imagePlugin.ReadSector(rootSector)) rootMs.Write(tmp, 0, tmp.Length);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
rootDirectory = rootMs.ToArray();
|
2017-10-02 14:24:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
for(int i = 0; i < rootDirectory.Length; i += 32)
|
2017-07-10 21:39:12 +01:00
|
|
|
|
{
|
|
|
|
|
|
// Not a correct entry
|
2019-04-26 01:29:29 +01:00
|
|
|
|
if(rootDirectory[i] < DIRENT_MIN && rootDirectory[i] != DIRENT_E5) continue;
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
|
|
|
|
|
// Deleted or subdirectory entry
|
2019-04-26 01:29:29 +01:00
|
|
|
|
if(rootDirectory[i] == DIRENT_SUBDIR || rootDirectory[i] == DIRENT_DELETED) continue;
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
|
|
|
|
|
// Not a volume label
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(rootDirectory[i + 0x0B] != 0x08 && rootDirectory[i + 0x0B] != 0x28) continue;
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2019-02-27 08:49:42 +00:00
|
|
|
|
DirectoryEntry entry =
|
2019-03-01 07:35:22 +00:00
|
|
|
|
Marshal.ByteArrayToStructureLittleEndian<DirectoryEntry>(rootDirectory, i, 32);
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
|
|
|
|
|
byte[] fullname = new byte[11];
|
2018-02-01 01:19:19 +00:00
|
|
|
|
Array.Copy(entry.filename, 0, fullname, 0, 8);
|
2017-07-10 21:39:12 +01:00
|
|
|
|
Array.Copy(entry.extension, 0, fullname, 8, 3);
|
2017-12-26 08:01:40 +00:00
|
|
|
|
string volname = Encoding.GetString(fullname).Trim();
|
2017-07-10 21:39:12 +01:00
|
|
|
|
if(!string.IsNullOrEmpty(volname))
|
2019-04-28 11:57:54 +01:00
|
|
|
|
XmlFsType.VolumeName =
|
|
|
|
|
|
entry.caseinfo.HasFlag(CaseInfo.AllLowerCase) ? volname.ToLower() : volname;
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
|
|
|
|
|
if(entry.ctime > 0 && entry.cdate > 0)
|
|
|
|
|
|
{
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.CreationDate = DateHandlers.DosToDateTime(entry.cdate, entry.ctime);
|
2017-12-24 02:37:41 +00:00
|
|
|
|
if(entry.ctime_ms > 0)
|
2018-04-09 18:47:29 +01:00
|
|
|
|
XmlFsType.CreationDate = XmlFsType.CreationDate.AddMilliseconds(entry.ctime_ms * 10);
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.CreationDateSpecified = true;
|
|
|
|
|
|
sb.AppendFormat("Volume created on {0}", XmlFsType.CreationDate).AppendLine();
|
2017-07-10 21:39:12 +01:00
|
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2017-07-10 21:39:12 +01:00
|
|
|
|
if(entry.mtime > 0 && entry.mdate > 0)
|
|
|
|
|
|
{
|
2018-02-01 01:19:19 +00:00
|
|
|
|
XmlFsType.ModificationDate = DateHandlers.DosToDateTime(entry.mdate, entry.mtime);
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.ModificationDateSpecified = true;
|
|
|
|
|
|
sb.AppendFormat("Volume last modified on {0}", XmlFsType.ModificationDate).AppendLine();
|
2014-06-07 17:21:40 +01:00
|
|
|
|
}
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
|
|
|
|
|
if(entry.adate > 0)
|
2017-12-23 03:59:48 +00:00
|
|
|
|
sb.AppendFormat("Volume last accessed on {0:d}", DateHandlers.DosToDateTime(entry.adate, 0))
|
2017-12-19 20:33:03 +00:00
|
|
|
|
.AppendLine();
|
2017-08-25 03:28:55 +01:00
|
|
|
|
|
|
|
|
|
|
break;
|
2014-06-07 17:21:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-07-10 21:39:12 +01:00
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
if(!string.IsNullOrEmpty(XmlFsType.VolumeName))
|
|
|
|
|
|
sb.AppendFormat("Volume label: {0}", XmlFsType.VolumeName).AppendLine();
|
|
|
|
|
|
if(XmlFsType.Bootable)
|
2014-06-07 17:21:40 +01:00
|
|
|
|
{
|
2018-01-30 01:08:59 +00:00
|
|
|
|
// Intel short jump
|
|
|
|
|
|
if(bpbSector[0] == 0xEB && bpbSector[1] < 0x80)
|
|
|
|
|
|
{
|
2018-02-01 01:19:19 +00:00
|
|
|
|
int sigSize = bpbSector[510] == 0x55 && bpbSector[511] == 0xAA ? 2 : 0;
|
2018-04-09 18:47:29 +01:00
|
|
|
|
byte[] bootCode = new byte[512 - sigSize - bpbSector[1] - 2];
|
2018-01-30 01:08:59 +00:00
|
|
|
|
Array.Copy(bpbSector, bpbSector[1] + 2, bootCode, 0, bootCode.Length);
|
2018-02-03 19:11:41 +00:00
|
|
|
|
Sha1Context.Data(bootCode, out _);
|
2018-01-30 01:08:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
// Intel big jump
|
|
|
|
|
|
else if(bpbSector[0] == 0xE9 && BitConverter.ToUInt16(bpbSector, 1) < 0x1FC)
|
|
|
|
|
|
{
|
|
|
|
|
|
int sigSize = bpbSector[510] == 0x55 && bpbSector[511] == 0xAA ? 2 : 0;
|
2018-02-01 01:19:19 +00:00
|
|
|
|
byte[] bootCode = new byte[512 - sigSize - BitConverter.ToUInt16(bpbSector, 1) - 3];
|
2018-04-09 18:47:29 +01:00
|
|
|
|
Array.Copy(bpbSector, BitConverter.ToUInt16(bpbSector, 1) + 3, bootCode, 0, bootCode.Length);
|
2018-02-03 19:11:41 +00:00
|
|
|
|
Sha1Context.Data(bootCode, out _);
|
2018-01-30 01:08:59 +00:00
|
|
|
|
}
|
2018-02-01 01:19:19 +00:00
|
|
|
|
|
2017-07-10 21:39:12 +01:00
|
|
|
|
sb.AppendLine("Volume is bootable");
|
|
|
|
|
|
sb.AppendFormat("Boot code's SHA1: {0}", bootChk).AppendLine();
|
2018-01-30 01:08:59 +00:00
|
|
|
|
string bootName = knownBootHashes.FirstOrDefault(t => t.hash == bootChk).name;
|
|
|
|
|
|
if(string.IsNullOrWhiteSpace(bootName)) sb.AppendLine("Unknown boot code.");
|
2018-02-01 01:19:19 +00:00
|
|
|
|
else sb.AppendFormat("Boot code corresponds to {0}", bootName).AppendLine();
|
2014-04-14 02:29:13 +00:00
|
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
|
information = sb.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|