Block device Read/write

Topics: Using Cosmos (Developing your own OS, projects, etc)
May 12, 2013 at 2:40 PM
Hi,

I'm trying to read and write some data to Block Device (e.g. HDD), but I have some problems.

I was trying to write data using this line:
BlockDevice.Devices[0].WriteBlock(1, 1, new byte[] { 0x04 });
and then I thought that BlockCount variable will turn into 1.
So I tried to print out:
BlockDevice.Devices[0].BlockCount
But I got 0 :(

I'm also confused about read function:
BlockDevice.Devices[0].ReadBlock();
I can't understand how Read function can be void and wich data must be in the third parameter? I would at least expect ref keyword so a byte array would be used as a buffer.

I couldn't find any documentation on how to use these functions so please help me!

Regards!
Coordinator
May 12, 2013 at 3:13 PM
What cosmos version are you using?



May 12, 2013 at 3:24 PM
I'm using the last version: 92560
Coordinator
May 12, 2013 at 3:30 PM
That's not really the last release...

But the latest release has some issues with installing sql localdb.
We need some more people involved to get us moving.. :)



Developer
May 13, 2013 at 4:02 PM
to: rddezh9
Read And Write Block Functions are as follow
ReadBlock(ulong pos, ulong BlockCount, byte[] data);
WriteBlock(ulong pos, ulong BlockCount, byte[] data);

Where byte[] data array length must be equal's to BlockCount*512 Else it will throw an error or maybe system halt
But you are trying to write/read a single byte to HDD, which is not possible from above code

So use:
byte[] aData = new byte[512]; 
aData[0] = 0x04;

//it will write aData to Disk/partition 0th block
//But my advice is to first check is the BlockDevice is an ATA or partition
BlockDevice.Devices[0].WriteBlock(0UL,1U,aData); // or simply BlockDevice.Devices[0].WriteBlock(0,1,aData);

//And for Read Block
//It will write All Data of Disk/Partition to aData
//And must sure that aData array length must be (BlockCount)*512
BlockDevice.Devices[0].ReadBlock(0UL,1U,aData);
Regards
Aman Priyadarshi
May 13, 2013 at 4:19 PM
Aman,

thank you very much for this reply.

It's working now, so thank you again.

Regards,
rddezh9
Developer
May 13, 2013 at 4:21 PM
Edited May 13, 2013 at 4:21 PM
Feel Free to ask any doubt :)
May 15, 2013 at 10:40 AM
I can help you, but I'm not sure if I have enough knowledge.

Greetings
rddezh9



2013/5/13 AtomOS <[email removed]>

From: AtomOS

Fell Free to ask any doubt :)

Read the full discussion online.

To add a post to this discussion, reply to this email ([email removed])

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com




--
Lep pozdrav! Vaš Okno v svet
Oct 30, 2013 at 12:05 AM
What can i do if my BlockDevice count is 0... When I boot my OS in VirtualBox the count is 5, however, when I boot it in qemu the count is 0 (i am using raw image created with qemu-img).
Oct 30, 2013 at 12:15 AM

In VirtualBox are you using the already made/pre-partitioned HD file? It's named ATI OR Vmware or something

Coordinator
Oct 30, 2013 at 5:52 AM

Qemu is used by virtualbox. Directly using qemu means you need to make a lot more settings.. The drive is on a default ata controller?

Op 30 okt. 2013 01:05 schreef "AlienNinja" <[email removed]>:

From: AlienNinja

What can i do if my BlockDevice count is 0... When I boot my OS in VirtualBox the count is 5, however, when I boot it in qemu the count is 0 (i am using raw image created with qemu-img).

Read the full discussion online.

To add a post to this discussion, reply to this email ([email removed])

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Oct 30, 2013 at 10:53 AM
Edited Oct 30, 2013 at 10:54 AM
I'm using hard drive made in Oracle VM VirtualBox... Nothing special about it... It is set as IDE Primary Master, type is normal VDI, dynamically allocated... It might be pre-partitioned though... Is there a way to make partitions on a raw image made in qemu? I also might not be starting qemu right... Im using "qemu-system-i386.exe -hdd hdd.img -cd system.iso -boot d" command...
Oct 30, 2013 at 11:14 AM
I knew i was using qemu wrong... Sorry about that... The command i was using was wrong... I it "-hda", not "-hdd"... I'm such an idiot... Thanks everyone for trying to help