Files
Aaru/DiscImageChef.Partitions/RioKarma.cs

113 lines
4.0 KiB
C#
Raw Normal View History

2017-05-19 20:28:49 +01:00
// /***************************************************************************
* DiscImageChef.Helpers/BigEndianStructure.cs: * DiscImageChef.Helpers/DiscImageChef.Helpers.csproj: Added code that directly marshals from a big-endian byte array. But untested with nested structures. * DiscImageChef.Partitions/Acorn.cs: Added support for Acorn FileCore partition, closes #4. * DiscImageChef.Partitions/BSD.cs: Moved BSD partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. * DiscImageChef.Partitions/DEC.cs: Added support for DEC disklabels, closes #11. * DiscImageChef.Partitions/DragonFlyBSD.cs: Added support for DragonFly BSD 64-bit disklabels. * DiscImageChef.Partitions/PC98.cs: Added support for NEC PC-9800 partitions. * DiscImageChef.Partitions/RioKarma.cs: Added support for Rio Karma partitions. * DiscImageChef.Partitions/SGI.cs: Added support for SGI DVHs, closes #9. * DiscImageChef.Partitions/UNIX.cs: Moved UNIX partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. * TODO: * README.md: * DiscImageChef.Partitions/DiscImageChef.Partitions.csproj: Added support for Acorn FileCore partition, closes #4. Added support for DEC disklabels, closes #11. Added support for SGI DVHs, closes #9. Moved BSD partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. Added support for DragonFly BSD 64-bit disklabels. Added support for NEC PC-9800 partitions. Added support for Rio Karma partitions. Moved UNIX partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. * DiscImageChef.Partitions/GPT.cs: Added new partition type UUIDs. * DiscImageChef.Partitions/MBR.cs: Moved BSD partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. Moved UNIX partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. * DiscImageChef.Partitions/Sun.cs: Added new partition types. Prepare structures for marshaling.
2016-08-21 08:27:43 +01:00
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : RioKarma.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Partitioning scheme plugins.
//
// --[ Description ] ----------------------------------------------------------
//
// Manages Rio Karma partitions.
//
// --[ 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-05-19 20:28:49 +01:00
// Copyright © 2011-2017 Natalia Portillo
* DiscImageChef.Helpers/BigEndianStructure.cs: * DiscImageChef.Helpers/DiscImageChef.Helpers.csproj: Added code that directly marshals from a big-endian byte array. But untested with nested structures. * DiscImageChef.Partitions/Acorn.cs: Added support for Acorn FileCore partition, closes #4. * DiscImageChef.Partitions/BSD.cs: Moved BSD partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. * DiscImageChef.Partitions/DEC.cs: Added support for DEC disklabels, closes #11. * DiscImageChef.Partitions/DragonFlyBSD.cs: Added support for DragonFly BSD 64-bit disklabels. * DiscImageChef.Partitions/PC98.cs: Added support for NEC PC-9800 partitions. * DiscImageChef.Partitions/RioKarma.cs: Added support for Rio Karma partitions. * DiscImageChef.Partitions/SGI.cs: Added support for SGI DVHs, closes #9. * DiscImageChef.Partitions/UNIX.cs: Moved UNIX partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. * TODO: * README.md: * DiscImageChef.Partitions/DiscImageChef.Partitions.csproj: Added support for Acorn FileCore partition, closes #4. Added support for DEC disklabels, closes #11. Added support for SGI DVHs, closes #9. Moved BSD partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. Added support for DragonFly BSD 64-bit disklabels. Added support for NEC PC-9800 partitions. Added support for Rio Karma partitions. Moved UNIX partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. * DiscImageChef.Partitions/GPT.cs: Added new partition type UUIDs. * DiscImageChef.Partitions/MBR.cs: Moved BSD partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. Moved UNIX partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. * DiscImageChef.Partitions/Sun.cs: Added new partition types. Prepare structures for marshaling.
2016-08-21 08:27:43 +01:00
// ****************************************************************************/
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using DiscImageChef.CommonTypes;
using DiscImageChef.ImagePlugins;
namespace DiscImageChef.PartPlugins
{
class RioKarma : PartPlugin
{
const ushort KarmaMagic = 0xAB56;
const byte EntryMagic = 0x4D;
public RioKarma()
{
Name = "Rio Karma partitioning";
PluginUUID = new Guid("246A6D93-4F1A-1F8A-344D-50187A5513A9");
}
public override bool GetInformation(ImagePlugin imagePlugin, out List<Partition> partitions)
{
partitions = new List<Partition>();
byte[] sector = imagePlugin.ReadSector(0);
if(sector.Length < 512)
return false;
RioKarmaTable table = new RioKarmaTable();
IntPtr tablePtr = Marshal.AllocHGlobal(512);
Marshal.Copy(sector, 0, tablePtr, 512);
table = (RioKarmaTable)Marshal.PtrToStructure(tablePtr, typeof(RioKarmaTable));
Marshal.FreeHGlobal(tablePtr);
if(table.magic != KarmaMagic)
return false;
ulong counter = 0;
foreach(RioKarmaEntry entry in table.entries)
{
Partition part = new Partition();
part.PartitionStartSector = entry.offset;
part.PartitionStart = (ulong)(entry.offset * sector.Length);
part.PartitionLength = entry.size;
part.PartitionSectors = (ulong)(entry.size * sector.Length);
part.PartitionType = "Rio Karma";
part.PartitionSequence = counter;
if(entry.type == EntryMagic)
{
partitions.Add(part);
counter++;
}
}
return true;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct RioKarmaTable
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 270)]
public byte[] reserved;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public RioKarmaEntry[] entries;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 208)]
public byte[] padding;
public ushort magic;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct RioKarmaEntry
{
public uint reserved;
* DiscImageChef.Helpers/BigEndianStructure.cs: * DiscImageChef.Helpers/DiscImageChef.Helpers.csproj: Added code that directly marshals from a big-endian byte array. But untested with nested structures. * DiscImageChef.Partitions/Acorn.cs: Added support for Acorn FileCore partition, closes #4. * DiscImageChef.Partitions/BSD.cs: Moved BSD partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. * DiscImageChef.Partitions/DEC.cs: Added support for DEC disklabels, closes #11. * DiscImageChef.Partitions/DragonFlyBSD.cs: Added support for DragonFly BSD 64-bit disklabels. * DiscImageChef.Partitions/PC98.cs: Added support for NEC PC-9800 partitions. * DiscImageChef.Partitions/RioKarma.cs: Added support for Rio Karma partitions. * DiscImageChef.Partitions/SGI.cs: Added support for SGI DVHs, closes #9. * DiscImageChef.Partitions/UNIX.cs: Moved UNIX partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. * TODO: * README.md: * DiscImageChef.Partitions/DiscImageChef.Partitions.csproj: Added support for Acorn FileCore partition, closes #4. Added support for DEC disklabels, closes #11. Added support for SGI DVHs, closes #9. Moved BSD partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. Added support for DragonFly BSD 64-bit disklabels. Added support for NEC PC-9800 partitions. Added support for Rio Karma partitions. Moved UNIX partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. * DiscImageChef.Partitions/GPT.cs: Added new partition type UUIDs. * DiscImageChef.Partitions/MBR.cs: Moved BSD partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. Moved UNIX partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. * DiscImageChef.Partitions/Sun.cs: Added new partition types. Prepare structures for marshaling.
2016-08-21 08:27:43 +01:00
public byte type;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public byte[] reserved2;
public uint offset;
public uint size;
}
}
}