flat assembler
Message board for the users of flat assembler.

Index > OS Construction > fat12 root directory

Author
Thread Post new topic Reply to topic
abuashraf



Joined: 11 Nov 2006
Posts: 88
abuashraf 23 Jul 2008, 03:29
Hi guys

I'm trying to write a simple com programe that prints the names
of the entries of a fat12 floppy,I mean prints names of files and directories...
as a start I just want to print the names that are existed in the first sector
of the root directory,and I did that ,but my proplem is that my programe also
prints the volume name of the floppy,so can you help me not to print the volume name.
here's my program
Code:
        use16                            
        org     0x100                        

start:
        push    cs                       ; Push CS on stack
        pop     ds                       ; Move CS into DS
        push    ds                       ; Push DS
        pop     es                       ; Move DS into ES

        mov     [count],3                ;try three times
        mov     bx,buffer

tryagain:
    mov     ah,02h                   ;first sector of the root directory
        mov     al,1                     ;number of sectors to read
 mov     ch,0                     ;track
     mov     cl,2                     ;sector
    mov     dh,1                     ;head
      mov     dl,1
        int     13h
        jnc     printbuffer
                  
        dec     [count]
        cmp     [count],0
        jne     tryagain

floppyerror:                             ;there is an error in the floppy
        mov si,fdd_err                  
        call print                       
        ret                              

printbuffer:
        xor     ax,ax
        mov     bx,ax
        mov     dx,ax
        mov     si,ax
        mov     di,ax
        mov     di,buffer
        mov     cx,512                   ;bytes per sector
  @loop:
        mov     al,[di+bx]
        cmp     al,0xE5                  ;deleted file
        je      del                      ;yes don't print it
        cmp     al,0                     ;is it end of files?
        je      checkagain               ;go and check
  no: call      putc    
        inc     bx
        inc     dx
        cmp     dx,11                   ;is it the end of the file name
        jne     again
        call    newline

     del:
        add     di,32
        xor     bx,bx                    ;make bx zero
        mov     dx,bx                    ;make dx zero
       
     checkagain:
        cmp     dx,0
        jne     no 
               
     again:   
        loop    @loop
                      
quit:
        ret                              


;----------------------------------------------------;
;  print.                                            ;
;----------------------------------------------------;
print:
        mov     ah,0Eh                   ; Request display
again1:
        lodsb                            ; load a byte into AL from DS:SI
        or      al,al                    ; Or AL
        jz      done1                    ; Jump 0, to label done1
        int     10h                      ; Call interrupt service
        jmp     again1                   ; Jump to label again1
done1:
        ret                              ; Return  


;----------------------------------------------------;
;prints out a single char from al                    ;
;----------------------------------------------------;
putc:
        pusha                             ;push all general registers
        cmp     al,9                      ;is it tab ?
        je      tab
        mov     ah,0Eh                    ;print out the char
        int     10h
        popa                              ;pop all general registers
        ret
tab:
        mov     al,' '                    ;save ' ' in al 
        call    putc                      ;print out the tab
        call    putc
        call    putc
        call    putc
        call    putc
        call    putc
        call    putc
        popa
        ret                               ;return!

newline:
        push    ax bx cx dx               ;push registers in the stack
      mov     ah,03                     ;get the cursor position
  mov     bh,00                     ;set page number to zero(normal)
  int     10h                       ;call BIOS
        mov     ah,02                     ;set cursor position
      mov     bh,00                     ;set page number to zero(normal)
  inc     dh                        ;increament the row number
        mov     dl,00                     ;set the column number to zero
    int     10h                       ;call BIOS
        pop     dx cx bx ax               ;pop registers from the stack
     ret  


;----------------------------------------------------;
;variables and messages                              ;
;----------------------------------------------------;
volume_name      db      0x8
val             db      ? 
fdd_err db 'floppy error',0 
count db 0            
buffer:
        times 512 db ' '
                  dd 0    
Post 23 Jul 2008, 03:29
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20416
Location: In your JS exploiting you and your system
revolution 23 Jul 2008, 04:55
This is from the dim dark recesses of my memory, so some information following my be incorrect ...

Each entry in the directory has a "attributes" byte (offset 0x0B). The bits inside the attributes byte give information like hidden/system/archive/read only/directory/volume label. So what you need to do is check if the volume flag (bit 3) is set.

Try this:
Code:
...
  @loop:
        test    byte[di+0x0b],1 shl 3  ;is it a volume label?
        jnz     del
        mov     al,[di+bx]
...    


Last edited by revolution on 23 Jul 2008, 04:58; edited 1 time in total
Post 23 Jul 2008, 04:55
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386 23 Jul 2008, 04:56
abuashraf wrote:
my proplem is that my programe also prints the volume name of the floppy,so can you help me not to print the volume name.


Check the attrib's, b3 = 8 is V - so ban entries having this bit set Idea

EDIT : too late Sad Sad Sad Sad Sad Sad Sad Sad Sad Sad
Post 23 Jul 2008, 04:56
View user's profile Send private message Reply with quote
abuashraf



Joined: 11 Nov 2006
Posts: 88
abuashraf 23 Jul 2008, 05:25
it's working perfectly,thank you revolution,
but would you please give some explain about the formula
Code:
test    byte[di+0x0b],1 shl 3    

because I didn't understand it Embarassed
Post 23 Jul 2008, 05:25
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386 23 Jul 2008, 05:31
> would you please give some explain about the formula
> byte[di+0x0b],1 shl 3

1 shl 3 is 8 see my post above
0x0b or $0B or decimal 11 is the name length (8+3) and just after it the attrib byte is sitting Idea
Post 23 Jul 2008, 05:31
View user's profile Send private message Reply with quote
neville



Joined: 13 Jul 2008
Posts: 507
Location: New Zealand
neville 25 Jul 2008, 04:08
What happened to the rest of our posts here ?
Post 25 Jul 2008, 04:08
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 25 Jul 2008, 04:20
Post 25 Jul 2008, 04:20
View user's profile Send private message Reply with quote
neville



Joined: 13 Jul 2008
Posts: 507
Location: New Zealand
neville 25 Jul 2008, 04:48
oh i see, you split it. How do you find such splits without a link as above?
Post 25 Jul 2008, 04:48
View user's profile Send private message Visit poster's website Reply with quote
abuashraf



Joined: 11 Nov 2006
Posts: 88
abuashraf 25 Jul 2008, 05:01
Now I'm trying to read the contents of the first sector of the root directory,
but without using an array,so I'm just trying to load the contents into
some place in memory,but the problem is when I try to read from that place I get random stuff,and garbage data,here's my new code:

Code:
start: 
        push    cs                       ; Push CS on stack 
        pop     ds                       ; Move CS into DS 
        push    ds                       ; Push DS 
        pop     es                       ; Move DS into ES 

        mov     [count],3                ;try three times 
        mov     bx,0x200             ;here was the old buffer
       .
       .
       .
printbuffer: 
        xor     ax,ax 
        mov     bx,ax 
        mov     dx,ax 
        mov     si,ax 
        mov     di,ax 
        mov     di,0x200
       .
       .
    

so,what should I do to fix this?
Thanx.
Post 25 Jul 2008, 05:01
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4352
Location: Now
edfed 25 Jul 2008, 20:10
look at this maybe it can help you a bit...
Post 25 Jul 2008, 20:10
View user's profile Send private message Visit poster's website Reply with quote
abuashraf



Joined: 11 Nov 2006
Posts: 88
abuashraf 26 Jul 2008, 05:39
I used the combination
Code:
[es:0x200]
    

and it's working now.


Thanx.
Post 26 Jul 2008, 05:39
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 27 Jul 2008, 02:55
There's another such example of similar thing here (see VFAT.ASM).
Post 27 Jul 2008, 02:55
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4352
Location: Now
edfed 27 Jul 2008, 09:52
have anyone tried to make it for fat32 LFN?

as it is free in europe to make so...
Post 27 Jul 2008, 09:52
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.