[syslinux] [PATCH 1/1] SYSLINUX/COMBOOT: Abstract searchdir and fix the opendir call

Gene Cumm gene.cumm at gmail.com
Sat Mar 21 05:46:58 PDT 2009


From: Gene Cumm <gene.cumm at gmail.com>

SYSLINUX/COMBOOT: Abstract searchdir and fix the opendir call

Signed-off-by: Gene Cumm <gene.cumm at gmail.com>

---

First, change comboot.inc such that INT 22h AX=0020h (opendir) is
about as simple and similar in behavior to INT 22h AX=0006h
(openfile).

Next, rename the function searchdir to searchdir4any, create a new
function called searchdir and move all regular file-specific code to
searchdir.  This allows for future expansion into a more generic
directory searching capability.

Last, create a function searchdir4dir designed to find a directory.
This function is designed to act just like searchdir except it returns
a handle to a directory.

This also removes the COMBOOT API requirement on INT 22h AX=0020h to
have a trailing '/' in the filename, cleaning up the API as it
probably should have been in the first place.  (Thank you HPA for
making me think about how wrong that was).

HPA: If you need me to separate this patch into multiple patches,
please let me know.



diff --git a/core/comboot.inc b/core/comboot.inc
index 2ff5f33..0d4f931 100644
--- a/core/comboot.inc
+++ b/core/comboot.inc
@@ -1067,12 +1067,8 @@ comapi_opendir:
 		mov di,InitRD
 		call mangle_name
 		pop ds
-		call searchdir
-		jnz comapi_err	; Didn't find a directory
-		cmp eax,0
-		jz comapi_err	; Found nothing
-			;ZF is unset
-		call alloc_fill_dir
+		call searchdir4dir
+		jz comapi_err
 		mov P_EAX,eax
 		mov P_CX,SECTOR_SIZE
 		mov P_SI,si
diff --git a/core/ldlinux.asm b/core/ldlinux.asm
index 2219d5f..0bd7d0d 100644
--- a/core/ldlinux.asm
+++ b/core/ldlinux.asm
@@ -984,10 +984,10 @@ allocate_file:
 ;	Assumes DS == ES == CS.
 ;
 ;	     If successful:
-;		ZF clear
+;		ZF set
 ;		SI	= file pointer
 ;	     If unsuccessful
-;		ZF set
+;		ZF clear
 ;		EAX clobbered
 ;
 alloc_fill_dir:
@@ -999,12 +999,14 @@ alloc_fill_dir:
 		mov [si+file_sector],eax	; Current sector
 		mov dword [si+file_bytesleft],0	; Current offset
 		mov [si+file_left],eax		; Beginning sector
+		xor bx,bx			; ZF <- 1
 		pop bx
 		ret

 .alloc_failure:
+		xor eax,eax		; ZF <- 1
+		and bx,bx		; ZF = 0; BX from allocate_file not 0
 		pop bx
-		xor eax,eax			; ZF <- 1
 		ret

 ;
@@ -1289,7 +1291,7 @@ close_dir:
 .closed:	ret

 ;
-; searchdir:
+; searchdir4any:
 ;
 ;	Open a file
 ;
@@ -1299,13 +1301,15 @@ close_dir:
 ;		ZF clear
 ;		SI		= file pointer
 ;		EAX		= file length in bytes
+;		DL		= FAT attributes
 ;	     If unsuccessful
 ;		ZF set
 ;
 ; Assumes CS == DS == ES, and trashes BX and CX.
 ;
-searchdir:
+searchdir4any:
 		mov eax,[CurrentDir]
+		mov dl,0
 		cmp byte [di],'/'	; Root directory?
 		jne .notroot
 		mov eax,[RootDir]
@@ -1332,7 +1336,7 @@ searchdir:
 		dec dx
 		cmp dx,si
 		jz .founddir
-
+.searchname:
 		mov [PrevDir],eax	; Remember last directory searched

 		push di
@@ -1344,7 +1348,58 @@ searchdir:
 		cmp byte [di-1],'/'	; Do we expect a directory
 		je .isdir

-		; Otherwise, it should be a file
+		; Otherwise, desired file is found
+		ret			; Done!
+
+		; If we expected a directory, it better be one...
+.isdir:
+		test dl,10h		; Subdirectory
+		jz .badfile
+
+		xor eax,eax
+		xchg eax,[si+file_sector] ; Get sector number and free file structure
+		jmp .pathwalk		; Walk the next bit of the path
+
+		; Found the desired directory; ZF set but EAX not 0
+.founddir:
+		and eax,eax		; Sector 0 is bad number
+		jz .notfound
+		call alloc_fill_dir	; re-allocate it
+		jnz .alloc_dir_failure
+		and eax,eax
+		ret
+
+.alloc_dir_failure:
+		xor eax,eax
+		ret
+
+.badfile:
+		xor eax,eax
+		mov [si],eax		; Free file structure
+
+.notfound:
+		xor eax,eax		; Zero out EAX
+		ret
+
+;
+; searchdir:
+;
+;	Open a file
+;
+;	     On entry:
+;		DS:DI	= filename
+;	     If successful:
+;		ZF clear
+;		SI		= file pointer
+;		EAX		= file length in bytes
+;	     If unsuccessful
+;		ZF set
+;
+; Assumes CS == DS == ES, and trashes BX and CX.
+;
+searchdir:
+		call searchdir4any
+		jz .notfound
 .isfile:
 		test dl,18h		; Subdirectory|Volume Label
 		jnz .badfile		; If not a file, it's a bad thing
@@ -1359,20 +1414,37 @@ searchdir:
 		and eax,eax		; EAX != 0
 		jz .badfile
 		ret			; Done!
+.badfile:
+		xor eax,eax
+		mov [si],eax		; Free file structure

-		; If we expected a directory, it better be one...
+.notfound:
+		xor eax,eax		; Zero out EAX
+		ret
+
+;
+; searchdir4dir:
+;
+;	Open a directory
+;
+;	     On entry:
+;		DS:DI	= filename
+;	     If successful:
+;		ZF clear
+;		SI		= file pointer
+;		EAX		= file length in bytes = 0
+;	     If unsuccessful
+;		ZF set
+;
+; Assumes CS == DS == ES, and trashes BX and CX.
+;
+searchdir4dir:
+		call searchdir4any
+		jz .notfound
 .isdir:
 		test dl,10h		; Subdirectory
 		jz .badfile
-
-		xor eax,eax
-		xchg eax,[si+file_sector] ; Get sector number and free file structure
-		jmp .pathwalk		; Walk the next bit of the path
-
-		; Found the desired directory; ZF set but EAX not 0
-.founddir:
 		ret
-
 .badfile:
 		xor eax,eax
 		mov [si],eax		; Free file structure




More information about the Syslinux mailing list