Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
104e6f0cd2 | |||
949af8fa19 |
@ -1,10 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace BlubbFish.Tools.Raid.HP.Raid45
|
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; }
|
||||||
@ -14,36 +16,39 @@ namespace BlubbFish.Tools.Raid.HP.Raid45
|
|||||||
public Int64 End { get; private set; }
|
public Int64 End { get; private set; }
|
||||||
public FileStream[] InputDisks { get; private set; }
|
public FileStream[] InputDisks { get; private set; }
|
||||||
public FileStream OutputDisk { 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, 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)
|
/*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) {
|
internal void SetOutputFile(String output) => this.OutputDisk = File.OpenWrite(output);
|
||||||
this.OutputDisk = File.OpenWrite(output);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Close() {
|
private void Close() {
|
||||||
|
//this.OutputDisk.Flush();
|
||||||
this.OutputDisk.Close();
|
this.OutputDisk.Close();
|
||||||
this.InputDisks[0].Close();
|
this.InputDisks[0].Close();
|
||||||
this.InputDisks[1].Close();
|
this.InputDisks[1].Close();
|
||||||
this.InputDisks[2].Close();
|
this.InputDisks[2].Close();
|
||||||
this.InputDisks[3].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) {
|
internal void SetParameters(UInt32 sector, UInt32 stripe, UInt32 parity) {
|
||||||
@ -58,16 +63,40 @@ 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]);
|
//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;
|
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 + 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 {
|
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 +107,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;
|
||||||
}
|
}
|
||||||
@ -90,25 +122,30 @@ namespace BlubbFish.Tools.Raid.HP.Raid45
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Copy(Int32 inputdisk, Int64 incount, Int64 outcount, Span<Byte> buffer) {
|
private void Copy(Int32 inputdisk, Int64 incount, Int64 outcount, Span<Byte> /*Byte[]*/ buffer) {
|
||||||
try {
|
try {
|
||||||
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);
|
||||||
|
/*_ = 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) {
|
} 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)");
|
||||||
Console.WriteLine(this.InputDisks[inputdisk].Name + " Read(" + buffer.Length + ", 0, " + (Int32)this.Sector + ")");
|
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;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 +156,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)");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
33
hp-raid45-recovery/Libc.cs
Normal file
33
hp-raid45-recovery/Libc.cs
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user