From 2e7f2cd6fe00312f24efe2cdb12f9d649e02bfec Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 6 Apr 2019 12:35:47 +0100 Subject: [PATCH] Support FATX volume label. --- DiscImageChef.Filesystems/FATX/Info.cs | 21 ++++++++++++++++++--- DiscImageChef.Filesystems/FATX/Structs.cs | 12 +++++++----- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/DiscImageChef.Filesystems/FATX/Info.cs b/DiscImageChef.Filesystems/FATX/Info.cs index 138cf86fe..660d334a6 100644 --- a/DiscImageChef.Filesystems/FATX/Info.cs +++ b/DiscImageChef.Filesystems/FATX/Info.cs @@ -58,11 +58,17 @@ namespace DiscImageChef.Filesystems.FATX information = ""; if(imagePlugin.Info.SectorSize < 512) return; + bool bigEndian = true; + byte[] sector = imagePlugin.ReadSector(partition.Start); Superblock fatxSb = Marshal.ByteArrayToStructureBigEndian(sector); - if(fatxSb.magic == FATX_CIGAM) fatxSb = Marshal.ByteArrayToStructureLittleEndian(sector); + if(fatxSb.magic == FATX_CIGAM) + { + fatxSb = Marshal.ByteArrayToStructureLittleEndian(sector); + bigEndian = false; + } if(fatxSb.magic != FATX_MAGIC) return; @@ -79,12 +85,21 @@ namespace DiscImageChef.Filesystems.FATX .AppendLine(); sb.AppendFormat("Root directory starts on cluster {0}", fatxSb.rootDirectoryCluster).AppendLine(); + string volumeLabel = StringHandlers.CToString(fatxSb.volumeLabel, + bigEndian ? Encoding.BigEndianUnicode : Encoding.Unicode, + true); + + sb.AppendFormat("Volume label: {0}", volumeLabel).AppendLine(); + information = sb.ToString(); XmlFsType = new FileSystemType { - Type = "FATX filesystem", - ClusterSize = (int)(fatxSb.sectorsPerCluster * imagePlugin.Info.SectorSize) + Type = "FATX filesystem", + ClusterSize = + (int)(fatxSb.sectorsPerCluster * logicalSectorsPerPhysicalSectors * + imagePlugin.Info.SectorSize), + VolumeName = volumeLabel }; XmlFsType.Clusters = (long)((partition.End - partition.Start + 1) * imagePlugin.Info.SectorSize / (ulong)XmlFsType.ClusterSize); diff --git a/DiscImageChef.Filesystems/FATX/Structs.cs b/DiscImageChef.Filesystems/FATX/Structs.cs index ab80415b4..710049bff 100644 --- a/DiscImageChef.Filesystems/FATX/Structs.cs +++ b/DiscImageChef.Filesystems/FATX/Structs.cs @@ -39,11 +39,13 @@ namespace DiscImageChef.Filesystems.FATX [StructLayout(LayoutKind.Sequential, Pack = 1)] struct Superblock { - public uint magic; - public uint id; - public uint sectorsPerCluster; - public uint rootDirectoryCluster; - public ushort unknown; + public uint magic; + public uint id; + public uint sectorsPerCluster; + public uint rootDirectoryCluster; + // TODO: Undetermined size + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] + public byte[] volumeLabel; } [StructLayout(LayoutKind.Sequential, Pack = 1)]