Skip to content

int13h Read and write don't check for errors #6

@joshudson

Description

@joshudson

I was looking into adding LBA bios extensions (I have plans...) and I found this issue.

extended_read_disk always writes its return value to AL (not AX), but the invocation does:

	mov	ah, 0
	cpu	186
	shl	ax, 9
	extended_read_disk
	shr	ax, 9
	cpu	8086
	mov	ah, 0x02	; Put read code back

	cmp	al, 0
	je	rd_error

throwing AL away after extended_read_disk. Here I found disk read errors are thrown away. I was scratching my head on how this worked because extended_read_disk clearly sets AL to 0 on a successful read, but I finally figured out that AL is thrown away by the SHR instruction; thus the error code is never checked.

It's almost like the code wants the caller to do a ~read like the ~lseek, but even so that does nothing until this code is fixed. The following assembly change should fix the errors not being checked but will immediately break until the C code is fixed:

	sub  al, 1
	adc  ah, 0        ; Preserve CF through the following SHR
	shr	ax, 9
	cpu	8086
	mov	ah, 0x02	; Put read code back
	
	jc	rd_error

Checking lseek is useless anyway: lseek will happily seek out of bounds. Only checking read or write matters. Thus, the error code returned is always wrong. So rd_error and wr_error need work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions