FAT/root woes 
Author Message
 FAT/root woes

Ive been trying to work with the FAT and root and the following NASM
program (assemble as a COM file) doesnt seem to be obtaining the root...
it obtains something but i dont think its the root... although maybe im
wrong... to get the root i used the following "algorithm":

- Write boot sector to "boot_buffer"
- Take the number of reserved sectors (boot_buffer offset 0Eh) which is
number of sectors before first FAT; take the size of the FAT (offset
16h); and find the number of FATs (offset 10h)... Then I do:
reverved_sectors + (fat_size * number_of_fats)
- To find the number of maximum root entriees i take the value from
offset 11h of the boot buffer.To get a size of the root in bytes I
multiply this by 32 (size of a directory entry)... To get the size of
the root in sectors i divide by the value in offset 0Bh

the listing to my program is below:

; FAT and Root Project

org 100h

section .text

main:
        call    save_bootsect
        call    save_root
        call    exit

save_bootsect:
        mov     al,     3               ; Drive... A = 0, B = 1, C = 2
        mov     cx,     1               ; Number of sectors to read
        xor     dx,     dx              ; Sector 0
        mov     bx,     boot_buffer     ; Buffer to write 512 bytes of
data to
        int     25h

        pop     dx                      ; DOS error -- extra word on
stack

        jc      bootsect_l32            ; Maybe disk > 32mb... try for
32+ mb

        ret

bootsect_l32:
        mov     word [read_packet + 4], boot_buffer     ; Address of
                                                        ; boot_buffer in
int
                                                        ; 25h data
packet
        mov     word [read_packet + 5], ds              ; Address of
data seg
        mov     word [read_packet + 2], 1               ; 1st sector
        mov     word [read_packet + 3], 1               ; Read 1 sector
        mov     al,     3                               ; Drive C
        mov     cx,     0ffffh                          ; Indicates disk

Quote:
> 32mb

        mov     bx,     read_packet                     ; Packet address

        int     25h

        pop     dx

        jc      near    error

        ret

save_root:
        mov     ah,     byte [boot_buffer + 22]         ; FAT size (high
byte)
        mov     al,     byte [boot_buffer + 23]         ; FAT size (low
byte)
        mov     cl,     byte [boot_buffer + 16]         ; Number of FATs

        xor     ch,     ch
        mul     cl

        mov     bh,     byte [boot_buffer + 14]         ; Reserved
sectors
        mov     bl,     byte [boot_buffer + 15]

        add     bx,     ax                              ; BX = Sector of
root

        mov     ah,     byte [boot_buffer + 17]         ; Root entry
size
        mov     al,     byte [boot_buffer + 18]

        mov     cx,     32
        mul     cx

        mov     word [root_size],       ax

        mov     ch,     byte [boot_buffer + 11]         ; Sector size
        mov     cl,     byte [boot_buffer + 12]

        div     cx

        mov     cx,     ax                              ; Root length in
sec
        mov     dx,     bx                              ; DX = first
sector
        mov     al,     3
        mov     bx,     root_buffer

        int     25h

        pop     dx

        jc      root_l32

        ret

root_l32:
        mov     word [read_packet + 4], root_buffer     ; Address of
                                                        ; boot_buffer in
int
                                                        ; 25h data
packet
        mov     word [read_packet + 5], ds              ; Address of
data seg
        mov     word [read_packet + 2], dx              ; 1st sector of
root
        mov     word [read_packet + 3], cx              ; Read (CX)
sectors
        mov     al,     3
        mov     cx,     0ffffh                          ; Indicates disk

Quote:
> 32mb

        mov     bx,     read_packet                     ; Packet address

        int     25h

        pop     dx

        jc      error

        ret

error:
        mov     ah,     09
        mov     dx,     error_msg
        int     21h

        call    exit

exit:
        mov     ah,     4ch
        int     21h

section .data

        read_packet     dw      0, 0, 0, 0, 0
        boot_buffer     times 512       db      0
        root_buffer     times 16384     db      0

        root_size       dw      0

        error_msg       db      "Error!$"



Sun, 08 Jul 2001 03:00:00 GMT  
 FAT/root woes

Quote:
> Ive been trying to work with the FAT and root and the following NASM
> program (assemble as a COM file) doesnt seem to be obtaining the root...
> save_root:
>         mov     ah,     byte [boot_buffer + 22]         ; FAT size (high byte)
>         mov     al,     byte [boot_buffer + 23]         ; FAT size (low byte)

  I think you have those backwards.  That word is stored in
normal Intel order.

Quote:
>         mov     cl,     byte [boot_buffer + 16]         ; Number of FATs

>         xor     ch,     ch
>         mul     cl

>         mov     bh,     byte [boot_buffer + 14]         ; Reserved sectors
>         mov     bl,     byte [boot_buffer + 15]

  Backwards again.

Quote:
>         add     bx,     ax                              ; BX = Sector of root
>         mov     ah,     byte [boot_buffer + 17]         ; Root entry size
>         mov     al,     byte [boot_buffer + 18]

  Well, you're consistent :)

Quote:
>         mov     cx,     32
>         mul     cx

>         mov     word [root_size],       ax

  Is the root directory limited to 65K bytes?  I don't know
myself.  I went to some extra effort in BOOTP to work
correctly even if you format a partition with room for over
2048 files in the root directory.

Quote:
>         mov     ch,     byte [boot_buffer + 11]         ; Sector size
>         mov     cl,     byte [boot_buffer + 12]

  Just assume 512 bytes per sector.  Nobody uses anything
else anymore.
--
http://www.erols.com/johnfine/
http://www.geocities.com/SiliconValley/Peaks/8600/


Sun, 08 Jul 2001 03:00:00 GMT  
 FAT/root woes
Well Bart, ever heared of little- or big endian. Intel processors use little
endian mode (as does the boot structure) meaning that the lsb of a word is
stored in the lowest memory byte. If you regard this, your mistake is simple
!!! I have modified the part of your code where the mistake is made.

!!        mov     ah,     byte [boot_buffer + 22]         ; FAT size (high
byte)
!!        mov     al,     byte [boot_buffer + 23]         ; FAT size (low
byte)
          MOV AX,WORD[...]

        mov     cl,     byte [boot_buffer + 16]         ; Number of FATs
         xor     ch,     ch
!!        mul     cl
          MUL CX  ;We need to use a word since ax > 255 !!!!

!!        mov     bh,     byte [boot_buffer + 14]         ; Reserved sectors

!!        mov     bl,     byte [boot_buffer + 15]
          MOV BX,WORD [...]

        add     bx,     ax                              ; BX = Sector of
root

!!        mov     ah,     byte [boot_buffer + 17]         ; Root entry size
!!        mov     al,     byte [boot_buffer + 18]
        MOV AX,WORD [...]
        mov     cx,     32
        mul     cx

        mov     word [root_size],       ax

!!        mov     ch,     byte [boot_buffer + 11]         ; Sector size
!!        mov     cl,     byte [boot_buffer + 12]
        MOV CX,WORD [...]
        div     cx

        mov     cx,     ax                              ; Root length in
sec
        mov     dx,     bx                              ; DX = first
sector
        mov     al,     3
        mov     bx,     root_buffer

        int     25h

        pop     dx

        jc      root_l32

        ret

"Bart \"The Good Guy\" Trzynadlowski" schreef:

Quote:
> Ive been trying to work with the FAT and root and the following NASM
> save_root:



Sun, 08 Jul 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Information on FAT/root needed

2. whats wrong with my FAT/root code:

3. Information on FAT/root needed

4. Working w/ FAT/Root

5. whats wrong with my FAT/root code:

6. pretty technical...Boot Record, FAT, and Root Directory

7. How Fat is Fat?

8. New FAT old FAT

9. how to deal with FAT/root? whats wrong w/ my SRC?

10. how to deal with FAT/root? whats wrong w/ my SRC?

11. fat clients in dolphin

 

 
Powered by phpBB® Forum Software