2007-03-26 14:18:08 +02:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2007-05-30 15:48:21 +02:00
|
|
|
|
;; ;;
|
2007-03-26 14:18:08 +02:00
|
|
|
|
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
|
|
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
|
;; ;;
|
2007-05-30 15:48:21 +02:00
|
|
|
|
;; RAMDISK functions ;;
|
|
|
|
|
;; (C) 2004 Ville Turjanmaa, License: GPL ;;
|
|
|
|
|
;; Addings by M.Lisovin ;;
|
|
|
|
|
;; LFN support by diamond ;;
|
2007-03-26 14:18:08 +02:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
2007-07-27 15:52:03 +02:00
|
|
|
|
$Revision$
|
|
|
|
|
|
|
|
|
|
|
2005-10-13 07:34:10 +02:00
|
|
|
|
; calculate fat chain
|
|
|
|
|
|
|
|
|
|
calculatefatchain:
|
|
|
|
|
|
|
|
|
|
pushad
|
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov esi,RAMDISK+512
|
|
|
|
|
mov edi,RAMDISK_FAT
|
2005-10-13 07:34:10 +02:00
|
|
|
|
|
|
|
|
|
fcnew:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov eax,dword [esi]
|
|
|
|
|
mov ebx,dword [esi+4]
|
|
|
|
|
mov ecx,dword [esi+8]
|
|
|
|
|
mov edx,ecx
|
|
|
|
|
shr edx,4 ;8 ok
|
|
|
|
|
shr dx,4 ;7 ok
|
|
|
|
|
xor ch,ch
|
2005-10-13 07:34:10 +02:00
|
|
|
|
shld ecx,ebx,20 ;6 ok
|
2008-03-01 17:20:40 +01:00
|
|
|
|
shr cx,4 ;5 ok
|
2005-10-13 07:34:10 +02:00
|
|
|
|
shld ebx,eax,12
|
2008-03-01 17:20:40 +01:00
|
|
|
|
and ebx,0x0fffffff ;4 ok
|
|
|
|
|
shr bx,4 ;3 ok
|
|
|
|
|
shl eax,4
|
|
|
|
|
and eax,0x0fffffff ;2 ok
|
|
|
|
|
shr ax,4 ;1 ok
|
|
|
|
|
mov dword [edi],eax
|
|
|
|
|
mov dword [edi+4],ebx
|
|
|
|
|
mov dword [edi+8],ecx
|
|
|
|
|
mov dword [edi+12],edx
|
|
|
|
|
add edi,16
|
|
|
|
|
add esi,12
|
|
|
|
|
|
|
|
|
|
cmp edi,RAMDISK_FAT+2856*2 ;2849 clusters
|
|
|
|
|
jnz fcnew
|
2005-10-13 07:34:10 +02:00
|
|
|
|
|
|
|
|
|
popad
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
restorefatchain: ; restore fat chain
|
|
|
|
|
|
|
|
|
|
pushad
|
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov esi,RAMDISK_FAT
|
|
|
|
|
mov edi,RAMDISK+512
|
2005-10-13 07:34:10 +02:00
|
|
|
|
|
|
|
|
|
fcnew2:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov eax,dword [esi]
|
|
|
|
|
mov ebx,dword [esi+4]
|
|
|
|
|
shl ax,4
|
|
|
|
|
shl eax,4
|
|
|
|
|
shl bx,4
|
|
|
|
|
shr ebx,4
|
2005-10-13 07:34:10 +02:00
|
|
|
|
shrd eax,ebx,8
|
2008-03-01 17:20:40 +01:00
|
|
|
|
shr ebx,8
|
|
|
|
|
mov dword [edi],eax
|
|
|
|
|
mov word [edi+4],bx
|
|
|
|
|
add edi,6
|
|
|
|
|
add esi,8
|
|
|
|
|
|
|
|
|
|
cmp edi,RAMDISK+512+4278 ;4274 bytes - all used FAT
|
|
|
|
|
jb fcnew2
|
|
|
|
|
|
|
|
|
|
mov esi,RAMDISK+512 ; duplicate fat chain
|
|
|
|
|
mov edi,RAMDISK+512+0x1200
|
|
|
|
|
mov ecx,1069 ;4274/4
|
2005-10-13 07:34:10 +02:00
|
|
|
|
cld
|
2008-03-01 17:20:40 +01:00
|
|
|
|
rep movsd
|
2005-10-13 07:34:10 +02:00
|
|
|
|
|
|
|
|
|
popad
|
|
|
|
|
ret
|
|
|
|
|
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
|
|
|
|
ramdisk_free_space:
|
|
|
|
|
;---------------------------------------------
|
|
|
|
|
;
|
|
|
|
|
; returns free space in edi
|
|
|
|
|
; rewr.by Mihasik
|
|
|
|
|
;---------------------------------------------
|
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push eax ebx ecx
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov edi,RAMDISK_FAT ;start of FAT
|
|
|
|
|
xor ax,ax ;Free cluster=0x0000 in FAT
|
|
|
|
|
xor ebx,ebx ;counter
|
|
|
|
|
mov ecx,2849 ;2849 clusters
|
|
|
|
|
cld
|
2005-10-06 19:56:22 +02:00
|
|
|
|
rdfs1:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
repne scasw
|
|
|
|
|
jnz rdfs2 ;if last cluster not 0
|
|
|
|
|
inc ebx
|
|
|
|
|
test ecx, ecx
|
|
|
|
|
jnz rdfs1
|
2005-10-06 19:56:22 +02:00
|
|
|
|
rdfs2:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
shl ebx,9 ;free clusters*512
|
|
|
|
|
mov edi,ebx
|
2006-12-24 08:50:24 +01:00
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop ecx ebx eax
|
|
|
|
|
ret
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expand_filename:
|
|
|
|
|
;---------------------------------------------
|
|
|
|
|
;
|
|
|
|
|
; exapand filename with '.' to 11 character
|
|
|
|
|
; eax - pointer to filename
|
|
|
|
|
;---------------------------------------------
|
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push esi edi ebx
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov edi,esp ; check for '.' in the name
|
|
|
|
|
add edi,12+8
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov esi,eax
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov eax,edi
|
|
|
|
|
mov [eax+0],dword ' '
|
|
|
|
|
mov [eax+4],dword ' '
|
|
|
|
|
mov [eax+8],dword ' '
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
|
|
|
|
flr1:
|
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp [esi],byte '.'
|
|
|
|
|
jne flr2
|
|
|
|
|
mov edi,eax
|
|
|
|
|
add edi,7
|
|
|
|
|
jmp flr3
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
|
|
|
|
flr2:
|
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov bl,[esi]
|
|
|
|
|
mov [edi],bl
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
|
|
|
|
flr3:
|
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
inc esi
|
|
|
|
|
inc edi
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov ebx,eax
|
|
|
|
|
add ebx,11
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp edi,ebx
|
|
|
|
|
jbe flr1
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop ebx edi esi
|
|
|
|
|
ret
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
|
|
|
|
fileread:
|
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
|
;
|
|
|
|
|
; fileread - sys floppy
|
|
|
|
|
;
|
|
|
|
|
; eax points to filename 11 chars
|
|
|
|
|
; ebx first wanted block ; 1+ ; if 0 then set to 1
|
|
|
|
|
; ecx number of blocks to read ; 1+ ; if 0 then set to 1
|
|
|
|
|
; edx mem location to return data
|
|
|
|
|
; esi length of filename 12*X 0=root
|
|
|
|
|
;
|
|
|
|
|
; ret ebx = size or 0xffffffff file not found
|
|
|
|
|
; eax = 0 ok read or other = errormsg
|
|
|
|
|
;
|
|
|
|
|
;--------------------------------------------------------------
|
2008-03-01 17:20:40 +01:00
|
|
|
|
test ebx,ebx ;if ebx=0 - set to 1
|
|
|
|
|
jnz frfl5
|
|
|
|
|
inc ebx
|
2005-10-06 19:56:22 +02:00
|
|
|
|
frfl5:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
test ecx,ecx ;if ecx=0 - set to 1
|
|
|
|
|
jnz frfl6
|
|
|
|
|
inc ecx
|
2005-10-06 19:56:22 +02:00
|
|
|
|
frfl6:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
test esi,esi ; return ramdisk root
|
|
|
|
|
jnz fr_noroot ;if not root
|
|
|
|
|
cmp ebx,14 ;14 clusters=root dir
|
|
|
|
|
ja oorr
|
|
|
|
|
cmp ecx,14
|
|
|
|
|
ja oorr
|
|
|
|
|
jmp fr_do
|
2005-10-06 19:56:22 +02:00
|
|
|
|
oorr:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov eax,5 ;out of root range (fnf)
|
|
|
|
|
xor ebx,ebx
|
|
|
|
|
dec ebx ;0xffffffff
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
fr_do: ;reading rootdir
|
|
|
|
|
mov edi,edx
|
|
|
|
|
dec ebx
|
|
|
|
|
push edx
|
|
|
|
|
mov edx,ecx
|
|
|
|
|
add edx,ebx
|
|
|
|
|
cmp edx,15 ;ebx+ecx=14+1
|
|
|
|
|
pushf
|
|
|
|
|
jbe fr_do1
|
|
|
|
|
sub edx,14
|
|
|
|
|
sub ecx,edx
|
2005-10-06 19:56:22 +02:00
|
|
|
|
fr_do1:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
shl ebx,9
|
|
|
|
|
mov esi,RAMDISK+512*19
|
|
|
|
|
add esi,ebx
|
|
|
|
|
shl ecx,7
|
|
|
|
|
cld
|
|
|
|
|
rep movsd
|
|
|
|
|
popf
|
|
|
|
|
pop edx
|
|
|
|
|
jae fr_do2
|
|
|
|
|
xor eax,eax ; ok read
|
|
|
|
|
xor ebx,ebx
|
|
|
|
|
ret
|
|
|
|
|
fr_do2: ;if last cluster
|
|
|
|
|
mov eax,6 ;end of file
|
|
|
|
|
xor ebx,ebx
|
|
|
|
|
ret
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
|
|
|
|
fr_noroot:
|
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
sub esp,32
|
|
|
|
|
call expand_filename
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
dec ebx
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push eax
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push eax ebx ecx edx esi edi
|
|
|
|
|
call rd_findfile
|
|
|
|
|
je fifound
|
|
|
|
|
add esp,32+28 ;if file not found
|
|
|
|
|
ret
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
|
|
|
|
fifound:
|
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov ebx,[edi-11+28] ;file size
|
|
|
|
|
mov [esp+20],ebx
|
|
|
|
|
mov [esp+24],ebx
|
|
|
|
|
add edi,0xf
|
|
|
|
|
movzx eax,word [edi]
|
|
|
|
|
mov edi,eax ;edi=cluster
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
|
|
|
|
frnew:
|
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
add eax,31 ;bootsector+2*fat+filenames
|
|
|
|
|
shl eax,9 ;*512
|
|
|
|
|
add eax,RAMDISK ;image base
|
|
|
|
|
mov ebx,[esp+8]
|
|
|
|
|
mov ecx,512 ;[esp+4]
|
|
|
|
|
|
|
|
|
|
cmp [esp+16],dword 0 ; wanted cluster ?
|
|
|
|
|
jne frfl7
|
|
|
|
|
call memmove
|
|
|
|
|
add [esp+8],dword 512
|
|
|
|
|
dec dword [esp+12] ; last wanted cluster ?
|
|
|
|
|
je frnoread
|
|
|
|
|
jmp frfl8
|
2005-10-06 19:56:22 +02:00
|
|
|
|
frfl7:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
dec dword [esp+16]
|
2005-10-06 19:56:22 +02:00
|
|
|
|
frfl8:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
movzx eax,word [edi*2+RAMDISK_FAT] ; find next cluster from FAT
|
|
|
|
|
mov edi,eax
|
|
|
|
|
cmp edi,4095 ;eof - cluster
|
|
|
|
|
jz frnoread2
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp [esp+24],dword 512 ;eof - size
|
|
|
|
|
jb frnoread
|
|
|
|
|
sub [esp+24],dword 512
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
jmp frnew
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
|
|
|
|
frnoread2:
|
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp [esp+16],dword 0 ; eof without read ?
|
|
|
|
|
je frnoread
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop edi esi edx ecx
|
|
|
|
|
add esp,4
|
|
|
|
|
pop ebx ; ebx <- eax : size of file
|
|
|
|
|
add esp,36
|
|
|
|
|
mov eax,6 ; end of file
|
|
|
|
|
ret
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
|
|
|
|
frnoread:
|
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop edi esi edx ecx
|
|
|
|
|
add esp,4
|
|
|
|
|
pop ebx ; ebx <- eax : size of file
|
|
|
|
|
add esp,36
|
|
|
|
|
xor eax,eax ;read ok
|
|
|
|
|
ret
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rd_findfile:
|
|
|
|
|
;by Mihasik
|
|
|
|
|
;IN: eax - pointer to filename OUT: filestring+11 in edi or notZero in flags and fnf in eax,ebx
|
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov edi,RAMDISK+512*18+512 ;Point at directory
|
|
|
|
|
cld
|
2005-10-06 19:56:22 +02:00
|
|
|
|
rd_newsearch:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov esi,eax
|
|
|
|
|
mov ecx,11
|
|
|
|
|
rep cmpsb
|
|
|
|
|
je rd_ff
|
|
|
|
|
add cl,21
|
|
|
|
|
add edi,ecx
|
|
|
|
|
cmp edi,RAMDISK+512*33
|
|
|
|
|
jb rd_newsearch
|
|
|
|
|
mov eax,5 ;if file not found - eax=5
|
|
|
|
|
xor ebx,ebx
|
|
|
|
|
dec ebx ;ebx=0xffffffff and zf=0
|
2005-10-06 19:56:22 +02:00
|
|
|
|
rd_ff:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
ret
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
2006-04-24 16:28:05 +02:00
|
|
|
|
; \begin{diamond}
|
|
|
|
|
|
|
|
|
|
uni2ansi_str:
|
|
|
|
|
; convert UNICODE zero-terminated string to ASCII-string (codepage 866)
|
|
|
|
|
; in: esi->source, edi->buffer (may be esi=edi)
|
|
|
|
|
; destroys: eax,esi,edi
|
2008-03-01 17:20:40 +01:00
|
|
|
|
lodsw
|
|
|
|
|
test ax, ax
|
|
|
|
|
jz .done
|
|
|
|
|
cmp ax, 0x80
|
|
|
|
|
jb .ascii
|
|
|
|
|
cmp ax, 0x401
|
|
|
|
|
jz .yo1
|
|
|
|
|
cmp ax, 0x451
|
|
|
|
|
jz .yo2
|
|
|
|
|
cmp ax, 0x410
|
|
|
|
|
jb .unk
|
|
|
|
|
cmp ax, 0x440
|
|
|
|
|
jb .rus1
|
|
|
|
|
cmp ax, 0x450
|
|
|
|
|
jb .rus2
|
2006-04-24 16:28:05 +02:00
|
|
|
|
.unk:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov al, '_'
|
|
|
|
|
jmp .doit
|
2006-04-24 16:28:05 +02:00
|
|
|
|
.yo1:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov al, '<27>'
|
|
|
|
|
jmp .doit
|
2006-04-24 16:28:05 +02:00
|
|
|
|
.yo2:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov al, '<27>'
|
|
|
|
|
jmp .doit
|
2006-04-24 16:28:05 +02:00
|
|
|
|
.rus1:
|
|
|
|
|
; 0x410-0x43F -> 0x80-0xAF
|
2008-03-01 17:20:40 +01:00
|
|
|
|
add al, 0x70
|
|
|
|
|
jmp .doit
|
2006-04-24 16:28:05 +02:00
|
|
|
|
.rus2:
|
2006-05-05 14:40:02 +02:00
|
|
|
|
; 0x440-0x44F -> 0xE0-0xEF
|
2008-03-01 17:20:40 +01:00
|
|
|
|
add al, 0xA0
|
2006-04-24 16:28:05 +02:00
|
|
|
|
.ascii:
|
|
|
|
|
.doit:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
stosb
|
|
|
|
|
jmp uni2ansi_str
|
2006-04-24 16:28:05 +02:00
|
|
|
|
.done:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov byte [edi], 0
|
|
|
|
|
ret
|
2006-04-24 16:28:05 +02:00
|
|
|
|
|
2006-05-05 14:40:02 +02:00
|
|
|
|
ansi2uni_char:
|
|
|
|
|
; convert ANSI character in al to UNICODE character in ax, using cp866 encoding
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov ah, 0
|
2006-05-05 14:40:02 +02:00
|
|
|
|
; 0x00-0x7F - trivial map
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp al, 0x80
|
|
|
|
|
jb .ret
|
2006-05-05 14:40:02 +02:00
|
|
|
|
; 0x80-0xAF -> 0x410-0x43F
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp al, 0xB0
|
|
|
|
|
jae @f
|
|
|
|
|
add ax, 0x410-0x80
|
2006-05-05 14:40:02 +02:00
|
|
|
|
.ret:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
ret
|
2006-05-05 14:40:02 +02:00
|
|
|
|
@@:
|
|
|
|
|
; 0xE0-0xEF -> 0x440-0x44F
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp al, 0xE0
|
|
|
|
|
jb .unk
|
|
|
|
|
cmp al, 0xF0
|
|
|
|
|
jae @f
|
|
|
|
|
add ax, 0x440-0xE0
|
|
|
|
|
ret
|
2006-05-05 14:40:02 +02:00
|
|
|
|
; 0xF0 -> 0x401
|
|
|
|
|
; 0xF1 -> 0x451
|
|
|
|
|
@@:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp al, '<27>'
|
|
|
|
|
jz .yo1
|
|
|
|
|
cmp al, '<27>'
|
|
|
|
|
jz .yo2
|
2006-05-05 14:40:02 +02:00
|
|
|
|
.unk:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov al, '_' ; ah=0
|
|
|
|
|
ret
|
2006-05-05 14:40:02 +02:00
|
|
|
|
.yo1:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov ax, 0x401
|
|
|
|
|
ret
|
2006-05-05 14:40:02 +02:00
|
|
|
|
.yo2:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov ax, 0x451
|
|
|
|
|
ret
|
2006-05-05 14:40:02 +02:00
|
|
|
|
|
2006-04-24 16:28:05 +02:00
|
|
|
|
char_toupper:
|
|
|
|
|
; convert character to uppercase, using cp866 encoding
|
|
|
|
|
; in: al=symbol
|
|
|
|
|
; out: al=converted symbol
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp al, 'a'
|
|
|
|
|
jb .ret
|
|
|
|
|
cmp al, 'z'
|
|
|
|
|
jbe .az
|
|
|
|
|
cmp al, '<27>'
|
|
|
|
|
jb .ret
|
|
|
|
|
cmp al, '<27>'
|
|
|
|
|
jb .rus1
|
|
|
|
|
cmp al, '<27>'
|
|
|
|
|
ja .ret
|
2006-04-24 16:28:05 +02:00
|
|
|
|
; 0xE0-0xEF -> 0x90-0x9F
|
2008-03-01 17:20:40 +01:00
|
|
|
|
sub al, '<27>'-'<27>'
|
2006-04-24 16:28:05 +02:00
|
|
|
|
.ret:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
ret
|
2006-04-24 16:28:05 +02:00
|
|
|
|
.rus1:
|
|
|
|
|
; 0xA0-0xAF -> 0x80-0x8F
|
|
|
|
|
.az:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
and al, not 0x20
|
|
|
|
|
ret
|
2006-04-24 16:28:05 +02:00
|
|
|
|
|
|
|
|
|
fat_get_name:
|
|
|
|
|
; in: edi->FAT entry
|
|
|
|
|
; out: CF=1 - no valid entry
|
|
|
|
|
; else CF=0 and ebp->ASCIIZ-name
|
|
|
|
|
; (maximum length of filename is 255 (wide) symbols without trailing 0,
|
|
|
|
|
; but implementation requires buffer 261 words)
|
|
|
|
|
; destroys eax
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp byte [edi], 0
|
|
|
|
|
jz .no
|
|
|
|
|
cmp byte [edi], 0xE5
|
|
|
|
|
jnz @f
|
2006-04-24 16:28:05 +02:00
|
|
|
|
.no:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
stc
|
|
|
|
|
ret
|
|
|
|
|
@@:
|
|
|
|
|
cmp byte [edi+11], 0xF
|
|
|
|
|
jz .longname
|
|
|
|
|
test byte [edi+11], 8
|
|
|
|
|
jnz .no
|
|
|
|
|
push ecx
|
|
|
|
|
push edi ebp
|
|
|
|
|
test byte [ebp-4], 1
|
|
|
|
|
jnz .unicode_short
|
|
|
|
|
|
|
|
|
|
mov eax, [edi]
|
|
|
|
|
mov ecx, [edi+4]
|
|
|
|
|
mov [ebp], eax
|
|
|
|
|
mov [ebp+4], ecx
|
|
|
|
|
|
|
|
|
|
mov ecx, 8
|
|
|
|
|
@@:
|
|
|
|
|
cmp byte [ebp+ecx-1], ' '
|
|
|
|
|
loope @b
|
|
|
|
|
|
|
|
|
|
mov eax, [edi+8]
|
|
|
|
|
cmp al, ' '
|
|
|
|
|
je .done
|
|
|
|
|
shl eax, 8
|
|
|
|
|
mov al, '.'
|
|
|
|
|
|
|
|
|
|
lea ebp, [ebp+ecx+1]
|
|
|
|
|
mov [ebp], eax
|
|
|
|
|
mov ecx, 3
|
|
|
|
|
@@:
|
|
|
|
|
rol eax, 8
|
|
|
|
|
cmp al, ' '
|
|
|
|
|
jne .done
|
|
|
|
|
loop @b
|
|
|
|
|
dec ebp
|
2006-12-24 08:50:24 +01:00
|
|
|
|
.done:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
and byte [ebp+ecx+1], 0 ; CF=0
|
|
|
|
|
pop ebp edi ecx
|
|
|
|
|
ret
|
2006-05-05 14:40:02 +02:00
|
|
|
|
.unicode_short:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov ecx, 8
|
|
|
|
|
push ecx
|
|
|
|
|
@@:
|
|
|
|
|
mov al, [edi]
|
|
|
|
|
inc edi
|
|
|
|
|
call ansi2uni_char
|
|
|
|
|
mov [ebp], ax
|
|
|
|
|
inc ebp
|
|
|
|
|
inc ebp
|
|
|
|
|
loop @b
|
|
|
|
|
pop ecx
|
|
|
|
|
@@:
|
|
|
|
|
cmp word [ebp-2], ' '
|
|
|
|
|
jnz @f
|
|
|
|
|
dec ebp
|
|
|
|
|
dec ebp
|
|
|
|
|
loop @b
|
|
|
|
|
@@:
|
|
|
|
|
mov word [ebp], '.'
|
|
|
|
|
inc ebp
|
|
|
|
|
inc ebp
|
|
|
|
|
mov ecx, 3
|
|
|
|
|
push ecx
|
|
|
|
|
@@:
|
|
|
|
|
mov al, [edi]
|
|
|
|
|
inc edi
|
|
|
|
|
call ansi2uni_char
|
|
|
|
|
mov [ebp], ax
|
|
|
|
|
inc ebp
|
|
|
|
|
inc ebp
|
|
|
|
|
loop @b
|
|
|
|
|
pop ecx
|
|
|
|
|
@@:
|
|
|
|
|
cmp word [ebp-2], ' '
|
|
|
|
|
jnz @f
|
|
|
|
|
dec ebp
|
|
|
|
|
dec ebp
|
|
|
|
|
loop @b
|
|
|
|
|
dec ebp
|
|
|
|
|
dec ebp
|
|
|
|
|
@@:
|
|
|
|
|
and word [ebp], 0 ; CF=0
|
|
|
|
|
pop ebp edi ecx
|
|
|
|
|
ret
|
2006-04-24 16:28:05 +02:00
|
|
|
|
.longname:
|
|
|
|
|
; LFN
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov al, byte [edi]
|
|
|
|
|
and eax, 0x3F
|
|
|
|
|
dec eax
|
|
|
|
|
cmp al, 20
|
|
|
|
|
jae .no ; ignore invalid entries
|
|
|
|
|
mov word [ebp+260*2], 0 ; force null-terminating for orphans
|
|
|
|
|
imul eax, 13*2
|
|
|
|
|
add ebp, eax
|
|
|
|
|
test byte [edi], 0x40
|
|
|
|
|
jz @f
|
|
|
|
|
mov word [ebp+13*2], 0
|
|
|
|
|
@@:
|
|
|
|
|
push eax
|
2006-04-24 16:28:05 +02:00
|
|
|
|
; now copy name from edi to ebp ...
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov eax, [edi+1]
|
|
|
|
|
mov [ebp], eax ; symbols 1,2
|
|
|
|
|
mov eax, [edi+5]
|
|
|
|
|
mov [ebp+4], eax ; 3,4
|
|
|
|
|
mov eax, [edi+9]
|
|
|
|
|
mov [ebp+8], ax ; 5
|
|
|
|
|
mov eax, [edi+14]
|
|
|
|
|
mov [ebp+10], eax ; 6,7
|
|
|
|
|
mov eax, [edi+18]
|
|
|
|
|
mov [ebp+14], eax ; 8,9
|
|
|
|
|
mov eax, [edi+22]
|
|
|
|
|
mov [ebp+18], eax ; 10,11
|
|
|
|
|
mov eax, [edi+28]
|
|
|
|
|
mov [ebp+22], eax ; 12,13
|
2006-04-24 16:28:05 +02:00
|
|
|
|
; ... done
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop eax
|
|
|
|
|
sub ebp, eax
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz @f
|
2006-04-24 16:28:05 +02:00
|
|
|
|
; if this is not first entry, more processing required
|
2008-03-01 17:20:40 +01:00
|
|
|
|
stc
|
|
|
|
|
ret
|
2006-04-24 16:28:05 +02:00
|
|
|
|
@@:
|
|
|
|
|
; if this is first entry:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
test byte [ebp-4], 1
|
|
|
|
|
jnz .ret
|
2006-04-24 16:28:05 +02:00
|
|
|
|
; buffer at ebp contains UNICODE name, convert it to ANSI
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push esi edi
|
|
|
|
|
mov esi, ebp
|
|
|
|
|
mov edi, ebp
|
|
|
|
|
call uni2ansi_str
|
|
|
|
|
pop edi esi
|
2006-05-05 14:40:02 +02:00
|
|
|
|
.ret:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
clc
|
|
|
|
|
ret
|
2006-04-24 16:28:05 +02:00
|
|
|
|
|
|
|
|
|
fat_compare_name:
|
|
|
|
|
; compares ASCIIZ-names, case-insensitive (cp866 encoding)
|
|
|
|
|
; in: esi->name, ebp->name
|
|
|
|
|
; out: if names match: ZF=1 and esi->next component of name
|
|
|
|
|
; else: ZF=0, esi is not changed
|
|
|
|
|
; destroys eax
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push ebp esi
|
2006-04-24 16:28:05 +02:00
|
|
|
|
.loop:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov al, [ebp]
|
|
|
|
|
inc ebp
|
|
|
|
|
call char_toupper
|
|
|
|
|
push eax
|
|
|
|
|
lodsb
|
|
|
|
|
call char_toupper
|
|
|
|
|
cmp al, [esp]
|
|
|
|
|
jnz .done
|
|
|
|
|
pop eax
|
|
|
|
|
test al, al
|
|
|
|
|
jnz .loop
|
|
|
|
|
dec esi
|
|
|
|
|
pop eax
|
|
|
|
|
pop ebp
|
|
|
|
|
xor eax, eax ; set ZF flag
|
|
|
|
|
ret
|
2006-04-24 16:28:05 +02:00
|
|
|
|
.done:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp al, '/'
|
|
|
|
|
jnz @f
|
|
|
|
|
cmp byte [esp], 0
|
|
|
|
|
jnz @f
|
|
|
|
|
mov [esp+4], esi
|
2006-04-24 16:28:05 +02:00
|
|
|
|
@@:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop eax
|
|
|
|
|
pop esi ebp
|
|
|
|
|
ret
|
2006-04-24 16:28:05 +02:00
|
|
|
|
|
2006-05-05 14:40:02 +02:00
|
|
|
|
fat_time_to_bdfe:
|
|
|
|
|
; in: eax=FAT time
|
|
|
|
|
; out: eax=BDFE time
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push ecx edx
|
|
|
|
|
mov ecx, eax
|
|
|
|
|
mov edx, eax
|
|
|
|
|
shr eax, 11
|
|
|
|
|
shl eax, 16 ; hours
|
|
|
|
|
and edx, 0x1F
|
|
|
|
|
add edx, edx
|
|
|
|
|
mov al, dl ; seconds
|
|
|
|
|
shr ecx, 5
|
|
|
|
|
and ecx, 0x3F
|
|
|
|
|
mov ah, cl ; minutes
|
|
|
|
|
pop edx ecx
|
|
|
|
|
ret
|
2006-05-05 14:40:02 +02:00
|
|
|
|
|
|
|
|
|
fat_date_to_bdfe:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push ecx edx
|
|
|
|
|
mov ecx, eax
|
|
|
|
|
mov edx, eax
|
|
|
|
|
shr eax, 9
|
|
|
|
|
add ax, 1980
|
|
|
|
|
shl eax, 16 ; year
|
|
|
|
|
and edx, 0x1F
|
|
|
|
|
mov al, dl ; day
|
|
|
|
|
shr ecx, 5
|
|
|
|
|
and ecx, 0xF
|
|
|
|
|
mov ah, cl ; month
|
|
|
|
|
pop edx ecx
|
|
|
|
|
ret
|
2006-05-05 14:40:02 +02:00
|
|
|
|
|
2006-06-15 15:13:03 +02:00
|
|
|
|
bdfe_to_fat_time:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push edx
|
|
|
|
|
mov edx, eax
|
|
|
|
|
shr eax, 16
|
|
|
|
|
and dh, 0x3F
|
|
|
|
|
shl eax, 6
|
|
|
|
|
or al, dh
|
|
|
|
|
shr dl, 1
|
|
|
|
|
and dl, 0x1F
|
|
|
|
|
shl eax, 5
|
|
|
|
|
or al, dl
|
|
|
|
|
pop edx
|
|
|
|
|
ret
|
2006-06-15 15:13:03 +02:00
|
|
|
|
|
|
|
|
|
bdfe_to_fat_date:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push edx
|
|
|
|
|
mov edx, eax
|
|
|
|
|
shr eax, 16
|
|
|
|
|
sub ax, 1980
|
|
|
|
|
and dh, 0xF
|
|
|
|
|
shl eax, 4
|
|
|
|
|
or al, dh
|
|
|
|
|
and dl, 0x1F
|
|
|
|
|
shl eax, 5
|
|
|
|
|
or al, dl
|
|
|
|
|
pop edx
|
|
|
|
|
ret
|
2006-06-15 15:13:03 +02:00
|
|
|
|
|
2006-05-05 14:40:02 +02:00
|
|
|
|
fat_entry_to_bdfe:
|
|
|
|
|
; convert FAT entry at edi to BDFE (block of data of folder entry) at esi, advance esi
|
|
|
|
|
; destroys eax
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov eax, [ebp-4]
|
|
|
|
|
mov [esi+4], eax ; ASCII/UNICODE name
|
2006-06-15 15:13:03 +02:00
|
|
|
|
fat_entry_to_bdfe2:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
movzx eax, byte [edi+11]
|
|
|
|
|
mov [esi], eax ; attributes
|
|
|
|
|
movzx eax, word [edi+14]
|
|
|
|
|
call fat_time_to_bdfe
|
|
|
|
|
mov [esi+8], eax ; creation time
|
|
|
|
|
movzx eax, word [edi+16]
|
|
|
|
|
call fat_date_to_bdfe
|
|
|
|
|
mov [esi+12], eax ; creation date
|
|
|
|
|
and dword [esi+16], 0 ; last access time is not supported on FAT
|
|
|
|
|
movzx eax, word [edi+18]
|
|
|
|
|
call fat_date_to_bdfe
|
|
|
|
|
mov [esi+20], eax ; last access date
|
|
|
|
|
movzx eax, word [edi+22]
|
|
|
|
|
call fat_time_to_bdfe
|
|
|
|
|
mov [esi+24], eax ; last write time
|
|
|
|
|
movzx eax, word [edi+24]
|
|
|
|
|
call fat_date_to_bdfe
|
|
|
|
|
mov [esi+28], eax ; last write date
|
|
|
|
|
mov eax, [edi+28]
|
|
|
|
|
mov [esi+32], eax ; file size (low dword)
|
|
|
|
|
xor eax, eax
|
|
|
|
|
mov [esi+36], eax ; file size (high dword)
|
|
|
|
|
test ebp, ebp
|
|
|
|
|
jz .ret
|
|
|
|
|
push ecx edi
|
|
|
|
|
lea edi, [esi+40]
|
|
|
|
|
mov esi, ebp
|
|
|
|
|
test byte [esi-4], 1
|
|
|
|
|
jz .ansi
|
|
|
|
|
mov ecx, 260/2
|
|
|
|
|
rep movsd
|
|
|
|
|
mov [edi-2], ax
|
|
|
|
|
@@:
|
|
|
|
|
mov esi, edi
|
|
|
|
|
pop edi ecx
|
2006-06-15 15:13:03 +02:00
|
|
|
|
.ret:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
ret
|
2006-05-12 14:47:52 +02:00
|
|
|
|
.ansi:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov ecx, 264/4
|
|
|
|
|
rep movsd
|
|
|
|
|
mov [edi-1], al
|
|
|
|
|
jmp @b
|
2006-05-05 14:40:02 +02:00
|
|
|
|
|
2006-06-15 15:13:03 +02:00
|
|
|
|
bdfe_to_fat_entry:
|
|
|
|
|
; convert BDFE at edx to FAT entry at edi
|
|
|
|
|
; destroys eax
|
|
|
|
|
; attributes byte
|
2008-03-01 17:20:40 +01:00
|
|
|
|
test byte [edi+11], 8 ; volume label?
|
|
|
|
|
jnz @f
|
|
|
|
|
mov al, [edx]
|
|
|
|
|
and al, 0x27
|
|
|
|
|
and byte [edi+11], 0x10
|
|
|
|
|
or byte [edi+11], al
|
|
|
|
|
@@:
|
|
|
|
|
mov eax, [edx+8]
|
|
|
|
|
call bdfe_to_fat_time
|
|
|
|
|
mov [edi+14], ax ; creation time
|
|
|
|
|
mov eax, [edx+12]
|
|
|
|
|
call bdfe_to_fat_date
|
|
|
|
|
mov [edi+16], ax ; creation date
|
|
|
|
|
mov eax, [edx+20]
|
|
|
|
|
call bdfe_to_fat_date
|
|
|
|
|
mov [edi+18], ax ; last access date
|
|
|
|
|
mov eax, [edx+24]
|
|
|
|
|
call bdfe_to_fat_time
|
|
|
|
|
mov [edi+22], ax ; last write time
|
|
|
|
|
mov eax, [edx+28]
|
|
|
|
|
call bdfe_to_fat_date
|
|
|
|
|
mov [edi+24], ax ; last write date
|
|
|
|
|
ret
|
2006-06-15 15:13:03 +02:00
|
|
|
|
|
|
|
|
|
ramdisk_root_first:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov edi, RAMDISK+512*19
|
|
|
|
|
clc
|
|
|
|
|
ret
|
2006-06-15 15:13:03 +02:00
|
|
|
|
ramdisk_root_next:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
add edi, 0x20
|
|
|
|
|
cmp edi, RAMDISK+512*33
|
|
|
|
|
cmc
|
|
|
|
|
ret
|
2006-06-15 15:13:03 +02:00
|
|
|
|
|
2006-06-26 14:13:58 +02:00
|
|
|
|
ramdisk_root_extend_dir:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
stc
|
|
|
|
|
ret
|
2006-06-26 14:13:58 +02:00
|
|
|
|
|
2006-10-09 14:34:00 +02:00
|
|
|
|
uglobal
|
|
|
|
|
; this is for delete support
|
2008-03-01 17:20:40 +01:00
|
|
|
|
rd_prev_sector dd ?
|
|
|
|
|
rd_prev_prev_sector dd ?
|
2006-10-09 14:34:00 +02:00
|
|
|
|
endg
|
|
|
|
|
|
2006-06-26 14:13:58 +02:00
|
|
|
|
ramdisk_notroot_next:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
add edi, 0x20
|
|
|
|
|
test edi, 0x1FF
|
|
|
|
|
jz ramdisk_notroot_next_sector
|
|
|
|
|
ret ; CF=0
|
2006-06-26 14:13:58 +02:00
|
|
|
|
ramdisk_notroot_next_sector:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push ecx
|
|
|
|
|
mov ecx, [eax]
|
|
|
|
|
push [rd_prev_sector]
|
|
|
|
|
pop [rd_prev_prev_sector]
|
|
|
|
|
mov [rd_prev_sector], ecx
|
|
|
|
|
mov ecx, [ecx*2+RAMDISK_FAT]
|
|
|
|
|
and ecx, 0xFFF
|
|
|
|
|
cmp ecx, 2849
|
|
|
|
|
jae ramdisk_notroot_first.err2
|
|
|
|
|
mov [eax], ecx
|
|
|
|
|
pop ecx
|
2006-06-26 14:13:58 +02:00
|
|
|
|
ramdisk_notroot_first:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov eax, [eax]
|
|
|
|
|
cmp eax, 2
|
|
|
|
|
jb .err
|
|
|
|
|
cmp eax, 2849
|
|
|
|
|
jae .err
|
|
|
|
|
shl eax, 9
|
|
|
|
|
lea edi, [eax+(31 shl 9)+RAMDISK]
|
|
|
|
|
clc
|
|
|
|
|
ret
|
2006-06-26 14:13:58 +02:00
|
|
|
|
.err2:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop ecx
|
2006-06-26 14:13:58 +02:00
|
|
|
|
.err:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
stc
|
|
|
|
|
ret
|
2006-06-26 14:13:58 +02:00
|
|
|
|
ramdisk_notroot_next_write:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
test edi, 0x1FF
|
|
|
|
|
jz ramdisk_notroot_next_sector
|
2006-06-26 14:13:58 +02:00
|
|
|
|
ramdisk_root_next_write:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
ret
|
2006-06-26 14:13:58 +02:00
|
|
|
|
|
|
|
|
|
ramdisk_notroot_extend_dir:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pusha
|
|
|
|
|
xor eax, eax
|
|
|
|
|
mov edi, RAMDISK_FAT
|
|
|
|
|
mov ecx, 2849
|
|
|
|
|
repnz scasw
|
|
|
|
|
jnz .notfound
|
|
|
|
|
mov word [edi-2], 0xFFF
|
|
|
|
|
sub edi, RAMDISK_FAT
|
|
|
|
|
shr edi, 1
|
|
|
|
|
dec edi
|
|
|
|
|
mov eax, [esp+28]
|
|
|
|
|
mov ecx, [eax]
|
|
|
|
|
mov [RAMDISK_FAT+ecx*2], di
|
|
|
|
|
mov [eax], edi
|
|
|
|
|
shl edi, 9
|
|
|
|
|
add edi, (31 shl 9)+RAMDISK
|
|
|
|
|
mov [esp], edi
|
|
|
|
|
xor eax, eax
|
|
|
|
|
mov ecx, 128
|
|
|
|
|
rep stosd
|
|
|
|
|
popa
|
|
|
|
|
clc
|
|
|
|
|
ret
|
2006-06-26 14:13:58 +02:00
|
|
|
|
.notfound:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
popa
|
|
|
|
|
stc
|
|
|
|
|
ret
|
2006-06-26 14:13:58 +02:00
|
|
|
|
|
2006-04-24 16:28:05 +02:00
|
|
|
|
rd_find_lfn:
|
2007-05-24 13:27:05 +02:00
|
|
|
|
; in: esi+ebp -> name
|
2006-04-24 16:28:05 +02:00
|
|
|
|
; out: CF=1 - file not found
|
|
|
|
|
; else CF=0 and edi->direntry
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push esi edi
|
|
|
|
|
push 0
|
|
|
|
|
push ramdisk_root_first
|
|
|
|
|
push ramdisk_root_next
|
2006-06-26 14:13:58 +02:00
|
|
|
|
.loop:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
call fat_find_lfn
|
|
|
|
|
jc .notfound
|
|
|
|
|
cmp byte [esi], 0
|
|
|
|
|
jz .found
|
2007-05-24 13:27:05 +02:00
|
|
|
|
.continue:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
test byte [edi+11], 10h
|
|
|
|
|
jz .notfound
|
|
|
|
|
movzx eax, word [edi+26]
|
|
|
|
|
mov [esp+8], eax
|
|
|
|
|
mov dword [esp+4], ramdisk_notroot_first
|
|
|
|
|
mov dword [esp], ramdisk_notroot_next
|
2009-02-01 19:48:32 +01:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .loop
|
|
|
|
|
mov dword [esp+4], ramdisk_root_first
|
|
|
|
|
mov dword [esp], ramdisk_notroot_next
|
2008-03-01 17:20:40 +01:00
|
|
|
|
jmp .loop
|
2006-06-15 15:13:03 +02:00
|
|
|
|
.notfound:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
add esp, 12
|
|
|
|
|
pop edi esi
|
|
|
|
|
stc
|
|
|
|
|
ret
|
2006-06-26 14:13:58 +02:00
|
|
|
|
.found:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
test ebp, ebp
|
|
|
|
|
jz @f
|
|
|
|
|
mov esi, ebp
|
|
|
|
|
xor ebp, ebp
|
|
|
|
|
jmp .continue
|
2007-05-24 13:27:05 +02:00
|
|
|
|
@@:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov eax, [esp+8]
|
|
|
|
|
add esp, 16 ; CF=0
|
|
|
|
|
pop esi
|
|
|
|
|
ret
|
2006-04-24 16:28:05 +02:00
|
|
|
|
|
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
|
;
|
|
|
|
|
; fs_RamdiskRead - LFN variant for reading sys floppy
|
|
|
|
|
;
|
|
|
|
|
; esi points to filename
|
|
|
|
|
; ebx pointer to 64-bit number = first wanted byte, 0+
|
|
|
|
|
; may be ebx=0 - start from first byte
|
|
|
|
|
; ecx number of bytes to read, 0+
|
|
|
|
|
; edx mem location to return data
|
|
|
|
|
;
|
2006-05-10 16:30:38 +02:00
|
|
|
|
; ret ebx = bytes read or 0xffffffff file not found
|
2006-04-24 16:28:05 +02:00
|
|
|
|
; eax = 0 ok read or other = errormsg
|
|
|
|
|
;
|
|
|
|
|
;--------------------------------------------------------------
|
|
|
|
|
fs_RamdiskRead:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp byte [esi], 0
|
|
|
|
|
jnz @f
|
|
|
|
|
or ebx, -1
|
|
|
|
|
mov eax, 10 ; access denied
|
|
|
|
|
ret
|
|
|
|
|
@@:
|
|
|
|
|
push edi
|
|
|
|
|
call rd_find_lfn
|
|
|
|
|
jnc .found
|
|
|
|
|
pop edi
|
|
|
|
|
or ebx, -1
|
|
|
|
|
mov eax, 5 ; file not found
|
|
|
|
|
ret
|
2006-04-24 16:28:05 +02:00
|
|
|
|
.found:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
test ebx, ebx
|
|
|
|
|
jz .l1
|
|
|
|
|
cmp dword [ebx+4], 0
|
|
|
|
|
jz @f
|
|
|
|
|
xor ebx, ebx
|
2006-04-24 16:28:05 +02:00
|
|
|
|
.reteof:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov eax, 6 ; EOF
|
|
|
|
|
pop edi
|
|
|
|
|
ret
|
2006-04-24 16:28:05 +02:00
|
|
|
|
@@:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov ebx, [ebx]
|
2006-04-24 16:28:05 +02:00
|
|
|
|
.l1:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push ecx edx
|
|
|
|
|
push 0
|
|
|
|
|
mov eax, [edi+28]
|
|
|
|
|
sub eax, ebx
|
|
|
|
|
jb .eof
|
|
|
|
|
cmp eax, ecx
|
|
|
|
|
jae @f
|
|
|
|
|
mov ecx, eax
|
|
|
|
|
mov byte [esp], 6 ; EOF
|
|
|
|
|
@@:
|
|
|
|
|
movzx edi, word [edi+26] ; cluster
|
2006-04-24 16:28:05 +02:00
|
|
|
|
.new:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
jecxz .done
|
|
|
|
|
test edi, edi
|
|
|
|
|
jz .eof
|
|
|
|
|
cmp edi, 0xFF8
|
|
|
|
|
jae .eof
|
|
|
|
|
lea eax, [edi+31] ; bootsector+2*fat+filenames
|
|
|
|
|
shl eax, 9 ; *512
|
|
|
|
|
add eax, RAMDISK ; image base
|
2006-04-24 16:28:05 +02:00
|
|
|
|
; now eax points to data of cluster
|
2008-03-01 17:20:40 +01:00
|
|
|
|
sub ebx, 512
|
|
|
|
|
jae .skip
|
|
|
|
|
lea eax, [eax+ebx+512]
|
|
|
|
|
neg ebx
|
|
|
|
|
push ecx
|
|
|
|
|
cmp ecx, ebx
|
|
|
|
|
jbe @f
|
|
|
|
|
mov ecx, ebx
|
|
|
|
|
@@:
|
|
|
|
|
mov ebx, edx
|
|
|
|
|
call memmove
|
|
|
|
|
add edx, ecx
|
|
|
|
|
sub [esp], ecx
|
|
|
|
|
pop ecx
|
|
|
|
|
xor ebx, ebx
|
2006-04-24 16:28:05 +02:00
|
|
|
|
.skip:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
movzx edi, word [edi*2+RAMDISK_FAT] ; find next cluster from FAT
|
|
|
|
|
jmp .new
|
2006-04-24 16:28:05 +02:00
|
|
|
|
.eof:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov ebx, edx
|
|
|
|
|
pop eax edx ecx
|
|
|
|
|
sub ebx, edx
|
|
|
|
|
jmp .reteof
|
2006-04-24 16:28:05 +02:00
|
|
|
|
.done:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov ebx, edx
|
|
|
|
|
pop eax edx ecx edi
|
|
|
|
|
sub ebx, edx
|
|
|
|
|
ret
|
2006-05-05 14:40:02 +02:00
|
|
|
|
|
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
|
;
|
|
|
|
|
; fs_RamdiskReadFolder - LFN variant for reading sys floppy folder
|
|
|
|
|
;
|
|
|
|
|
; esi points to filename; only root is folder on ramdisk
|
2006-05-12 14:47:52 +02:00
|
|
|
|
; ebx pointer to structure 32-bit number = first wanted block
|
|
|
|
|
; & flags (bitfields)
|
|
|
|
|
; flags: bit 0: 0=ANSI names, 1=UNICODE names
|
2006-05-05 14:40:02 +02:00
|
|
|
|
; ecx number of blocks to read, 0+
|
|
|
|
|
; edx mem location to return data
|
|
|
|
|
;
|
|
|
|
|
; ret ebx = size or 0xffffffff file not found
|
|
|
|
|
; eax = 0 ok read or other = errormsg
|
|
|
|
|
;
|
|
|
|
|
;--------------------------------------------------------------
|
|
|
|
|
fs_RamdiskReadFolder:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push edi
|
|
|
|
|
cmp byte [esi], 0
|
|
|
|
|
jz .root
|
|
|
|
|
call rd_find_lfn
|
|
|
|
|
jnc .found
|
|
|
|
|
pop edi
|
|
|
|
|
or ebx, -1
|
|
|
|
|
mov eax, ERROR_FILE_NOT_FOUND
|
|
|
|
|
ret
|
2006-06-26 14:13:58 +02:00
|
|
|
|
.found:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
test byte [edi+11], 0x10
|
|
|
|
|
jnz .found_dir
|
|
|
|
|
pop edi
|
|
|
|
|
or ebx, -1
|
|
|
|
|
mov eax, ERROR_ACCESS_DENIED
|
|
|
|
|
ret
|
2006-06-26 14:13:58 +02:00
|
|
|
|
.found_dir:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
movzx eax, word [edi+26]
|
|
|
|
|
add eax, 31
|
|
|
|
|
push 0
|
|
|
|
|
jmp .doit
|
2006-06-26 14:13:58 +02:00
|
|
|
|
.root:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov eax, 19
|
|
|
|
|
push 14
|
2006-06-26 14:13:58 +02:00
|
|
|
|
.doit:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push esi ecx ebp
|
|
|
|
|
sub esp, 262*2 ; reserve space for LFN
|
|
|
|
|
mov ebp, esp
|
|
|
|
|
push dword [ebx+4] ; for fat_get_name: read ANSI/UNICODE names
|
|
|
|
|
mov ebx, [ebx]
|
2006-05-05 14:40:02 +02:00
|
|
|
|
; init header
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push eax ecx
|
|
|
|
|
mov edi, edx
|
|
|
|
|
mov ecx, 32/4
|
|
|
|
|
xor eax, eax
|
|
|
|
|
rep stosd
|
|
|
|
|
mov byte [edx], 1 ; version
|
|
|
|
|
pop ecx eax
|
|
|
|
|
mov esi, edi ; esi points to block of data of folder entry (BDFE)
|
2006-06-26 14:13:58 +02:00
|
|
|
|
.main_loop:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov edi, eax
|
|
|
|
|
shl edi, 9
|
|
|
|
|
add edi, RAMDISK
|
|
|
|
|
push eax
|
2006-05-05 14:40:02 +02:00
|
|
|
|
.l1:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
call fat_get_name
|
|
|
|
|
jc .l2
|
|
|
|
|
cmp byte [edi+11], 0xF
|
|
|
|
|
jnz .do_bdfe
|
|
|
|
|
add edi, 0x20
|
|
|
|
|
test edi, 0x1FF
|
|
|
|
|
jnz .do_bdfe
|
|
|
|
|
pop eax
|
|
|
|
|
inc eax
|
|
|
|
|
dec byte [esp+262*2+16]
|
|
|
|
|
jz .done
|
|
|
|
|
jns @f
|
2006-06-26 14:13:58 +02:00
|
|
|
|
; read next sector from FAT
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov eax, [(eax-31-1)*2+RAMDISK_FAT]
|
|
|
|
|
and eax, 0xFFF
|
|
|
|
|
cmp eax, 0xFF8
|
|
|
|
|
jae .done
|
|
|
|
|
add eax, 31
|
|
|
|
|
mov byte [esp+262*2+16], 0
|
|
|
|
|
@@:
|
|
|
|
|
mov edi, eax
|
|
|
|
|
shl edi, 9
|
|
|
|
|
add edi, RAMDISK
|
|
|
|
|
push eax
|
2006-06-26 14:13:58 +02:00
|
|
|
|
.do_bdfe:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
inc dword [edx+8] ; new file found
|
|
|
|
|
dec ebx
|
|
|
|
|
jns .l2
|
|
|
|
|
dec ecx
|
|
|
|
|
js .l2
|
|
|
|
|
inc dword [edx+4] ; new file block copied
|
|
|
|
|
call fat_entry_to_bdfe
|
2006-05-05 14:40:02 +02:00
|
|
|
|
.l2:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
add edi, 0x20
|
|
|
|
|
test edi, 0x1FF
|
|
|
|
|
jnz .l1
|
|
|
|
|
pop eax
|
|
|
|
|
inc eax
|
|
|
|
|
dec byte [esp+262*2+16]
|
|
|
|
|
jz .done
|
|
|
|
|
jns @f
|
2006-06-26 14:13:58 +02:00
|
|
|
|
; read next sector from FAT
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov eax, [(eax-31-1)*2+RAMDISK_FAT]
|
|
|
|
|
and eax, 0xFFF
|
|
|
|
|
cmp eax, 0xFF8
|
|
|
|
|
jae .done
|
|
|
|
|
add eax, 31
|
|
|
|
|
mov byte [esp+262*2+16], 0
|
|
|
|
|
@@:
|
|
|
|
|
jmp .main_loop
|
2006-06-26 14:13:58 +02:00
|
|
|
|
.done:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
add esp, 262*2+4
|
|
|
|
|
pop ebp
|
|
|
|
|
mov ebx, [edx+4]
|
|
|
|
|
xor eax, eax
|
|
|
|
|
dec ecx
|
|
|
|
|
js @f
|
|
|
|
|
mov al, ERROR_END_OF_FILE
|
2006-05-05 14:40:02 +02:00
|
|
|
|
@@:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop ecx esi edi edi
|
|
|
|
|
ret
|
2006-04-24 16:28:05 +02:00
|
|
|
|
|
2006-05-30 09:32:30 +02:00
|
|
|
|
iglobal
|
|
|
|
|
label fat_legal_chars byte
|
|
|
|
|
; 0 = not allowed
|
|
|
|
|
; 1 = allowed only in long names
|
|
|
|
|
; 3 = allowed
|
2008-03-01 17:20:40 +01:00
|
|
|
|
times 32 db 0
|
2006-05-30 09:32:30 +02:00
|
|
|
|
; ! " # $ % & ' ( ) * + , - . /
|
2008-03-01 17:20:40 +01:00
|
|
|
|
db 1,3,0,3,3,3,3,3,3,3,0,1,1,3,3,0
|
2006-05-30 09:32:30 +02:00
|
|
|
|
; 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
|
2008-03-01 17:20:40 +01:00
|
|
|
|
db 3,3,3,3,3,3,3,3,3,3,0,1,0,1,0,0
|
2006-05-30 09:32:30 +02:00
|
|
|
|
; @ A B C D E F G H I J K L M N O
|
2008-03-01 17:20:40 +01:00
|
|
|
|
db 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
|
2006-05-30 09:32:30 +02:00
|
|
|
|
; P Q R S T U V W X Y Z [ \ ] ^ _
|
2008-03-01 17:20:40 +01:00
|
|
|
|
db 3,3,3,3,3,3,3,3,3,3,3,1,0,1,3,3
|
2006-05-30 09:32:30 +02:00
|
|
|
|
; ` a b c d e f g h i j k l m n o
|
2008-03-01 17:20:40 +01:00
|
|
|
|
db 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
|
2006-05-30 09:32:30 +02:00
|
|
|
|
; p q r s t u v w x y z { | } ~
|
2008-03-01 17:20:40 +01:00
|
|
|
|
db 3,3,3,3,3,3,3,3,3,3,3,3,0,3,3,0
|
2006-05-30 09:32:30 +02:00
|
|
|
|
endg
|
|
|
|
|
|
|
|
|
|
fat_name_is_legal:
|
|
|
|
|
; in: esi->(long) name
|
|
|
|
|
; out: CF set <=> legal
|
|
|
|
|
; destroys eax
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push esi
|
|
|
|
|
xor eax, eax
|
|
|
|
|
@@:
|
|
|
|
|
lodsb
|
|
|
|
|
test al, al
|
|
|
|
|
jz .done
|
|
|
|
|
cmp al, 80h
|
|
|
|
|
jae .big
|
|
|
|
|
test [fat_legal_chars+eax], 1
|
|
|
|
|
jnz @b
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.err:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop esi
|
|
|
|
|
clc
|
|
|
|
|
ret
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.big:
|
|
|
|
|
; 0x80-0xAF, 0xE0-0xEF
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp al, 0xB0
|
|
|
|
|
jb @b
|
|
|
|
|
cmp al, 0xE0
|
|
|
|
|
jb .err
|
|
|
|
|
cmp al, 0xF0
|
|
|
|
|
jb @b
|
|
|
|
|
jmp .err
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.done:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
sub esi, [esp]
|
|
|
|
|
cmp esi, 257
|
|
|
|
|
pop esi
|
|
|
|
|
ret
|
2006-05-30 09:32:30 +02:00
|
|
|
|
|
|
|
|
|
fat_next_short_name:
|
|
|
|
|
; in: edi->8+3 name
|
|
|
|
|
; out: name corrected
|
|
|
|
|
; CF=1 <=> error
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pushad
|
|
|
|
|
mov ecx, 8
|
|
|
|
|
mov al, '~'
|
|
|
|
|
std
|
|
|
|
|
push edi
|
|
|
|
|
add edi, 7
|
|
|
|
|
repnz scasb
|
|
|
|
|
pop edi
|
|
|
|
|
cld
|
|
|
|
|
jz .tilde
|
2006-05-30 09:32:30 +02:00
|
|
|
|
; tilde is not found, insert "~1" at end
|
2008-03-01 17:20:40 +01:00
|
|
|
|
add edi, 6
|
|
|
|
|
cmp word [edi], ' '
|
|
|
|
|
jnz .insert_tilde
|
|
|
|
|
@@: dec edi
|
|
|
|
|
cmp byte [edi], ' '
|
|
|
|
|
jz @b
|
|
|
|
|
inc edi
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.insert_tilde:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov word [edi], '~1'
|
|
|
|
|
popad
|
|
|
|
|
clc
|
|
|
|
|
ret
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.tilde:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push edi
|
|
|
|
|
add edi, 7
|
|
|
|
|
xor ecx, ecx
|
2006-05-30 09:32:30 +02:00
|
|
|
|
@@:
|
|
|
|
|
; after tilde may be only digits and trailing spaces
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp byte [edi], '~'
|
|
|
|
|
jz .break
|
|
|
|
|
cmp byte [edi], ' '
|
|
|
|
|
jz .space
|
|
|
|
|
cmp byte [edi], '9'
|
|
|
|
|
jnz .found
|
|
|
|
|
dec edi
|
|
|
|
|
jmp @b
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.space:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
dec edi
|
|
|
|
|
inc ecx
|
|
|
|
|
jmp @b
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.found:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
inc byte [edi]
|
|
|
|
|
add dword [esp], 8
|
|
|
|
|
jmp .zerorest
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.break:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
jecxz .noplace
|
|
|
|
|
inc edi
|
|
|
|
|
mov al, '1'
|
|
|
|
|
@@:
|
|
|
|
|
xchg al, [edi]
|
|
|
|
|
inc edi
|
|
|
|
|
cmp al, ' '
|
|
|
|
|
mov al, '0'
|
|
|
|
|
jnz @b
|
2007-04-18 16:58:48 +02:00
|
|
|
|
.succ:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop edi
|
|
|
|
|
popad
|
|
|
|
|
clc
|
|
|
|
|
ret
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.noplace:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
dec edi
|
|
|
|
|
cmp edi, [esp]
|
|
|
|
|
jz .err
|
|
|
|
|
add dword [esp], 8
|
|
|
|
|
mov word [edi], '~1'
|
|
|
|
|
inc edi
|
|
|
|
|
inc edi
|
|
|
|
|
@@:
|
|
|
|
|
mov byte [edi], '0'
|
2007-04-18 16:58:48 +02:00
|
|
|
|
.zerorest:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
inc edi
|
|
|
|
|
cmp edi, [esp]
|
|
|
|
|
jb @b
|
|
|
|
|
pop edi
|
|
|
|
|
popad
|
|
|
|
|
;clc ; automatically
|
|
|
|
|
ret
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.err:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop edi
|
|
|
|
|
popad
|
|
|
|
|
stc
|
|
|
|
|
ret
|
2006-05-30 09:32:30 +02:00
|
|
|
|
|
|
|
|
|
fat_gen_short_name:
|
|
|
|
|
; in: esi->long name
|
|
|
|
|
; edi->buffer (8+3=11 chars)
|
|
|
|
|
; out: buffer filled
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pushad
|
|
|
|
|
mov eax, ' '
|
|
|
|
|
push edi
|
|
|
|
|
stosd
|
|
|
|
|
stosd
|
|
|
|
|
stosd
|
|
|
|
|
pop edi
|
|
|
|
|
xor eax, eax
|
|
|
|
|
push 8
|
|
|
|
|
pop ebx
|
|
|
|
|
lea ecx, [edi+8]
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.loop:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
lodsb
|
|
|
|
|
test al, al
|
|
|
|
|
jz .done
|
|
|
|
|
call char_toupper
|
|
|
|
|
cmp al, ' '
|
|
|
|
|
jz .space
|
|
|
|
|
cmp al, 80h
|
|
|
|
|
ja .big
|
|
|
|
|
test [fat_legal_chars+eax], 2
|
|
|
|
|
jnz .symbol
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.inv_symbol:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov al, '_'
|
|
|
|
|
or bh, 1
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.symbol:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp al, '.'
|
|
|
|
|
jz .dot
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.normal_symbol:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
dec bl
|
|
|
|
|
jns .store
|
|
|
|
|
mov bl, 0
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.space:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
or bh, 1
|
|
|
|
|
jmp .loop
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.store:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
stosb
|
|
|
|
|
jmp .loop
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.big:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp al, 0xB0
|
|
|
|
|
jb .normal_symbol
|
|
|
|
|
cmp al, 0xE0
|
|
|
|
|
jb .inv_symbol
|
|
|
|
|
cmp al, 0xF0
|
|
|
|
|
jb .normal_symbol
|
|
|
|
|
jmp .inv_symbol
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.dot:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
test bh, 2
|
|
|
|
|
jz .firstdot
|
|
|
|
|
pop ebx
|
|
|
|
|
add ebx, edi
|
|
|
|
|
sub ebx, ecx
|
|
|
|
|
push ebx
|
|
|
|
|
cmp ebx, ecx
|
|
|
|
|
jb @f
|
|
|
|
|
pop ebx
|
|
|
|
|
push ecx
|
|
|
|
|
@@:
|
|
|
|
|
cmp edi, ecx
|
|
|
|
|
jbe .skip
|
|
|
|
|
@@:
|
|
|
|
|
dec edi
|
|
|
|
|
mov al, [edi]
|
|
|
|
|
dec ebx
|
|
|
|
|
mov [ebx], al
|
|
|
|
|
mov byte [edi], ' '
|
|
|
|
|
cmp edi, ecx
|
|
|
|
|
ja @b
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.skip:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov bh, 3
|
|
|
|
|
jmp @f
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.firstdot:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp bl, 8
|
|
|
|
|
jz .space
|
|
|
|
|
push edi
|
|
|
|
|
or bh, 2
|
|
|
|
|
@@:
|
|
|
|
|
mov edi, ecx
|
|
|
|
|
mov bl, 3
|
|
|
|
|
jmp .loop
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.done:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
test bh, 2
|
|
|
|
|
jz @f
|
|
|
|
|
pop edi
|
2006-05-30 09:32:30 +02:00
|
|
|
|
@@:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
lea edi, [ecx-8]
|
|
|
|
|
test bh, 1
|
|
|
|
|
jz @f
|
|
|
|
|
call fat_next_short_name
|
2006-05-30 09:32:30 +02:00
|
|
|
|
@@:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
popad
|
|
|
|
|
ret
|
2006-05-30 09:32:30 +02:00
|
|
|
|
|
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
|
;
|
2007-02-05 15:20:36 +01:00
|
|
|
|
; fs_RamdiskRewrite - LFN variant for writing ramdisk
|
|
|
|
|
; fs_RamdiskCreateFolder - create folder on ramdisk
|
2006-05-30 09:32:30 +02:00
|
|
|
|
;
|
2007-02-05 15:20:36 +01:00
|
|
|
|
; esi points to file/folder name
|
2006-05-30 09:32:30 +02:00
|
|
|
|
; ebx ignored (reserved)
|
2007-02-05 15:20:36 +01:00
|
|
|
|
; ecx number of bytes to write, 0+ (ignored for folders)
|
|
|
|
|
; edx mem location to data (ignored for folders)
|
2006-05-30 09:32:30 +02:00
|
|
|
|
;
|
|
|
|
|
; ret ebx = number of written bytes
|
|
|
|
|
; eax = 0 ok read or other = errormsg
|
|
|
|
|
;
|
|
|
|
|
;--------------------------------------------------------------
|
|
|
|
|
@@:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov eax, ERROR_ACCESS_DENIED
|
|
|
|
|
xor ebx, ebx
|
|
|
|
|
ret
|
2006-05-30 09:32:30 +02:00
|
|
|
|
|
2007-02-05 15:20:36 +01:00
|
|
|
|
fs_RamdiskCreateFolder:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov al, 1 ; create folder
|
|
|
|
|
jmp fs_RamdiskRewrite.common
|
2007-02-05 15:20:36 +01:00
|
|
|
|
|
2006-05-30 09:32:30 +02:00
|
|
|
|
fs_RamdiskRewrite:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
xor eax, eax ; create file
|
2007-02-05 15:20:36 +01:00
|
|
|
|
.common:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp byte [esi], 0
|
|
|
|
|
jz @b
|
|
|
|
|
pushad
|
|
|
|
|
xor edi, edi
|
|
|
|
|
push esi
|
|
|
|
|
test ebp, ebp
|
|
|
|
|
jz @f
|
|
|
|
|
mov esi, ebp
|
|
|
|
|
@@:
|
|
|
|
|
lodsb
|
|
|
|
|
test al, al
|
|
|
|
|
jz @f
|
|
|
|
|
cmp al, '/'
|
|
|
|
|
jnz @b
|
|
|
|
|
lea edi, [esi-1]
|
|
|
|
|
jmp @b
|
|
|
|
|
@@:
|
|
|
|
|
pop esi
|
|
|
|
|
test edi, edi
|
|
|
|
|
jnz .noroot
|
|
|
|
|
test ebp, ebp
|
|
|
|
|
jnz .hasebp
|
|
|
|
|
push ramdisk_root_extend_dir
|
|
|
|
|
push ramdisk_root_next_write
|
|
|
|
|
push edi
|
|
|
|
|
push ramdisk_root_first
|
|
|
|
|
push ramdisk_root_next
|
|
|
|
|
jmp .common1
|
2007-05-24 13:27:05 +02:00
|
|
|
|
.hasebp:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov eax, ERROR_ACCESS_DENIED
|
|
|
|
|
cmp byte [ebp], 0
|
|
|
|
|
jz .ret1
|
|
|
|
|
push ebp
|
|
|
|
|
xor ebp, ebp
|
|
|
|
|
call rd_find_lfn
|
|
|
|
|
pop esi
|
|
|
|
|
jc .notfound0
|
|
|
|
|
jmp .common0
|
2006-06-26 14:13:58 +02:00
|
|
|
|
.noroot:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov eax, ERROR_ACCESS_DENIED
|
|
|
|
|
cmp byte [edi+1], 0
|
|
|
|
|
jz .ret1
|
2006-05-30 09:32:30 +02:00
|
|
|
|
; check existence
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov byte [edi], 0
|
|
|
|
|
push edi
|
|
|
|
|
call rd_find_lfn
|
|
|
|
|
pop esi
|
|
|
|
|
mov byte [esi], '/'
|
|
|
|
|
jnc @f
|
2007-05-24 13:27:05 +02:00
|
|
|
|
.notfound0:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov eax, ERROR_FILE_NOT_FOUND
|
2006-06-26 14:13:58 +02:00
|
|
|
|
.ret1:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov [esp+28], eax
|
|
|
|
|
popad
|
|
|
|
|
xor ebx, ebx
|
|
|
|
|
ret
|
2006-06-26 14:13:58 +02:00
|
|
|
|
@@:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
inc esi
|
2007-05-24 13:27:05 +02:00
|
|
|
|
.common0:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
test byte [edi+11], 0x10 ; must be directory
|
|
|
|
|
mov eax, ERROR_ACCESS_DENIED
|
|
|
|
|
jz .ret1
|
|
|
|
|
movzx ebp, word [edi+26] ; ebp=cluster
|
|
|
|
|
mov eax, ERROR_FAT_TABLE
|
|
|
|
|
cmp ebp, 2
|
|
|
|
|
jb .ret1
|
|
|
|
|
cmp ebp, 2849
|
|
|
|
|
jae .ret1
|
|
|
|
|
push ramdisk_notroot_extend_dir
|
|
|
|
|
push ramdisk_notroot_next_write
|
|
|
|
|
push ebp
|
|
|
|
|
push ramdisk_notroot_first
|
|
|
|
|
push ramdisk_notroot_next
|
2006-06-26 14:13:58 +02:00
|
|
|
|
.common1:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
call fat_find_lfn
|
|
|
|
|
jc .notfound
|
2007-02-05 15:20:36 +01:00
|
|
|
|
; found
|
2008-03-01 17:20:40 +01:00
|
|
|
|
test byte [edi+11], 10h
|
|
|
|
|
jz .exists_file
|
2007-02-05 15:20:36 +01:00
|
|
|
|
; found directory; if we are creating directory, return OK,
|
|
|
|
|
; if we are creating file, say "access denied"
|
2008-03-01 17:20:40 +01:00
|
|
|
|
add esp, 20
|
|
|
|
|
popad
|
|
|
|
|
test al, al
|
|
|
|
|
mov eax, ERROR_ACCESS_DENIED
|
|
|
|
|
jz @f
|
|
|
|
|
mov al, 0
|
|
|
|
|
@@:
|
|
|
|
|
xor ebx, ebx
|
|
|
|
|
ret
|
2007-02-05 15:20:36 +01:00
|
|
|
|
.exists_file:
|
|
|
|
|
; found file; if we are creating directory, return "access denied",
|
|
|
|
|
; if we are creating file, delete existing file and continue
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp byte [esp+20+28], 0
|
|
|
|
|
jz @f
|
|
|
|
|
add esp, 20
|
|
|
|
|
popad
|
|
|
|
|
mov eax, ERROR_ACCESS_DENIED
|
|
|
|
|
xor ebx, ebx
|
|
|
|
|
ret
|
2006-06-26 14:13:58 +02:00
|
|
|
|
@@:
|
|
|
|
|
; delete FAT chain
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push edi
|
|
|
|
|
xor eax, eax
|
|
|
|
|
mov dword [edi+28], eax ; zero size
|
|
|
|
|
xchg ax, word [edi+26] ; start cluster
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .done1
|
|
|
|
|
@@:
|
|
|
|
|
cmp eax, 0xFF8
|
|
|
|
|
jae .done1
|
|
|
|
|
lea edi, [RAMDISK_FAT + eax*2] ; position in FAT
|
|
|
|
|
xor eax, eax
|
|
|
|
|
xchg ax, [edi]
|
|
|
|
|
jmp @b
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.done1:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop edi
|
|
|
|
|
call get_time_for_file
|
|
|
|
|
mov [edi+22], ax
|
|
|
|
|
call get_date_for_file
|
|
|
|
|
mov [edi+24], ax
|
|
|
|
|
mov [edi+18], ax
|
|
|
|
|
or byte [edi+11], 20h ; set 'archive' attribute
|
|
|
|
|
jmp .doit
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.notfound:
|
|
|
|
|
; file is not found; generate short name
|
2008-03-01 17:20:40 +01:00
|
|
|
|
call fat_name_is_legal
|
|
|
|
|
jc @f
|
|
|
|
|
add esp, 20
|
|
|
|
|
popad
|
|
|
|
|
mov eax, ERROR_FILE_NOT_FOUND
|
|
|
|
|
xor ebx, ebx
|
|
|
|
|
ret
|
|
|
|
|
@@:
|
|
|
|
|
sub esp, 12
|
|
|
|
|
mov edi, esp
|
|
|
|
|
call fat_gen_short_name
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.test_short_name_loop:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push esi edi ecx
|
|
|
|
|
mov esi, edi
|
|
|
|
|
lea eax, [esp+12+12+8]
|
|
|
|
|
mov [eax], ebp
|
|
|
|
|
call dword [eax-4]
|
|
|
|
|
jc .found
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.test_short_name_entry:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp byte [edi+11], 0xF
|
|
|
|
|
jz .test_short_name_cont
|
|
|
|
|
mov ecx, 11
|
|
|
|
|
push esi edi
|
|
|
|
|
repz cmpsb
|
|
|
|
|
pop edi esi
|
|
|
|
|
jz .short_name_found
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.test_short_name_cont:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
lea eax, [esp+12+12+8]
|
|
|
|
|
call dword [eax-8]
|
|
|
|
|
jnc .test_short_name_entry
|
|
|
|
|
jmp .found
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.short_name_found:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop ecx edi esi
|
|
|
|
|
call fat_next_short_name
|
|
|
|
|
jnc .test_short_name_loop
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.disk_full:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
add esp, 12+20
|
|
|
|
|
popad
|
|
|
|
|
mov eax, ERROR_DISK_FULL
|
|
|
|
|
xor ebx, ebx
|
|
|
|
|
ret
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.found:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop ecx edi esi
|
2006-05-30 09:32:30 +02:00
|
|
|
|
; now find space in directory
|
|
|
|
|
; we need to save LFN <=> LFN is not equal to short name <=> generated name contains '~'
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov al, '~'
|
|
|
|
|
push ecx edi
|
|
|
|
|
mov ecx, 8
|
|
|
|
|
repnz scasb
|
|
|
|
|
push 1
|
|
|
|
|
pop eax ; 1 entry
|
|
|
|
|
jnz .notilde
|
2006-05-30 09:32:30 +02:00
|
|
|
|
; we need ceil(strlen(esi)/13) additional entries = floor((strlen(esi)+12+13)/13) total
|
2008-03-01 17:20:40 +01:00
|
|
|
|
xor eax, eax
|
|
|
|
|
@@:
|
|
|
|
|
cmp byte [esi], 0
|
|
|
|
|
jz @f
|
|
|
|
|
inc esi
|
|
|
|
|
inc eax
|
|
|
|
|
jmp @b
|
|
|
|
|
@@:
|
|
|
|
|
sub esi, eax
|
|
|
|
|
add eax, 12+13
|
|
|
|
|
mov ecx, 13
|
|
|
|
|
push edx
|
|
|
|
|
cdq
|
|
|
|
|
div ecx
|
|
|
|
|
pop edx
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.notilde:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push -1
|
|
|
|
|
push -1
|
2006-05-30 09:32:30 +02:00
|
|
|
|
; find <eax> successive entries in directory
|
2008-03-01 17:20:40 +01:00
|
|
|
|
xor ecx, ecx
|
|
|
|
|
push eax
|
|
|
|
|
lea eax, [esp+12+8+12+8]
|
|
|
|
|
mov [eax], ebp
|
|
|
|
|
call dword [eax-4]
|
|
|
|
|
pop eax
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.scan_dir:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp byte [edi], 0
|
|
|
|
|
jz .free
|
|
|
|
|
cmp byte [edi], 0xE5
|
|
|
|
|
jz .free
|
|
|
|
|
xor ecx, ecx
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.scan_cont:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push eax
|
|
|
|
|
lea eax, [esp+12+8+12+8]
|
|
|
|
|
call dword [eax-8]
|
|
|
|
|
pop eax
|
|
|
|
|
jnc .scan_dir
|
|
|
|
|
push eax
|
|
|
|
|
lea eax, [esp+12+8+12+8]
|
|
|
|
|
call dword [eax+8] ; extend directory
|
|
|
|
|
pop eax
|
|
|
|
|
jnc .scan_dir
|
|
|
|
|
add esp, 8+8+12+20
|
|
|
|
|
popad
|
|
|
|
|
mov eax, ERROR_DISK_FULL
|
|
|
|
|
xor ebx, ebx
|
|
|
|
|
ret
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.free:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
test ecx, ecx
|
|
|
|
|
jnz @f
|
|
|
|
|
mov [esp], edi
|
|
|
|
|
mov ecx, [esp+8+8+12+8]
|
|
|
|
|
mov [esp+4], ecx
|
|
|
|
|
xor ecx, ecx
|
|
|
|
|
@@:
|
|
|
|
|
inc ecx
|
|
|
|
|
cmp ecx, eax
|
|
|
|
|
jb .scan_cont
|
2006-05-30 09:32:30 +02:00
|
|
|
|
; found!
|
|
|
|
|
; calculate name checksum
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push esi ecx
|
|
|
|
|
mov esi, [esp+8+8]
|
|
|
|
|
mov ecx, 11
|
|
|
|
|
xor eax, eax
|
|
|
|
|
@@:
|
|
|
|
|
ror al, 1
|
|
|
|
|
add al, [esi]
|
|
|
|
|
inc esi
|
|
|
|
|
loop @b
|
|
|
|
|
pop ecx esi
|
|
|
|
|
pop edi
|
|
|
|
|
pop dword [esp+8+12+8]
|
2006-05-30 09:32:30 +02:00
|
|
|
|
; edi points to last entry in free chunk
|
2008-03-01 17:20:40 +01:00
|
|
|
|
dec ecx
|
|
|
|
|
jz .nolfn
|
|
|
|
|
push esi
|
|
|
|
|
push eax
|
|
|
|
|
mov al, 40h
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.writelfn:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
or al, cl
|
|
|
|
|
mov esi, [esp+4]
|
|
|
|
|
push ecx
|
|
|
|
|
dec ecx
|
|
|
|
|
imul ecx, 13
|
|
|
|
|
add esi, ecx
|
|
|
|
|
stosb
|
|
|
|
|
mov cl, 5
|
|
|
|
|
call .read_symbols
|
|
|
|
|
mov ax, 0xF
|
|
|
|
|
stosw
|
|
|
|
|
mov al, [esp+4]
|
|
|
|
|
stosb
|
|
|
|
|
mov cl, 6
|
|
|
|
|
call .read_symbols
|
|
|
|
|
xor eax, eax
|
|
|
|
|
stosw
|
|
|
|
|
mov cl, 2
|
|
|
|
|
call .read_symbols
|
|
|
|
|
pop ecx
|
|
|
|
|
lea eax, [esp+8+8+12+8]
|
|
|
|
|
call dword [eax+4] ; next write
|
|
|
|
|
xor eax, eax
|
|
|
|
|
loop .writelfn
|
|
|
|
|
pop eax
|
|
|
|
|
pop esi
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.nolfn:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
xchg esi, [esp]
|
|
|
|
|
mov ecx, 11
|
|
|
|
|
rep movsb
|
|
|
|
|
mov word [edi], 20h ; attributes
|
|
|
|
|
sub edi, 11
|
|
|
|
|
pop esi ecx
|
|
|
|
|
add esp, 12
|
|
|
|
|
mov byte [edi+13], 0 ; tenths of a second at file creation time
|
|
|
|
|
call get_time_for_file
|
|
|
|
|
mov [edi+14], ax ; creation time
|
|
|
|
|
mov [edi+22], ax ; last write time
|
|
|
|
|
call get_date_for_file
|
|
|
|
|
mov [edi+16], ax ; creation date
|
|
|
|
|
mov [edi+24], ax ; last write date
|
|
|
|
|
mov [edi+18], ax ; last access date
|
|
|
|
|
and word [edi+20], 0 ; high word of cluster
|
|
|
|
|
and word [edi+26], 0 ; low word of cluster - to be filled
|
|
|
|
|
and dword [edi+28], 0 ; file size - to be filled
|
|
|
|
|
cmp byte [esp+20+28], 0
|
|
|
|
|
jz .doit
|
2007-02-05 15:20:36 +01:00
|
|
|
|
; create directory
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov byte [edi+11], 10h ; attributes: folder
|
|
|
|
|
mov ecx, 32*2
|
|
|
|
|
mov edx, edi
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.doit:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push edx
|
|
|
|
|
push ecx
|
|
|
|
|
push edi
|
|
|
|
|
add edi, 26 ; edi points to low word of cluster
|
|
|
|
|
push edi
|
|
|
|
|
jecxz .done
|
|
|
|
|
mov ecx, 2849
|
|
|
|
|
mov edi, RAMDISK_FAT
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.write_loop:
|
|
|
|
|
; allocate new cluster
|
2008-03-01 17:20:40 +01:00
|
|
|
|
xor eax, eax
|
|
|
|
|
repnz scasw
|
|
|
|
|
jnz .disk_full2
|
|
|
|
|
dec edi
|
|
|
|
|
dec edi
|
2007-04-18 08:37:14 +02:00
|
|
|
|
|
|
|
|
|
; lea eax, [edi-(RAMDISK_FAT)]
|
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov eax, edi
|
|
|
|
|
sub eax, RAMDISK_FAT
|
2007-04-18 08:37:14 +02:00
|
|
|
|
|
2008-03-01 17:20:40 +01:00
|
|
|
|
shr eax, 1 ; eax = cluster
|
|
|
|
|
mov word [edi], 0xFFF ; mark as last cluster
|
|
|
|
|
xchg edi, [esp]
|
|
|
|
|
stosw
|
|
|
|
|
pop edi
|
|
|
|
|
push edi
|
|
|
|
|
inc ecx
|
2006-05-30 09:32:30 +02:00
|
|
|
|
; write data
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp byte [esp+16+20+28], 0
|
|
|
|
|
jnz .writedir
|
|
|
|
|
shl eax, 9
|
|
|
|
|
add eax, RAMDISK+31*512
|
2007-02-05 15:20:36 +01:00
|
|
|
|
.writefile:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov ebx, edx
|
|
|
|
|
xchg eax, ebx
|
|
|
|
|
push ecx
|
|
|
|
|
mov ecx, 512
|
|
|
|
|
cmp dword [esp+12], ecx
|
|
|
|
|
jae @f
|
|
|
|
|
mov ecx, [esp+12]
|
|
|
|
|
@@:
|
|
|
|
|
call memmove
|
|
|
|
|
add edx, ecx
|
|
|
|
|
sub [esp+12], ecx
|
|
|
|
|
pop ecx
|
|
|
|
|
jnz .write_loop
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.done:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov ebx, edx
|
|
|
|
|
pop edi edi ecx edx
|
|
|
|
|
sub ebx, edx
|
|
|
|
|
mov [edi+28], ebx
|
|
|
|
|
add esp, 20
|
|
|
|
|
mov [esp+16], ebx
|
|
|
|
|
popad
|
|
|
|
|
xor eax, eax
|
|
|
|
|
ret
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.disk_full2:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov ebx, edx
|
|
|
|
|
pop edi edi ecx edx
|
|
|
|
|
sub ebx, edx
|
|
|
|
|
mov [edi+28], ebx
|
|
|
|
|
add esp, 20
|
|
|
|
|
mov [esp+16], ebx
|
|
|
|
|
popad
|
|
|
|
|
push ERROR_DISK_FULL
|
|
|
|
|
pop eax
|
|
|
|
|
ret
|
2007-02-05 15:20:36 +01:00
|
|
|
|
.writedir:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov edi, eax
|
|
|
|
|
shl edi, 9
|
|
|
|
|
add edi, RAMDISK+31*512
|
|
|
|
|
mov esi, edx
|
|
|
|
|
mov ecx, 32/4
|
|
|
|
|
push ecx
|
|
|
|
|
rep movsd
|
|
|
|
|
mov dword [edi-32], '. '
|
|
|
|
|
mov dword [edi-32+4], ' '
|
|
|
|
|
mov dword [edi-32+8], ' '
|
|
|
|
|
mov byte [edi-32+11], 10h
|
|
|
|
|
mov word [edi-32+26], ax
|
|
|
|
|
mov esi, edx
|
|
|
|
|
pop ecx
|
|
|
|
|
rep movsd
|
|
|
|
|
mov dword [edi-32], '.. '
|
|
|
|
|
mov dword [edi-32+4], ' '
|
|
|
|
|
mov dword [edi-32+8], ' '
|
|
|
|
|
mov byte [edi-32+11], 10h
|
|
|
|
|
mov eax, [esp+16+8]
|
|
|
|
|
mov word [edi-32+26], ax
|
|
|
|
|
xor eax, eax
|
|
|
|
|
mov ecx, (512-32*2)/4
|
|
|
|
|
rep stosd
|
|
|
|
|
pop edi edi ecx edx
|
|
|
|
|
add esp, 20
|
|
|
|
|
popad
|
|
|
|
|
xor eax, eax
|
|
|
|
|
xor ebx, ebx
|
|
|
|
|
ret
|
2006-05-30 09:32:30 +02:00
|
|
|
|
|
|
|
|
|
.read_symbol:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
or ax, -1
|
|
|
|
|
test esi, esi
|
|
|
|
|
jz .retFFFF
|
|
|
|
|
lodsb
|
|
|
|
|
test al, al
|
|
|
|
|
jnz ansi2uni_char
|
|
|
|
|
xor eax, eax
|
|
|
|
|
xor esi, esi
|
2006-05-30 09:32:30 +02:00
|
|
|
|
.retFFFF:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
ret
|
2006-05-30 09:32:30 +02:00
|
|
|
|
|
|
|
|
|
.read_symbols:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
call .read_symbol
|
|
|
|
|
stosw
|
|
|
|
|
loop .read_symbols
|
|
|
|
|
ret
|
2006-05-30 09:32:30 +02:00
|
|
|
|
|
2006-08-18 15:32:18 +02:00
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
|
;
|
|
|
|
|
; fs_RamdiskWrite - LFN variant for writing to sys floppy
|
|
|
|
|
;
|
|
|
|
|
; esi points to filename
|
|
|
|
|
; ebx pointer to 64-bit number = first wanted byte, 0+
|
|
|
|
|
; may be ebx=0 - start from first byte
|
|
|
|
|
; ecx number of bytes to write, 0+
|
|
|
|
|
; edx mem location to data
|
|
|
|
|
;
|
|
|
|
|
; ret ebx = bytes written (maybe 0)
|
|
|
|
|
; eax = 0 ok write or other = errormsg
|
|
|
|
|
;
|
|
|
|
|
;--------------------------------------------------------------
|
|
|
|
|
@@:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push ERROR_ACCESS_DENIED
|
2006-08-18 15:32:18 +02:00
|
|
|
|
fs_RamdiskWrite.ret0:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop eax
|
|
|
|
|
xor ebx, ebx
|
|
|
|
|
ret
|
2006-08-18 15:32:18 +02:00
|
|
|
|
|
|
|
|
|
fs_RamdiskWrite:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp byte [esi], 0
|
|
|
|
|
jz @b
|
|
|
|
|
pushad
|
|
|
|
|
call rd_find_lfn
|
|
|
|
|
jnc .found
|
|
|
|
|
popad
|
|
|
|
|
push ERROR_FILE_NOT_FOUND
|
|
|
|
|
jmp .ret0
|
2006-08-18 15:32:18 +02:00
|
|
|
|
.found:
|
|
|
|
|
; must not be directory
|
2008-03-01 17:20:40 +01:00
|
|
|
|
test byte [edi+11], 10h
|
|
|
|
|
jz @f
|
|
|
|
|
popad
|
|
|
|
|
push ERROR_ACCESS_DENIED
|
|
|
|
|
jmp .ret0
|
2006-08-18 15:32:18 +02:00
|
|
|
|
@@:
|
|
|
|
|
; FAT does not support files larger than 4GB
|
2008-03-01 17:20:40 +01:00
|
|
|
|
test ebx, ebx
|
|
|
|
|
jz .l1
|
|
|
|
|
cmp dword [ebx+4], 0
|
|
|
|
|
jz @f
|
2006-08-18 15:32:18 +02:00
|
|
|
|
.eof:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
popad
|
|
|
|
|
push ERROR_END_OF_FILE
|
|
|
|
|
jmp .ret0
|
2006-08-18 15:32:18 +02:00
|
|
|
|
@@:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov ebx, [ebx]
|
2006-08-18 15:32:18 +02:00
|
|
|
|
.l1:
|
|
|
|
|
; now edi points to direntry, ebx=start byte to write,
|
|
|
|
|
; ecx=number of bytes to write, edx=data pointer
|
2008-03-01 17:20:40 +01:00
|
|
|
|
call fat_update_datetime
|
2006-08-18 15:32:18 +02:00
|
|
|
|
|
|
|
|
|
; extend file if needed
|
2008-03-01 17:20:40 +01:00
|
|
|
|
add ecx, ebx
|
|
|
|
|
jc .eof ; FAT does not support files larger than 4GB
|
|
|
|
|
push 0 ; return value=0
|
|
|
|
|
cmp ecx, [edi+28]
|
|
|
|
|
jbe .length_ok
|
|
|
|
|
cmp ecx, ebx
|
|
|
|
|
jz .length_ok
|
|
|
|
|
call ramdisk_extend_file
|
|
|
|
|
jnc .length_ok
|
2006-08-18 15:32:18 +02:00
|
|
|
|
; ramdisk_extend_file can return two error codes: FAT table error or disk full.
|
|
|
|
|
; First case is fatal error, in second case we may write some data
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov [esp], eax
|
|
|
|
|
cmp al, ERROR_DISK_FULL
|
|
|
|
|
jz .disk_full
|
|
|
|
|
pop eax
|
|
|
|
|
mov [esp+28], eax
|
|
|
|
|
popad
|
|
|
|
|
xor ebx, ebx
|
|
|
|
|
ret
|
2006-08-18 15:32:18 +02:00
|
|
|
|
.disk_full:
|
|
|
|
|
; correct number of bytes to write
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov ecx, [edi+28]
|
|
|
|
|
cmp ecx, ebx
|
|
|
|
|
ja .length_ok
|
2006-08-18 15:32:18 +02:00
|
|
|
|
.ret:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop eax
|
|
|
|
|
mov [esp+28], eax ; eax=return value
|
|
|
|
|
sub edx, [esp+20]
|
|
|
|
|
mov [esp+16], edx ; ebx=number of written bytes
|
|
|
|
|
popad
|
|
|
|
|
ret
|
2006-08-18 15:32:18 +02:00
|
|
|
|
.length_ok:
|
|
|
|
|
; now ebx=start pos, ecx=end pos, both lie inside file
|
2008-03-01 17:20:40 +01:00
|
|
|
|
sub ecx, ebx
|
|
|
|
|
jz .ret
|
|
|
|
|
movzx edi, word [edi+26] ; starting cluster
|
2006-08-18 15:32:18 +02:00
|
|
|
|
.write_loop:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
sub ebx, 0x200
|
|
|
|
|
jae .next_cluster
|
|
|
|
|
push ecx
|
|
|
|
|
neg ebx
|
|
|
|
|
cmp ecx, ebx
|
|
|
|
|
jbe @f
|
|
|
|
|
mov ecx, ebx
|
|
|
|
|
@@:
|
|
|
|
|
mov eax, edi
|
|
|
|
|
shl eax, 9
|
|
|
|
|
add eax, RAMDISK+31*512+0x200
|
|
|
|
|
sub eax, ebx
|
|
|
|
|
mov ebx, eax
|
|
|
|
|
mov eax, edx
|
|
|
|
|
call memmove
|
|
|
|
|
xor ebx, ebx
|
|
|
|
|
add edx, ecx
|
|
|
|
|
sub [esp], ecx
|
|
|
|
|
pop ecx
|
|
|
|
|
jz .ret
|
2006-08-18 15:32:18 +02:00
|
|
|
|
.next_cluster:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
movzx edi, word [edi*2+RAMDISK_FAT]
|
|
|
|
|
jmp .write_loop
|
2006-08-18 15:32:18 +02:00
|
|
|
|
|
|
|
|
|
ramdisk_extend_file.zero_size:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
xor eax, eax
|
|
|
|
|
jmp ramdisk_extend_file.start_extend
|
2006-08-18 15:32:18 +02:00
|
|
|
|
|
|
|
|
|
; extends file on ramdisk to given size, new data area is filled by 0
|
|
|
|
|
; in: edi->direntry, ecx=new size
|
2006-08-21 15:06:02 +02:00
|
|
|
|
; out: CF=0 => OK, eax=0
|
2006-08-18 15:32:18 +02:00
|
|
|
|
; CF=1 => error, eax=code (ERROR_FAT_TABLE or ERROR_DISK_FULL)
|
|
|
|
|
ramdisk_extend_file:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push ecx
|
2006-08-18 15:32:18 +02:00
|
|
|
|
; find the last cluster of file
|
2008-03-01 17:20:40 +01:00
|
|
|
|
movzx eax, word [edi+26] ; first cluster
|
|
|
|
|
mov ecx, [edi+28]
|
|
|
|
|
jecxz .zero_size
|
|
|
|
|
@@:
|
|
|
|
|
sub ecx, 0x200
|
|
|
|
|
jbe @f
|
|
|
|
|
mov eax, [eax*2+RAMDISK_FAT]
|
|
|
|
|
and eax, 0xFFF
|
|
|
|
|
jz .fat_err
|
|
|
|
|
cmp eax, 0xFF8
|
|
|
|
|
jb @b
|
2006-08-18 15:32:18 +02:00
|
|
|
|
.fat_err:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop ecx
|
|
|
|
|
push ERROR_FAT_TABLE
|
|
|
|
|
pop eax
|
|
|
|
|
stc
|
|
|
|
|
ret
|
|
|
|
|
@@:
|
|
|
|
|
push eax
|
|
|
|
|
mov eax, [eax*2+RAMDISK_FAT]
|
|
|
|
|
and eax, 0xFFF
|
|
|
|
|
cmp eax, 0xFF8
|
|
|
|
|
pop eax
|
|
|
|
|
jb .fat_err
|
2006-08-18 15:32:18 +02:00
|
|
|
|
; set length to full number of sectors and make sure that last sector is zero-padded
|
2008-03-01 17:20:40 +01:00
|
|
|
|
sub [edi+28], ecx
|
|
|
|
|
push eax edi
|
|
|
|
|
mov edi, eax
|
|
|
|
|
shl edi, 9
|
|
|
|
|
lea edi, [edi+RAMDISK+31*512+0x200+ecx]
|
|
|
|
|
neg ecx
|
|
|
|
|
xor eax, eax
|
|
|
|
|
rep stosb
|
|
|
|
|
pop edi eax
|
2006-08-18 15:32:18 +02:00
|
|
|
|
.start_extend:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop ecx
|
2006-08-18 15:32:18 +02:00
|
|
|
|
; now do extend
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push edx esi
|
|
|
|
|
mov esi, RAMDISK_FAT+2*2 ; start scan from cluster 2
|
|
|
|
|
mov edx, 2847 ; number of clusters to scan
|
2006-08-18 15:32:18 +02:00
|
|
|
|
.extend_loop:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp [edi+28], ecx
|
|
|
|
|
jae .extend_done
|
2006-08-18 15:32:18 +02:00
|
|
|
|
; add new sector
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push ecx
|
|
|
|
|
mov ecx, edx
|
|
|
|
|
push edi
|
|
|
|
|
mov edi, esi
|
|
|
|
|
jecxz .disk_full
|
|
|
|
|
push eax
|
|
|
|
|
xor eax, eax
|
|
|
|
|
repnz scasw
|
|
|
|
|
pop eax
|
|
|
|
|
jnz .disk_full
|
|
|
|
|
mov word [edi-2], 0xFFF
|
|
|
|
|
mov esi, edi
|
|
|
|
|
mov edx, ecx
|
|
|
|
|
sub edi, RAMDISK_FAT
|
|
|
|
|
shr edi, 1
|
|
|
|
|
dec edi ; now edi=new cluster
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .first_cluster
|
|
|
|
|
mov [RAMDISK_FAT+eax*2], di
|
|
|
|
|
jmp @f
|
2006-08-18 15:32:18 +02:00
|
|
|
|
.first_cluster:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop eax ; eax->direntry
|
|
|
|
|
push eax
|
|
|
|
|
mov [eax+26], di
|
|
|
|
|
@@:
|
|
|
|
|
push edi
|
|
|
|
|
shl edi, 9
|
|
|
|
|
add edi, RAMDISK+31*512
|
|
|
|
|
xor eax, eax
|
|
|
|
|
mov ecx, 512/4
|
|
|
|
|
rep stosd
|
|
|
|
|
pop eax ; eax=new cluster
|
|
|
|
|
pop edi ; edi->direntry
|
|
|
|
|
pop ecx ; ecx=required size
|
|
|
|
|
add dword [edi+28], 0x200
|
|
|
|
|
jmp .extend_loop
|
2006-08-18 15:32:18 +02:00
|
|
|
|
.extend_done:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov [edi+28], ecx
|
|
|
|
|
pop esi edx
|
|
|
|
|
xor eax, eax ; CF=0
|
|
|
|
|
ret
|
2006-08-18 15:32:18 +02:00
|
|
|
|
.disk_full:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop edi ecx
|
|
|
|
|
pop esi edx
|
|
|
|
|
stc
|
|
|
|
|
push ERROR_DISK_FULL
|
|
|
|
|
pop eax
|
|
|
|
|
ret
|
2006-08-18 15:32:18 +02:00
|
|
|
|
|
2006-08-21 15:06:02 +02:00
|
|
|
|
fat_update_datetime:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
call get_time_for_file
|
|
|
|
|
mov [edi+22], ax ; last write time
|
|
|
|
|
call get_date_for_file
|
|
|
|
|
mov [edi+24], ax ; last write date
|
|
|
|
|
mov [edi+18], ax ; last access date
|
|
|
|
|
ret
|
2006-08-21 15:06:02 +02:00
|
|
|
|
|
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
|
;
|
|
|
|
|
; fs_RamdiskSetFileEnd - set end of file on ramdisk
|
|
|
|
|
;
|
|
|
|
|
; esi points to filename
|
|
|
|
|
; ebx points to 64-bit number = new file size
|
|
|
|
|
; ecx ignored (reserved)
|
|
|
|
|
; edx ignored (reserved)
|
|
|
|
|
;
|
|
|
|
|
; ret eax = 0 ok or other = errormsg
|
|
|
|
|
;
|
|
|
|
|
;--------------------------------------------------------------
|
|
|
|
|
fs_RamdiskSetFileEnd:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp byte [esi], 0
|
|
|
|
|
jnz @f
|
2006-08-21 15:06:02 +02:00
|
|
|
|
.access_denied:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push ERROR_ACCESS_DENIED
|
|
|
|
|
jmp .ret
|
|
|
|
|
@@:
|
|
|
|
|
push edi
|
|
|
|
|
call rd_find_lfn
|
|
|
|
|
jnc @f
|
|
|
|
|
pop edi
|
|
|
|
|
push ERROR_FILE_NOT_FOUND
|
2006-08-21 15:06:02 +02:00
|
|
|
|
.ret:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop eax
|
|
|
|
|
ret
|
2006-08-21 15:06:02 +02:00
|
|
|
|
@@:
|
|
|
|
|
; must not be directory
|
2008-03-01 17:20:40 +01:00
|
|
|
|
test byte [edi+11], 10h
|
|
|
|
|
jz @f
|
|
|
|
|
pop edi
|
|
|
|
|
jmp .access_denied
|
2006-08-21 15:06:02 +02:00
|
|
|
|
@@:
|
|
|
|
|
; file size must not exceed 4Gb
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp dword [ebx+4], 0
|
|
|
|
|
jz @f
|
|
|
|
|
pop edi
|
|
|
|
|
push ERROR_END_OF_FILE
|
|
|
|
|
jmp .ret
|
2006-08-21 15:06:02 +02:00
|
|
|
|
@@:
|
|
|
|
|
; set file modification date/time to current
|
2008-03-01 17:20:40 +01:00
|
|
|
|
call fat_update_datetime
|
|
|
|
|
mov eax, [ebx]
|
|
|
|
|
cmp eax, [edi+28]
|
|
|
|
|
jb .truncate
|
|
|
|
|
ja .expand
|
|
|
|
|
pop edi
|
|
|
|
|
xor eax, eax
|
|
|
|
|
ret
|
2006-08-21 15:06:02 +02:00
|
|
|
|
.expand:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push ecx
|
|
|
|
|
mov ecx, eax
|
|
|
|
|
call ramdisk_extend_file
|
|
|
|
|
pop ecx
|
|
|
|
|
pop edi
|
|
|
|
|
ret
|
2006-08-21 15:06:02 +02:00
|
|
|
|
.truncate:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov [edi+28], eax
|
|
|
|
|
push ecx
|
|
|
|
|
movzx ecx, word [edi+26]
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .zero_size
|
2006-08-21 15:06:02 +02:00
|
|
|
|
; find new last sector
|
|
|
|
|
@@:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
sub eax, 0x200
|
|
|
|
|
jbe @f
|
|
|
|
|
movzx ecx, word [RAMDISK_FAT+ecx*2]
|
|
|
|
|
jmp @b
|
2006-08-21 15:06:02 +02:00
|
|
|
|
@@:
|
|
|
|
|
; zero data at the end of last sector
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push ecx
|
|
|
|
|
mov edi, ecx
|
|
|
|
|
shl edi, 9
|
|
|
|
|
lea edi, [edi+RAMDISK+31*512+eax+0x200]
|
|
|
|
|
mov ecx, eax
|
|
|
|
|
neg ecx
|
|
|
|
|
xor eax, eax
|
|
|
|
|
rep stosb
|
|
|
|
|
pop ecx
|
2006-08-21 15:06:02 +02:00
|
|
|
|
; terminate FAT chain
|
2008-03-01 17:20:40 +01:00
|
|
|
|
lea ecx, [RAMDISK_FAT+ecx+ecx]
|
|
|
|
|
push dword [ecx]
|
|
|
|
|
mov word [ecx], 0xFFF
|
|
|
|
|
pop ecx
|
|
|
|
|
and ecx, 0xFFF
|
|
|
|
|
jmp .delete
|
2006-08-21 15:06:02 +02:00
|
|
|
|
.zero_size:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
and word [edi+26], 0
|
2006-08-21 15:06:02 +02:00
|
|
|
|
.delete:
|
|
|
|
|
; delete FAT chain starting with ecx
|
|
|
|
|
; mark all clusters as free
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp ecx, 0xFF8
|
|
|
|
|
jae .deleted
|
|
|
|
|
lea ecx, [RAMDISK_FAT+ecx+ecx]
|
|
|
|
|
push dword [ecx]
|
|
|
|
|
and word [ecx], 0
|
|
|
|
|
pop ecx
|
|
|
|
|
and ecx, 0xFFF
|
|
|
|
|
jmp .delete
|
2006-08-21 15:06:02 +02:00
|
|
|
|
.deleted:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop ecx
|
|
|
|
|
pop edi
|
|
|
|
|
xor eax, eax
|
|
|
|
|
ret
|
2006-08-21 15:06:02 +02:00
|
|
|
|
|
2006-06-15 15:13:03 +02:00
|
|
|
|
fs_RamdiskGetFileInfo:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp byte [esi], 0
|
|
|
|
|
jnz @f
|
|
|
|
|
mov eax, 2 ; unsupported
|
|
|
|
|
ret
|
2006-06-15 15:13:03 +02:00
|
|
|
|
@@:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push edi
|
|
|
|
|
call rd_find_lfn
|
2006-06-15 15:13:03 +02:00
|
|
|
|
fs_GetFileInfo_finish:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
jnc @f
|
|
|
|
|
pop edi
|
|
|
|
|
mov eax, ERROR_FILE_NOT_FOUND
|
|
|
|
|
ret
|
|
|
|
|
@@:
|
|
|
|
|
push esi ebp
|
|
|
|
|
xor ebp, ebp
|
|
|
|
|
mov esi, edx
|
|
|
|
|
and dword [esi+4], 0
|
|
|
|
|
call fat_entry_to_bdfe2
|
|
|
|
|
pop ebp esi
|
|
|
|
|
pop edi
|
|
|
|
|
xor eax, eax
|
|
|
|
|
ret
|
2006-06-15 15:13:03 +02:00
|
|
|
|
|
|
|
|
|
fs_RamdiskSetFileInfo:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp byte [esi], 0
|
|
|
|
|
jnz @f
|
|
|
|
|
mov eax, 2 ; unsupported
|
|
|
|
|
ret
|
|
|
|
|
@@:
|
|
|
|
|
push edi
|
|
|
|
|
call rd_find_lfn
|
|
|
|
|
jnc @f
|
|
|
|
|
pop edi
|
|
|
|
|
mov eax, ERROR_FILE_NOT_FOUND
|
|
|
|
|
ret
|
|
|
|
|
@@:
|
|
|
|
|
call bdfe_to_fat_entry
|
|
|
|
|
pop edi
|
|
|
|
|
xor eax, eax
|
|
|
|
|
ret
|
2006-06-15 15:13:03 +02:00
|
|
|
|
|
2006-10-09 14:34:00 +02:00
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
|
;
|
|
|
|
|
; fs_RamdiskDelete - delete file or empty folder from ramdisk
|
|
|
|
|
;
|
|
|
|
|
; esi points to filename
|
|
|
|
|
;
|
|
|
|
|
; ret eax = 0 ok or other = errormsg
|
|
|
|
|
;
|
|
|
|
|
;--------------------------------------------------------------
|
|
|
|
|
fs_RamdiskDelete:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp byte [esi], 0
|
|
|
|
|
jnz @f
|
2006-10-09 14:34:00 +02:00
|
|
|
|
; cannot delete root!
|
|
|
|
|
.access_denied:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
push ERROR_ACCESS_DENIED
|
2006-10-09 14:34:00 +02:00
|
|
|
|
.pop_ret:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop eax
|
|
|
|
|
ret
|
|
|
|
|
@@:
|
|
|
|
|
and [rd_prev_sector], 0
|
|
|
|
|
and [rd_prev_prev_sector], 0
|
|
|
|
|
push edi
|
|
|
|
|
call rd_find_lfn
|
|
|
|
|
jnc .found
|
|
|
|
|
pop edi
|
|
|
|
|
push ERROR_FILE_NOT_FOUND
|
|
|
|
|
jmp .pop_ret
|
2006-10-09 14:34:00 +02:00
|
|
|
|
.found:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp dword [edi], '. '
|
|
|
|
|
jz .access_denied2
|
|
|
|
|
cmp dword [edi], '.. '
|
|
|
|
|
jz .access_denied2
|
|
|
|
|
test byte [edi+11], 10h
|
|
|
|
|
jz .dodel
|
2006-10-09 14:34:00 +02:00
|
|
|
|
; we can delete only empty folders!
|
2008-03-01 17:20:40 +01:00
|
|
|
|
movzx eax, word [edi+26]
|
|
|
|
|
push ebx
|
|
|
|
|
mov ebx, eax
|
|
|
|
|
shl ebx, 9
|
|
|
|
|
add ebx, RAMDISK + 31*0x200 + 2*0x20
|
2006-10-09 14:34:00 +02:00
|
|
|
|
.checkempty:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
cmp byte [ebx], 0
|
|
|
|
|
jz .empty
|
|
|
|
|
cmp byte [ebx], 0xE5
|
|
|
|
|
jnz .notempty
|
|
|
|
|
add ebx, 0x20
|
|
|
|
|
test ebx, 0x1FF
|
|
|
|
|
jnz .checkempty
|
|
|
|
|
movzx eax, word [RAMDISK_FAT + eax*2]
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .empty
|
|
|
|
|
mov ebx, eax
|
|
|
|
|
shl ebx, 9
|
|
|
|
|
add ebx, RAMDISK + 31*0x200
|
|
|
|
|
jmp .checkempty
|
2006-10-09 14:34:00 +02:00
|
|
|
|
.notempty:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop ebx
|
2006-10-09 14:34:00 +02:00
|
|
|
|
.access_denied2:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop edi
|
|
|
|
|
jmp .access_denied
|
2006-10-09 14:34:00 +02:00
|
|
|
|
.empty:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop ebx
|
2006-10-09 14:34:00 +02:00
|
|
|
|
.dodel:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
movzx eax, word [edi+26]
|
2006-10-09 14:34:00 +02:00
|
|
|
|
; delete folder entry
|
2008-03-01 17:20:40 +01:00
|
|
|
|
mov byte [edi], 0xE5
|
2006-10-09 14:34:00 +02:00
|
|
|
|
; delete LFN (if present)
|
|
|
|
|
.lfndel:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
test edi, 0x1FF
|
|
|
|
|
jnz @f
|
|
|
|
|
cmp [rd_prev_sector], 0
|
|
|
|
|
jz @f
|
|
|
|
|
cmp [rd_prev_sector], -1
|
|
|
|
|
jz .lfndone
|
|
|
|
|
mov edi, [rd_prev_sector]
|
|
|
|
|
push [rd_prev_prev_sector]
|
|
|
|
|
pop [rd_prev_sector]
|
|
|
|
|
or [rd_prev_prev_sector], -1
|
|
|
|
|
shl edi, 9
|
|
|
|
|
add edi, RAMDISK + 31*0x200 + 0x200
|
|
|
|
|
@@:
|
|
|
|
|
sub edi, 0x20
|
|
|
|
|
cmp byte [edi], 0xE5
|
|
|
|
|
jz .lfndone
|
|
|
|
|
cmp byte [edi+11], 0xF
|
|
|
|
|
jnz .lfndone
|
|
|
|
|
mov byte [edi], 0xE5
|
|
|
|
|
jmp .lfndel
|
2006-10-09 14:34:00 +02:00
|
|
|
|
.lfndone:
|
|
|
|
|
; delete FAT chain
|
2008-03-01 17:20:40 +01:00
|
|
|
|
test eax, eax
|
|
|
|
|
jz .done
|
|
|
|
|
lea eax, [RAMDISK_FAT + eax*2]
|
|
|
|
|
push dword [eax]
|
|
|
|
|
and word [eax], 0
|
|
|
|
|
pop eax
|
|
|
|
|
and eax, 0xFFF
|
|
|
|
|
jmp .lfndone
|
2006-10-09 14:34:00 +02:00
|
|
|
|
.done:
|
2008-03-01 17:20:40 +01:00
|
|
|
|
pop edi
|
|
|
|
|
xor eax, eax
|
|
|
|
|
ret
|
2006-10-09 14:34:00 +02:00
|
|
|
|
|
2006-05-12 14:47:52 +02:00
|
|
|
|
; \end{diamond}
|