-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create Hardware.cs #1
Open
Gor32
wants to merge
1
commit into
master
Choose a base branch
from
Gor32-patch-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.IO; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading; | ||
|
||
|
||
/* | ||
please QLND-ing | ||
*/ | ||
|
||
|
||
/////////////////////////////////// TEST /////////////////////////////////////// | ||
namespace Hardware | ||
{ | ||
class HDD { | ||
|
||
static private int MAX_LENGTH_BYTES = 10; | ||
|
||
// your path can modify | ||
public static string path = | ||
@"c:\Users\Home\documents\visual studio 2015\Projects\OS\Hardware\HDD.txt"; | ||
|
||
// kaskatelia esi uxaki threadi hamarem senc grel te che amen mi methodi | ||
// mejel karam open cloaase anem | ||
static private FileStream fs = File.Open(path, FileMode.Open, FileAccess.ReadWrite); | ||
|
||
private class Write { | ||
Write(){} | ||
|
||
public Write(byte[] data, long offset, int length) | ||
{ | ||
this.data = data; | ||
this.offset = offset; | ||
this.length = length; | ||
} | ||
|
||
public byte[] data; | ||
public long offset; | ||
public int length; | ||
} | ||
|
||
public static void ThreadPoolCallbackWrite(Object threadContext) | ||
{ | ||
Write threads = (Write)threadContext; | ||
write(threads.data,threads.offset,threads.length); | ||
} | ||
|
||
/* | ||
MAX_OFFSET = log2(HDD.SIZE) | ||
*/ | ||
//[MethodImpl(MethodImplOptions.Synchronized)] | ||
public static void write(byte[] data, long offset, int length = -1) { | ||
|
||
if (length == -1) length = data.Length; | ||
|
||
int count = 0; | ||
while(length / MAX_LENGTH_BYTES > 1) { | ||
byte[] dataX = new byte[MAX_LENGTH_BYTES]; | ||
|
||
for (int i = 0; i < MAX_LENGTH_BYTES; i++) | ||
dataX[i] = data[count + i]; | ||
|
||
count += MAX_LENGTH_BYTES; | ||
|
||
Write state = new Write(dataX, MAX_LENGTH_BYTES, MAX_LENGTH_BYTES); | ||
ThreadPool.QueueUserWorkItem(HDD.ThreadPoolCallbackWrite, (Object)state); | ||
length -= MAX_LENGTH_BYTES; | ||
} | ||
|
||
// Thread newThread = new Thread(raed); | ||
// newThread.Start(data,offset,length); | ||
//var fs = File.Open(path,FileMode.Open,FileAccess.Write); | ||
|
||
fs.Seek(offset,SeekOrigin.Begin); | ||
|
||
fs.Write(data, 0, length); | ||
|
||
Console.WriteLine("write "+path); | ||
// fs.Close(); | ||
|
||
} | ||
|
||
private class Read | ||
{ | ||
Read() { } | ||
|
||
public Read(byte[] data, long offset, int count) | ||
{ | ||
this.data = data; | ||
this.offset = offset; | ||
this.count = count; | ||
} | ||
|
||
public byte[] data; | ||
public long offset; | ||
public int count; | ||
} | ||
|
||
public static void ThreadPoolCallbackRead(Object threadContext) | ||
{ | ||
Read threads = (Read)threadContext; | ||
read(ref threads.data, threads.offset, threads.count); | ||
} | ||
|
||
/* | ||
MAX_OFFSET = log2(HDD.SIZE) | ||
*/ | ||
// count <= raed.Length | ||
//[MethodImpl(MethodImplOptions.Synchronized)] | ||
public static void read(ref byte[] data, long offset, int count) { | ||
|
||
//var fs = File.Open(path,FileMode.Open,FileAccess.Read); | ||
|
||
/* | ||
Hl@ chem grel axper asim esqan@ qcem mi hat qlnges eli ) | ||
*/ | ||
|
||
fs.Seek(offset, SeekOrigin.Begin); | ||
|
||
fs.Read(data, 0, count); | ||
|
||
//for test :) | ||
for(int i = 0;i<count; i++) Console.WriteLine(data[i]); | ||
|
||
Console.WriteLine("read "+ path); | ||
//fs.Close(); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
|
||
//int intValue = 13; | ||
//byte [] intValueOnByteArray = BitConverter.GetBytes(intValue); | ||
|
||
byte[] intBytes = new byte[31]; | ||
for (byte i = 0; i <31; i++) intBytes[i] = i; | ||
|
||
long writeOffset = 0; | ||
long readOffset = 0; | ||
|
||
int readCount = 2; | ||
intBytes[1] = 115; | ||
HDD.write(intBytes, writeOffset); | ||
HDD.read(ref intBytes, readOffset, readCount); | ||
|
||
|
||
|
||
} | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
/* | ||
31.03.2017 | ||
if you have a question write [email protected] | ||
*/ | ||
/* | ||
please help us | ||
*/ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use relative path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
Directory.GetCurrentDirectory()+"\\HDD.txt"; is true ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try yourself and put in working code.