// /*************************************************************************** // Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : NeXT.cs // Author(s) : Natalia Portillo // // Component : Partitioning scheme plugins. // // --[ Description ] ---------------------------------------------------------- // // Manages NeXTStep and OpenStep disklabels. // // --[ 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 . // // ---------------------------------------------------------------------------- // Copyright © 2011-2025 Natalia Portillo // ****************************************************************************/ // Information learnt from XNU source and testing against real disks using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Runtime.InteropServices; using System.Text; using Aaru.CommonTypes; using Aaru.CommonTypes.Attributes; using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Interfaces; using Aaru.Helpers; using Aaru.Logging; using Marshal = Aaru.Helpers.Marshal; namespace Aaru.Partitions; /// /// Implements decoding of NeXT disklabels [SuppressMessage("ReSharper", "UnusedMember.Local")] [SuppressMessage("ReSharper", "UnusedType.Local")] public sealed partial class NeXTDisklabel : IPartition { /// "NeXT" const uint NEXT_MAGIC1 = 0x4E655854; /// "dlV2" const uint NEXT_MAGIC2 = 0x646C5632; /// "dlV3" const uint NEXT_MAGIC3 = 0x646C5633; /// 180 const ushort DISKTAB_START = 0xB4; /// 44 const ushort DISKTAB_ENTRY_SIZE = 0x2C; const string MODULE_NAME = "NeXT disklabel plugin"; #region IPartition Members /// public string Name => Localization.NeXTDisklabel_Name; /// public Guid Id => new("246A6D93-4F1A-1F8A-344D-50187A5513A9"); /// public string Author => Authors.NATALIA_PORTILLO; /// public bool GetInformation(IMediaImage imagePlugin, out List partitions, ulong sectorOffset) { var magicFound = false; byte[] labelSector; uint sectorSize = imagePlugin.Info.SectorSize is 2352 or 2448 ? 2048 : imagePlugin.Info.SectorSize; partitions = []; ulong labelPosition = 0; ErrorNumber errno; foreach(ulong i in new ulong[] { 0, 4, 15, 16 }.TakeWhile(i => i + sectorOffset < imagePlugin.Info.Sectors)) { errno = imagePlugin.ReadSector(i + sectorOffset, false, out labelSector, out _); if(errno != ErrorNumber.NoError) continue; var magic = BigEndianBitConverter.ToUInt32(labelSector, 0x00); if(magic != NEXT_MAGIC1 && magic != NEXT_MAGIC2 && magic != NEXT_MAGIC3) continue; magicFound = true; labelPosition = i + sectorOffset; break; } if(!magicFound) return false; uint sectorsToRead = 7680 / imagePlugin.Info.SectorSize; if(7680 % imagePlugin.Info.SectorSize > 0) sectorsToRead++; errno = imagePlugin.ReadSectors(labelPosition, false, sectorsToRead, out labelSector, out _); if(errno != ErrorNumber.NoError) return false; Label label = Marshal.ByteArrayToStructureBigEndian