Page 2 of 3

Re: How to implement a filesystem

Posted: Sat Jul 26, 2014 5:18 pm
by mateuszb

Re: How to implement a filesystem

Posted: Sat Jul 26, 2014 6:45 pm
by deleted
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!!

Re: How to implement a filesystem

Posted: Sat Jul 26, 2014 7:27 pm
by Bender
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. :))

Re: How to implement a filesystem

Posted: Sat Jul 26, 2014 7:35 pm
by deleted
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()?

Re: How to implement a filesystem

Posted: Sat Jul 26, 2014 9:10 pm
by Bender
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.

Re: How to implement a filesystem

Posted: Sun Jul 27, 2014 3:09 am
by embryo
Evans wrote:Embryo how do you make it so that the hdd provides the library with raw bytes?
Like this:

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

Posted: Sun Jul 27, 2014 7:49 am
by deleted
Ok thanks guys. I will take another look :)

Re: How to implement a filesystem

Posted: Mon Jul 28, 2014 9:51 am
by deleted
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

Re: How to implement a filesystem

Posted: Mon Jul 28, 2014 12:17 pm
by deleted
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

Posted: Mon Jul 28, 2014 12:54 pm
by madanra
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:
  • 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
All of these involve reading or writing a whole number of sectors.

Re: How to implement a filesystem

Posted: Mon Jul 28, 2014 1:26 pm
by Brendan
Hi,
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?
In general; you need to:
  • 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.
Note that to write individual byte/s, you have to read a whole sector (if it's not cached), modify it in RAM, then write a whole sector. This may be done by the storage device driver itself (e.g. if your "storage device interface" allows byte access), or it might be done by the file system code (e.g. if your "storage device interface" only supports blocks/sectors).


Cheers,

Brendan

Re: How to implement a filesystem

Posted: Mon Jul 28, 2014 6:00 pm
by deleted
Ok thanks, you and JamesM need to have a solid tutorial on this stuff :wink:

Also the link in your signature is broken [-X :)

Thanks!!

Re: How to implement a filesystem

Posted: Tue Jul 29, 2014 12:06 am
by Combuster
Ok thanks, you and JamesM need to have a solid tutorial on this stuff
See the Beginner Mistakes why not.

Re: How to implement a filesystem

Posted: Tue Jul 29, 2014 12:08 am
by iansjack
wxwsk8er wrote:Ok thanks, you and JamesM need to have a solid tutorial on this stuff :wink:
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.

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

Posted: Tue Jul 29, 2014 5:12 am
by deleted
I agree with you, I meant more of a theory tutorial. But anyway...