Home arrow Forums
OSDEV Forums  


<< Start < Previous 1 2 Next > End >>
Spectre
User

Junior Osdever
Posts: 13
graphgraph
Karma: 0  
Fat - 2004/10/26 00:12 I was wondering how do i start making a simple Fat and if its necessary to write a fat after you code a bootsector.
  | | The administrator has disabled public write access.
OSDEV
Community
Advertisement
   
DRF
User

Platinum Osdever
Posts: 123
graphgraph
Karma: 1  
Re: Fat - 2004/10/26 18:19 Is this setting up FAT in the bootloader or the kernel? And also pmode or real mode? As I have done it in real mode and in the bootloader but not pmode so can't give you anything other than theory for pmode.

Daniel
  | | The administrator has disabled public write access.
Spectre
User

Junior Osdever
Posts: 13
graphgraph
Karma: 0  
Re: Fat - 2004/10/27 23:48 I want to make a simple os that runs on a floppy and I was wondering if i need to write a FAT for it.
  | | The administrator has disabled public write access.
DRF
User

Platinum Osdever
Posts: 123
graphgraph
Karma: 1  
Re: Fat - 2004/10/28 16:31 Well you don't 'need' FAT. There are quite a few different file systems around or you could design and implement your own. So FAT isn't the only way to make an OS. Also my early testing kernels used direct sector addressing without FAT (tho that meant no easy read/write as eveything had to be compiled and put in certain locations by hand staticly mapped).

The FAT12 system is the most commonly used on floppy disks, it is fairly easy to implement though I haven't done any filesystem work in a while.

The bootloader must contain some basic information first (to be read by other computers) the basic information needed is:
Disk Name,
Reserved sectors (where the bootloader is)
Root directory entrys and FAT table locations. (With this table you can read and write data to and from a floppy disk, so you could hide the kernel and bootloader within the hidden sectors and have the rest of the disk available for use like any other disk).

Code:

...
jmp main ; Jump to the start of the boot loader code
OEM_ID db "DFOS " ; 8 char sys ID
BytesPerSector dw 512 ; Sector size in bytes
SectorsPerCluster db 1 ; Sector per cluster
ReservedSectors dw 4 ; Reserved sectors (This I think for this should become 2 for the boot strap, was 1)
TotalFATs db 2 ; Number of fats
MaxRootEntries dw 224 ; Root directory entries
TotalSectorsSmall dw 2880 ; Total Sectors
MediaDescriptor db 0F0h ; Format ID (FAT12 ID number)
SectorsPerFAT dw 9 ; Sectors per FAT
SectorsPerTrack dw 18 ; Sectors per track
NumHeads dw 2 ; Number of heads (2 as double sided floppy)
HiddenSectors dd 0 ; Special hidden sectors
TotalSectorsLarge dd 0 ; More sectors
DriveNumber db 0 ; Drive Number (Primary Floppy is normally 0)
Flags db 0 ; Reserved
Signature db 41 ; Boot signature
VolumeID dd 435101793 ; Volume serial number
VolumeLabel db "NO NAME " ; Volume label (11 bytes)
SystemID db "FAT12 " ; File system (8 bytes)

main:
...


The above is an example. If you have space in your bootloader cutting and pasting that into the very start of the bootloader code (after [org 0x7c00]) will allow FAT12 access but by 3rd party FAT12 drivers. (DOS/Linux etc).

I've summarised in my own style (which may not be to readable to some) on my site, www.dftech.cwc.net/osdev/ in the tutorials and doc's section. But the bootloader changes are the easiest thing to do first and te most fundamental. (Just realised I copyed that from a version of my bootloader that used multiple sectors to avoid the 512byte limit, so the number of hidden sectors is probably different from yours, and just 1)

Hope that helpped if not look up my notes on the subject and feel free to ask any questions.

Daniel
  | | The administrator has disabled public write access.
Spectre
User

Junior Osdever
Posts: 13
graphgraph
Karma: 0  
Re: Fat - 2004/10/30 04:07 I was reading your LBA to CHS tutorial and I am wondering what you do if you get mixed numbers in the equations?
and is sector 2,880 necessarily on the second head last cylinder?
and is the last cylinder 40 or 80?
  | | The administrator has disabled public write access.
DRF
User

Platinum Osdever
Posts: 123
graphgraph
Karma: 1  
Re: Fat - 2004/10/31 15:18 The equation I can't say to much about as I obtained it from the internet by looking though various datasheets to discover them. The implementation I use isn't copied however.
So the maths from any site on the subject is:
Sector = (LBA mod SectorsPerTrack)+1
Cylinder = (LBA/SectorsPerTrack)/NumHeads
Head = (LBA/SectorsPerTrack) mod NumHeads

LBA is a user variable constantly changing (I would imagine)
The Sectors Per track and NumHeads variables are (or rather in this case will have to be) defined within the operating system itself. So this formula will work on any drive but a hard drive has a different number of sectors per track and a different number of heads and so on. So by changing the variables you can get it to work for different types of drives.
On a floppy disk drive you have 2 heads (one above one below I think but not sure) and 18 sectors per track. So LBA sector 2,880 is going to be at (forgive my maths not done this in a while).

Sector=(2880 mod 18) +1
Which comes to '2' (at least on the computers calculator)
Cylinder = (2880 / 18) / 2
which comes to 80
Head = (2880 / 18) mod 2
Which comes to 0 (In computers addresses often start at 0 rather than 1)

I apologise if I'm wrong in those numbers I mostly stuck to numbers I could do on paper for formula testing so not sure if I'm using the right functions on the calc on the computer. One way to test theorys is to make a small bit of implmentation on a floppy disk. But the values returned in this case are so the BIOS knows: How far to rotate the disk, how far to move the heads to the edge/middle and to use either the top head or the below head to read the data.

You shouldn't get 2 values returned from those forumlas. I like u questioned them first and did some tests on paper to ensure that they did return values that looked realistic based upon some facts aquired from datasheets (which I've since lost) unfortunatly. A look on the OS resources site revealed http://www.nondot.org/sabre/os/files/Disk/CHSTranslation.txt which has an in depth discussion/document on the matter but it refers more to use in the hard drive and all the examples are base on hard drives and decompiled existing OS's rather than write and optimised logical code. I personally find it murder to wade though all that unreleated info but it may help. The formulas they use are slightly different but similar and will return the same results the formulas I used are (or should) be easy to convert into assembly code.
When reading assembly versions of the forumla remember however that they are optimised a little so rather than perform a particular function twice you just save relavant info from one of the other formulas out of the 3 to use in the later ones.

Hope it helps,
Daniel
  | | The administrator has disabled public write access.
Spectre
User

Junior Osdever
Posts: 13
graphgraph
Karma: 0  
Re: Fat - 2004/11/11 23:59 Is all this code in the first sector of the floppy (bootsector) or does it go into the next sectors after the boot signature?
  | | The administrator has disabled public write access.
DRF
User

Platinum Osdever
Posts: 123
graphgraph
Karma: 1  
Re: Fat - 2004/11/18 05:06 The boot sector of a floppy disk should in most cases have the FAT table as the first thing. Then normally after that the main loop and at the end the procedures for things like loading another sector or displaying text. If you go over the 512byte limit you can all ways carry some of the functions over into an other sector and just implement a load sector function in the first sector and all the staticly addressed tables. Everything else can then be moved into the second sector (tho it can be as many sectors as you like, well within reason). I personally have a FAT table and some hardware checks and a load sector and display text procedure in my first sector then in a second stage added the functions to find and load a kernel from the FAT filesystem.

Daniel
  | | The administrator has disabled public write access.
H4evr
User

Fresh Osdever
Posts: 3
graphgraph
Karma: 0  
Re: Fat - 2005/10/04 14:16 Hi.
Can you guys tell me how to read a file into memory (and accessing it) being the filesystem FAT12?

Thanks in advance.
  | | The administrator has disabled public write access.
gaf
User

Platinum Osdever
Posts: 153
graph
Karma: 10  
Re: Fat - 2005/10/06 14:15 Hello H4evr,
in order to read data from the floppy you have to write an own driver first. You'll find information on how this can be done in the os wiki which also provides links to the official papers aswell as other usefull documents. In case that your operating system is running in real-mode rather than protected mode you could alternativly use the BIOS interface which would save you from writing a lot of code. The best source of information about the BIOS and low-level hardware interfacing in general is "Ralf Brown's interrupt list" which can also be browsed online.

Once you've established a basic driver interface that allows you to read/write sectors you should have a look at the FAT12 filesystem. It really shouldn't be too hard to find tutorials and documents about it using google or by searching the wiki (fat) as the filesystem is well known and simple enough to by interesting for hobby operating system.

regards,
gaf
  | | The administrator has disabled public write access.
<< Start < Previous 1 2 Next > End >>

A WebArticles site. Sponsored by Evoleto. Motorola V525 / Business Directory / Delaware Incorporation / Home Made Bazaar