Page 1 of 1
Hard-Drive Management
Posted: Tue Sep 15, 2015 1:23 pm
by DarkGV
Hey OS-Dev.
I need to do a final course project and I just started doing an OS, but I need a little help about Hard-Drive management.. Is there a way to manage the hard drive c based ? I need inline assembly? How does my system recognize the hard-drive ? (that's the main question)
Can someone please help me??
I'm not english, so sorry if there's some grammar mistake :s
Re: Hard-Drive Management
Posted: Tue Sep 15, 2015 1:29 pm
by BrightLight
What exactly does "manage/recognize the hard drive" mean?
If you mean how does the system detect hard drives, read about BIOS INT 0x13. For reading/writing sectors in protected/long mode, read
ATA and
AHCI.
Re: Hard-Drive Management
Posted: Tue Sep 15, 2015 1:40 pm
by DarkGV
I want to create a file and "insert" it into the Xth sector...
I need to do that with assembly ? What if my kernel is written in c ?? Do I need to use inline assembly or something ?
Re: Hard-Drive Management
Posted: Tue Sep 15, 2015 2:01 pm
by glauxosdever
Hi,
DarkGV wrote:I need to do that with assembly ? What if my kernel is written in c ?? Do I need to use inline assembly or something ?
If you are writing your own bootloader, then you will definitely need to use INT 0x13 to load the kernel, before switching to Protected Mode. Your options are:
- Use pure assembly
- Use a really outdated and ancient compiler that can emit 16-bit code (with inline assembly)
If you are not writing a bootloader, you shouldn't use INT 0x13 and you can do the kernel hard disk driver in C.
DarkGV wrote:I want to create a file and "insert" it into the Xth sector...
This question is undefined: Do you want to create a file from inside your own OS, or do you want to create one from the host OS so it is read by your OS? Those details are really important when asking for help.
omarrx024 wrote:If you mean how does the system detect hard drives, read about BIOS INT 0x13.
INT 0x13 shouldn't be used by the OS to detect drives. It's better to do it in Protected Mode while the kernel is being executed, because then you can have total control over drives.
Regards,
glauxosdever
Re: Hard-Drive Management
Posted: Tue Sep 15, 2015 2:14 pm
by DarkGV
I want to create from inside my OS.
Like notepad from windows..
the user writes (for example):
CreateFile and it executes CreateFile function.
My CreateFile needs to know where and how to write.. I have a problem to do that in C.
Re: Hard-Drive Management
Posted: Tue Sep 15, 2015 2:25 pm
by glauxosdever
Hi,
DarkGV wrote:I want to create from inside my OS.
Like notepad from windows..
the user writes (for example):
CreateFile and it executes CreateFile function.
My CreateFile needs to know where and how to write.. I have a problem to do that in C.
You will need to use the IDE ports to detect the drives and read from and write to them (see IDE, ATA and AHCI articles in the wiki). Yes, you can do it in C once you have implemented port I/O functions. When you get more advanced, don't forget to implement a filesystem too, so your files are structured and organized.
Regards,
glauxosdever
Re: Hard-Drive Management
Posted: Tue Sep 15, 2015 2:33 pm
by DarkGV
The I/O functions are those which are used in VGA and keyboard right?
Re: Hard-Drive Management
Posted: Tue Sep 15, 2015 2:47 pm
by sortie
DarkGV wrote:I need to do a final course project and I just started doing an OS, but I need a little help about Hard-Drive management.. Is there a way to manage the hard drive c based ? I need inline assembly? How does my system recognize the hard-drive ? (that's the main question)
Hi DarkGV,
You are saying this is a final course project? School, university?
You are lacking several important concepts such as filesystems, PCI, ATA, hardware interfaces, drivers, what support drivers need from the core kernel.
Please don't make this your final course project. You're not ready. This is too hard for you. A simple harddisk driver requires a lot of other stuff from the kernel that you aren't ready for. The CreateFile function is a high level Windows API for user-space. It implies the existence of a filesystem driver in addition to a harddisk.
I suggest you pick another project.
Re: Hard-Drive Management
Posted: Tue Sep 15, 2015 3:15 pm
by neon
glauxosdever wrote:DarkGV wrote:I need to do that with assembly ? What if my kernel is written in c ?? Do I need to use inline assembly or something ?
If you are writing your own bootloader, then you will definitely need to use INT 0x13 to load the kernel, before switching to Protected Mode. Your options are:
- Use pure assembly
- Use a really outdated and ancient compiler that can emit 16-bit code (with inline assembly)
Alternatively,
- Use C with EFI disk services
- Use C and switch between protected/long mode and real mode
-- Modern boot loaders use these methods so shouldn't be ignored.
The original poster is not providing nearly enough information to make any recommendation on a course of action. If he has the actual project description that he can provide us, we might be able to. Until then, we are just guessing. I do not see an operating system project as any kind of school project -- it is simply not going to happen.