extlinux: Correct the directory block end condition syslinux-3.63-pre3
authorH. Peter Anvin <hpa@zytor.com>
Mon, 7 Apr 2008 23:39:15 +0000 (16:39 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Mon, 7 Apr 2008 23:41:00 +0000 (16:41 -0700)
ext2/3 directory blocks are *not* ended with inode == 0; that reflects
a deleted block (like 0xe5 in FAT.)  Directory blocks are ended by
directory block exhaustion; the last block is simply made as large as
the whole directory block.

extlinux.asm

index 8b2eff5..c96e110 100644 (file)
@@ -1116,25 +1116,32 @@ searchdir:
                jmp .skipslash
 
 .readdir:
+               mov cx,[SecPerClust]
+               push cx
+               shl cx,SECTOR_SHIFT
                mov bx,trackbuf
+               add cx,bx
+               mov [EndBlock],cx
+               pop cx
                push bx
-               mov cx,[SecPerClust]
                call getfssec
                pop bx
                pushf                   ; Save EOF flag
                push si                 ; Save filesystem pointer
 .getent:
-               cmp dword [bx+d_inode],0
-               je .endblock
+               cmp bx,[EndBlock]
+               jae .endblock
 
                push di
+               cmp dword [bx+d_inode],0        ; Zero inode = void entry
+               je .nope
+
                movzx cx,byte [bx+d_name_len]
                lea si,[bx+d_name]
                repe cmpsb
                je .maybe
 .nope:
                pop di
-
                add bx,[bx+d_rec_len]
                jmp .getent
 
@@ -1232,6 +1239,7 @@ SymlinkBuf        resb    SYMLINK_SECTORS*SECTOR_SIZE+64
 SymlinkTmpBuf   equ    trackbuf
 SymlinkTmpBufEnd equ   trackbuf+SYMLINK_SECTORS*SECTOR_SIZE+64
 ThisDir                resd    1
+EndBlock       resw    1
 SymlinkCtr     resb    1
 
                section .text