Trying to learn assembly and I'm trying to play with files at the moment. I want to be able to see what's in a directory so I've used the getdents call to read the information. The problem I'm struggling with now is how to make use of what I've got. The entries don't seem to be fixed length and also only the file name is terminated by a 0. Also in the code below I'm reading to a 600 byte buffer but I know the directory I'm reading require more like 900. I had thought of putting it all on the stack instead of the reserved bytes but as I'm new to assembly I not sure if that would make any difference. I had imagined the eax would be set to -ve to show there was more to read but it's not! Does anybody have more experience with this system call??
section .text
global _start
_start:
;open the directory
;------------------
mov eax,5 ;system call for open
mov ebx,dir ;the file we want to open
mov ecx,0 ;read only
int 80h
;check file valid
;----------------
test eax,eax
jns read_dir
jmp exit_prog
read_dir:
mov dword[fd],eax ;move the file descripter for dir to the variable
mov eax,141 ;getdents sys_call
mov ebx,dword[fd] ;the file descripter for dir
mov ecx,dirent ;pointer to dirent struct
mov edx,600 ;buffer
int 80h
print_info:
;print what we read
;------------------
mov eax,4 ;write
mov ebx,1 ;stdio
mov ecx,dirent ;output
mov edx,600 ;length
int 80h
exit_prog:
;exit
;----
mov eax,1 ;sys call exit
int 80h
section .data
dir db '../../Downloads',0
mesg db 'reading dir',10
mesgLen equ $-mesg
errormsg db 'error',10
errorLen equ $-errormsg
section .bss
fd resd 1
dirent resb 600