Files
Aaru/DiscImageChef.Filesystems/ECMA67.cs

128 lines
5.2 KiB
C#
Raw Normal View History

// /***************************************************************************
2016-09-17 16:56:09 +01:00
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : ECMA67.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : ECMA-67 plugin.
//
// --[ Description ] ----------------------------------------------------------
//
// Identifies the ECMA-67 file system and shows information.
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2011-2018 Natalia Portillo
2016-09-17 16:56:09 +01:00
// ****************************************************************************/
using System;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using DiscImageChef.CommonTypes;
using DiscImageChef.DiscImages;
2017-12-21 14:30:38 +00:00
using Schemas;
2016-09-17 16:56:09 +01:00
namespace DiscImageChef.Filesystems
{
public class ECMA67 : IFilesystem
2016-09-17 16:56:09 +01:00
{
2018-06-20 22:22:21 +01:00
readonly byte[] ecma67_magic = {0x56, 0x4F, 0x4C};
2018-06-22 08:08:38 +01:00
public Encoding Encoding { get; private set; }
public string Name => "ECMA-67";
public Guid Id => new Guid("62A2D44A-CBC1-4377-B4B6-28C5C92034A1");
2017-12-26 08:01:40 +00:00
public FileSystemType XmlFsType { get; private set; }
2016-09-17 16:56:09 +01:00
public bool Identify(IMediaImage imagePlugin, Partition partition)
2016-09-17 16:56:09 +01:00
{
2017-12-19 20:33:03 +00:00
if(partition.Start > 0) return false;
2016-09-17 16:56:09 +01:00
2017-12-19 20:33:03 +00:00
if(partition.End < 8) return false;
2016-09-17 16:56:09 +01:00
byte[] sector = imagePlugin.ReadSector(6);
2017-12-19 20:33:03 +00:00
if(sector.Length != 128) return false;
2016-09-17 16:56:09 +01:00
2018-06-22 08:08:38 +01:00
VolumeLabel vol = new VolumeLabel();
IntPtr volPtr = Marshal.AllocHGlobal(Marshal.SizeOf(vol));
2016-09-17 16:56:09 +01:00
Marshal.Copy(sector, 0, volPtr, Marshal.SizeOf(vol));
vol = (VolumeLabel)Marshal.PtrToStructure(volPtr, typeof(VolumeLabel));
Marshal.FreeHGlobal(volPtr);
2018-06-20 22:22:21 +01:00
return ecma67_magic.SequenceEqual(vol.labelIdentifier) && vol.labelNumber == 1 && vol.recordLength == 0x31;
2016-09-17 16:56:09 +01:00
}
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
2018-06-22 08:08:38 +01:00
Encoding encoding)
2016-09-17 16:56:09 +01:00
{
2017-12-26 08:01:40 +00:00
Encoding = encoding ?? Encoding.GetEncoding("iso-8859-1");
2016-09-17 16:56:09 +01:00
byte[] sector = imagePlugin.ReadSector(6);
StringBuilder sbInformation = new StringBuilder();
2018-06-22 08:08:38 +01:00
VolumeLabel vol = new VolumeLabel();
IntPtr volPtr = Marshal.AllocHGlobal(Marshal.SizeOf(vol));
2016-09-17 16:56:09 +01:00
Marshal.Copy(sector, 0, volPtr, Marshal.SizeOf(vol));
vol = (VolumeLabel)Marshal.PtrToStructure(volPtr, typeof(VolumeLabel));
Marshal.FreeHGlobal(volPtr);
sbInformation.AppendLine("ECMA-67");
sbInformation.AppendFormat("Volume name: {0}", Encoding.ASCII.GetString(vol.volumeIdentifier)).AppendLine();
sbInformation.AppendFormat("Volume owner: {0}", Encoding.ASCII.GetString(vol.owner)).AppendLine();
2017-12-26 08:01:40 +00:00
XmlFsType = new FileSystemType
{
2018-06-22 08:08:38 +01:00
Type = "ECMA-67",
ClusterSize = 256,
2018-06-22 08:08:38 +01:00
Clusters = (long)(partition.End - partition.Start + 1),
VolumeName = Encoding.ASCII.GetString(vol.volumeIdentifier)
};
2016-09-17 16:56:09 +01:00
information = sbInformation.ToString();
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct VolumeLabel
{
2018-06-22 08:08:38 +01:00
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public byte[] labelIdentifier;
public byte labelNumber;
2018-06-22 08:08:38 +01:00
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
public byte[] volumeIdentifier;
public byte volumeAccessibility;
2018-06-22 08:08:38 +01:00
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 26)]
public byte[] reserved1;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 14)]
public byte[] owner;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[] reserved2;
public byte surface;
2018-06-22 08:08:38 +01:00
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public byte[] reserved3;
public byte recordLength;
2018-06-22 08:08:38 +01:00
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public byte[] reserved4;
public byte fileLabelAllocation;
public byte labelStandardVersion;
2018-06-22 08:08:38 +01:00
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 48)]
public byte[] reserved5;
}
2016-09-17 16:56:09 +01:00
}
}