First Version

This commit is contained in:
BlubbFish 2020-05-23 00:18:48 +02:00
parent 86d5268bcf
commit 949af8fa19
3 changed files with 52 additions and 32 deletions

View File

@ -5,6 +5,9 @@ namespace BlubbFish.Tools.Raid.HP.Raid45
{ {
internal class CopyProcess internal class CopyProcess
{ {
private Int32 CursorOrigRow;
private Int32 CursorOrigCol;
public Int32[,] Mode { get; } public Int32[,] Mode { get; }
public UInt32 Sector { get; private set; } public UInt32 Sector { get; private set; }
@ -16,27 +19,21 @@ namespace BlubbFish.Tools.Raid.HP.Raid45
public FileStream OutputDisk { get; private set; } public FileStream OutputDisk { get; private set; }
public CopyProcess() { public CopyProcess() => this.Mode = new Int32[4, 3] {
this.Mode = new Int32[4, 3] {
{ 0, 1, 2 }, { 0, 1, 2 },
{ 0, 1, 3 }, { 0, 1, 3 },
{ 0, 2, 3 }, { 0, 2, 3 },
{ 1, 2, 3 } { 1, 2, 3 }
}; };
}
internal void SetInputFiles(String disk1, String disk2, String disk3, String disk4) { internal void SetInputFiles(String disk1, String disk2, String disk3, String disk4) => this.InputDisks = new FileStream[] {
this.InputDisks = new FileStream[] {
File.OpenRead(disk1), File.OpenRead(disk1),
File.OpenRead(disk2), File.OpenRead(disk2),
File.OpenRead(disk3), File.OpenRead(disk3),
File.OpenRead(disk4) File.OpenRead(disk4)
}; };
}
internal void SetOutputFile(String output) { internal void SetOutputFile(String output) => this.OutputDisk = File.OpenWrite(output);
this.OutputDisk = File.OpenWrite(output);
}
private void Close() { private void Close() {
this.OutputDisk.Close(); this.OutputDisk.Close();
@ -58,16 +55,39 @@ namespace BlubbFish.Tools.Raid.HP.Raid45
} }
internal void Running() { internal void Running() {
Console.Clear();
Int64 incount = this.Start / this.Stripe; Int64 incount = this.Start / this.Stripe;
Int64 outcount = 0; Int64 outcount = 0;
Console.WriteLine("alloc buffer " + this.Sector); Span<Byte> buffer = new Span<Byte>(new Byte[this.Stripe * this.Sector]);
Span<Byte> buffer = new Span<Byte>(new Byte[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; UInt32 startmode = (UInt32)(this.Start / (this.Stripe * this.Parity)) % 4;
while (true) { while (true) {
for (UInt32 diskmode = startmode; diskmode < 4; diskmode++) { 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++) { 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 + 45, this.CursorOrigRow + 1);
Console.Write((DateTime.Now - starttime).TotalSeconds.ToString("F3") + " sec");
Console.SetCursorPosition(this.CursorOrigCol + 60, this.CursorOrigRow + 1);
Console.Write((((Double)outcount + 3) * this.Stripe * this.Sector / (DateTime.Now - starttime).TotalSeconds).ToString("F0") + " byte/s");
try { try {
for (UInt32 disk = 0; disk < 3; disk++) { for (UInt32 disk = 0; disk < 3; disk++) {
this.Copy(this.Mode[diskmode, disk], incount, outcount, buffer); this.Copy(this.Mode[diskmode, disk], incount, outcount, buffer);
@ -78,9 +98,12 @@ namespace BlubbFish.Tools.Raid.HP.Raid45
this.Close(); this.Close();
return; 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++; incount++;
if (incount * this.Stripe >= this.End && this.End != 0) { if (incount * this.Stripe >= this.End && this.End != 0) {
Console.WriteLine("done"); Console.WriteLine("\nWe reached the end.");
this.Close(); this.Close();
return; return;
} }
@ -95,11 +118,11 @@ namespace BlubbFish.Tools.Raid.HP.Raid45
if(this.InputDisks[inputdisk].Length <= incount * this.Stripe * this.Sector) { if(this.InputDisks[inputdisk].Length <= incount * this.Stripe * this.Sector) {
throw new OverflowException("EOF of " + this.InputDisks[inputdisk].Name + " reached"); 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(); buffer.Clear();
} }
this.InputDisks[inputdisk].Seek(incount * this.Stripe * this.Sector, SeekOrigin.Begin); _ = this.InputDisks[inputdisk].Seek(incount * this.Stripe * this.Sector, SeekOrigin.Begin);
this.InputDisks[inputdisk].Read(buffer); _ = this.InputDisks[inputdisk].Read(buffer);
} catch (Exception e) { } catch (Exception e) {
Console.WriteLine("Error while reading: " + this.InputDisks[inputdisk].Name); 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 + " Seek(" + incount * this.Stripe * this.Sector + ", Begin)");
@ -108,7 +131,7 @@ namespace BlubbFish.Tools.Raid.HP.Raid45
} }
try { 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.Write(buffer);
this.OutputDisk.Flush(); this.OutputDisk.Flush();
} catch (Exception e) { } catch (Exception e) {
@ -119,13 +142,7 @@ namespace BlubbFish.Tools.Raid.HP.Raid45
throw e; 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)");
} }
} }
} }

View File

@ -63,7 +63,7 @@ namespace BlubbFish.Tools.Raid.HP.Raid45
} }
try { try {
FileStream f = File.OpenRead(CmdArgs.Instance.GetArgumentData("--disk" + i)); FileStream f = File.OpenRead(CmdArgs.Instance.GetArgumentData("--disk" + i));
f.ReadByte(); _ = f.ReadByte();
f.Close(); f.Close();
} catch (Exception e) { } catch (Exception e) {
Console.WriteLine("--disk" + i + " could not be open. [" + CmdArgs.Instance.GetArgumentData("--disk" + i) + "]\n\n" + e.Message); Console.WriteLine("--disk" + i + " could not be open. [" + CmdArgs.Instance.GetArgumentData("--disk" + i) + "]\n\n" + e.Message);
@ -89,13 +89,16 @@ namespace BlubbFish.Tools.Raid.HP.Raid45
Console.WriteLine("Using Output with \"" + CmdArgs.Instance.GetArgumentData("--out") + "\""); Console.WriteLine("Using Output with \"" + CmdArgs.Instance.GetArgumentData("--out") + "\"");
if (File.Exists(CmdArgs.Instance.GetArgumentData("--out"))) { if (File.Exists(CmdArgs.Instance.GetArgumentData("--out"))) {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("ATTENTIONE ATTENTIONE!!!!!!!:\n" + Console.WriteLine("ATTENTIONE ATTENTIONE!!!!!!!:\n" +
"The target existing, if you shure to overwrite this file press [y] to continue.\n" + "The target existing, if you shure to overwrite this file press [y] to continue.\n" +
"Every other key will exit the programm!"); "Every other key will exit the programm!");
if (Console.ReadKey().Key != ConsoleKey.Y) { if (Console.ReadKey().Key != ConsoleKey.Y) {
Console.ResetColor();
return false; return false;
} }
Console.WriteLine("You want it you have it!"); Console.WriteLine("You want it you have it!");
Console.ResetColor();
} }
try { try {
@ -145,7 +148,7 @@ namespace BlubbFish.Tools.Raid.HP.Raid45
Console.WriteLine("-------------------------------------------------------------------------------"); Console.WriteLine("-------------------------------------------------------------------------------");
Console.WriteLine("Press [return] to Start."); Console.WriteLine("Press [return] to Start.");
Console.ReadLine(); _ = Console.ReadLine();
Console.WriteLine("-------------------------------------------------------------------------------"); Console.WriteLine("-------------------------------------------------------------------------------");
return true; return true;
} }

View File

@ -2,7 +2,7 @@
"profiles": { "profiles": {
"hp-raid45-recovery": { "hp-raid45-recovery": {
"commandName": "Project", "commandName": "Project",
"commandLineArgs": "--disk1 G:\\img\\disk1.img --disk2 G:\\img\\disk2.img --disk3 G:\\img\\disk3.img --disk4 G:\\img\\disk4.img --start 4 --end 8 --out G:\\img\\test.img --paritysize 1 --sectorsize 4 --stripesize 1" "commandLineArgs": "--disk1 X:\\raid5-disk4.img --disk2 X:\\raid5-disk2.img --disk3 X:\\raid5-disk3.img --disk4 X:\\raid5-disk1.img --start 88064 --end 2321920 --out D:\\disks\\disk.img"
} }
} }
} }