From: Gene Cumm <gene.cumm at gmail.com>
COMBOOT API: Improve readdir. Now returns C struct stat st_mode
compatible data in DX rather than the raw data from a FAT filesystem
or C struct dirent d_mode compatible data.
Signed-off-by: Gene Cumm <gene.cumm at gmail.com>
---
If I return something that's compatible with the C struct stat st_mode
member, this can be used for more that just determining the type of
file. It might be forseeable that something else in st_mode may prove
useful. My reasoning is that I can change the COMBOOT API now before
it's in a release but changing after release (and looking like 3.74,
right now) should probably be avoided at all costs (preferably, it's
cast in stone). I may, down the road, look at how to return a date in
another register but I also see that as acceptable as it doesn't
change existing behavior, thereby breaking existing code.
diff --git a/core/comboot.inc b/core/comboot.inc
index 2ff5f33..bab3d6a 100644
--- a/core/comboot.inc
+++ b/core/comboot.inc
@@ -1092,7 +1092,7 @@ comapi_readdir:
mov si,P_SI
call readdir
mov P_EAX,eax
- mov P_DL,dl
+ mov P_DX,dx
mov P_EBX,ebx
mov P_SI,si
ret
diff --git a/core/ldlinux.asm b/core/ldlinux.asm
index a24f396..bb5bf14 100644
--- a/core/ldlinux.asm
+++ b/core/ldlinux.asm
@@ -1377,6 +1377,40 @@ searchdir:
ret
;
+; fatattr_to_st_mode: Translate a FAT attribute to struct stat st_mode.
+;
+; DL FAT Attribute
+;
+; Returns st_mode
+; DX st_mode
+;
+
+fatattr_to_st_mode:
+ push eax
+ test dl,0xC8 ; 0x80 Unknown 0x40 Device(Internal)
+ ; 0x08 Label
+ jnz .zero
+ mov ax,0444o
+ test dl,1 ; 1 ReadOnly
+ jnz .is_ro
+ add ax,0222o
+.is_ro:
+ test dl,0x10 ; 0x10 Directory
+ jz .not_dir
+ add ax,040111o ; Dir and Execute
+ jmp .done
+.not_dir:
+ add ax,0100000o ; Regular file
+.done:
+ mov dx,ax
+ jmp .end
+.zero: ; Any condition that will result in an all zero return
+ mov dx,0
+.end:
+ pop eax
+ ret
+
+;
; readdir: Read one file from a directory
;
; ES:DI -> String buffer (filename)
@@ -1550,6 +1584,7 @@ readdir:
.get_info:
mov ebx,[gs:si+28] ; length
mov dl,[gs:si+11] ; type
+ call fatattr_to_st_mode
.next_entry:
add si,DIRENT_SIZE
dec cx
diff --git a/doc/comboot.txt b/doc/comboot.txt
index 5f57da7..135a5bc 100644
--- a/doc/comboot.txt
+++ b/doc/comboot.txt
@@ -947,16 +947,17 @@ AX=0021h [3.74] Read directory
Input: AX 0020h
SI directory handle
ES:DI buffer for file name
- Output: DL Type of file
+ Output: DX Mode of file
SI directory handle, or 0 if end of directory was reached
EAX Size of file
EBX Inode of file
Read one filename from the directory, incrementing the
directory structure at SI as appropriate, storing the filename
- into the buffer at ES:DI, and returning the type of the file
- in DL, the file length in EAX, the inode/file number in EBX
- and the updated directory handle.
+ into the buffer at ES:DI, and returning the mode of the file
+ in DX, the file length in EAX, the inode/file number in EBX
+ and the updated directory handle. The mode in DX is compatible
+ with the struct stat st_mode member.
AX=0022h [3.74] Close directory