2017-08-07 16:06:51 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Copyright © 2011-2018 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;
|
|
|
|
|
|
using DiscImageChef.CommonTypes;
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
namespace DiscImageChef.Partitions
|
2017-08-07 16:06:51 +01:00
|
|
|
|
{
|
2017-08-07 16:15:28 +01: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"
|
2017-12-20 17:15:26 +00:00
|
|
|
|
public class Plan9 : PartitionPlugin
|
2017-08-07 16:06:51 +01:00
|
|
|
|
{
|
|
|
|
|
|
public Plan9()
|
|
|
|
|
|
{
|
2017-08-07 16:15:28 +01:00
|
|
|
|
Name = "Plan9 partition table";
|
2017-12-20 17:15:26 +00:00
|
|
|
|
PluginUuid = new Guid("F0BF4FFC-056E-4E7C-8B65-4EAEE250ADD9");
|
2017-08-07 16:15:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
public override bool GetInformation(DiscImages.ImagePlugin imagePlugin, out List<Partition> partitions,
|
2017-12-19 20:33:03 +00:00
|
|
|
|
ulong sectorOffset)
|
2017-08-07 16:15:28 +01:00
|
|
|
|
{
|
|
|
|
|
|
partitions = new List<Partition>();
|
2017-11-08 17:05:00 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(sectorOffset + 2 >= imagePlugin.GetSectors()) return false;
|
2017-11-08 17:05:00 +00:00
|
|
|
|
|
2017-08-07 16:15:28 +01:00
|
|
|
|
byte[] sector = imagePlugin.ReadSector(sectorOffset + 1);
|
|
|
|
|
|
// While all of Plan9 is supposedly UTF-8, it uses ASCII strcmp for reading its partition table
|
|
|
|
|
|
string[] really = StringHandlers.CToString(sector).Split(new[] {'\n'});
|
|
|
|
|
|
|
|
|
|
|
|
foreach(string part in really)
|
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(part.Length < 5 || part.Substring(0, 5) != "part ") break;
|
2017-08-07 16:15:28 +01:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
string[] tokens = part.Split(new[] {' '});
|
2017-08-07 16:15:28 +01:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(tokens.Length != 4) break;
|
2017-08-07 16:15:28 +01:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(!ulong.TryParse(tokens[2], out ulong start) || !ulong.TryParse(tokens[3], out ulong end)) break;
|
2017-08-07 16:15:28 +01:00
|
|
|
|
|
|
|
|
|
|
Partition _part = new Partition
|
|
|
|
|
|
{
|
|
|
|
|
|
Length = (end - start) + 1,
|
|
|
|
|
|
Offset = (start + sectorOffset) * imagePlugin.GetSectorSize(),
|
|
|
|
|
|
Scheme = Name,
|
|
|
|
|
|
Sequence = (ulong)partitions.Count,
|
|
|
|
|
|
Size = ((end - start) + 1) * imagePlugin.GetSectorSize(),
|
|
|
|
|
|
Start = start + sectorOffset,
|
|
|
|
|
|
Type = tokens[1]
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
partitions.Add(_part);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
return partitions.Count > 0;
|
2017-08-07 16:06:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|