test feature add libc

This commit is contained in:
BlubbFish 2020-06-15 13:24:49 +02:00
parent 949af8fa19
commit 104e6f0cd2
2 changed files with 53 additions and 6 deletions

View File

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

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