From 01656b767bb83472b1d741a430eab10070d762d4 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 7 Aug 2017 16:15:28 +0100 Subject: [PATCH] Added support for Plan9 partition tables. --- .../DiscImageChef.Partitions.csproj | 3 +- DiscImageChef.Partitions/Plan9.cs | 52 ++++++++++++++++++- README.md | 1 + 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/DiscImageChef.Partitions/DiscImageChef.Partitions.csproj b/DiscImageChef.Partitions/DiscImageChef.Partitions.csproj index c87361e0d..51eb378fb 100644 --- a/DiscImageChef.Partitions/DiscImageChef.Partitions.csproj +++ b/DiscImageChef.Partitions/DiscImageChef.Partitions.csproj @@ -55,6 +55,7 @@ + @@ -96,7 +97,7 @@ - + diff --git a/DiscImageChef.Partitions/Plan9.cs b/DiscImageChef.Partitions/Plan9.cs index 51b6d8ee2..c5683eaca 100644 --- a/DiscImageChef.Partitions/Plan9.cs +++ b/DiscImageChef.Partitions/Plan9.cs @@ -30,12 +30,60 @@ // Copyright © 2011-2017 Natalia Portillo // ****************************************************************************/ using System; -namespace DiscImageChef.Partitions +using System.Collections.Generic; +using DiscImageChef.CommonTypes; + +namespace DiscImageChef.PartPlugins { - public class Plan9 + // 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" + public class Plan9 : PartPlugin { public Plan9() { + Name = "Plan9 partition table"; + PluginUUID = new Guid("F0BF4FFC-056E-4E7C-8B65-4EAEE250ADD9"); + } + + public override bool GetInformation(ImagePlugins.ImagePlugin imagePlugin, out List partitions, ulong sectorOffset) + { + partitions = new List(); + 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) + { + if(part.Length < 5 || part.Substring(0, 5) != "part ") + break; + + string[] tokens = part.Split(new[] { ' ' }); + + if(tokens.Length != 4) + break; + + if(!ulong.TryParse(tokens[2], out ulong start) || + !ulong.TryParse(tokens[3], out ulong end)) + break; + + 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); + } + + return partitions.Count>0; } } } diff --git a/README.md b/README.md index 2b7979b8f..b965938bf 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ Supported partitioning schemes * Minix subpartitions inside MBR * NEC PC9800 partitions * NeXT disklabel +* Plan9 partition table * Rio Karma partitions * SGI volume headers * Solaris slices inside MBR