Parsing directory entries?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
CWood
Member
Member
Posts: 127
Joined: Sun Jun 20, 2010 1:21 pm

Parsing directory entries?

Post by CWood »

Probably me being a noob again, but I am trying to parse directories in ISO 9660. I use this code:

Code: Select all

ParseDirectoryEntry:
	mov	ecx, [es:bx+0x0A]
	mov	eax, [es:bx+0x02]

	push	ax
	xor	eax, eax
	pop	ax
	xor	ah, ah

	cmp	eax, 0
	je	ParseDirectoryEntry

	cmp	cl, 0
	je	.zero

	ret

	.zero:
		mov	cl, 1
		ret
However for some reason, I get a value of 0 in cl, and a value in eax which makes my reading code err, with an error code for the FDD, even though my drive number is still fish (the ASCII, haven't got an ASCII table handy to look it up, somewhere in the range of 240 last time I checked). But either way, the reading code works because I am getting the PVD, but not the root with this code (asside: for some reason, I can't read higher than something like sector 0x87 or 0xB7, I forget which. Is this normal for int 13 42?)
JohnWilson
Posts: 14
Joined: Wed Jun 23, 2010 11:08 pm

Re: Parsing directory entries?

Post by JohnWilson »

Without symbols or comments it's hard to understand what you're trying to do. So I assume your point is that ES:BX point at an ISO 9660 dir entry. Do you really want your code to go into an infinite loop just because the file's starting logical block number is a multiple of 256? And why do you want to add one to the length of a file just because it's a multiple of 256? I doubt you intended either of those (you're mixing bytes and dwords oddly -- and even when MOVZX used to be slow it was still a better deal than a four-instruction sequence, FWIW). What were you intending to have happen? And obviously, you should make sure ES:BX really are pointing at good data.

John Wilson
D Bit
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Parsing directory entries?

Post by Brendan »

Hi,

To make things easier, I've added comments and optimised it a bit:

Code: Select all

;Parse A Directory Entry
;
;This routine checks some stuff in a thingy-whatsit that may or may not be related to some
;sort of (page directory, phone directory?) entry; and may return some sort of values and other
;stuff (but might not return too).

;Input
; es:bx    The address of a thingy-whatsit
;
;Output
; eax      Something that's guaranteed to be non-zero
; ecx      "stuff" in the highest 24-bits, with maybe some sort of flag in the lowest byte?
;_______________________________________________________________________________________________

ParseDirectoryEntry:
   mov ecx,[es:bx+0x0A]              ;ecx = something
   movzx eax,byte [es:bx+0x02]       ;eax = something else
   xor cl,cl                         ;ecx = assumed value to return, with "stuff" in highest 24-bits
   test al,al                        ;Is something else zero?
   je ParseDirectoryEntry            ; yes, keep looping until an IRQ changes the thingy-whatsit

   cmp [es:bx+0x0A],1                ;Is something less than one (or, is something zero)?
   adc cl,0                          ;Set CL=1 if something was zero, else leave CL=0 (and don't upset the "stuff"!)
   ret
Hope that helps someone ... :P


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
JohnWilson
Posts: 14
Joined: Wed Jun 23, 2010 11:08 pm

Re: Parsing directory entries?

Post by JohnWilson »

Still there, death2all?
CWood
Member
Member
Posts: 127
Joined: Sun Jun 20, 2010 1:21 pm

Re: Parsing directory entries?

Post by CWood »

Certainly am, yes. That code, Brendan, was, in fact, more than it was worth. I think the bug lies elsewhere... possibly in this code here:

Code: Select all

;************************************************;
; Reads a series of sectors
; Cx=>Number of blocks to read
; EAX=>Starting sector		- Anything above B6 causes an err???
; ES:BX=>Buffer to read to
; DL=>Drive #
; Carry set on err
;************************************************;

ReadSectors:
	.MAIN:
		mov	[DriveNum], dl
		mov	di, 5

		push	ax
		mov	ah, 45h
		mov	al, 0x00	; Lock drive to prevent tray opening

		int	0x13

		cmp	ah, 0
		pop	ax
		jne	.End

	.SECTORLOOP:
		push	eax
		push	ds
		push	es
		push	bx
		push	cx
		push	di

		push	dword 0	;Block number
		push	dword eax
		push	word es	; Read to es:bx
		push	word bx
		push	word cx
		push	word 10h	; Size: 10h

		mov	ah, 0x42

		push	ss
		pop	ds

		mov	si, sp

		mov	dl, [DriveNum]
		int	0x13

		push	ax
		mov	al, ah
		mov	ah, 0x0E
		int	0x10
		pop	ax

		add	esp, 0x10

	.CONTINUE:
		pop	di
		pop	cx
		pop	bx
		pop	es
		pop	ds

		cmp	ah, 0
		pop	eax
		je	.SUCCESS

	.LOOP:
		dec	di
		jnz	.SECTORLOOP

	.SUCCESS:
		clc

		push	ax
		mov	ax, 0x4501	; Unlock drive

		mov	dl, [DriveNum]
		int	0x13

		cmp	ah, 0
		pop	ax
		jne	.SUCCESS

	.End:
		ret
Please excuse my lack of comments, I don't have much time to devote, and I try to get as much done as possible in what time I have.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Parsing directory entries?

Post by Combuster »

death2all wrote:Please excuse my lack of comments, I don't have much time to devote, and I try to get as much done as possible in what time I have.
From personal experience: short term gain = long term fail here. I know that some well placed comments saved me a lot of time later on. I've also seen a lot of cases where I didn't bother to document and I had again to figure out how some things worked.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Parsing directory entries?

Post by Solar »

+{infinity}
Every good solution is obvious once you've found it.
CWood
Member
Member
Posts: 127
Joined: Sun Jun 20, 2010 1:21 pm

Re: Parsing directory entries?

Post by CWood »

haha oops... trying to read in #bytes rather than #sectors :S
Post Reply