mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
* FileSystemIDandChk/Plugins/ODS.cs:
Use StringHandlers class to prevent garbage coming from strings (even if they are not C strings, it does not hurt). * FileSystemIDandChk/Plugins/AppleHFS.cs: Use constants. * FileSystemIDandChk/Plugins/BFS.cs: * FileSystemIDandChk/Plugins/AppleMFS.cs: * FileSystemIDandChk/Plugins/AppleHFSPlus.cs: Use constants and EndianAwareBinaryReader class. * FileSystemIDandChk/Plugins/Opera.cs: Use a superblock structure and EndianAwareBinaryReader class, reduces lots of code. git-svn-id: svn://claunia.com/FileSystemIDandChk@15 17725271-3d32-4980-a8cb-9ff532f270ba
This commit is contained in:
@@ -42,93 +42,67 @@ namespace FileSystemIDandChk.Plugins
|
||||
|
||||
fileStream.Seek(0 + offset, SeekOrigin.Begin);
|
||||
|
||||
byte[] record_type = new byte[1];
|
||||
byte[] sync_bytes = new byte[5];
|
||||
byte[] record_version = new byte[1];
|
||||
byte[] volume_flags = new byte[1];
|
||||
byte[] volume_comment = new byte[32];
|
||||
byte[] volume_label = new byte[32];
|
||||
byte[] volume_id = new byte[4];
|
||||
byte[] block_size = new byte[4];
|
||||
byte[] block_count = new byte[4];
|
||||
byte[] root_dirid = new byte[4];
|
||||
byte[] rootdir_blocks = new byte[4];
|
||||
byte[] rootdir_bsize = new byte[4];
|
||||
byte[] last_root_copy = new byte[4];
|
||||
EndianAwareBinaryReader eabr = new EndianAwareBinaryReader(fileStream, false); // BigEndian
|
||||
OperaSuperBlock sb = new OperaSuperBlock();
|
||||
byte[] cString;
|
||||
|
||||
fileStream.Read(record_type, 0, 1);
|
||||
fileStream.Read(sync_bytes, 0, 5);
|
||||
fileStream.Read(record_version, 0, 1);
|
||||
fileStream.Read(volume_flags, 0, 1);
|
||||
fileStream.Read(volume_comment, 0, 32);
|
||||
fileStream.Read(volume_label, 0, 32);
|
||||
fileStream.Read(volume_id, 0, 4);
|
||||
fileStream.Read(block_size, 0, 4);
|
||||
fileStream.Read(block_count, 0, 4);
|
||||
fileStream.Read(root_dirid, 0, 4);
|
||||
fileStream.Read(rootdir_blocks, 0, 4);
|
||||
fileStream.Read(rootdir_bsize, 0, 4);
|
||||
fileStream.Read(last_root_copy, 0, 4);
|
||||
sb.record_type = eabr.ReadByte();
|
||||
sb.sync_bytes = eabr.ReadBytes(5);
|
||||
sb.record_version = eabr.ReadByte();
|
||||
sb.volume_flags = eabr.ReadByte();
|
||||
cString = eabr.ReadBytes(32);
|
||||
sb.volume_comment = StringHandlers.CToString(cString);
|
||||
cString = eabr.ReadBytes(32);
|
||||
sb.volume_label = StringHandlers.CToString(cString);
|
||||
sb.volume_id = eabr.ReadInt32();
|
||||
sb.block_size = eabr.ReadInt32();
|
||||
sb.block_count = eabr.ReadInt32();
|
||||
sb.root_dirid = eabr.ReadInt32();
|
||||
sb.rootdir_blocks = eabr.ReadInt32();
|
||||
sb.rootdir_bsize = eabr.ReadInt32();
|
||||
sb.last_root_copy = eabr.ReadInt32();
|
||||
|
||||
if (record_type[0] != 1 || record_version[0] != 1)
|
||||
if (sb.record_type != 1 || sb.record_version != 1)
|
||||
return;
|
||||
if(Encoding.ASCII.GetString(sync_bytes) != "ZZZZZ")
|
||||
if(Encoding.ASCII.GetString(sb.sync_bytes) != "ZZZZZ")
|
||||
return;
|
||||
|
||||
// Swapping data (C# is LE, Opera is BE)
|
||||
volume_id = Swapping.SwapFourBytes(volume_id);
|
||||
block_size = Swapping.SwapFourBytes(block_size);
|
||||
block_count = Swapping.SwapFourBytes(block_count);
|
||||
root_dirid = Swapping.SwapFourBytes(root_dirid);
|
||||
rootdir_blocks = Swapping.SwapFourBytes(rootdir_blocks);
|
||||
rootdir_bsize = Swapping.SwapFourBytes(rootdir_bsize);
|
||||
last_root_copy = Swapping.SwapFourBytes(last_root_copy);
|
||||
if (sb.volume_comment.Length == 0)
|
||||
sb.volume_comment = "Not set.";
|
||||
|
||||
int vid = BitConverter.ToInt32(volume_id, 0);
|
||||
int rdid = BitConverter.ToInt32(root_dirid, 0);
|
||||
|
||||
StringBuilder VolumeComment = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < volume_comment.Length; i++)
|
||||
{
|
||||
if (volume_comment[i] != 0x00)
|
||||
VolumeComment.Append((char)volume_comment[i]);
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (VolumeComment.Length == 0)
|
||||
VolumeComment.Append("Not set.");
|
||||
|
||||
StringBuilder VolumeLabel = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < volume_label.Length; i++)
|
||||
{
|
||||
if (volume_label[i] != 0x00)
|
||||
VolumeLabel.Append((char)volume_label[i]);
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (VolumeLabel.Length == 0)
|
||||
VolumeLabel.Append("Not set.");
|
||||
|
||||
int bs = BitConverter.ToInt32(block_size, 0);
|
||||
int vblocks = BitConverter.ToInt32(block_count, 0);
|
||||
int rbs = BitConverter.ToInt32(rootdir_bsize, 0);
|
||||
int rblocks = BitConverter.ToInt32(rootdir_blocks, 0);
|
||||
if (sb.volume_label.Length == 0)
|
||||
sb.volume_label = "Not set.";
|
||||
|
||||
SuperBlockMetadata.AppendFormat("Opera filesystem disc.").AppendLine();
|
||||
SuperBlockMetadata.AppendFormat("Volume label: {0}", VolumeLabel.ToString()).AppendLine();
|
||||
SuperBlockMetadata.AppendFormat("Volume comment: {0}", VolumeComment.ToString()).AppendLine();
|
||||
SuperBlockMetadata.AppendFormat("Volume identifier: 0x{0}", vid.ToString("X")).AppendLine();
|
||||
SuperBlockMetadata.AppendFormat("Block size: {0} bytes", bs).AppendLine();
|
||||
SuperBlockMetadata.AppendFormat("Volume size: {0} blocks, {1} bytes", vblocks, bs*vblocks).AppendLine();
|
||||
SuperBlockMetadata.AppendFormat("Root directory identifier: 0x{0}", rdid.ToString("X")).AppendLine();
|
||||
SuperBlockMetadata.AppendFormat("Root directory block size: {0} bytes", rbs).AppendLine();
|
||||
SuperBlockMetadata.AppendFormat("Root directory size: {0} blocks, {1} bytes", rblocks, rbs*rblocks).AppendLine();
|
||||
SuperBlockMetadata.AppendFormat("Last root directory copy: {0}", BitConverter.ToInt32(last_root_copy, 0)).AppendLine();
|
||||
SuperBlockMetadata.AppendFormat("Volume label: {0}", sb.volume_label).AppendLine();
|
||||
SuperBlockMetadata.AppendFormat("Volume comment: {0}", sb.volume_comment).AppendLine();
|
||||
SuperBlockMetadata.AppendFormat("Volume identifier: 0x{0:X8}", sb.volume_id).AppendLine();
|
||||
SuperBlockMetadata.AppendFormat("Block size: {0} bytes", sb.block_size).AppendLine();
|
||||
SuperBlockMetadata.AppendFormat("Volume size: {0} blocks, {1} bytes", sb.block_count, sb.block_size*sb.block_count).AppendLine();
|
||||
SuperBlockMetadata.AppendFormat("Root directory identifier: 0x{0:X8}", sb.root_dirid).AppendLine();
|
||||
SuperBlockMetadata.AppendFormat("Root directory block size: {0} bytes", sb.rootdir_bsize).AppendLine();
|
||||
SuperBlockMetadata.AppendFormat("Root directory size: {0} blocks, {1} bytes", sb.rootdir_blocks, sb.rootdir_bsize*sb.rootdir_blocks).AppendLine();
|
||||
SuperBlockMetadata.AppendFormat("Last root directory copy: {0}", sb.last_root_copy).AppendLine();
|
||||
|
||||
information = SuperBlockMetadata.ToString();
|
||||
}
|
||||
|
||||
private struct OperaSuperBlock
|
||||
{
|
||||
public byte record_type; // Record type, must be 1
|
||||
public byte[] sync_bytes; // 5 bytes, "ZZZZZ" = new byte[5];
|
||||
public byte record_version; // Record version, must be 1
|
||||
public byte volume_flags; // Volume flags
|
||||
public string volume_comment; // 32 bytes, volume comment
|
||||
public string volume_label; // 32 bytes, volume label
|
||||
public Int32 volume_id; // Volume ID
|
||||
public Int32 block_size; // Block size in bytes
|
||||
public Int32 block_count; // Blocks in volume
|
||||
public Int32 root_dirid; // Root directory ID
|
||||
public Int32 rootdir_blocks; // Root directory blocks
|
||||
public Int32 rootdir_bsize; // Root directory block size
|
||||
public Int32 last_root_copy; // Last root directory copy
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user