Writing bytes to a drive

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Fathergorgi1
Posts: 8
Joined: Sat Nov 11, 2017 8:33 pm

Writing bytes to a drive

Post by Fathergorgi1 »

Hello! I am creating my own Hobby OS and I would like to know if I can write raw bytes to certain sectors to a drive. Is there anyway I can do this in C. And if not can I do it in assembly then link it with C.
Eventually I want to do something like this...

Code: Select all

char data[512] = "...";
write(data,[SECTOR])
Thank you in advance :)
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

Re: Writing bytes to a drive

Post by BenLunt »

Well, if it was that easy, we would have Operating Systems coming out of our...well you know. Besides, each OS would be almost the same anyway, since the C language/compiler would pretty much indicate what kind of OS it could be.

Sorry/Happily to say (depending on how you look at it), you have to do all of it yourself. Period. Yes, you can port libraries and other's code to your project, but by doing that, you aren't really making your own, are you?

There are many tutorials, posts, etc., on this site as well as others. Might I suggest a few good books?

Ben
- http://www.fysnet.net/osdesign_book_series.htm
Fathergorgi1
Posts: 8
Joined: Sat Nov 11, 2017 8:33 pm

Re: Writing bytes to a drive

Post by Fathergorgi1 »

Oh okay, I don't mind some extra work put into my OS. Are there any external articles that can get me started?

Thanks anyway! :wink:
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

Re: Writing bytes to a drive

Post by BenLunt »

Well, of course. Where are you at?

If you are at the point where you can use C to "start" to read from the disk, does this mean you have a boot loader which has now loaded your kernel? Have you made it that far yet?

If you are at the boot loader part, you need to write the boot code and use the firmware (Legacy BIOS or UEFI) and read from the disk that way.

If you have a loaded kernel, you need to write a driver for the desired media, in this case, probably an ATA drive.

Where are you at? Boot loader? Have a look at https://github.com/fysnet/FYSOS. This is the boot loader code for the book series I might of hinted to before.

If you are at the Kernel stage, there is a post at viewtopic.php?f=1&t=33152 of someone asking how to read from the disk.

- Ben
Post Reply