2017-08-07 16:06:51 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2017-08-07 16:06:51 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : Plan9.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Partitioning scheme plugins.
|
2017-08-07 16:06:51 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Manages Plan9 partitions.
|
2017-08-07 16:06:51 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-12-03 16:07:10 +00:00
|
|
|
|
// Copyright © 2011-2023 Natalia Portillo
|
2017-08-07 16:06:51 +01:00
|
|
|
|
// ****************************************************************************/
|
2017-12-19 19:33:46 +00:00
|
|
|
|
|
2017-08-07 16:06:51 +01:00
|
|
|
|
using System;
|
2017-08-07 16:15:28 +01:00
|
|
|
|
using System.Collections.Generic;
|
2017-12-21 07:08:26 +00:00
|
|
|
|
using System.Linq;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
using Aaru.CommonTypes.Enums;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
2020-07-20 15:43:52 +01:00
|
|
|
|
using Aaru.Helpers;
|
2017-08-07 16:15:28 +01:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
namespace Aaru.Partitions;
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
// This is the most stupid or the most intelligent partition scheme ever done, pick or take
|
|
|
|
|
|
// At sector 1 from offset, text resides (yes, TEXT) in following format:
|
|
|
|
|
|
// "part type start end\n"
|
|
|
|
|
|
// One line per partition, start and end relative to offset
|
|
|
|
|
|
// e.g.: "part nvram 10110 10112\npart fossil 10112 3661056\n"
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
/// <summary>Implements decoding of Plan-9 partitions</summary>
|
|
|
|
|
|
public sealed class Plan9 : IPartition
|
2017-08-07 16:06:51 +01:00
|
|
|
|
{
|
2021-08-17 14:25:12 +01:00
|
|
|
|
/// <inheritdoc />
|
2022-11-29 03:13:21 +00:00
|
|
|
|
public string Name => Localization.Plan9_Name;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public Guid Id => new("F0BF4FFC-056E-4E7C-8B65-4EAEE250ADD9");
|
|
|
|
|
|
/// <inheritdoc />
|
2022-11-29 03:13:21 +00:00
|
|
|
|
public string Author => Authors.NataliaPortillo;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool GetInformation(IMediaImage imagePlugin, out List<Partition> partitions, ulong sectorOffset)
|
2017-08-07 16:06:51 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
partitions = new List<Partition>();
|
2017-08-07 16:15:28 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(sectorOffset + 2 >= imagePlugin.Info.Sectors)
|
|
|
|
|
|
return false;
|
2017-11-08 17:05:00 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSector(sectorOffset + 1, out byte[] sector);
|
2017-11-08 17:05:00 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return false;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
// While all of Plan9 is supposedly UTF-8, it uses ASCII strcmp for reading its partition table
|
|
|
|
|
|
string[] really = StringHandlers.CToString(sector).Split('\n');
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-14 01:15:06 +00:00
|
|
|
|
foreach(string[] tokens in really.TakeWhile(part => part.Length >= 5 && part[..5] == "part ").
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Select(part => part.Split(' ')).TakeWhile(tokens => tokens.Length == 4))
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!ulong.TryParse(tokens[2], out ulong start) ||
|
|
|
|
|
|
!ulong.TryParse(tokens[3], out ulong end))
|
|
|
|
|
|
break;
|
2017-08-07 16:15:28 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
var part = new Partition
|
2017-12-24 03:11:33 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Length = end - start + 1,
|
|
|
|
|
|
Offset = (start + sectorOffset) * imagePlugin.Info.SectorSize,
|
|
|
|
|
|
Scheme = Name,
|
|
|
|
|
|
Sequence = (ulong)partitions.Count,
|
|
|
|
|
|
Size = (end - start + 1) * imagePlugin.Info.SectorSize,
|
|
|
|
|
|
Start = start + sectorOffset,
|
|
|
|
|
|
Type = tokens[1]
|
|
|
|
|
|
};
|
2017-08-07 16:15:28 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
partitions.Add(part);
|
2017-08-07 16:06:51 +01:00
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
return partitions.Count > 0;
|
2017-08-07 16:06:51 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|