Page 1 of 1

How do I write to hard disk?

Posted: Thu Mar 24, 2022 7:50 am
by Caffeine
Hi,

I am trying to implement a FAT32 file system into my OS, but have a few questions on how to implement it.

How do I write to my hard drive and how do I find out where on the hard drive the filesystem goes? Is there a way by using the grub mbi specificatons?

Thanks.

Re: How do I write to hard disk?

Posted: Thu Mar 24, 2022 8:53 am
by iansjack
That's a big question.

If you are using a VM, rather than a real computer, you might like to look here: https://wiki.osdev.org/ATA_PIO_Mode It's fairly simple to write a basic ATA driver to read and write sectors on a hard disk. The filesystem goes on a partition on the disk; the partition table in sector 0 of the disk lists partitions and where to find them on the disk. It's easier, at fist, to use your host operating system to create the partition and filesystem on your disk rather than writing the code for yourself.

Re: How do I write to hard disk?

Posted: Thu Mar 24, 2022 11:26 am
by Caffeine
iansjack wrote:That's a big question.

If you are using a VM, rather than a real computer, you might like to look here: https://wiki.osdev.org/ATA_PIO_Mode It's fairly simple to write a basic ATA driver to read and write sectors on a hard disk. The filesystem goes on a partition on the disk; the partition table in sector 0 of the disk lists partitions and where to find them on the disk. It's easier, at fist, to use your host operating system to create the partition and filesystem on your disk rather than writing the code for yourself.
Thanks! I'll check out the page.

Re: How do I write to hard disk?

Posted: Thu Mar 24, 2022 5:55 pm
by Octocontrabass
Multiboot can tell you which partition your kernel was loaded from. You'll have to parse the partition tables yourself, though.

Multiboot can't tell you exactly which device it loaded your kernel from. The best it can give you is the BIOS device number, and you're on your own to figure out how that translates into an actual storage device. Any reasonably modern PC supports EDD 3.0, which is the most accurate way to identify the device, but it's a BIOS call that requires you to either switch back to real mode or implement virtual 8086 mode.

Re: How do I write to hard disk?

Posted: Fri Mar 25, 2022 9:08 am
by Caffeine
Octocontrabass wrote:Multiboot can tell you which partition your kernel was loaded from. You'll have to parse the partition tables yourself, though.

Multiboot can't tell you exactly which device it loaded your kernel from. The best it can give you is the BIOS device number, and you're on your own to figure out how that translates into an actual storage device. Any reasonably modern PC supports EDD 3.0, which is the most accurate way to identify the device, but it's a BIOS call that requires you to either switch back to real mode or implement virtual 8086 mode.
Thanks!