Page 1 of 1

Fat12 Directory

Posted: Mon May 04, 2009 10:22 am
by sakuya84
Hi guys,
i'm working on my bootloader and new to FS.
my bootloader is a two stage type,and it work right if the second stage is on the root,
i need to know how to load it from a directory such System\stage2.sys
can you help me?

thank you in advance for your answer..

Re: Fat12 Directory

Posted: Mon May 04, 2009 10:29 am
by Love4Boobies
Are you sure you understand exactly what a file system is and what it does?

Re: Fat12 Directory

Posted: Mon May 04, 2009 10:41 am
by sakuya84
if i don't misundarstand what i read..
fat12 keep a table of the file and directory in a part of the disk called root directory.

what i don't really understand is how tell him that the second stage is'nt on a:\stage2.sys but in a:\system\stage2.sys (just to use a windows example)
because if i leave the stage2.sys on a: my bootloader load the file and it works, but in the second case not
so i thought that i need to tell him that the file is under system. no?

Re: Fat12 Directory

Posted: Mon May 04, 2009 10:46 am
by ruisleipa
Basically you find the entry called "system" from the root directory and then find the "stage2.sys" in that directory.

Re: Fat12 Directory

Posted: Mon May 04, 2009 10:54 am
by sakuya84
ok it's what i tried to to:

Code: Select all

 ;----------------------------------------------------
     ; Find System Folder
     ;----------------------------------------------------  
		  mov     cx, WORD [bpbRootEntries]             ; load loop counter
          mov     di, 0x0200                            ; locate first root entry
     .LOOPS:
          push    cx
          mov     cx, 0x000B                            ; eleven character name
          mov     si, SysFolder                         ; image name to find
          push    di
     rep  cmpsb                                         ; test for entry match
          pop     di
          je      FIND_S2
          pop     cx
          add     di, 0x0020                            ; queue next directory entry
          loop    .LOOPS
          jmp     FAILURE
with this i search on root directory the sysfolder
and now the things become pretty confused to me..... i copied the same thing and i don't resetted di

Code: Select all

 ;----------------------------------------------------
     ; Find stage 2
     ;----------------------------------------------------

     ; browse root directory for binary image
       FIND_S2:
		  mov     cx, WORD [bpbRootEntries]             ; load loop counter
      .LOOP:
          push    cx
          mov     cx, 0x000B                            ; eleven character name
          mov     si, ImageName                         ; image name to find
          push    di
     rep  cmpsb                                         ; test for entry match
          pop     di
          je      LOAD_FAT
          pop     cx
          add     di, 0x0020                            ; queue next directory entry
          loop    .LOOP
          jmp     FAILURE
but i'm pretty sure that something it's wrong.

PS: when i compiling this it give me an error on times 0 filler
times value -19 is negative. i reached the max dimension of 512byte?

Re: Fat12 Directory

Posted: Mon May 04, 2009 11:01 am
by Love4Boobies
First of all, you never mentioned FAT12 in your original post, you said you were developing a boot loader and a file system so I assumed you were working on your own design. The root directory in your example is A: and for FAT12 and FAT16 it has a fixed location and size. This region doesn't even exist on FAT32 volumes.

The first thing you need to do is to find out where the root directory region ends. After that, you calculate the start of the data region (i.e. the first sector of cluster 2) as follows:

Code: Select all

RootDirSectors = ((BPB_RootEntCnt * 32) + (BPB_BytsPerSec – 1)) / BPB_BytsPerSec;
FirstDataSector = BPB_ResvdSecCnt + (BPB_NumFATs * BPB_FATSz16) + RootDirSectors;
The TIMES error, just as you said, shows up because it can't turn the counter backwards and start deleting code to get to the position it needs to reach :) Don't forget that the 2nd stage isn't limited to 512 bytes. You wrote the first stage - just make it load more sectors (if the sector size is 512 bytes).

Re: Fat12 Directory

Posted: Mon May 04, 2009 11:19 am
by sakuya84
i'm sorry for never tell i was working on fat12 ^^'''''

after i've done this what i need to do ?

i resolved the times error shortening the string variable

Re: Fat12 Directory

Posted: Tue May 05, 2009 12:16 am
by egos
And System directory can occupies more than one claster (sector). Take account that in FAT12/16 its structure is differ from root directory. I could see how you are making the search of the dir entries, but I don't see how you are loading the directories.

Re: Fat12 Directory

Posted: Tue May 05, 2009 5:36 am
by jal
sakuya84 wrote:can you help me?
Read. It's a simple, straightforward description. If you do not understand it, I do not believe you can develop an OS.


JAL