1
0
Fork 0
mirror of https://github.com/dosbox-staging/dosbox-staging synced 2025-12-04 16:27:29 -05:00
3 DOS filesystem tests
Daniel Bomar edited this page 2025-01-12 14:24:56 -06:00

Read after delete test

Real DOS (tested with MS-DOS 6.22 in a VM) allows files to be deleted while file handles are currently open. Reading and writing to the handle after delete is technically undefined behavior in DOS but in practice, it should return the old deleted data if nothing else wrote to the disk in the same location.

In DOSBox Staging, this behavior is defined to always return the old file data. This assembly program tests this behavior.

To test

  1. Copy the code below to a text file. Ex: unread.asm
  2. Download NASM (can be built from host, doesn't have to be the DOS version): https://www.nasm.us/
  3. nasm unread.asm -o unread.com
  4. Copy unread.com to a folder to be mounted with DOSBox
  5. Create a test.txt in that same folder with some text to read back
  6. Run the program. On success, test.txt will be deleted and the text will be output to the DOS console.
org 100h

section .text

; open file
mov ah, 3dh
mov al, 0h
lea dx, [file_name]
int 21h
jc open_error_fn
mov [handle], ax

; delete file
mov ah, 41h
lea dx, [file_name]
int 21h
jc delete_error_fn

; read file
mov ah, 3fh
mov bx, [handle]
mov cx, 32
lea dx, [str]
int 21h
jc read_error_fn

; append newline and M$ termination to file contents
lea dx, [str]
mov bx, dx
add bx, ax
mov word [bx], 13
inc bx
mov word [bx], 10
inc bx
mov word [bx], '$'

; print the string we read from the file
mov ah, 09h
int 21h

end:
mov ah, 0h
int 21h

open_error_fn:
lea dx, [open_error]
jmp print_error

delete_error_fn:
lea dx, [delete_error]
jmp print_error

read_error_fn:
lea dx, [read_error]

print_error:
mov ah, 09h
int 21h
jmp end

section .data

file_name: db 'test.txt', 0
open_error: db 'Failed to open file', 13, 10, '$'
delete_error: db 'Failed to delete file', 13, 10, '$'
read_error: db 'Failed to read file', 13, 10, '$'

section .bss
handle: resb 2
str: resb 64