How to implement a filesystem
Re: How to implement a filesystem
Ok thanks to you all. I now know what I am dealing with, but how do I write to the FAT? Do I export a byte? Can you give me a snippet of code as to how I go about doing this?
Once again thanks to you all!!
Once again thanks to you all!!
- Bender
- Member
- Posts: 449
- Joined: Wed Aug 21, 2013 3:53 am
- Libera.chat IRC: bender|
- Location: Asia, Singapore
Re: How to implement a filesystem
If you're talking about disks, you don't write bytes, you write sectors. A sector is the fundamental unit of a disk (usually 512 or 2048 bytes in size). There are different types of disks (IDE, SATA, FDD etc.) and thus the procedure would vary with each type of disk, hence there is no such code that can work for all n situations.
I hope you do know what a ramdisk is. If you just want a filesystem implementation to only load configuration files or modules a ramdisk is better and efficient. (Although a ramdisk can use sh*tload of memory if you keep stuffing it. )
I hope you do know what a ramdisk is. If you just want a filesystem implementation to only load configuration files or modules a ramdisk is better and efficient. (Although a ramdisk can use sh*tload of memory if you keep stuffing it. )
"In a time of universal deceit - telling the truth is a revolutionary act." -- George Orwell
(R3X Runtime VM)(CHIP8 Interpreter OS)
(R3X Runtime VM)(CHIP8 Interpreter OS)
Re: How to implement a filesystem
Alright, thanks. I think I might use a ram disk. But for future reference, how do I write a sector? Do you have a method? outport_sector()?
- Bender
- Member
- Posts: 449
- Joined: Wed Aug 21, 2013 3:53 am
- Libera.chat IRC: bender|
- Location: Asia, Singapore
Re: How to implement a filesystem
wxwsk8er wrote:Alright, thanks. I think I might use a ram disk. But for future reference, how do I write a sector? Do you have a method? outport_sector()?
There is no such standard method for writing sectors. Every device has it's own mechanism.
Sorry, but I'm not supposed to post blocks of code here. The only hint I can give you is to look at other implementations (e.g. Linux or other open-source OSes), refer to the manuals, and the wiki at OSDev.org which has excellent information on different types of storage devices.
"In a time of universal deceit - telling the truth is a revolutionary act." -- George Orwell
(R3X Runtime VM)(CHIP8 Interpreter OS)
(R3X Runtime VM)(CHIP8 Interpreter OS)
Re: How to implement a filesystem
Like this:Evans wrote:Embryo how do you make it so that the hdd provides the library with raw bytes?
Code: Select all
int startSector=xxx; // points to FAT table
int sectorCount=yyy; // should be enough to contain an information we need
byte bs[]=driver.readSectors(startSector,sectorCount);
FileInformation fs[]=fatLibrary.getRootFiles(bs);
Re: How to implement a filesystem
Ok thanks guys. I will take another look
Re: How to implement a filesystem
Ok, so does anyone who has a working FAT driver want to show me how you
write to a sector, or even the FAT itself? Thanks in advance -- wxwsk8er
write to a sector, or even the FAT itself? Thanks in advance -- wxwsk8er
Re: How to implement a filesystem
So how do you write sectors if you don't send a byte at a time using the io bus, then do you write to the disc using a fputs kinda thing?
Re: How to implement a filesystem
fputs is part of the C library, which depends on the filesystem you're asking about how to implement - so by definition it's not available.
There are broadly-speaking three ways to read or write to an IDE/ATA hard disk:
There are broadly-speaking three ways to read or write to an IDE/ATA hard disk:
- Using the BIOS. This is the slowest method, and only works in real mode. Typically you would only use it in a bootloader. Have a look at ATA in x86 RealMode (BIOS) for more information. (Unless you're using very old computers, ignore the section about CHS and skip to LBA)
- PIO (Programmed Input/Output). This is still pretty slow & CPU intensive, but faster than BIOS, and can be used in protected/long mode. See ATA PIO Mode.
- DMA (Direct Memory Access). This is the fastest & best way to read a disk. See ATA/ATAPI using DMA
Re: How to implement a filesystem
Hi,
Cheers,
Brendan
In general; you need to:wxwsk8er wrote:So how do you write sectors if you don't send a byte at a time using the io bus, then do you write to the disc using a fputs kinda thing?
- Design some sort of interface for storage device drivers to implement. This may or may not look like whatever the OS uses for normal file IO (which may or may not look like POSIX-ish "open()", "read()" and "write()", functions).
- Implement (possibly extremely simple) "device detection" code capable of starting device driver/s. This typically begins with code to scan PCI buses.
- Write one or more storage device drivers that implement the "storage device interface" you previously designed.
- Use the "storage device interface" you previously designed to write to the disk.
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re: How to implement a filesystem
Ok thanks, you and JamesM need to have a solid tutorial on this stuff
Also the link in your signature is broken
Thanks!!
Also the link in your signature is broken
Thanks!!
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: How to implement a filesystem
See the Beginner Mistakes why not.Ok thanks, you and JamesM need to have a solid tutorial on this stuff
Re: How to implement a filesystem
OS development tutorials cause more problems than they solve IMO. They encourage people who aren't prepared to put in much effort to copy code parrot-fashion with no understanding of what they are doing. And they are always going to contain errors which people take as gospel and repeat.wxwsk8er wrote:Ok thanks, you and JamesM need to have a solid tutorial on this stuff
To have any success in this sort of low-level programming you must first learn how to do research. All the information that you need is readily available in the form of documentation of hardware and source code for operating systems ranging from the simplest to Linux, FreeBSD, OS X, and the like.
You could do worse than buying one of the many books explaining how the Linux kernel works (similar are available for BSD and OS X) and studying them.
Re: How to implement a filesystem
I agree with you, I meant more of a theory tutorial. But anyway...