2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2016-09-18 05:09:02 +01:00
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : ZFS.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : ZFS filesystem plugin.
|
2016-09-18 05:09:02 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2016-09-18 05:09:55 +01:00
|
|
|
|
// Identifies the ZFS filesystem and shows information.
|
2016-09-18 05:09:02 +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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2018-12-29 17:34:38 +00:00
|
|
|
|
// Copyright © 2011-2019 Natalia Portillo
|
2016-09-18 05:09:02 +01:00
|
|
|
|
// ****************************************************************************/
|
2016-09-18 05:09:55 +01:00
|
|
|
|
|
2016-09-18 05:09:02 +01:00
|
|
|
|
using System;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
using System.Collections.Generic;
|
2017-12-22 08:43:22 +00:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
using System.Text;
|
2017-07-19 16:31:08 +01:00
|
|
|
|
using DiscImageChef.CommonTypes;
|
2018-06-25 19:08:16 +01:00
|
|
|
|
using DiscImageChef.CommonTypes.Interfaces;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using Schemas;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
|
2016-09-18 05:09:02 +01:00
|
|
|
|
namespace DiscImageChef.Filesystems
|
|
|
|
|
|
{
|
2016-09-18 05:09:55 +01:00
|
|
|
|
/*
|
|
|
|
|
|
* The ZFS on-disk structure is quite undocumented, so this has been checked using several test images and reading the comments and headers (but not the code)
|
|
|
|
|
|
* of ZFS-On-Linux.
|
2018-08-29 22:15:43 +01:00
|
|
|
|
*
|
2016-09-18 05:09:55 +01:00
|
|
|
|
* The most basic structure, the vdev label, is as follows:
|
|
|
|
|
|
* 8KiB of blank space
|
|
|
|
|
|
* 8KiB reserved for boot code, stored as a ZIO block with magic and checksum
|
|
|
|
|
|
* 112KiB of nvlist, usually encoded using XDR
|
|
|
|
|
|
* 128KiB of copies of the 1KiB uberblock
|
2018-08-29 22:15:43 +01:00
|
|
|
|
*
|
2016-09-18 05:09:55 +01:00
|
|
|
|
* Two vdev labels, L0 and L1 are stored at the start of the vdev.
|
|
|
|
|
|
* Another two, L2 and L3 are stored at the end.
|
2018-08-29 22:15:43 +01:00
|
|
|
|
*
|
2016-09-18 05:09:55 +01:00
|
|
|
|
* The nvlist is nothing more than a double linked list of name/value pairs where name is a string and value is an arbitrary type (and can be an array of it).
|
|
|
|
|
|
* On-disk they are stored sequentially (no pointers) and can be encoded in XDR (an old Sun serialization method that stores everything as 4 bytes chunks) or
|
|
|
|
|
|
* natively (that is as the host natively stores that values, for example on Intel an extended float would be 10 bytes (80 bit).
|
|
|
|
|
|
* It can also be encoded little or big endian.
|
|
|
|
|
|
* Because of this variations, ZFS stored a header indicating the used encoding and endianess before the encoded nvlist.
|
|
|
|
|
|
*/
|
2017-12-22 08:43:22 +00:00
|
|
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public class ZFS : IFilesystem
|
2016-09-18 05:09:02 +01:00
|
|
|
|
{
|
2017-12-22 08:43:22 +00:00
|
|
|
|
const ulong ZEC_MAGIC = 0x0210DA7AB10C7A11;
|
|
|
|
|
|
const ulong ZEC_CIGAM = 0x117A0CB17ADA1002;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
|
|
|
|
|
|
// These parameters define how the nvlist is stored
|
2017-12-22 08:43:22 +00:00
|
|
|
|
const byte NVS_LITTLE_ENDIAN = 1;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
const byte NVS_BIG_ENDIAN = 0;
|
|
|
|
|
|
const byte NVS_NATIVE = 0;
|
|
|
|
|
|
const byte NVS_XDR = 1;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
const ulong UBERBLOCK_MAGIC = 0x00BAB10C;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
const uint ZFS_MAGIC = 0x58465342;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
public FileSystemType XmlFsType { get; private set; }
|
2018-06-22 08:08:38 +01:00
|
|
|
|
public Encoding Encoding { get; private set; }
|
|
|
|
|
|
public string Name => "ZFS Filesystem Plugin";
|
|
|
|
|
|
public Guid Id => new Guid("0750014F-A714-4692-A369-E23F6EC3659C");
|
2018-08-29 22:15:43 +01:00
|
|
|
|
public string Author => "Natalia Portillo";
|
2017-10-12 23:54:02 +01:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
2016-09-18 05:09:55 +01:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize < 512) return false;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
|
|
|
|
|
|
byte[] sector;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
ulong magic;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
|
2017-07-19 16:37:11 +01:00
|
|
|
|
if(partition.Start + 31 < partition.End)
|
2016-09-18 05:09:55 +01:00
|
|
|
|
{
|
2017-07-19 16:37:11 +01:00
|
|
|
|
sector = imagePlugin.ReadSector(partition.Start + 31);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
magic = BitConverter.ToUInt64(sector, 0x1D8);
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(magic == ZEC_MAGIC || magic == ZEC_CIGAM) return true;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
|
if(partition.Start + 16 >= partition.End) return false;
|
|
|
|
|
|
|
|
|
|
|
|
sector = imagePlugin.ReadSector(partition.Start + 16);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
magic = BitConverter.ToUInt64(sector, 0x1D8);
|
2017-12-22 08:43:22 +00:00
|
|
|
|
return magic == ZEC_MAGIC || magic == ZEC_CIGAM;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
|
2018-06-22 08:08:38 +01:00
|
|
|
|
Encoding encoding)
|
2016-09-18 05:09:55 +01:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
// ZFS is always UTF-8
|
2018-06-22 08:08:38 +01:00
|
|
|
|
Encoding = Encoding.UTF8;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
information = "";
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize < 512) return;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
|
|
|
|
|
|
byte[] sector;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
ulong magic;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
|
|
|
|
|
|
ulong nvlistOff = 32;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
uint nvlistLen = 114688 / imagePlugin.Info.SectorSize;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
|
2017-07-19 16:37:11 +01:00
|
|
|
|
if(partition.Start + 31 < partition.End)
|
2016-09-18 05:09:55 +01:00
|
|
|
|
{
|
2017-07-19 16:37:11 +01:00
|
|
|
|
sector = imagePlugin.ReadSector(partition.Start + 31);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
magic = BitConverter.ToUInt64(sector, 0x1D8);
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(magic == ZEC_MAGIC || magic == ZEC_CIGAM) nvlistOff = 32;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-07-19 16:37:11 +01:00
|
|
|
|
if(partition.Start + 16 < partition.End)
|
2016-09-18 05:09:55 +01:00
|
|
|
|
{
|
2017-07-19 16:37:11 +01:00
|
|
|
|
sector = imagePlugin.ReadSector(partition.Start + 16);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
magic = BitConverter.ToUInt64(sector, 0x1D8);
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(magic == ZEC_MAGIC || magic == ZEC_CIGAM) nvlistOff = 17;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
sb.AppendLine("ZFS filesystem");
|
|
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
byte[] nvlist = imagePlugin.ReadSectors(partition.Start + nvlistOff, nvlistLen);
|
2016-09-18 05:09:55 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
sb.AppendLine(!DecodeNvList(nvlist, out Dictionary<string, NVS_Item> decodedNvList)
|
|
|
|
|
|
? "Could not decode nvlist"
|
|
|
|
|
|
: PrintNvList(decodedNvList));
|
2016-09-18 05:09:55 +01:00
|
|
|
|
|
|
|
|
|
|
information = sb.ToString();
|
|
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType = new FileSystemType {Type = "ZFS filesystem"};
|
|
|
|
|
|
if(decodedNvList.TryGetValue("name", out NVS_Item tmpObj)) XmlFsType.VolumeName = (string)tmpObj.value;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
if(decodedNvList.TryGetValue("guid", out tmpObj)) XmlFsType.VolumeSerial = $"{(ulong)tmpObj.value}";
|
2016-09-18 05:09:55 +01:00
|
|
|
|
if(decodedNvList.TryGetValue("pool_guid", out tmpObj))
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.VolumeSetIdentifier = $"{(ulong)tmpObj.value}";
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool DecodeNvList(byte[] nvlist, out Dictionary<string, NVS_Item> decodedNvList)
|
|
|
|
|
|
{
|
|
|
|
|
|
byte[] tmp = new byte[nvlist.Length - 4];
|
|
|
|
|
|
Array.Copy(nvlist, 4, tmp, 0, nvlist.Length - 4);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
bool xdr = nvlist[0] == 1;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
bool littleEndian = nvlist[1] == 1;
|
|
|
|
|
|
|
|
|
|
|
|
return DecodeNvList(tmp, out decodedNvList, xdr, littleEndian);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Decode native nvlist
|
2017-12-19 20:33:03 +00:00
|
|
|
|
static bool DecodeNvList(byte[] nvlist, out Dictionary<string, NVS_Item> decodedNvList, bool xdr,
|
2018-06-22 08:08:38 +01:00
|
|
|
|
bool littleEndian)
|
2016-09-18 05:09:55 +01:00
|
|
|
|
{
|
|
|
|
|
|
decodedNvList = new Dictionary<string, NVS_Item>();
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(nvlist == null || nvlist.Length < 16) return false;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(!xdr) return false;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
|
2018-06-20 22:22:21 +01:00
|
|
|
|
int offset = 8;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
while(offset < nvlist.Length)
|
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
NVS_Item item = new NVS_Item();
|
|
|
|
|
|
int currOff = offset;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
|
|
|
|
|
|
item.encodedSize = BigEndianBitConverter.ToUInt32(nvlist, offset);
|
|
|
|
|
|
|
|
|
|
|
|
// Finished
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(item.encodedSize == 0) break;
|
|
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
offset += 4;
|
|
|
|
|
|
item.decodedSize = BigEndianBitConverter.ToUInt32(nvlist, offset);
|
|
|
|
|
|
offset += 4;
|
2018-06-20 22:22:21 +01:00
|
|
|
|
uint nameLength = BigEndianBitConverter.ToUInt32(nvlist, offset);
|
2016-09-18 05:09:55 +01:00
|
|
|
|
offset += 4;
|
2017-12-20 17:26:28 +00:00
|
|
|
|
if(nameLength % 4 > 0) nameLength += 4 - nameLength % 4;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
byte[] nameBytes = new byte[nameLength];
|
2016-09-18 05:09:55 +01:00
|
|
|
|
Array.Copy(nvlist, offset, nameBytes, 0, nameLength);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
item.name = StringHandlers.CToString(nameBytes);
|
|
|
|
|
|
offset += (int)nameLength;
|
|
|
|
|
|
item.dataType = (NVS_DataTypes)BigEndianBitConverter.ToUInt32(nvlist, offset);
|
|
|
|
|
|
offset += 4;
|
|
|
|
|
|
item.elements = BigEndianBitConverter.ToUInt32(nvlist, offset);
|
|
|
|
|
|
offset += 4;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
|
|
|
|
|
|
if(item.elements == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
decodedNvList.Add(item.name, item);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch(item.dataType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_BOOLEAN:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_BOOLEAN_ARRAY:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_BOOLEAN_VALUE:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool[] boolArray = new bool[item.elements];
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
uint temp = BigEndianBitConverter.ToUInt32(nvlist, offset);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
boolArray[i] = temp > 0;
|
|
|
|
|
|
offset += 4;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
item.value = boolArray;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
uint temp = BigEndianBitConverter.ToUInt32(nvlist, offset);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
item.value = temp > 0;
|
|
|
|
|
|
offset += 4;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_BYTE:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_BYTE_ARRAY:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_UINT8:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_UINT8_ARRAY:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
byte[] byteArray = new byte[item.elements];
|
|
|
|
|
|
Array.Copy(nvlist, offset, byteArray, 0, item.elements);
|
|
|
|
|
|
offset += (int)item.elements;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(item.elements % 4 > 0) offset += 4 - (int)(item.elements % 4);
|
2016-09-18 05:09:55 +01:00
|
|
|
|
item.value = byteArray;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
item.value = nvlist[offset];
|
|
|
|
|
|
offset += 4;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
2018-06-22 08:08:38 +01:00
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_DOUBLE:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
double[] doubleArray = new double[item.elements];
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
double temp = BigEndianBitConverter.ToDouble(nvlist, offset);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
doubleArray[i] = temp;
|
|
|
|
|
|
offset += 8;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
item.value = doubleArray;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
item.value = BigEndianBitConverter.ToDouble(nvlist, offset);
|
|
|
|
|
|
offset += 8;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_HRTIME:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
DateTime[] hrtimeArray = new DateTime[item.elements];
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DateTime temp =
|
2017-12-23 03:59:48 +00:00
|
|
|
|
DateHandlers.UnixHrTimeToDateTime(BigEndianBitConverter.ToUInt64(nvlist, offset));
|
2018-06-22 08:08:38 +01:00
|
|
|
|
hrtimeArray[i] = temp;
|
|
|
|
|
|
offset += 8;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
item.value = hrtimeArray;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
item.value =
|
2017-12-23 03:59:48 +00:00
|
|
|
|
DateHandlers.UnixHrTimeToDateTime(BigEndianBitConverter.ToUInt64(nvlist, offset));
|
2016-09-18 05:09:55 +01:00
|
|
|
|
offset += 8;
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_INT16:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_INT16_ARRAY:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
short[] shortArray = new short[item.elements];
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
short temp = BigEndianBitConverter.ToInt16(nvlist, offset);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
shortArray[i] = temp;
|
|
|
|
|
|
offset += 4;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
item.value = shortArray;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
item.value = BigEndianBitConverter.ToInt16(nvlist, offset);
|
|
|
|
|
|
offset += 4;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_INT32:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_INT32_ARRAY:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
int[] intArray = new int[item.elements];
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
int temp = BigEndianBitConverter.ToInt32(nvlist, offset);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
intArray[i] = temp;
|
|
|
|
|
|
offset += 4;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
item.value = intArray;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
item.value = BigEndianBitConverter.ToInt32(nvlist, offset);
|
|
|
|
|
|
offset += 4;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_INT64:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_INT64_ARRAY:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
long[] longArray = new long[item.elements];
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
long temp = BigEndianBitConverter.ToInt64(nvlist, offset);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
longArray[i] = temp;
|
|
|
|
|
|
offset += 8;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
item.value = longArray;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
item.value = BigEndianBitConverter.ToInt64(nvlist, offset);
|
|
|
|
|
|
offset += 8;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_INT8:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_INT8_ARRAY:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
sbyte[] sbyteArray = new sbyte[item.elements];
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
sbyte temp = (sbyte)nvlist[offset];
|
|
|
|
|
|
sbyteArray[i] = temp;
|
|
|
|
|
|
offset++;
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
item.value = sbyteArray;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(sbyteArray.Length % 4 > 0) offset += 4 - sbyteArray.Length % 4;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
item.value = BigEndianBitConverter.ToInt64(nvlist, offset);
|
|
|
|
|
|
offset += 4;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_STRING:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_STRING_ARRAY:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] stringArray = new string[item.elements];
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
uint strLength = BigEndianBitConverter.ToUInt32(nvlist, offset);
|
|
|
|
|
|
offset += 4;
|
|
|
|
|
|
byte[] strBytes = new byte[strLength];
|
|
|
|
|
|
Array.Copy(nvlist, offset, strBytes, 0, strLength);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
stringArray[i] = StringHandlers.CToString(strBytes);
|
|
|
|
|
|
offset += (int)strLength;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(strLength % 4 > 0) offset += 4 - (int)(strLength % 4);
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
item.value = stringArray;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
uint strLength = BigEndianBitConverter.ToUInt32(nvlist, offset);
|
|
|
|
|
|
offset += 4;
|
|
|
|
|
|
byte[] strBytes = new byte[strLength];
|
|
|
|
|
|
Array.Copy(nvlist, offset, strBytes, 0, strLength);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
item.value = StringHandlers.CToString(strBytes);
|
|
|
|
|
|
offset += (int)strLength;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(strLength % 4 > 0) offset += 4 - (int)(strLength % 4);
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_UINT16:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_UINT16_ARRAY:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
ushort[] ushortArray = new ushort[item.elements];
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
ushort temp = BigEndianBitConverter.ToUInt16(nvlist, offset);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
ushortArray[i] = temp;
|
|
|
|
|
|
offset += 4;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
item.value = ushortArray;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
item.value = BigEndianBitConverter.ToUInt16(nvlist, offset);
|
|
|
|
|
|
offset += 4;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_UINT32:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_UINT32_ARRAY:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
uint[] uintArray = new uint[item.elements];
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
uint temp = BigEndianBitConverter.ToUInt32(nvlist, offset);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
uintArray[i] = temp;
|
|
|
|
|
|
offset += 4;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
item.value = uintArray;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
item.value = BigEndianBitConverter.ToUInt32(nvlist, offset);
|
|
|
|
|
|
offset += 4;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_UINT64:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_UINT64_ARRAY:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
ulong[] ulongArray = new ulong[item.elements];
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
ulong temp = BigEndianBitConverter.ToUInt64(nvlist, offset);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
ulongArray[i] = temp;
|
|
|
|
|
|
offset += 8;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
item.value = ulongArray;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
item.value = BigEndianBitConverter.ToUInt64(nvlist, offset);
|
|
|
|
|
|
offset += 8;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_NVLIST:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(item.elements > 1) goto default;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
|
|
|
|
|
|
byte[] subListBytes = new byte[item.encodedSize - (offset - currOff)];
|
|
|
|
|
|
Array.Copy(nvlist, offset, subListBytes, 0, subListBytes.Length);
|
2017-12-24 02:37:41 +00:00
|
|
|
|
if(DecodeNvList(subListBytes, out Dictionary<string, NVS_Item> subList, true, littleEndian))
|
|
|
|
|
|
item.value = subList;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
else goto default;
|
2016-09-18 05:09:55 +01:00
|
|
|
|
offset = (int)(currOff + item.encodedSize);
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
byte[] unknown = new byte[item.encodedSize - (offset - currOff)];
|
|
|
|
|
|
Array.Copy(nvlist, offset, unknown, 0, unknown.Length);
|
|
|
|
|
|
item.value = unknown;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
offset = (int)(currOff + item.encodedSize);
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
decodedNvList.Add(item.name, item);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return decodedNvList.Count > 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static string PrintNvList(Dictionary<string, NVS_Item> decodedNvList)
|
|
|
|
|
|
{
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
foreach(NVS_Item item in decodedNvList.Values)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(item.elements == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
sb.AppendFormat("{0} is not set", item.name).AppendLine();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch(item.dataType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_BOOLEAN:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_BOOLEAN_ARRAY:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_BOOLEAN_VALUE:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
|
|
|
|
|
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((bool[])item.value)[i]).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
else sb.AppendFormat("{0} = {1}", item.name, (bool)item.value).AppendLine();
|
|
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_BYTE:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_BYTE_ARRAY:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_UINT8:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_UINT8_ARRAY:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
|
|
|
|
|
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((byte[])item.value)[i]).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
else sb.AppendFormat("{0} = {1}", item.name, (byte)item.value).AppendLine();
|
|
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_DOUBLE:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
|
|
|
|
|
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((double[])item.value)[i]).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
else sb.AppendFormat("{0} = {1}", item.name, (double)item.value).AppendLine();
|
|
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_HRTIME:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((DateTime[])item.value)[i])
|
|
|
|
|
|
.AppendLine();
|
|
|
|
|
|
else sb.AppendFormat("{0} = {1}", item.name, (DateTime)item.value).AppendLine();
|
|
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_INT16:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_INT16_ARRAY:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
|
|
|
|
|
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((short[])item.value)[i]).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
else sb.AppendFormat("{0} = {1}", item.name, (short)item.value).AppendLine();
|
|
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_INT32:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_INT32_ARRAY:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
|
|
|
|
|
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((int[])item.value)[i]).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
else sb.AppendFormat("{0} = {1}", item.name, (int)item.value).AppendLine();
|
|
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_INT64:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_INT64_ARRAY:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
|
|
|
|
|
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((long[])item.value)[i]).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
else sb.AppendFormat("{0} = {1}", item.name, (long)item.value).AppendLine();
|
|
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_INT8:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_INT8_ARRAY:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
|
|
|
|
|
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((sbyte[])item.value)[i]).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
else sb.AppendFormat("{0} = {1}", item.name, (sbyte)item.value).AppendLine();
|
|
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_STRING:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_STRING_ARRAY:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
|
|
|
|
|
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((string[])item.value)[i]).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
else sb.AppendFormat("{0} = {1}", item.name, (string)item.value).AppendLine();
|
|
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_UINT16:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_UINT16_ARRAY:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
|
|
|
|
|
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((ushort[])item.value)[i]).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
else sb.AppendFormat("{0} = {1}", item.name, (ushort)item.value).AppendLine();
|
|
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_UINT32:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_UINT32_ARRAY:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
|
|
|
|
|
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((uint[])item.value)[i]).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
else sb.AppendFormat("{0} = {1}", item.name, (uint)item.value).AppendLine();
|
|
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_UINT64:
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_UINT64_ARRAY:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
|
|
|
|
|
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((ulong[])item.value)[i]).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
else sb.AppendFormat("{0} = {1}", item.name, (ulong)item.value).AppendLine();
|
|
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case NVS_DataTypes.DATA_TYPE_NVLIST:
|
|
|
|
|
|
if(item.elements == 1)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sb.AppendFormat("{0} =\n{1}", item.name,
|
|
|
|
|
|
PrintNvList((Dictionary<string, NVS_Item>)item.value)).AppendLine();
|
2016-09-18 05:09:55 +01:00
|
|
|
|
else
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sb.AppendFormat("{0} = {1} elements nvlist[], unable to print", item.name, item.elements)
|
|
|
|
|
|
.AppendLine();
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
if(item.elements > 1)
|
|
|
|
|
|
for(int i = 0; i < item.elements; i++)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sb.AppendFormat("{0}[{1}] = Unknown data type {2}", item.name, i, item.dataType)
|
|
|
|
|
|
.AppendLine();
|
|
|
|
|
|
else sb.AppendFormat("{0} = Unknown data type {1}", item.name, item.dataType).AppendLine();
|
|
|
|
|
|
|
2016-09-18 05:09:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-24 02:37:41 +00:00
|
|
|
|
struct ZIO_Checksum
|
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
|
|
|
|
|
|
public ulong[] word;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// There is an empty ZIO at sector 16 or sector 31, with magic and checksum, to detect it is really ZFS I suppose.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct ZIO_Empty
|
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 472)]
|
2019-05-11 20:49:32 +01:00
|
|
|
|
public readonly byte[] empty;
|
|
|
|
|
|
public readonly ulong magic;
|
|
|
|
|
|
public readonly ZIO_Checksum checksum;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// This structure indicates which encoding method and endianness is used to encode the nvlist
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct NVS_Method
|
|
|
|
|
|
{
|
2019-05-11 20:49:32 +01:00
|
|
|
|
public readonly byte encoding;
|
|
|
|
|
|
public readonly byte endian;
|
|
|
|
|
|
public readonly byte reserved1;
|
|
|
|
|
|
public readonly byte reserved2;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// This structure gives information about the encoded nvlist
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct NVS_XDR_Header
|
|
|
|
|
|
{
|
2019-05-11 20:49:32 +01:00
|
|
|
|
public readonly NVS_Method encodingAndEndian;
|
|
|
|
|
|
public readonly uint version;
|
|
|
|
|
|
public readonly uint flags;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum NVS_DataTypes : uint
|
|
|
|
|
|
{
|
|
|
|
|
|
DATA_TYPE_UNKNOWN = 0,
|
|
|
|
|
|
DATA_TYPE_BOOLEAN,
|
|
|
|
|
|
DATA_TYPE_BYTE,
|
|
|
|
|
|
DATA_TYPE_INT16,
|
|
|
|
|
|
DATA_TYPE_UINT16,
|
|
|
|
|
|
DATA_TYPE_INT32,
|
|
|
|
|
|
DATA_TYPE_UINT32,
|
|
|
|
|
|
DATA_TYPE_INT64,
|
|
|
|
|
|
DATA_TYPE_UINT64,
|
|
|
|
|
|
DATA_TYPE_STRING,
|
|
|
|
|
|
DATA_TYPE_BYTE_ARRAY,
|
|
|
|
|
|
DATA_TYPE_INT16_ARRAY,
|
|
|
|
|
|
DATA_TYPE_UINT16_ARRAY,
|
|
|
|
|
|
DATA_TYPE_INT32_ARRAY,
|
|
|
|
|
|
DATA_TYPE_UINT32_ARRAY,
|
|
|
|
|
|
DATA_TYPE_INT64_ARRAY,
|
|
|
|
|
|
DATA_TYPE_UINT64_ARRAY,
|
|
|
|
|
|
DATA_TYPE_STRING_ARRAY,
|
|
|
|
|
|
DATA_TYPE_HRTIME,
|
|
|
|
|
|
DATA_TYPE_NVLIST,
|
|
|
|
|
|
DATA_TYPE_NVLIST_ARRAY,
|
|
|
|
|
|
DATA_TYPE_BOOLEAN_VALUE,
|
|
|
|
|
|
DATA_TYPE_INT8,
|
|
|
|
|
|
DATA_TYPE_UINT8,
|
|
|
|
|
|
DATA_TYPE_BOOLEAN_ARRAY,
|
|
|
|
|
|
DATA_TYPE_INT8_ARRAY,
|
|
|
|
|
|
DATA_TYPE_UINT8_ARRAY,
|
|
|
|
|
|
DATA_TYPE_DOUBLE
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// This represent an encoded nvpair (an item of an nvlist)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
struct NVS_Item
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Size in bytes when encoded in XDR
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public uint encodedSize;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Size in bytes when decoded
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public uint decodedSize;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// On disk, it is null-padded for alignment to 4 bytes and prepended by a 4 byte length indicator
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string name;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Data type
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public NVS_DataTypes dataType;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// How many elements are here
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public uint elements;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// On disk size is relative to <see cref="dataType" /> and <see cref="elements" /> always aligned to 4 bytes
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public object value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct DVA
|
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
|
2019-05-11 20:49:32 +01:00
|
|
|
|
public readonly ulong[] word;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct SPA_BlockPointer
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Data virtual address
|
|
|
|
|
|
/// </summary>
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
|
2019-05-11 20:49:32 +01:00
|
|
|
|
public readonly DVA[] dataVirtualAddress;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Block properties
|
|
|
|
|
|
/// </summary>
|
2019-05-11 20:49:32 +01:00
|
|
|
|
public readonly ulong properties;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Reserved for future expansion
|
|
|
|
|
|
/// </summary>
|
2019-05-11 20:49:32 +01:00
|
|
|
|
public readonly ulong[] padding;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// TXG when block was allocated
|
|
|
|
|
|
/// </summary>
|
2019-05-11 20:49:32 +01:00
|
|
|
|
public readonly ulong birthTxg;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Transaction group at birth
|
|
|
|
|
|
/// </summary>
|
2019-05-11 20:49:32 +01:00
|
|
|
|
public readonly ulong birth;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Fill count
|
|
|
|
|
|
/// </summary>
|
2019-05-11 20:49:32 +01:00
|
|
|
|
public readonly ulong fill;
|
|
|
|
|
|
public readonly ZIO_Checksum checksum;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct ZFS_Uberblock
|
|
|
|
|
|
{
|
2019-05-11 20:49:32 +01:00
|
|
|
|
public readonly ulong magic;
|
|
|
|
|
|
public readonly ulong spaVersion;
|
|
|
|
|
|
public readonly ulong lastTxg;
|
|
|
|
|
|
public readonly ulong guidSum;
|
|
|
|
|
|
public readonly ulong timestamp;
|
|
|
|
|
|
public readonly SPA_BlockPointer mosPtr;
|
|
|
|
|
|
public readonly ulong softwareVersion;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
2016-09-18 05:09:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|