2017-08-02 13:57:04 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2017-08-02 13:57:53 +01:00
|
|
|
|
// Filename : XENIX.cs
|
2017-08-02 13:57:04 +01:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-08-02 13:57:53 +01:00
|
|
|
|
// Component : Partitioning scheme plugins.
|
2017-08-02 13:57:04 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-08-02 13:57:53 +01:00
|
|
|
|
// Manages XENIX partitions.
|
2017-08-02 13:57:04 +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-02 13:57:04 +01:00
|
|
|
|
// ****************************************************************************/
|
2017-08-02 13:57:53 +01:00
|
|
|
|
|
2017-08-02 13:57:04 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2017-08-02 13:57:53 +01:00
|
|
|
|
using System.Runtime.InteropServices;
|
2017-08-02 13:57:04 +01:00
|
|
|
|
using DiscImageChef.CommonTypes;
|
2017-08-02 13:57:53 +01:00
|
|
|
|
using DiscImageChef.Console;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
using DiscImageChef.DiscImages;
|
2017-08-02 13:57:04 +01:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
namespace DiscImageChef.Partitions
|
2017-08-02 13:57:04 +01:00
|
|
|
|
{
|
2017-08-02 13:57:53 +01:00
|
|
|
|
// TODO: Find better documentation, this is working for XENIX 2 but not for SCO OpenServer...
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public class XENIX : IPartition
|
2017-08-02 13:57:04 +01:00
|
|
|
|
{
|
2017-08-02 13:57:53 +01:00
|
|
|
|
const ushort PAMAGIC = 0x1234;
|
|
|
|
|
|
const int MAXPARTS = 16;
|
|
|
|
|
|
const uint XENIX_BSIZE = 1024;
|
|
|
|
|
|
// Can't find this in any documentation but everything is aligned to this offset (in sectors)
|
|
|
|
|
|
const uint XENIX_OFFSET = 977;
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public string Name => "XENIX";
|
|
|
|
|
|
public Guid Id => new Guid("53BE01DE-E68B-469F-A17F-EC2E4BD61CD9");
|
2017-08-02 13:57:04 +01:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool GetInformation(IMediaImage imagePlugin, out List<Partition> partitions, ulong sectorOffset)
|
2017-08-02 13:57:04 +01:00
|
|
|
|
{
|
|
|
|
|
|
partitions = new List<Partition>();
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(42 + sectorOffset >= imagePlugin.Info.Sectors) return false;
|
2017-08-02 13:57:04 +01:00
|
|
|
|
|
2017-08-02 13:57:53 +01:00
|
|
|
|
byte[] tblsector = imagePlugin.ReadSector(42 + sectorOffset);
|
2017-08-02 13:57:04 +01:00
|
|
|
|
|
2017-08-02 13:57:53 +01:00
|
|
|
|
GCHandle handle = GCHandle.Alloc(tblsector, GCHandleType.Pinned);
|
|
|
|
|
|
partable xnxtbl = (partable)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(partable));
|
|
|
|
|
|
handle.Free();
|
2017-08-02 13:57:04 +01:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("XENIX plugin", "xnxtbl.p_magic = 0x{0:X4} (should be 0x{1:X4})", xnxtbl.p_magic,
|
|
|
|
|
|
PAMAGIC);
|
2017-08-02 13:57:04 +01:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(xnxtbl.p_magic != PAMAGIC) return false;
|
2017-08-02 13:57:04 +01:00
|
|
|
|
|
2017-08-02 13:57:53 +01:00
|
|
|
|
for(int i = 0; i < MAXPARTS; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.DebugWriteLine("XENIX plugin", "xnxtbl.p[{0}].p_off = {1}", i, xnxtbl.p[i].p_off);
|
|
|
|
|
|
DicConsole.DebugWriteLine("XENIX plugin", "xnxtbl.p[{0}].p_size = {1}", i, xnxtbl.p[i].p_size);
|
2017-12-21 06:06:19 +00:00
|
|
|
|
if(xnxtbl.p[i].p_size <= 0) continue;
|
|
|
|
|
|
|
|
|
|
|
|
Partition part = new Partition
|
2017-08-02 13:57:53 +01:00
|
|
|
|
{
|
2017-12-21 06:06:19 +00:00
|
|
|
|
Start =
|
2017-12-26 06:05:12 +00:00
|
|
|
|
(ulong)((xnxtbl.p[i].p_off + XENIX_OFFSET) * XENIX_BSIZE) / imagePlugin.Info.SectorSize +
|
2017-12-21 06:06:19 +00:00
|
|
|
|
sectorOffset,
|
2017-12-26 06:05:12 +00:00
|
|
|
|
Length = (ulong)(xnxtbl.p[i].p_size * XENIX_BSIZE) / imagePlugin.Info.SectorSize,
|
2017-12-21 06:06:19 +00:00
|
|
|
|
Offset =
|
|
|
|
|
|
(ulong)((xnxtbl.p[i].p_off + XENIX_OFFSET) * XENIX_BSIZE) +
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imagePlugin.Info.SectorSize * sectorOffset,
|
2017-12-21 06:06:19 +00:00
|
|
|
|
Size = (ulong)(xnxtbl.p[i].p_size * XENIX_BSIZE),
|
|
|
|
|
|
Sequence = (ulong)i,
|
|
|
|
|
|
Type = "XENIX",
|
|
|
|
|
|
Scheme = Name
|
|
|
|
|
|
};
|
2017-08-02 13:57:53 +01:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(part.End < imagePlugin.Info.Sectors) partitions.Add(part);
|
2017-08-02 13:57:53 +01:00
|
|
|
|
}
|
2017-08-02 13:57:04 +01:00
|
|
|
|
|
2017-08-02 13:57:53 +01:00
|
|
|
|
return partitions.Count > 0;
|
|
|
|
|
|
}
|
2017-08-02 13:57:04 +01:00
|
|
|
|
|
2017-08-02 13:57:53 +01:00
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct partable
|
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
public ushort p_magic; /* magic number validity indicator */
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAXPARTS)] public partition[] p; /*partition headers*/
|
2017-08-02 13:57:53 +01:00
|
|
|
|
}
|
2017-08-02 13:57:04 +01:00
|
|
|
|
|
2017-08-02 13:57:53 +01:00
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct partition
|
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
public int p_off; /*start 1K block no of partition*/
|
|
|
|
|
|
public int p_size; /*# of 1K blocks in partition*/
|
2017-08-02 13:57:53 +01:00
|
|
|
|
}
|
2017-08-02 13:57:04 +01:00
|
|
|
|
}
|
2017-08-02 13:57:53 +01:00
|
|
|
|
}
|