2016-07-28 18:13:49 +01:00
|
|
|
// /***************************************************************************
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : FAT.cs
|
|
|
|
|
// 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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// Copyright © 2011-2016 Natalia Portillo
|
|
|
|
|
// ****************************************************************************/
|
2014-04-17 19:58:14 +00:00
|
|
|
|
2011-03-03 18:34:33 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Text;
|
2016-07-21 17:16:08 +01:00
|
|
|
using System.Collections.Generic;
|
2015-10-18 22:04:03 +01:00
|
|
|
using DiscImageChef.Console;
|
|
|
|
|
|
2016-07-21 16:15:39 +01:00
|
|
|
namespace DiscImageChef.Filesystems
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2016-07-28 22:25:26 +01:00
|
|
|
// TODO: Implement detecting DOS bootable disks
|
|
|
|
|
// TODO: Implement detecting Atari TOS bootable disks and printing corresponding fields
|
2016-07-21 16:15:39 +01:00
|
|
|
class FAT : Filesystem
|
2014-04-14 02:29:13 +00:00
|
|
|
{
|
2015-10-05 20:04:05 +01:00
|
|
|
public FAT()
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
Name = "Microsoft File Allocation Table";
|
|
|
|
|
PluginUUID = new Guid("33513B2C-0D26-0D2D-32C3-79D8611158E0");
|
2011-03-03 18:34:33 +00:00
|
|
|
}
|
2012-08-05 03:02:55 +00:00
|
|
|
|
2016-07-27 13:32:45 +01:00
|
|
|
public FAT(ImagePlugins.ImagePlugin imagePlugin, ulong partitionStart, ulong partitionEnd)
|
|
|
|
|
{
|
|
|
|
|
Name = "Microsoft File Allocation Table";
|
|
|
|
|
PluginUUID = new Guid("33513B2C-0D26-0D2D-32C3-79D8611158E0");
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-20 05:09:46 +01:00
|
|
|
public override bool Identify(ImagePlugins.ImagePlugin imagePlugin, ulong partitionStart, ulong partitionEnd)
|
2014-04-14 02:29:13 +00:00
|
|
|
{
|
2016-08-08 18:44:08 +01:00
|
|
|
if((2 + partitionStart) >= partitionEnd)
|
2014-07-09 19:49:14 +01:00
|
|
|
return false;
|
|
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
byte media_descriptor; // Not present on DOS <= 3, present on TOS but != of first FAT entry
|
|
|
|
|
byte fats_no; // Must be 1 or 2. Dunno if it can be 0 in the wild, but it CANNOT BE bigger than 2
|
|
|
|
|
byte[] fat32_signature = new byte[8]; // "FAT32 "
|
2016-07-28 22:25:26 +01:00
|
|
|
uint first_fat_entry; // No matter FAT size we read 4 bytes for checking
|
|
|
|
|
ushort bps, rsectors;
|
2014-04-14 02:29:13 +00:00
|
|
|
|
2015-04-20 05:09:46 +01:00
|
|
|
byte[] bpb_sector = imagePlugin.ReadSector(0 + partitionStart);
|
|
|
|
|
byte[] fat_sector = imagePlugin.ReadSector(1 + partitionStart);
|
2014-06-07 17:21:40 +01:00
|
|
|
|
|
|
|
|
bool bpb_found = true;
|
2012-08-05 03:02:55 +00:00
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
fats_no = bpb_sector[0x010]; // FATs, 1 or 2, maybe 0, never bigger
|
|
|
|
|
media_descriptor = bpb_sector[0x015]; // Media Descriptor if present is in 0x15
|
|
|
|
|
Array.Copy(bpb_sector, 0x52, fat32_signature, 0, 8); // FAT32 signature, if present, is in 0x52
|
|
|
|
|
bps = BitConverter.ToUInt16(bpb_sector, 0x00B); // Bytes per sector
|
2016-04-19 02:11:47 +01:00
|
|
|
if(bps == 0)
|
2014-04-14 02:29:13 +00:00
|
|
|
bps = 0x200;
|
|
|
|
|
rsectors = BitConverter.ToUInt16(bpb_sector, 0x00E); // Sectors between BPB and FAT, including the BPB sector => [BPB,FAT)
|
2016-04-19 02:11:47 +01:00
|
|
|
if(rsectors == 0)
|
2014-04-14 02:29:13 +00:00
|
|
|
rsectors = 1;
|
2016-08-08 18:44:08 +01:00
|
|
|
if(partitionEnd > (rsectors + partitionStart))
|
2015-04-20 05:09:46 +01:00
|
|
|
fat_sector = imagePlugin.ReadSector(rsectors + partitionStart); // First FAT entry
|
2016-04-19 02:11:47 +01:00
|
|
|
else
|
|
|
|
|
bpb_found = false;
|
2012-08-05 03:02:55 +00:00
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
if(bpb_found)
|
2014-04-14 02:29:13 +00:00
|
|
|
{
|
2014-06-07 17:21:40 +01:00
|
|
|
first_fat_entry = BitConverter.ToUInt32(fat_sector, 0); // Easier to manage
|
|
|
|
|
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "fats_no = {0}", fats_no);
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "media_descriptor = 0x{0:X2}", media_descriptor);
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "fat32_signature = {0}", StringHandlers.CToString(fat32_signature));
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "bps = {0}", bps);
|
|
|
|
|
DicConsole.DebugWriteLine("FAT plugin", "first_fat_entry = 0x{0:X8}", first_fat_entry);
|
2012-08-05 21:10:54 +00:00
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
if(fats_no > 2) // Must be 1 or 2, but as TOS makes strange things and I have not checked if it puts this to 0, ignore if 0. MUST NOT BE BIGGER THAN 2!
|
|
|
|
|
return false;
|
2012-08-05 03:02:55 +00:00
|
|
|
|
2014-06-07 17:21:40 +01:00
|
|
|
// Let's start the fun
|
2016-04-19 02:11:47 +01:00
|
|
|
if(Encoding.ASCII.GetString(fat32_signature) == "FAT32 ")
|
2014-06-07 17:21:40 +01:00
|
|
|
return true; // Seems easy, check reading
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
|
|
|
if((first_fat_entry & 0xFFFFFFF0) == 0xFFFFFFF0) // Seems to be FAT16
|
2014-06-07 17:21:40 +01:00
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
if((first_fat_entry & 0xFF) == media_descriptor)
|
2014-06-07 17:21:40 +01:00
|
|
|
return true; // It MUST be FAT16, or... maybe not :S
|
|
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
else if((first_fat_entry & 0x00FFFFF0) == 0x00FFFFF0)
|
2014-06-07 17:21:40 +01:00
|
|
|
{
|
|
|
|
|
//if((first_fat_entry & 0xFF) == media_descriptor) // Pre DOS<4 does not implement this, TOS does and is !=
|
|
|
|
|
return true; // It MUST be FAT12, or... maybe not :S
|
|
|
|
|
}
|
2014-04-14 02:29:13 +00:00
|
|
|
}
|
2014-06-07 17:21:40 +01:00
|
|
|
else
|
2014-04-14 02:29:13 +00:00
|
|
|
{
|
2014-06-07 17:21:40 +01:00
|
|
|
// This may create a lot of false positives, need to do extensive checkins...
|
2015-04-20 05:09:46 +01:00
|
|
|
fat_sector = imagePlugin.ReadSector(1 + partitionStart);
|
2014-06-07 17:21:40 +01:00
|
|
|
first_fat_entry = BitConverter.ToUInt32(fat_sector, 0);
|
|
|
|
|
byte fat_id = fat_sector[0];
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
if((first_fat_entry & 0x00FFFFF0) == 0x00FFFFF0)
|
2014-06-07 17:21:40 +01:00
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
if(fat_id == 0xFF)
|
2014-06-07 17:21:40 +01:00
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
if(imagePlugin.GetSectorSize() == 512 && imagePlugin.GetSectors() == 640)
|
2014-06-07 17:21:40 +01:00
|
|
|
return true;
|
2016-04-19 02:11:47 +01:00
|
|
|
if(imagePlugin.GetSectorSize() == 128)
|
2014-06-07 17:21:40 +01:00
|
|
|
{
|
|
|
|
|
if(imagePlugin.GetSectors() == 2002)
|
|
|
|
|
return true;
|
|
|
|
|
if(imagePlugin.GetSectors() == 4004)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
if(imagePlugin.GetSectorSize() == 1024)
|
2014-06-07 17:21:40 +01:00
|
|
|
{
|
|
|
|
|
if(imagePlugin.GetSectors() == 616)
|
|
|
|
|
return true;
|
|
|
|
|
if(imagePlugin.GetSectors() == 1232)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
if(fat_id == 0xFE)
|
2014-06-07 17:21:40 +01:00
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
if(imagePlugin.GetSectorSize() == 512 && imagePlugin.GetSectors() == 320)
|
2014-06-07 17:21:40 +01:00
|
|
|
return true;
|
2016-04-19 02:11:47 +01:00
|
|
|
if(imagePlugin.GetSectorSize() == 128)
|
2014-06-07 17:21:40 +01:00
|
|
|
{
|
|
|
|
|
if(imagePlugin.GetSectors() == 2002)
|
|
|
|
|
return true;
|
|
|
|
|
if(imagePlugin.GetSectors() == 4004)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
if(imagePlugin.GetSectorSize() == 1024)
|
2014-06-07 17:21:40 +01:00
|
|
|
{
|
|
|
|
|
if(imagePlugin.GetSectors() == 616)
|
|
|
|
|
return true;
|
|
|
|
|
if(imagePlugin.GetSectors() == 1232)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
if(fat_id == 0xFD && imagePlugin.GetSectors() == 2002)
|
2014-06-07 17:21:40 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2014-04-14 02:29:13 +00:00
|
|
|
}
|
2011-03-03 18:34:33 +00:00
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-20 05:09:46 +01:00
|
|
|
public override void GetInformation(ImagePlugins.ImagePlugin imagePlugin, ulong partitionStart, ulong partitionEnd, out string information)
|
2014-04-14 02:29:13 +00:00
|
|
|
{
|
|
|
|
|
information = "";
|
2016-04-19 02:11:47 +01:00
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
StringBuilder sb = new StringBuilder();
|
2015-12-05 17:10:27 +00:00
|
|
|
xmlFSType = new Schemas.FileSystemType();
|
2012-08-05 03:02:55 +00:00
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
byte[] dosString; // Space-padded
|
|
|
|
|
bool isFAT32 = false;
|
2016-07-28 22:25:26 +01:00
|
|
|
uint first_fat_entry;
|
2014-04-14 02:29:13 +00:00
|
|
|
byte media_descriptor, fats_no;
|
|
|
|
|
string fat32_signature;
|
2016-07-28 22:25:26 +01:00
|
|
|
ushort bps, rsectors;
|
2012-08-05 03:02:55 +00:00
|
|
|
|
2015-04-20 05:09:46 +01:00
|
|
|
byte[] bpb_sector = imagePlugin.ReadSector(0 + partitionStart);
|
|
|
|
|
byte[] fat_sector = imagePlugin.ReadSector(1 + partitionStart);
|
2014-06-07 17:21:40 +01:00
|
|
|
|
|
|
|
|
bool bpb_found = true;
|
|
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
fats_no = bpb_sector[0x010]; // FATs, 1 or 2, maybe 0, never bigger
|
|
|
|
|
media_descriptor = bpb_sector[0x015]; // Media Descriptor if present is in 0x15
|
2014-04-14 01:14:20 +00:00
|
|
|
dosString = new byte[8];
|
2014-04-14 02:29:13 +00:00
|
|
|
Array.Copy(bpb_sector, 0x52, dosString, 0, 8); // FAT32 signature, if present, is in 0x52
|
2014-04-14 01:14:20 +00:00
|
|
|
fat32_signature = Encoding.ASCII.GetString(dosString);
|
2014-04-14 02:29:13 +00:00
|
|
|
bps = BitConverter.ToUInt16(bpb_sector, 0x00B); // Bytes per sector
|
2016-04-19 02:11:47 +01:00
|
|
|
if(bps == 0)
|
2014-04-14 02:29:13 +00:00
|
|
|
bps = 0x200;
|
|
|
|
|
rsectors = BitConverter.ToUInt16(bpb_sector, 0x00E); // Sectors between BPB and FAT, including the BPB sector => [BPB,FAT)
|
2016-04-19 02:11:47 +01:00
|
|
|
if(rsectors == 0)
|
2014-04-14 02:29:13 +00:00
|
|
|
rsectors = 1;
|
2016-08-08 18:44:08 +01:00
|
|
|
if(partitionEnd > (rsectors + partitionStart))
|
2015-04-20 05:09:46 +01:00
|
|
|
fat_sector = imagePlugin.ReadSector(rsectors + partitionStart); // First FAT entry
|
2014-06-07 17:21:40 +01:00
|
|
|
else
|
2016-04-19 02:11:47 +01:00
|
|
|
bpb_found = false;
|
2012-08-05 03:02:55 +00:00
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
if(bpb_found)
|
2014-06-07 17:21:40 +01:00
|
|
|
{
|
|
|
|
|
first_fat_entry = BitConverter.ToUInt32(fat_sector, 0); // Easier to manage
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
if(fats_no > 2) // Must be 1 or 2, but as TOS makes strange things and I have not checked if it puts this to 0, ignore if 0. MUST NOT BE BIGGER THAN 2!
|
|
|
|
|
return;
|
2012-08-05 03:02:55 +00:00
|
|
|
|
2014-06-07 17:21:40 +01:00
|
|
|
// Let's start the fun
|
2016-04-19 02:11:47 +01:00
|
|
|
if(fat32_signature == "FAT32 ")
|
2014-06-07 17:21:40 +01:00
|
|
|
{
|
|
|
|
|
sb.AppendLine("Microsoft FAT32"); // Seems easy, check reading
|
2015-12-05 17:10:27 +00:00
|
|
|
xmlFSType.Type = "FAT32";
|
2014-06-07 17:21:40 +01:00
|
|
|
isFAT32 = true;
|
|
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
else if((first_fat_entry & 0xFFFFFFF0) == 0xFFFFFFF0) // Seems to be FAT16
|
2014-06-07 17:21:40 +01:00
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
if((first_fat_entry & 0xFF) == media_descriptor)
|
2015-12-05 17:10:27 +00:00
|
|
|
{
|
2014-06-07 17:21:40 +01:00
|
|
|
sb.AppendLine("Microsoft FAT16"); // It MUST be FAT16, or... maybe not :S
|
2015-12-05 17:10:27 +00:00
|
|
|
xmlFSType.Type = "FAT16";
|
|
|
|
|
}
|
2014-06-07 17:21:40 +01:00
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
else if((first_fat_entry & 0x00FFFFF0) == 0x00FFFFF0)
|
2014-06-07 17:21:40 +01:00
|
|
|
{
|
|
|
|
|
//if((first_fat_entry & 0xFF) == media_descriptor) // Pre DOS<4 does not implement this, TOS does and is !=
|
|
|
|
|
sb.AppendLine("Microsoft FAT12"); // It MUST be FAT12, or... maybe not :S
|
2015-12-05 17:10:27 +00:00
|
|
|
xmlFSType.Type = "FAT12";
|
2014-06-07 17:21:40 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return;
|
2016-04-19 02:11:47 +01:00
|
|
|
|
2014-06-07 17:21:40 +01:00
|
|
|
BIOSParameterBlock BPB = new BIOSParameterBlock();
|
|
|
|
|
ExtendedParameterBlock EPB = new ExtendedParameterBlock();
|
|
|
|
|
FAT32ParameterBlock FAT32PB = new FAT32ParameterBlock();
|
2016-04-19 02:11:47 +01:00
|
|
|
|
2014-04-14 01:14:20 +00:00
|
|
|
dosString = new byte[8];
|
2014-06-07 17:21:40 +01:00
|
|
|
Array.Copy(bpb_sector, 0x03, dosString, 0, 8);
|
2016-02-05 00:01:09 +00:00
|
|
|
BPB.OEMName = StringHandlers.CToString(dosString);
|
2014-06-07 17:21:40 +01:00
|
|
|
BPB.bps = BitConverter.ToUInt16(bpb_sector, 0x0B);
|
|
|
|
|
BPB.spc = bpb_sector[0x0D];
|
|
|
|
|
BPB.rsectors = BitConverter.ToUInt16(bpb_sector, 0x0E);
|
|
|
|
|
BPB.fats_no = bpb_sector[0x10];
|
|
|
|
|
BPB.root_ent = BitConverter.ToUInt16(bpb_sector, 0x11);
|
|
|
|
|
BPB.sectors = BitConverter.ToUInt16(bpb_sector, 0x13);
|
|
|
|
|
BPB.media = bpb_sector[0x15];
|
|
|
|
|
BPB.spfat = BitConverter.ToUInt16(bpb_sector, 0x16);
|
|
|
|
|
BPB.sptrk = BitConverter.ToUInt16(bpb_sector, 0x18);
|
|
|
|
|
BPB.heads = BitConverter.ToUInt16(bpb_sector, 0x1A);
|
|
|
|
|
BPB.hsectors = BitConverter.ToUInt32(bpb_sector, 0x1C);
|
|
|
|
|
BPB.big_sectors = BitConverter.ToUInt32(bpb_sector, 0x20);
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
|
|
|
if(isFAT32)
|
2014-04-14 02:29:13 +00:00
|
|
|
{
|
2014-06-07 17:21:40 +01:00
|
|
|
FAT32PB.spfat = BitConverter.ToUInt32(bpb_sector, 0x24);
|
|
|
|
|
FAT32PB.fat_flags = BitConverter.ToUInt16(bpb_sector, 0x28);
|
|
|
|
|
FAT32PB.version = BitConverter.ToUInt16(bpb_sector, 0x2A);
|
|
|
|
|
FAT32PB.root_cluster = BitConverter.ToUInt32(bpb_sector, 0x2C);
|
|
|
|
|
FAT32PB.fsinfo_sector = BitConverter.ToUInt16(bpb_sector, 0x30);
|
|
|
|
|
FAT32PB.backup_sector = BitConverter.ToUInt16(bpb_sector, 0x32);
|
|
|
|
|
FAT32PB.drive_no = bpb_sector[0x40];
|
|
|
|
|
FAT32PB.nt_flags = bpb_sector[0x41];
|
|
|
|
|
FAT32PB.signature = bpb_sector[0x42];
|
|
|
|
|
FAT32PB.serial_no = BitConverter.ToUInt32(bpb_sector, 0x43);
|
|
|
|
|
dosString = new byte[11];
|
|
|
|
|
Array.Copy(bpb_sector, 0x47, dosString, 0, 11);
|
2016-02-05 00:01:09 +00:00
|
|
|
FAT32PB.volume_label = StringHandlers.CToString(dosString);
|
2014-06-07 17:21:40 +01:00
|
|
|
dosString = new byte[8];
|
|
|
|
|
Array.Copy(bpb_sector, 0x52, dosString, 0, 8);
|
2016-02-05 00:01:09 +00:00
|
|
|
FAT32PB.fs_type = StringHandlers.CToString(dosString);
|
2014-04-14 02:29:13 +00:00
|
|
|
}
|
2014-06-07 17:21:40 +01:00
|
|
|
else
|
2014-04-14 02:29:13 +00:00
|
|
|
{
|
2014-06-07 17:21:40 +01:00
|
|
|
EPB.drive_no = bpb_sector[0x24];
|
|
|
|
|
EPB.nt_flags = bpb_sector[0x25];
|
|
|
|
|
EPB.signature = bpb_sector[0x26];
|
|
|
|
|
EPB.serial_no = BitConverter.ToUInt32(bpb_sector, 0x27);
|
|
|
|
|
dosString = new byte[11];
|
|
|
|
|
Array.Copy(bpb_sector, 0x2B, dosString, 0, 11);
|
2016-02-05 00:01:09 +00:00
|
|
|
EPB.volume_label = StringHandlers.CToString(dosString);
|
2014-06-07 17:21:40 +01:00
|
|
|
dosString = new byte[8];
|
|
|
|
|
Array.Copy(bpb_sector, 0x36, dosString, 0, 8);
|
2016-02-05 00:01:09 +00:00
|
|
|
EPB.fs_type = StringHandlers.CToString(dosString);
|
2014-06-07 17:21:40 +01:00
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
|
2014-06-07 17:21:40 +01:00
|
|
|
sb.AppendFormat("OEM Name: {0}", BPB.OEMName).AppendLine();
|
|
|
|
|
sb.AppendFormat("{0} bytes per sector.", BPB.bps).AppendLine();
|
|
|
|
|
sb.AppendFormat("{0} sectors per cluster.", BPB.spc).AppendLine();
|
2015-12-05 17:10:27 +00:00
|
|
|
xmlFSType.ClusterSize = BPB.bps * BPB.spc;
|
2014-06-07 17:21:40 +01:00
|
|
|
sb.AppendFormat("{0} sectors reserved between BPB and FAT.", BPB.rsectors).AppendLine();
|
|
|
|
|
sb.AppendFormat("{0} FATs.", BPB.fats_no).AppendLine();
|
2014-06-08 00:43:49 +01:00
|
|
|
sb.AppendFormat("{0} entries on root directory.", BPB.root_ent).AppendLine();
|
2016-04-19 02:11:47 +01:00
|
|
|
if(BPB.sectors == 0)
|
2015-12-05 17:10:27 +00:00
|
|
|
{
|
2014-06-07 17:21:40 +01:00
|
|
|
sb.AppendFormat("{0} sectors on volume ({1} bytes).", BPB.big_sectors, BPB.big_sectors * BPB.bps).AppendLine();
|
2015-12-05 17:10:27 +00:00
|
|
|
xmlFSType.Clusters = BPB.big_sectors / BPB.spc;
|
|
|
|
|
}
|
2014-06-07 17:21:40 +01:00
|
|
|
else
|
2015-12-05 17:10:27 +00:00
|
|
|
{
|
2014-06-07 17:21:40 +01:00
|
|
|
sb.AppendFormat("{0} sectors on volume ({1} bytes).", BPB.sectors, BPB.sectors * BPB.bps).AppendLine();
|
2015-12-05 17:10:27 +00:00
|
|
|
xmlFSType.Clusters = BPB.sectors / BPB.spc;
|
|
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
if((BPB.media & 0xF0) == 0xF0)
|
2014-06-07 17:21:40 +01:00
|
|
|
sb.AppendFormat("Media format: 0x{0:X2}", BPB.media).AppendLine();
|
2016-04-19 02:11:47 +01:00
|
|
|
if(fat32_signature == "FAT32 ")
|
2014-06-07 17:21:40 +01:00
|
|
|
sb.AppendFormat("{0} sectors per FAT.", FAT32PB.spfat).AppendLine();
|
|
|
|
|
else
|
|
|
|
|
sb.AppendFormat("{0} sectors per FAT.", BPB.spfat).AppendLine();
|
|
|
|
|
sb.AppendFormat("{0} sectors per track.", BPB.sptrk).AppendLine();
|
|
|
|
|
sb.AppendFormat("{0} heads.", BPB.heads).AppendLine();
|
|
|
|
|
sb.AppendFormat("{0} hidden sectors before BPB.", BPB.hsectors).AppendLine();
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
|
|
|
if(isFAT32)
|
2014-06-07 17:21:40 +01:00
|
|
|
{
|
|
|
|
|
sb.AppendFormat("Cluster of root directory: {0}", FAT32PB.root_cluster).AppendLine();
|
|
|
|
|
sb.AppendFormat("Sector of FSINFO structure: {0}", FAT32PB.fsinfo_sector).AppendLine();
|
|
|
|
|
sb.AppendFormat("Sector of backup FAT32 parameter block: {0}", FAT32PB.backup_sector).AppendLine();
|
|
|
|
|
sb.AppendFormat("Drive number: 0x{0:X2}", FAT32PB.drive_no).AppendLine();
|
|
|
|
|
sb.AppendFormat("Volume Serial Number: 0x{0:X8}", FAT32PB.serial_no).AppendLine();
|
2016-07-28 22:25:26 +01:00
|
|
|
xmlFSType.VolumeSerial = string.Format("{0:X8}", FAT32PB.serial_no);
|
2016-04-19 02:11:47 +01:00
|
|
|
if((FAT32PB.nt_flags & 0x01) == 0x01)
|
2014-04-14 02:29:13 +00:00
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
sb.AppendLine("Volume should be checked on next mount.");
|
|
|
|
|
if((EPB.nt_flags & 0x02) == 0x02)
|
|
|
|
|
sb.AppendLine("Disk surface should be checked also.");
|
2015-12-05 17:10:27 +00:00
|
|
|
xmlFSType.Dirty = true;
|
2014-04-14 02:29:13 +00:00
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
sb.AppendFormat("Volume label: {0}", EPB.volume_label).AppendLine();
|
2016-02-05 00:01:09 +00:00
|
|
|
if(!string.IsNullOrEmpty(EPB.volume_label))
|
|
|
|
|
xmlFSType.VolumeName = EPB.volume_label;
|
2014-04-14 02:29:13 +00:00
|
|
|
sb.AppendFormat("Filesystem type: {0}", EPB.fs_type).AppendLine();
|
|
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
else if(EPB.signature == 0x28 || EPB.signature == 0x29)
|
2014-06-07 17:21:40 +01:00
|
|
|
{
|
|
|
|
|
sb.AppendFormat("Drive number: 0x{0:X2}", EPB.drive_no).AppendLine();
|
|
|
|
|
sb.AppendFormat("Volume Serial Number: 0x{0:X8}", EPB.serial_no).AppendLine();
|
2016-07-28 22:25:26 +01:00
|
|
|
xmlFSType.VolumeSerial = string.Format("{0:X8}", EPB.serial_no);
|
2016-04-19 02:11:47 +01:00
|
|
|
if(EPB.signature == 0x29)
|
2014-06-07 17:21:40 +01:00
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
if((EPB.nt_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.");
|
|
|
|
|
if((EPB.nt_flags & 0x02) == 0x02)
|
|
|
|
|
sb.AppendLine("Disk surface should be checked also.");
|
2015-12-05 17:10:27 +00:00
|
|
|
xmlFSType.Dirty = true;
|
2014-06-07 17:21:40 +01:00
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
|
2014-06-07 17:21:40 +01:00
|
|
|
sb.AppendFormat("Volume label: {0}", EPB.volume_label).AppendLine();
|
2016-02-05 00:01:09 +00:00
|
|
|
if(!string.IsNullOrEmpty(EPB.volume_label))
|
|
|
|
|
xmlFSType.VolumeName = EPB.volume_label;
|
2014-06-07 17:21:40 +01:00
|
|
|
sb.AppendFormat("Filesystem type: {0}", EPB.fs_type).AppendLine();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sb.AppendLine("Pre-DOS 2.0 Microsoft FAT12.");
|
|
|
|
|
sb.AppendLine("***WARNING***");
|
|
|
|
|
sb.AppendLine("This may be a false positive.");
|
2016-01-16 03:54:55 +00:00
|
|
|
sb.AppendFormat("Disk image identifies disk type as {0}.", imagePlugin.GetMediaType()).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();
|
|
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>FAT's BIOS Parameter Block.</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public struct BIOSParameterBlock
|
|
|
|
|
{
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x03, OEM Name, 8 bytes, space-padded</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public string OEMName;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x0B, Bytes per sector</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort bps;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x0D, Sectors per cluster</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public byte spc;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x0E, Reserved sectors between BPB and FAT</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort rsectors;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x10, Number of FATs</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public byte fats_no;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x11, Number of entries on root directory</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort root_ent;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x13, Sectors in volume</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort sectors;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x15, Media descriptor</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public byte media;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x16, Sectors per FAT</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort spfat;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x18, Sectors per track</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort sptrk;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x1A, Heads</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort heads;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x1C, Hidden sectors before BPB</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint hsectors;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x20, Sectors in volume if > 65535</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint big_sectors;
|
2014-04-14 02:29:13 +00:00
|
|
|
}
|
2014-06-07 17:21:40 +01:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Atari Boot Block.
|
|
|
|
|
/// This only applies for bootable disks
|
|
|
|
|
/// From http://info-coach.fr/atari/software/FD-Soft.php
|
|
|
|
|
/// </summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public struct AtariBootBlock
|
|
|
|
|
{
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x01C, Atari ST use 16 bit for hidden sectors, probably so did old DOS</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort hsectors;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x01E, indicates if COMMAND.PRG must be executed after OS load</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort xflag;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x020, load mode for, or 0 if fname indicates boot file</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort ldmode;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x022, sector from which to boot</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort bsect;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x024, how many sectors to boot</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort bsects_no;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x026, RAM address where boot should be located</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint ldaddr;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x02A, RAM address to copy the FAT and root directory</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint fatbuf;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x02E, 11 bytes, name of boot file</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public string fname;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x039, unused</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort reserved;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x03B, 451 bytes boot code</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public byte[] boot_code;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x1FE, the sum of all the BPB+ABB must be 0x1234, so this bigendian value works as adjustment</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort checksum;
|
2014-04-14 02:29:13 +00:00
|
|
|
}
|
2013-12-14 20:35:03 +00:00
|
|
|
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>DOS Extended Parameter Block</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public struct ExtendedParameterBlock
|
|
|
|
|
{
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x24, Drive number<summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public byte drive_no;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x25, Volume flags if NT (must be 0x29 signature)<summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public byte nt_flags;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x26, EPB signature, 0x28 or 0x29<summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public byte signature;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x27, Volume serial number<summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint serial_no;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x2B, Volume label, 11 bytes, space-padded
|
|
|
|
|
/// Present only if signature == 0x29<summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public string volume_label;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x36, Filesystem type, 8 bytes, space-padded
|
|
|
|
|
/// Present only if signature == 0x29<summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public string fs_type;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>FAT32 Parameter Block</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public struct FAT32ParameterBlock
|
|
|
|
|
{
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x24, Sectors per FAT</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint spfat;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x28, FAT flags</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort fat_flags;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x2A, FAT32 version</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort version;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x2C, Cluster of root directory</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint root_cluster;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x30, Sector of FSINFO structure</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort fsinfo_sector;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x32, Sector of FAT32PB backup</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort backup_sector;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x34, 12 reserved bytes</summary>
|
2014-08-28 19:03:32 +01:00
|
|
|
public byte[] reserved;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x40, Drive number</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public byte drive_no;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x41, Volume flags</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public byte nt_flags;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x42, FAT32PB signature, should be 0x29</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public byte signature;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x43, Volume serial number</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint serial_no;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x47, Volume label, 11 bytes, space-padded</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public string volume_label;
|
2014-06-07 17:21:40 +01:00
|
|
|
/// <summary>0x52, Filesystem type, 8 bytes, space-padded, must be "FAT32 "</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public string fs_type;
|
|
|
|
|
}
|
2016-07-21 17:16:08 +01:00
|
|
|
|
|
|
|
|
public override Errno Mount()
|
|
|
|
|
{
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 00:43:22 +01:00
|
|
|
public override Errno Mount(bool debug)
|
|
|
|
|
{
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-21 17:16:08 +01:00
|
|
|
public override Errno Unmount()
|
|
|
|
|
{
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Errno MapBlock(string path, long fileBlock, ref long deviceBlock)
|
|
|
|
|
{
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Errno GetAttributes(string path, ref FileAttributes attributes)
|
|
|
|
|
{
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Errno ListXAttr(string path, ref List<string> xattrs)
|
|
|
|
|
{
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Errno GetXattr(string path, string xattr, ref byte[] buf)
|
|
|
|
|
{
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Errno Read(string path, long offset, long size, ref byte[] buf)
|
|
|
|
|
{
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Errno ReadDir(string path, ref List<string> contents)
|
|
|
|
|
{
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Errno StatFs(ref FileSystemInfo stat)
|
|
|
|
|
{
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Errno Stat(string path, ref FileEntryInfo stat)
|
|
|
|
|
{
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Errno ReadLink(string path, ref string dest)
|
|
|
|
|
{
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
}
|
2014-04-14 02:29:13 +00:00
|
|
|
}
|
2014-04-14 01:14:20 +00:00
|
|
|
}
|