From 104e6f0cd2865514b39798a6f4ce36fa50b85ecc Mon Sep 17 00:00:00 2001 From: BlubbFish Date: Mon, 15 Jun 2020 13:24:49 +0200 Subject: [PATCH] test feature add libc --- hp-raid45-recovery/CopyProcess.cs | 26 ++++++++++++++++++------ hp-raid45-recovery/Libc.cs | 33 +++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 hp-raid45-recovery/Libc.cs diff --git a/hp-raid45-recovery/CopyProcess.cs b/hp-raid45-recovery/CopyProcess.cs index a01ba39..bce3d36 100644 --- a/hp-raid45-recovery/CopyProcess.cs +++ b/hp-raid45-recovery/CopyProcess.cs @@ -1,8 +1,7 @@ using System; using System.IO; -namespace BlubbFish.Tools.Raid.HP.Raid45 -{ +namespace BlubbFish.Tools.Raid.HP.Raid45 { internal class CopyProcess { private Int32 CursorOrigRow; @@ -31,16 +30,25 @@ namespace BlubbFish.Tools.Raid.HP.Raid45 File.OpenRead(disk2), File.OpenRead(disk3), File.OpenRead(disk4) + /*Libc.Open(disk1, Libc.OpenFlags.O_RDONLY), + Libc.Open(disk2, Libc.OpenFlags.O_RDONLY), + Libc.Open(disk3, Libc.OpenFlags.O_RDONLY), + Libc.Open(disk4, Libc.OpenFlags.O_RDONLY),*/ }; internal void SetOutputFile(String output) => this.OutputDisk = File.OpenWrite(output); private void Close() { + //this.OutputDisk.Flush(); this.OutputDisk.Close(); this.InputDisks[0].Close(); this.InputDisks[1].Close(); this.InputDisks[2].Close(); this.InputDisks[3].Close(); + /*_ = Libc.Close(this.InputDisks[0]); + _ = Libc.Close(this.InputDisks[1]); + _ = Libc.Close(this.InputDisks[2]); + _ = Libc.Close(this.InputDisks[3]);*/ } internal void SetParameters(UInt32 sector, UInt32 stripe, UInt32 parity) { @@ -59,6 +67,7 @@ namespace BlubbFish.Tools.Raid.HP.Raid45 Int64 incount = this.Start / this.Stripe; Int64 outcount = 0; Span buffer = new Span(new Byte[this.Stripe * this.Sector]); + //Byte[] buffer = new Byte[this.Stripe * this.Sector]; Console.Write("Copy Buffer Size " + this.Stripe * this.Sector+" bytes"); Console.Write("\t\t\tStartsector: " + this.Start + "\t\tEndsector: " + this.End); @@ -83,10 +92,10 @@ namespace BlubbFish.Tools.Raid.HP.Raid45 Console.SetCursorPosition(this.CursorOrigCol + 10, this.CursorOrigRow + 1); Console.Write((outcount + 3) * this.Stripe * this.Sector + " byte"); - Console.SetCursorPosition(this.CursorOrigCol + 45, this.CursorOrigRow + 1); + Console.SetCursorPosition(this.CursorOrigCol + 40, this.CursorOrigRow + 1); Console.Write((DateTime.Now - starttime).TotalSeconds.ToString("F3") + " sec"); - Console.SetCursorPosition(this.CursorOrigCol + 60, this.CursorOrigRow + 1); + Console.SetCursorPosition(this.CursorOrigCol + 65, this.CursorOrigRow + 1); Console.Write((((Double)outcount + 3) * this.Stripe * this.Sector / (DateTime.Now - starttime).TotalSeconds).ToString("F0") + " byte/s"); try { for (UInt32 disk = 0; disk < 3; disk++) { @@ -113,8 +122,8 @@ namespace BlubbFish.Tools.Raid.HP.Raid45 } } - private void Copy(Int32 inputdisk, Int64 incount, Int64 outcount, Span buffer) { - try { + private void Copy(Int32 inputdisk, Int64 incount, Int64 outcount, Span /*Byte[]*/ buffer) { + try { if(this.InputDisks[inputdisk].Length <= incount * this.Stripe * this.Sector) { throw new OverflowException("EOF of " + this.InputDisks[inputdisk].Name + " reached"); } @@ -123,10 +132,15 @@ namespace BlubbFish.Tools.Raid.HP.Raid45 } _ = this.InputDisks[inputdisk].Seek(incount * this.Stripe * this.Sector, SeekOrigin.Begin); _ = this.InputDisks[inputdisk].Read(buffer); + /*_ = Libc.Seek(this.InputDisks[inputdisk], incount * this.Stripe * this.Sector, Libc.SeekFlag.SEEK_SET); + _ = Libc.Read(this.InputDisks[inputdisk], buffer, (Int32)(this.Stripe * this.Sector));*/ } catch (Exception e) { Console.WriteLine("Error while reading: " + this.InputDisks[inputdisk].Name); Console.WriteLine(this.InputDisks[inputdisk].Name + " Seek(" + incount * this.Stripe * this.Sector + ", Begin)"); Console.WriteLine(this.InputDisks[inputdisk].Name + " Read(" + buffer.Length + ", 0, " + (Int32)this.Sector + ")"); + /*Console.WriteLine("Error while reading: " + inputdisk); + Console.WriteLine(inputdisk+ " Seek(" + incount * this.Stripe * this.Sector + ", Begin)"); + Console.WriteLine(inputdisk + " Read(" + buffer.Length + ", 0, " + (Int32)this.Sector + ")");*/ throw e; } diff --git a/hp-raid45-recovery/Libc.cs b/hp-raid45-recovery/Libc.cs new file mode 100644 index 0000000..ca4e8a6 --- /dev/null +++ b/hp-raid45-recovery/Libc.cs @@ -0,0 +1,33 @@ +using System; +using System.Runtime.InteropServices; + +namespace BlubbFish.Tools.Raid.HP.Raid45 { + public static class Libc { + [Flags] + public enum OpenFlags { + O_RDONLY = 0, + O_WRONLY = 1, + O_RDWR = 2, + O_NONBLOCK = 4, + } + + [Flags] + public enum SeekFlag { + SEEK_SET = 0, + SEEK_CUR = 1, + SEEK_END = 2 + } + + [DllImport("libc", EntryPoint = "open")] + public static extern Int32 Open(String pathname, OpenFlags flags); + + [DllImport("libc", EntryPoint = "close")] + public static extern Int32 Close(Int32 fd); + + [DllImport("libc", EntryPoint = "read")] + public static extern Int32 Read(Int32 fd, Byte[] buf, Int32 count); + + [DllImport("libc", EntryPoint = "lseek")] + public static extern Int32 Seek(Int32 fd, Int64 offset, SeekFlag whence); + } +}