Page 1 of 1
Writing bytes to a drive
Posted: Sat Sep 01, 2018 7:23 pm
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
Re: Writing bytes to a drive
Posted: Sat Sep 01, 2018 9:08 pm
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
Re: Writing bytes to a drive
Posted: Sun Sep 02, 2018 5:30 pm
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!
Re: Writing bytes to a drive
Posted: Sun Sep 02, 2018 5:45 pm
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