mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[Aaru.Filesystems] Reformat and cleanup.
This commit is contained in:
@@ -55,13 +55,15 @@ namespace Aaru.Filesystems;
|
||||
*/
|
||||
/// <inheritdoc />
|
||||
/// <summary>Implements detection for the Zettabyte File System (ZFS)</summary>
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "UnusedType.Local"),
|
||||
SuppressMessage("ReSharper", "UnusedMember.Local"), SuppressMessage("ReSharper", "NotAccessedField.Local")]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
[SuppressMessage("ReSharper", "UnusedType.Local")]
|
||||
[SuppressMessage("ReSharper", "UnusedMember.Local")]
|
||||
[SuppressMessage("ReSharper", "NotAccessedField.Local")]
|
||||
public sealed partial class ZFS
|
||||
{
|
||||
static bool DecodeNvList(byte[] nvlist, out Dictionary<string, NVS_Item> decodedNvList)
|
||||
{
|
||||
byte[] tmp = new byte[nvlist.Length - 4];
|
||||
var tmp = new byte[nvlist.Length - 4];
|
||||
Array.Copy(nvlist, 4, tmp, 0, nvlist.Length - 4);
|
||||
bool xdr = nvlist[0] == 1;
|
||||
bool littleEndian = nvlist[1] == 1;
|
||||
@@ -81,7 +83,7 @@ public sealed partial class ZFS
|
||||
if(!xdr)
|
||||
return false;
|
||||
|
||||
int offset = 8;
|
||||
var offset = 8;
|
||||
|
||||
while(offset < nvlist.Length)
|
||||
{
|
||||
@@ -97,13 +99,13 @@ public sealed partial class ZFS
|
||||
offset += 4;
|
||||
item.decodedSize = BigEndianBitConverter.ToUInt32(nvlist, offset);
|
||||
offset += 4;
|
||||
uint nameLength = BigEndianBitConverter.ToUInt32(nvlist, offset);
|
||||
var nameLength = BigEndianBitConverter.ToUInt32(nvlist, offset);
|
||||
offset += 4;
|
||||
|
||||
if(nameLength % 4 > 0)
|
||||
nameLength += 4 - (nameLength % 4);
|
||||
nameLength += 4 - nameLength % 4;
|
||||
|
||||
byte[] nameBytes = new byte[nameLength];
|
||||
var nameBytes = new byte[nameLength];
|
||||
Array.Copy(nvlist, offset, nameBytes, 0, nameLength);
|
||||
item.name = StringHandlers.CToString(nameBytes);
|
||||
offset += (int)nameLength;
|
||||
@@ -126,11 +128,11 @@ public sealed partial class ZFS
|
||||
case NVS_DataTypes.DATA_TYPE_BOOLEAN_VALUE:
|
||||
if(item.elements > 1)
|
||||
{
|
||||
bool[] boolArray = new bool[item.elements];
|
||||
var boolArray = new bool[item.elements];
|
||||
|
||||
for(int i = 0; i < item.elements; i++)
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
{
|
||||
uint temp = BigEndianBitConverter.ToUInt32(nvlist, offset);
|
||||
var temp = BigEndianBitConverter.ToUInt32(nvlist, offset);
|
||||
boolArray[i] = temp > 0;
|
||||
offset += 4;
|
||||
}
|
||||
@@ -139,7 +141,7 @@ public sealed partial class ZFS
|
||||
}
|
||||
else
|
||||
{
|
||||
uint temp = BigEndianBitConverter.ToUInt32(nvlist, offset);
|
||||
var temp = BigEndianBitConverter.ToUInt32(nvlist, offset);
|
||||
item.value = temp > 0;
|
||||
offset += 4;
|
||||
}
|
||||
@@ -151,7 +153,7 @@ public sealed partial class ZFS
|
||||
case NVS_DataTypes.DATA_TYPE_UINT8_ARRAY:
|
||||
if(item.elements > 1)
|
||||
{
|
||||
byte[] byteArray = new byte[item.elements];
|
||||
var byteArray = new byte[item.elements];
|
||||
Array.Copy(nvlist, offset, byteArray, 0, item.elements);
|
||||
offset += (int)item.elements;
|
||||
|
||||
@@ -170,11 +172,11 @@ public sealed partial class ZFS
|
||||
case NVS_DataTypes.DATA_TYPE_DOUBLE:
|
||||
if(item.elements > 1)
|
||||
{
|
||||
double[] doubleArray = new double[item.elements];
|
||||
var doubleArray = new double[item.elements];
|
||||
|
||||
for(int i = 0; i < item.elements; i++)
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
{
|
||||
double temp = BigEndianBitConverter.ToDouble(nvlist, offset);
|
||||
var temp = BigEndianBitConverter.ToDouble(nvlist, offset);
|
||||
doubleArray[i] = temp;
|
||||
offset += 8;
|
||||
}
|
||||
@@ -191,9 +193,9 @@ public sealed partial class ZFS
|
||||
case NVS_DataTypes.DATA_TYPE_HRTIME:
|
||||
if(item.elements > 1)
|
||||
{
|
||||
DateTime[] hrtimeArray = new DateTime[item.elements];
|
||||
var hrtimeArray = new DateTime[item.elements];
|
||||
|
||||
for(int i = 0; i < item.elements; i++)
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
{
|
||||
DateTime temp =
|
||||
DateHandlers.UnixHrTimeToDateTime(BigEndianBitConverter.ToUInt64(nvlist, offset));
|
||||
@@ -216,11 +218,11 @@ public sealed partial class ZFS
|
||||
case NVS_DataTypes.DATA_TYPE_INT16_ARRAY:
|
||||
if(item.elements > 1)
|
||||
{
|
||||
short[] shortArray = new short[item.elements];
|
||||
var shortArray = new short[item.elements];
|
||||
|
||||
for(int i = 0; i < item.elements; i++)
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
{
|
||||
short temp = BigEndianBitConverter.ToInt16(nvlist, offset);
|
||||
var temp = BigEndianBitConverter.ToInt16(nvlist, offset);
|
||||
shortArray[i] = temp;
|
||||
offset += 4;
|
||||
}
|
||||
@@ -238,11 +240,11 @@ public sealed partial class ZFS
|
||||
case NVS_DataTypes.DATA_TYPE_INT32_ARRAY:
|
||||
if(item.elements > 1)
|
||||
{
|
||||
int[] intArray = new int[item.elements];
|
||||
var intArray = new int[item.elements];
|
||||
|
||||
for(int i = 0; i < item.elements; i++)
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
{
|
||||
int temp = BigEndianBitConverter.ToInt32(nvlist, offset);
|
||||
var temp = BigEndianBitConverter.ToInt32(nvlist, offset);
|
||||
intArray[i] = temp;
|
||||
offset += 4;
|
||||
}
|
||||
@@ -260,11 +262,11 @@ public sealed partial class ZFS
|
||||
case NVS_DataTypes.DATA_TYPE_INT64_ARRAY:
|
||||
if(item.elements > 1)
|
||||
{
|
||||
long[] longArray = new long[item.elements];
|
||||
var longArray = new long[item.elements];
|
||||
|
||||
for(int i = 0; i < item.elements; i++)
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
{
|
||||
long temp = BigEndianBitConverter.ToInt64(nvlist, offset);
|
||||
var temp = BigEndianBitConverter.ToInt64(nvlist, offset);
|
||||
longArray[i] = temp;
|
||||
offset += 8;
|
||||
}
|
||||
@@ -282,11 +284,11 @@ public sealed partial class ZFS
|
||||
case NVS_DataTypes.DATA_TYPE_INT8_ARRAY:
|
||||
if(item.elements > 1)
|
||||
{
|
||||
sbyte[] sbyteArray = new sbyte[item.elements];
|
||||
var sbyteArray = new sbyte[item.elements];
|
||||
|
||||
for(int i = 0; i < item.elements; i++)
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
{
|
||||
sbyte temp = (sbyte)nvlist[offset];
|
||||
var temp = (sbyte)nvlist[offset];
|
||||
sbyteArray[i] = temp;
|
||||
offset++;
|
||||
}
|
||||
@@ -294,7 +296,7 @@ public sealed partial class ZFS
|
||||
item.value = sbyteArray;
|
||||
|
||||
if(sbyteArray.Length % 4 > 0)
|
||||
offset += 4 - (sbyteArray.Length % 4);
|
||||
offset += 4 - sbyteArray.Length % 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -307,13 +309,13 @@ public sealed partial class ZFS
|
||||
case NVS_DataTypes.DATA_TYPE_STRING_ARRAY:
|
||||
if(item.elements > 1)
|
||||
{
|
||||
string[] stringArray = new string[item.elements];
|
||||
var stringArray = new string[item.elements];
|
||||
|
||||
for(int i = 0; i < item.elements; i++)
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
{
|
||||
uint strLength = BigEndianBitConverter.ToUInt32(nvlist, offset);
|
||||
var strLength = BigEndianBitConverter.ToUInt32(nvlist, offset);
|
||||
offset += 4;
|
||||
byte[] strBytes = new byte[strLength];
|
||||
var strBytes = new byte[strLength];
|
||||
Array.Copy(nvlist, offset, strBytes, 0, strLength);
|
||||
stringArray[i] = StringHandlers.CToString(strBytes);
|
||||
offset += (int)strLength;
|
||||
@@ -326,9 +328,9 @@ public sealed partial class ZFS
|
||||
}
|
||||
else
|
||||
{
|
||||
uint strLength = BigEndianBitConverter.ToUInt32(nvlist, offset);
|
||||
var strLength = BigEndianBitConverter.ToUInt32(nvlist, offset);
|
||||
offset += 4;
|
||||
byte[] strBytes = new byte[strLength];
|
||||
var strBytes = new byte[strLength];
|
||||
Array.Copy(nvlist, offset, strBytes, 0, strLength);
|
||||
item.value = StringHandlers.CToString(strBytes);
|
||||
offset += (int)strLength;
|
||||
@@ -342,11 +344,11 @@ public sealed partial class ZFS
|
||||
case NVS_DataTypes.DATA_TYPE_UINT16_ARRAY:
|
||||
if(item.elements > 1)
|
||||
{
|
||||
ushort[] ushortArray = new ushort[item.elements];
|
||||
var ushortArray = new ushort[item.elements];
|
||||
|
||||
for(int i = 0; i < item.elements; i++)
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
{
|
||||
ushort temp = BigEndianBitConverter.ToUInt16(nvlist, offset);
|
||||
var temp = BigEndianBitConverter.ToUInt16(nvlist, offset);
|
||||
ushortArray[i] = temp;
|
||||
offset += 4;
|
||||
}
|
||||
@@ -364,11 +366,11 @@ public sealed partial class ZFS
|
||||
case NVS_DataTypes.DATA_TYPE_UINT32_ARRAY:
|
||||
if(item.elements > 1)
|
||||
{
|
||||
uint[] uintArray = new uint[item.elements];
|
||||
var uintArray = new uint[item.elements];
|
||||
|
||||
for(int i = 0; i < item.elements; i++)
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
{
|
||||
uint temp = BigEndianBitConverter.ToUInt32(nvlist, offset);
|
||||
var temp = BigEndianBitConverter.ToUInt32(nvlist, offset);
|
||||
uintArray[i] = temp;
|
||||
offset += 4;
|
||||
}
|
||||
@@ -386,11 +388,11 @@ public sealed partial class ZFS
|
||||
case NVS_DataTypes.DATA_TYPE_UINT64_ARRAY:
|
||||
if(item.elements > 1)
|
||||
{
|
||||
ulong[] ulongArray = new ulong[item.elements];
|
||||
var ulongArray = new ulong[item.elements];
|
||||
|
||||
for(int i = 0; i < item.elements; i++)
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
{
|
||||
ulong temp = BigEndianBitConverter.ToUInt64(nvlist, offset);
|
||||
var temp = BigEndianBitConverter.ToUInt64(nvlist, offset);
|
||||
ulongArray[i] = temp;
|
||||
offset += 8;
|
||||
}
|
||||
@@ -408,7 +410,7 @@ public sealed partial class ZFS
|
||||
if(item.elements > 1)
|
||||
goto default;
|
||||
|
||||
byte[] subListBytes = new byte[item.encodedSize - (offset - currOff)];
|
||||
var subListBytes = new byte[item.encodedSize - (offset - currOff)];
|
||||
Array.Copy(nvlist, offset, subListBytes, 0, subListBytes.Length);
|
||||
|
||||
if(DecodeNvList(subListBytes, out Dictionary<string, NVS_Item> subList, true, littleEndian))
|
||||
@@ -420,7 +422,7 @@ public sealed partial class ZFS
|
||||
|
||||
break;
|
||||
default:
|
||||
byte[] unknown = new byte[item.encodedSize - (offset - currOff)];
|
||||
var unknown = new byte[item.encodedSize - (offset - currOff)];
|
||||
Array.Copy(nvlist, offset, unknown, 0, unknown.Length);
|
||||
item.value = unknown;
|
||||
offset = (int)(currOff + item.encodedSize);
|
||||
@@ -453,8 +455,10 @@ public sealed partial class ZFS
|
||||
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++)
|
||||
{
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((bool[])item.value)[i]).AppendLine();
|
||||
}
|
||||
else
|
||||
sb.AppendFormat("{0} = {1}", item.name, (bool)item.value).AppendLine();
|
||||
|
||||
@@ -464,24 +468,30 @@ public sealed partial class ZFS
|
||||
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++)
|
||||
{
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((byte[])item.value)[i]).AppendLine();
|
||||
}
|
||||
else
|
||||
sb.AppendFormat("{0} = {1}", item.name, (byte)item.value).AppendLine();
|
||||
|
||||
break;
|
||||
case NVS_DataTypes.DATA_TYPE_DOUBLE:
|
||||
if(item.elements > 1)
|
||||
for(int i = 0; i < item.elements; i++)
|
||||
{
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((double[])item.value)[i]).AppendLine();
|
||||
}
|
||||
else
|
||||
sb.AppendFormat("{0} = {1}", item.name, (double)item.value).AppendLine();
|
||||
|
||||
break;
|
||||
case NVS_DataTypes.DATA_TYPE_HRTIME:
|
||||
if(item.elements > 1)
|
||||
for(int i = 0; i < item.elements; i++)
|
||||
{
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((DateTime[])item.value)[i]).AppendLine();
|
||||
}
|
||||
else
|
||||
sb.AppendFormat("{0} = {1}", item.name, (DateTime)item.value).AppendLine();
|
||||
|
||||
@@ -489,8 +499,10 @@ public sealed partial class ZFS
|
||||
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++)
|
||||
{
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((short[])item.value)[i]).AppendLine();
|
||||
}
|
||||
else
|
||||
sb.AppendFormat("{0} = {1}", item.name, (short)item.value).AppendLine();
|
||||
|
||||
@@ -498,8 +510,10 @@ public sealed partial class ZFS
|
||||
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++)
|
||||
{
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((int[])item.value)[i]).AppendLine();
|
||||
}
|
||||
else
|
||||
sb.AppendFormat("{0} = {1}", item.name, (int)item.value).AppendLine();
|
||||
|
||||
@@ -507,8 +521,10 @@ public sealed partial class ZFS
|
||||
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++)
|
||||
{
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((long[])item.value)[i]).AppendLine();
|
||||
}
|
||||
else
|
||||
sb.AppendFormat("{0} = {1}", item.name, (long)item.value).AppendLine();
|
||||
|
||||
@@ -516,8 +532,10 @@ public sealed partial class ZFS
|
||||
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++)
|
||||
{
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((sbyte[])item.value)[i]).AppendLine();
|
||||
}
|
||||
else
|
||||
sb.AppendFormat("{0} = {1}", item.name, (sbyte)item.value).AppendLine();
|
||||
|
||||
@@ -525,8 +543,10 @@ public sealed partial class ZFS
|
||||
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++)
|
||||
{
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((string[])item.value)[i]).AppendLine();
|
||||
}
|
||||
else
|
||||
sb.AppendFormat("{0} = {1}", item.name, (string)item.value).AppendLine();
|
||||
|
||||
@@ -534,8 +554,10 @@ public sealed partial class ZFS
|
||||
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++)
|
||||
{
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((ushort[])item.value)[i]).AppendLine();
|
||||
}
|
||||
else
|
||||
sb.AppendFormat("{0} = {1}", item.name, (ushort)item.value).AppendLine();
|
||||
|
||||
@@ -543,8 +565,10 @@ public sealed partial class ZFS
|
||||
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++)
|
||||
{
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((uint[])item.value)[i]).AppendLine();
|
||||
}
|
||||
else
|
||||
sb.AppendFormat("{0} = {1}", item.name, (uint)item.value).AppendLine();
|
||||
|
||||
@@ -552,29 +576,41 @@ public sealed partial class ZFS
|
||||
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++)
|
||||
{
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
sb.AppendFormat("{0}[{1}] = {2}", item.name, i, ((ulong[])item.value)[i]).AppendLine();
|
||||
}
|
||||
else
|
||||
sb.AppendFormat("{0} = {1}", item.name, (ulong)item.value).AppendLine();
|
||||
|
||||
break;
|
||||
case NVS_DataTypes.DATA_TYPE_NVLIST:
|
||||
if(item.elements == 1)
|
||||
{
|
||||
sb.AppendFormat("{0} =\n{1}", item.name, PrintNvList((Dictionary<string, NVS_Item>)item.value)).
|
||||
AppendLine();
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendFormat(Localization._0_equals_1_elements_nvlist_array_unable_to_print, item.name,
|
||||
item.elements).AppendLine();
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
if(item.elements > 1)
|
||||
for(int i = 0; i < item.elements; i++)
|
||||
{
|
||||
for(var i = 0; i < item.elements; i++)
|
||||
{
|
||||
sb.AppendFormat(Localization._0_1_equals_unknown_data_type_2, item.name, i, item.dataType).
|
||||
AppendLine();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendFormat(Localization._0_equals_unknown_data_type_1, item.name, item.dataType).
|
||||
AppendLine();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user