diff --git a/Aaru.Filesystems/SonyPFS/Info.cs b/Aaru.Filesystems/SonyPFS/Info.cs index 1735a7374..5ae7f88bc 100644 --- a/Aaru.Filesystems/SonyPFS/Info.cs +++ b/Aaru.Filesystems/SonyPFS/Info.cs @@ -29,7 +29,9 @@ using System; using System.Text; using Aaru.CommonTypes.AaruMetadata; +using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Interfaces; +using Aaru.Helpers; using Partition = Aaru.CommonTypes.Partition; namespace Aaru.Filesystems; @@ -37,7 +39,31 @@ namespace Aaru.Filesystems; public partial class SonyPFS { /// - public bool Identify(IMediaImage imagePlugin, Partition partition) => throw new NotImplementedException(); + public bool Identify(IMediaImage imagePlugin, Partition partition) + { + uint sectorSize = imagePlugin.Info.SectorSize; + + if(sectorSize < 512) return false; + + // Superblock is at sector 0 relative to partition data start + int sbSize = Marshal.SizeOf(); + + var sectorsToRead = (uint)((sbSize + sectorSize - 1) / sectorSize); + + ErrorNumber errno = imagePlugin.ReadSectors(partition.Start, false, sectorsToRead, out byte[] sector, out _); + + if(errno != ErrorNumber.NoError) return false; + + if(sector.Length < sbSize) return false; + + SuperBlock sb = Marshal.ByteArrayToStructureLittleEndian(sector); + + if(sb.magic != PFS_SUPER_MAGIC) return false; + + if(sb.version > PFS_FORMAT_VERSION) return false; + + return true; + } /// public void GetInformation(IMediaImage imagePlugin, Partition partition, Encoding encoding, out string information,