|
|
|
@@ -1,10 +1,12 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace BlubbFish.Tools.Raid.HP.Raid45
|
|
|
|
|
{
|
|
|
|
|
namespace BlubbFish.Tools.Raid.HP.Raid45 {
|
|
|
|
|
internal class CopyProcess
|
|
|
|
|
{
|
|
|
|
|
private Int32 CursorOrigRow;
|
|
|
|
|
private Int32 CursorOrigCol;
|
|
|
|
|
|
|
|
|
|
public Int32[,] Mode { get; }
|
|
|
|
|
|
|
|
|
|
public UInt32 Sector { get; private set; }
|
|
|
|
@@ -14,36 +16,39 @@ namespace BlubbFish.Tools.Raid.HP.Raid45
|
|
|
|
|
public Int64 End { get; private set; }
|
|
|
|
|
public FileStream[] InputDisks { get; private set; }
|
|
|
|
|
public FileStream OutputDisk { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public CopyProcess() {
|
|
|
|
|
this.Mode = new Int32[4, 3] {
|
|
|
|
|
|
|
|
|
|
public CopyProcess() => this.Mode = new Int32[4, 3] {
|
|
|
|
|
{ 0, 1, 2 },
|
|
|
|
|
{ 0, 1, 3 },
|
|
|
|
|
{ 0, 2, 3 },
|
|
|
|
|
{ 1, 2, 3 }
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void SetInputFiles(String disk1, String disk2, String disk3, String disk4) {
|
|
|
|
|
this.InputDisks = new FileStream[] {
|
|
|
|
|
File.OpenRead(disk1),
|
|
|
|
|
File.OpenRead(disk2),
|
|
|
|
|
File.OpenRead(disk3),
|
|
|
|
|
File.OpenRead(disk4)
|
|
|
|
|
internal void SetInputFiles(String disk1, String disk2, String disk3, String disk4) => this.InputDisks = new FileStream[] {
|
|
|
|
|
File.OpenRead(disk1),
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
@@ -58,16 +63,40 @@ namespace BlubbFish.Tools.Raid.HP.Raid45
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void Running() {
|
|
|
|
|
Console.Clear();
|
|
|
|
|
Int64 incount = this.Start / this.Stripe;
|
|
|
|
|
Int64 outcount = 0;
|
|
|
|
|
Console.WriteLine("alloc buffer " + this.Sector);
|
|
|
|
|
Span<Byte> buffer = new Span<Byte>(new Byte[this.Sector]);
|
|
|
|
|
Span<Byte> buffer = new Span<Byte>(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);
|
|
|
|
|
Console.WriteLine("\nTotalsize: " + (this.End - this.Start) * this.Sector * 3+" bytes");
|
|
|
|
|
this.CursorOrigRow = Console.CursorTop;
|
|
|
|
|
this.CursorOrigCol = Console.CursorLeft;
|
|
|
|
|
|
|
|
|
|
DateTime starttime = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
UInt32 startmode = (UInt32)(this.Start / (this.Stripe * this.Parity)) % 4;
|
|
|
|
|
while (true) {
|
|
|
|
|
for (UInt32 diskmode = startmode; diskmode < 4; diskmode++) {
|
|
|
|
|
Console.WriteLine("Disk Mode: " + diskmode + ", [" + this.Mode[diskmode, 0] + ", " + this.Mode[diskmode, 1] + ", " + this.Mode[diskmode, 2] + "]");
|
|
|
|
|
Console.SetCursorPosition(this.CursorOrigCol, this.CursorOrigRow);
|
|
|
|
|
Console.Write("Diskmode " + diskmode + ":[" + this.Mode[diskmode, 0] + ", " + this.Mode[diskmode, 1] + ", " + this.Mode[diskmode, 2] + "]");
|
|
|
|
|
for (UInt32 paritys = 0; paritys < this.Parity; paritys++) {
|
|
|
|
|
Console.SetCursorPosition(this.CursorOrigCol + 30, this.CursorOrigRow);
|
|
|
|
|
Console.Write("[" + incount * this.Stripe + " s, " + (incount + 1) * this.Stripe + " s] -> [" + outcount * this.Stripe + " s, " + (outcount+3) * this.Stripe + " s]");
|
|
|
|
|
|
|
|
|
|
Console.SetCursorPosition(this.CursorOrigCol, this.CursorOrigRow + 1);
|
|
|
|
|
Console.Write(Math.Round(((Double)incount * this.Stripe - this.Start) / (this.End - this.Start) * 100.0, 3).ToString("F3") + "% ");
|
|
|
|
|
|
|
|
|
|
Console.SetCursorPosition(this.CursorOrigCol + 10, this.CursorOrigRow + 1);
|
|
|
|
|
Console.Write((outcount + 3) * this.Stripe * this.Sector + " byte");
|
|
|
|
|
|
|
|
|
|
Console.SetCursorPosition(this.CursorOrigCol + 40, this.CursorOrigRow + 1);
|
|
|
|
|
Console.Write((DateTime.Now - starttime).TotalSeconds.ToString("F3") + " sec");
|
|
|
|
|
|
|
|
|
|
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++) {
|
|
|
|
|
this.Copy(this.Mode[diskmode, disk], incount, outcount, buffer);
|
|
|
|
@@ -78,9 +107,12 @@ namespace BlubbFish.Tools.Raid.HP.Raid45
|
|
|
|
|
this.Close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//Console.SetCursorPosition(this.CursorOrigCol, this.CursorOrigRow+1);
|
|
|
|
|
//Console.Write("(" + incount * this.Stripe * this.Sector + " b, " + (incount + 1) * this.Stripe * this.Sector + " b) -> (" + (outcount - 3) * this.Stripe * this.Sector + " b, " + outcount * this.Stripe * this.Sector + " b)");
|
|
|
|
|
|
|
|
|
|
incount++;
|
|
|
|
|
if (incount * this.Stripe >= this.End && this.End != 0) {
|
|
|
|
|
Console.WriteLine("done");
|
|
|
|
|
Console.WriteLine("\nWe reached the end.");
|
|
|
|
|
this.Close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@@ -90,25 +122,30 @@ namespace BlubbFish.Tools.Raid.HP.Raid45
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Copy(Int32 inputdisk, Int64 incount, Int64 outcount, Span<Byte> buffer) {
|
|
|
|
|
try {
|
|
|
|
|
private void Copy(Int32 inputdisk, Int64 incount, Int64 outcount, Span<Byte> /*Byte[]*/ buffer) {
|
|
|
|
|
try {
|
|
|
|
|
if(this.InputDisks[inputdisk].Length <= incount * this.Stripe * this.Sector) {
|
|
|
|
|
throw new OverflowException("EOF of " + this.InputDisks[inputdisk].Name + " reached");
|
|
|
|
|
}
|
|
|
|
|
if(this.InputDisks[inputdisk].Length <= (incount * this.Stripe * this.Sector) + this.Sector) {
|
|
|
|
|
if(this.InputDisks[inputdisk].Length <= incount * this.Stripe * this.Sector + this.Sector) {
|
|
|
|
|
buffer.Clear();
|
|
|
|
|
}
|
|
|
|
|
this.InputDisks[inputdisk].Seek(incount * this.Stripe * this.Sector, SeekOrigin.Begin);
|
|
|
|
|
this.InputDisks[inputdisk].Read(buffer);
|
|
|
|
|
_ = 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
this.OutputDisk.Seek(outcount * this.Stripe * this.Sector, SeekOrigin.Begin);
|
|
|
|
|
_ = this.OutputDisk.Seek(outcount * this.Stripe * this.Sector, SeekOrigin.Begin);
|
|
|
|
|
this.OutputDisk.Write(buffer);
|
|
|
|
|
this.OutputDisk.Flush();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
@@ -119,13 +156,7 @@ namespace BlubbFish.Tools.Raid.HP.Raid45
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("["+Math.Round(((Double)outcount/4)*100, 3)+"] " +
|
|
|
|
|
"Copy disk" + (inputdisk + 1) + " " +
|
|
|
|
|
"[" + (incount * this.Stripe) + " s, " + ((incount + 1) * this.Stripe) + " s] " +
|
|
|
|
|
"(" + (incount * this.Stripe * this.Sector) + " b, " + ((incount + 1) * this.Stripe * this.Sector) + " b) " +
|
|
|
|
|
"-> out " +
|
|
|
|
|
"[" + (outcount * this.Stripe) + " s, " + ((outcount + 1) * this.Stripe) + " s] " +
|
|
|
|
|
"(" + (outcount * this.Stripe * this.Sector) + " b, " + ((outcount + 1) * this.Stripe * this.Sector) + " b)");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|