Compare commits

..

2 Commits
init ... master

Author SHA1 Message Date
104e6f0cd2 test feature add libc 2020-06-15 13:24:49 +02:00
949af8fa19 First Version 2020-05-23 00:18:48 +02:00
4 changed files with 103 additions and 36 deletions

View File

@ -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)");
}
}
}

View 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);
}
}

View File

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

View File

@ -2,7 +2,7 @@
"profiles": {
"hp-raid45-recovery": {
"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"
}
}
}