diff --git a/DiscImageChef.Filesystems/DiscImageChef.Filesystems.csproj b/DiscImageChef.Filesystems/DiscImageChef.Filesystems.csproj
index a2106e79..2f5a5684 100644
--- a/DiscImageChef.Filesystems/DiscImageChef.Filesystems.csproj
+++ b/DiscImageChef.Filesystems/DiscImageChef.Filesystems.csproj
@@ -130,6 +130,7 @@
+
@@ -186,22 +187,10 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
diff --git a/DiscImageChef.Filesystems/RBF.cs b/DiscImageChef.Filesystems/RBF.cs
index e5d9d706..3ee70f69 100644
--- a/DiscImageChef.Filesystems/RBF.cs
+++ b/DiscImageChef.Filesystems/RBF.cs
@@ -9,7 +9,7 @@
//
// --[ Description ] ----------------------------------------------------------
//
-// Description
+// Identifies the RBF filesystem and shows information.
//
// --[ License ] --------------------------------------------------------------
//
@@ -29,13 +29,391 @@
// ----------------------------------------------------------------------------
// Copyright © 2011-2017 Natalia Portillo
// ****************************************************************************/
+
using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+using System.Text;
+using DiscImageChef.CommonTypes;
+using DiscImageChef.Console;
+
namespace DiscImageChef.Filesystems
{
- public class RBF
+ public class RBF : Filesystem
{
+ ///
+ /// Identification sector. Wherever the sector this resides on, becomes LSN 0.
+ ///
+ [StructLayout(LayoutKind.Sequential, Pack = 1)]
+ struct RBF_IdSector
+ {
+ /// Sectors on disk
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
+ public byte[] dd_tot;
+ /// Tracks
+ public byte dd_tks;
+ /// Bytes in allocation map
+ public ushort dd_map;
+ /// Sectors per cluster
+ public ushort dd_bit;
+ /// LSN of root directory
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
+ public byte[] dd_dir;
+ /// Owner ID
+ public ushort dd_own;
+ /// Attributes
+ public byte dd_att;
+ /// Disk ID
+ public ushort dd_dsk;
+ /// Format byte
+ public byte dd_fmt;
+ /// Sectors per track
+ public ushort dd_spt;
+ /// Reserved
+ public ushort dd_res;
+ /// LSN of boot file
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
+ public byte[] dd_bt;
+ /// Size of boot file
+ public ushort dd_bsz;
+ /// Creation date
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
+ public byte[] dd_dat;
+ /// Volume name
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
+ public byte[] dd_nam;
+ /// Path options
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
+ public byte[] dd_opt;
+ /// Reserved
+ public byte reserved;
+ /// Magic number
+ public uint dd_sync;
+ /// LSN of allocation map
+ public uint dd_maplsn;
+ /// Size of an LSN
+ public ushort dd_lsnsize;
+ /// Version ID
+ public ushort dd_versid;
+ }
+
+ ///
+ /// Identification sector. Wherever the sector this resides on, becomes LSN 0.
+ /// Introduced on OS-9000, this can be big or little endian.
+ ///
+ [StructLayout(LayoutKind.Sequential, Pack = 1)]
+ struct RBF_NewIdSector
+ {
+ /// Magic number
+ public uint rid_sync;
+ /// Disk ID
+ public uint rid_diskid;
+ /// Sectors on disk
+ public uint rid_totblocks;
+ /// Cylinders
+ public ushort rid_cylinders;
+ /// Sectors in cylinder 0
+ public ushort rid_cyl0size;
+ /// Sectors per cylinder
+ public ushort rid_cylsize;
+ /// Heads
+ public ushort rid_heads;
+ /// Bytes per sector
+ public ushort rid_blocksize;
+ /// Disk format
+ public ushort rid_format;
+ /// Flags
+ public ushort rid_flags;
+ /// Padding
+ public ushort rid_unused1;
+ /// Sector of allocation bitmap
+ public uint rid_bitmap;
+ /// Sector of debugger FD
+ public uint rid_firstboot;
+ /// Sector of bootfile FD
+ public uint rid_bootfile;
+ /// Sector of root directory FD
+ public uint rid_rootdir;
+ /// Group owner of media
+ public ushort rid_group;
+ /// Owner of media
+ public ushort rid_owner;
+ /// Creation time
+ public uint rid_ctime;
+ /// Last write time for this structure
+ public uint rid_mtime;
+ /// Volume name
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
+ public byte[] rid_name;
+ /// Endian flag
+ public byte rid_endflag;
+ /// Padding
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
+ public byte[] rid_unused2;
+ /// Parity
+ public uint rid_parity;
+ }
+
+ /// Magic number for OS-9. Same for OS-9000?
+ const uint RBF_Sync = 0x4372757A;
+ const uint RBF_Cnys = 0x7A757243;
+
public RBF()
{
+ Name = "OS-9 Random Block File Plugin";
+ PluginUUID = new Guid("E864E45B-0B52-4D29-A858-7BDFA9199FB2");
+ CurrentEncoding = Encoding.GetEncoding("iso-8859-15");
+ }
+
+ public RBF(ImagePlugins.ImagePlugin imagePlugin, Partition partition, Encoding encoding)
+ {
+ Name = "OS-9 Random Block File Plugin";
+ PluginUUID = new Guid("E864E45B-0B52-4D29-A858-7BDFA9199FB2");
+ if(encoding == null)
+ CurrentEncoding = Encoding.GetEncoding("iso-8859-15");
+ else
+ CurrentEncoding = encoding;
+ }
+
+ public override bool Identify(ImagePlugins.ImagePlugin imagePlugin, Partition partition)
+ {
+ if(imagePlugin.GetSectorSize() < 256)
+ return false;
+
+ // Documentation says ID should be sector 0
+ // I've found that OS-9/X68000 has it on sector 4
+ // I've read OS-9/Apple2 has it on sector 15
+ foreach(ulong location in new[] { 0, 4, 15 })
+ {
+ RBF_IdSector RBFSb = new RBF_IdSector();
+
+ uint sbSize = (uint)(Marshal.SizeOf(RBFSb) / imagePlugin.GetSectorSize());
+ if(Marshal.SizeOf(RBFSb) % imagePlugin.GetSectorSize() != 0)
+ sbSize++;
+
+ byte[] sector = imagePlugin.ReadSectors(partition.Start + location, sbSize);
+ if(sector.Length < Marshal.SizeOf(RBFSb))
+ return false;
+
+ RBFSb = BigEndianMarshal.ByteArrayToStructureBigEndian(sector);
+ RBF_NewIdSector RBF9000Sb = BigEndianMarshal.ByteArrayToStructureBigEndian(sector);
+
+ DicConsole.DebugWriteLine("RBF plugin", "magic at {0} = 0x{1:X8} or 0x{2:X8} (expected 0x{3:X8} or 0x{4:X8})", location, RBFSb.dd_sync, RBF9000Sb.rid_sync, RBF_Sync, RBF_Cnys);
+
+ if(RBFSb.dd_sync == RBF_Sync || RBF9000Sb.rid_sync == RBF_Sync || RBF9000Sb.rid_sync == RBF_Cnys)
+ return true;
+ }
+
+ return false;
+ }
+
+ public override void GetInformation(ImagePlugins.ImagePlugin imagePlugin, Partition partition, out string information)
+ {
+ information = "";
+ if(imagePlugin.GetSectorSize() < 256)
+ return;
+
+ RBF_IdSector RBFSb = new RBF_IdSector();
+ RBF_NewIdSector RBF9000Sb = new RBF_NewIdSector();
+
+ foreach(ulong location in new[] { 0, 4, 15 })
+ {
+ uint sbSize = (uint)(Marshal.SizeOf(RBFSb) / imagePlugin.GetSectorSize());
+ if(Marshal.SizeOf(RBFSb) % imagePlugin.GetSectorSize() != 0)
+ sbSize++;
+
+ byte[] sector = imagePlugin.ReadSectors(partition.Start + location, sbSize);
+ if(sector.Length < Marshal.SizeOf(RBFSb))
+ return;
+
+ RBFSb = BigEndianMarshal.ByteArrayToStructureBigEndian(sector);
+ RBF9000Sb = BigEndianMarshal.ByteArrayToStructureBigEndian(sector);
+
+ DicConsole.DebugWriteLine("RBF plugin", "magic at {0} = 0x{1:X8} or 0x{2:X8} (expected 0x{3:X8} or 0x{4:X8})", location, RBFSb.dd_sync, RBF9000Sb.rid_sync, RBF_Sync, RBF_Cnys);
+
+ if(RBFSb.dd_sync == RBF_Sync || RBF9000Sb.rid_sync == RBF_Sync || RBF9000Sb.rid_sync == RBF_Cnys)
+ break;
+ }
+
+ if(RBFSb.dd_sync != RBF_Sync && RBF9000Sb.rid_sync != RBF_Sync && RBF9000Sb.rid_sync != RBF_Cnys)
+ return;
+
+ if(RBF9000Sb.rid_sync == RBF_Cnys)
+ RBF9000Sb = BigEndianMarshal.SwapStructureMembersEndian(RBF9000Sb);
+
+ StringBuilder sb = new StringBuilder();
+
+ sb.AppendLine("OS-9 Random Block File");
+
+ if(RBF9000Sb.rid_sync == RBF_Sync)
+ {
+ sb.AppendFormat("Volume ID: {0:X8}", RBF9000Sb.rid_diskid).AppendLine();
+ sb.AppendFormat("{0} blocks in volume", RBF9000Sb.rid_totblocks).AppendLine();
+ sb.AppendFormat("{0} cylinders", RBF9000Sb.rid_cylinders).AppendLine();
+ sb.AppendFormat("{0} blocks in cylinder 0", RBF9000Sb.rid_cyl0size).AppendLine();
+ sb.AppendFormat("{0} blocks per cylinder", RBF9000Sb.rid_cylsize).AppendLine();
+ sb.AppendFormat("{0} heads", RBF9000Sb.rid_heads).AppendLine();
+ sb.AppendFormat("{0} bytes per block", RBF9000Sb.rid_blocksize).AppendLine();
+ // TODO: Convert to flags?
+ if((RBF9000Sb.rid_format & 0x01) == 0x01)
+ sb.AppendLine("Disk is double sided");
+ else
+ sb.AppendLine("Disk is single sided");
+ if((RBF9000Sb.rid_format & 0x02) == 0x02)
+ sb.AppendLine("Disk is double density");
+ else
+ sb.AppendLine("Disk is single density");
+ if((RBF9000Sb.rid_format & 0x10) == 0x10)
+ sb.AppendLine("Disk is 384 TPI");
+ else if((RBF9000Sb.rid_format & 0x08) == 0x08)
+ sb.AppendLine("Disk is 192 TPI");
+ else if((RBF9000Sb.rid_format & 0x04) == 0x04)
+ sb.AppendLine("Disk is 96 TPI or 135 TPI");
+ else
+ sb.AppendLine("Disk is 48 TPI");
+ sb.AppendFormat("Allocation bitmap descriptor starts at block {0}", RBF9000Sb.rid_bitmap == 0 ? 1 : RBF9000Sb.rid_bitmap).AppendLine();
+ if(RBF9000Sb.rid_firstboot > 0)
+ sb.AppendFormat("Debugger descriptor starts at block {0}", RBF9000Sb.rid_firstboot).AppendLine();
+ if(RBF9000Sb.rid_bootfile > 0)
+ sb.AppendFormat("Boot file descriptor starts at block {0}", RBF9000Sb.rid_bootfile).AppendLine();
+ sb.AppendFormat("Root directory descriptor starts at block {0}", RBF9000Sb.rid_rootdir).AppendLine();
+ sb.AppendFormat("Disk is owned by group {0} user {1}", RBF9000Sb.rid_group, RBF9000Sb.rid_owner).AppendLine();
+ sb.AppendFormat("Volume was created on {0}", DateHandlers.UNIXToDateTime(RBF9000Sb.rid_ctime)).AppendLine();
+ sb.AppendFormat("Volume's identification block was last written on {0}", DateHandlers.UNIXToDateTime(RBF9000Sb.rid_mtime)).AppendLine();
+ sb.AppendFormat("Volume name: {0}", StringHandlers.CToString(RBF9000Sb.rid_name, CurrentEncoding)).AppendLine();
+
+ xmlFSType = new Schemas.FileSystemType
+ {
+ Type = "OS-9 Random Block File",
+ Bootable = RBF9000Sb.rid_bootfile > 0,
+ ClusterSize = RBF9000Sb.rid_blocksize,
+ Clusters = RBF9000Sb.rid_totblocks,
+ CreationDate = DateHandlers.UNIXToDateTime(RBF9000Sb.rid_ctime),
+ CreationDateSpecified = true,
+ ModificationDate = DateHandlers.UNIXToDateTime(RBF9000Sb.rid_mtime),
+ ModificationDateSpecified = true,
+ VolumeName = StringHandlers.CToString(RBF9000Sb.rid_name, CurrentEncoding),
+ VolumeSerial = string.Format("{0:X8}", RBF9000Sb.rid_diskid)
+ };
+ }
+ else
+ {
+ sb.AppendFormat("Volume ID: {0:X4}", RBFSb.dd_dsk).AppendLine();
+ sb.AppendFormat("{0} blocks in volume", LSNToUInt32(RBFSb.dd_tot)).AppendLine();
+ sb.AppendFormat("{0} tracks", RBFSb.dd_tks).AppendLine();
+ sb.AppendFormat("{0} sectors per track", RBFSb.dd_spt).AppendLine();
+ sb.AppendFormat("{0} bytes per sector", 256 << RBFSb.dd_lsnsize).AppendLine();
+ sb.AppendFormat("{0} sectors per cluster ({1} bytes)", RBFSb.dd_bit, RBFSb.dd_bit * (256 << RBFSb.dd_lsnsize)).AppendLine();
+ // TODO: Convert to flags?
+ if((RBFSb.dd_fmt & 0x01) == 0x01)
+ sb.AppendLine("Disk is double sided");
+ else
+ sb.AppendLine("Disk is single sided");
+ if((RBFSb.dd_fmt & 0x02) == 0x02)
+ sb.AppendLine("Disk is double density");
+ else
+ sb.AppendLine("Disk is single density");
+ if((RBFSb.dd_fmt & 0x10) == 0x10)
+ sb.AppendLine("Disk is 384 TPI");
+ else if((RBFSb.dd_fmt & 0x08) == 0x08)
+ sb.AppendLine("Disk is 192 TPI");
+ else if((RBFSb.dd_fmt & 0x04) == 0x04)
+ sb.AppendLine("Disk is 96 TPI or 135 TPI");
+ else
+ sb.AppendLine("Disk is 48 TPI");
+ sb.AppendFormat("Allocation bitmap descriptor starts at block {0}", RBFSb.dd_maplsn == 0 ? 1 : RBFSb.dd_maplsn).AppendLine();
+ sb.AppendFormat("{0} bytes in allocation bitmap", RBFSb.dd_map).AppendLine();
+ if(LSNToUInt32(RBFSb.dd_bt) > 0 && RBFSb.dd_bsz > 0)
+ sb.AppendFormat("Boot file starts at block {0} and has {1} bytes", LSNToUInt32(RBFSb.dd_bt), RBFSb.dd_bsz).AppendLine();
+ sb.AppendFormat("Root directory descriptor starts at block {0}", LSNToUInt32(RBFSb.dd_dir)).AppendLine();
+ sb.AppendFormat("Disk is owned by user {0}", RBFSb.dd_own).AppendLine();
+ sb.AppendFormat("Volume was created on {0}", DateHandlers.OS9ToDateTime(RBFSb.dd_dat)).AppendLine();
+ sb.AppendFormat("Volume attributes: {0:X2}", RBFSb.dd_att).AppendLine();
+ sb.AppendFormat("Volume name: {0}", StringHandlers.CToString(RBFSb.dd_nam, CurrentEncoding)).AppendLine();
+ sb.AppendFormat("Path descriptor options: {0}", StringHandlers.CToString(RBFSb.dd_opt, CurrentEncoding)).AppendLine();
+
+ xmlFSType = new Schemas.FileSystemType
+ {
+ Type = "OS-9 Random Block File",
+ Bootable = LSNToUInt32(RBFSb.dd_bt) > 0 && RBFSb.dd_bsz > 0,
+ ClusterSize = RBFSb.dd_bit * (256 << RBFSb.dd_lsnsize),
+ Clusters = LSNToUInt32(RBFSb.dd_tot),
+ CreationDate = DateHandlers.OS9ToDateTime(RBFSb.dd_dat),
+ CreationDateSpecified = true,
+ VolumeName = StringHandlers.CToString(RBFSb.dd_nam, CurrentEncoding),
+ VolumeSerial = string.Format("{0:X4}", RBFSb.dd_dsk)
+ };
+ }
+
+ information = sb.ToString();
+ }
+
+ public static uint LSNToUInt32(byte[] lsn)
+ {
+ if(lsn == null || lsn.Length != 3)
+ return 0;
+
+ return (uint)((lsn[0] << 16) + (lsn[1] << 8) + lsn[2]);
+ }
+
+ public override Errno Mount()
+ {
+ return Errno.NotImplemented;
+ }
+
+ public override Errno Mount(bool debug)
+ {
+ return Errno.NotImplemented;
+ }
+
+ public override Errno Unmount()
+ {
+ return Errno.NotImplemented;
+ }
+
+ public override Errno MapBlock(string path, long fileBlock, ref long deviceBlock)
+ {
+ return Errno.NotImplemented;
+ }
+
+ public override Errno GetAttributes(string path, ref FileAttributes attributes)
+ {
+ return Errno.NotImplemented;
+ }
+
+ public override Errno ListXAttr(string path, ref List xattrs)
+ {
+ return Errno.NotImplemented;
+ }
+
+ public override Errno GetXattr(string path, string xattr, ref byte[] buf)
+ {
+ return Errno.NotImplemented;
+ }
+
+ public override Errno Read(string path, long offset, long size, ref byte[] buf)
+ {
+ return Errno.NotImplemented;
+ }
+
+ public override Errno ReadDir(string path, ref List contents)
+ {
+ return Errno.NotImplemented;
+ }
+
+ public override Errno StatFs(ref FileSystemInfo stat)
+ {
+ return Errno.NotImplemented;
+ }
+
+ public override Errno Stat(string path, ref FileEntryInfo stat)
+ {
+ return Errno.NotImplemented;
+ }
+
+ public override Errno ReadLink(string path, ref string dest)
+ {
+ return Errno.NotImplemented;
}
}
-}
+}
\ No newline at end of file
diff --git a/README.md b/README.md
index db675058..8fdb72dd 100644
--- a/README.md
+++ b/README.md
@@ -143,6 +143,7 @@ Supported file systems for identification and information only
* Minix v3 file system
* NEC PC-Engine file system
* NILFS2
+* OS-9 Random Block File
* Professional File System
* QNX4 and QNX6 filesystems
* Reiser file systems