Compare commits

...
2 Commits
Author SHA1 Message Date
dunkaist a5818318bc kernel/fs: Unhardcode some magic numbers
Check kernel codestyle / Check kernel codestyle (pull_request) Successful in 24s
Test PR / Build (es_ES) (pull_request) Successful in 2m56s
Test PR / Build (en_US) (pull_request) Successful in 2m59s
Test PR / Build (ru_RU) (pull_request) Successful in 3m2s
2026-07-05 11:46:49 +01:00
dunkaist 2d12aae144 extfs: Split findInode into smaller functions 2026-07-05 11:28:33 +01:00
9 changed files with 368 additions and 320 deletions

No files matched your search

+5
View File
@@ -384,6 +384,11 @@ STDIN_FILENO = 0
STDOUT_FILENO = 1
STDERR_FILENO = 2
ENC_DEFAULT = 0
ENC_CP866 = 1
ENC_UTF16 = 2 ; Little endian
ENC_UTF8 = 3
SYSTEM_SHUTDOWN = 2
SYSTEM_REBOOT = 3
SYSTEM_RESTART = 4
+5 -5
View File
@@ -582,9 +582,9 @@ exFAT_entry_to_bdfe2:
push edi esi
mov edi, esi
mov esi, ebp
cmp byte [ebp-4], 2
cmp byte [ebp-4], ENC_UTF16
jz .utf16
cmp byte [ebp-4], 3
cmp byte [ebp-4], ENC_UTF8
jz .utf8
@@:
lodsw
@@ -593,14 +593,14 @@ exFAT_entry_to_bdfe2:
test al, al
jnz @b
pop esi edi
add esi, 264
add esi, FILENAME_LEN_CP866
.ret:
; DEBUGF 1, "K : exFAT_entry_to_bdfe +264 ESI:%x\n", esi
ret
.utf8:
push ecx
mov ecx, 519
mov ecx, FILENAME_LEN_UTF - 1
call UTF16to8_string
pop ecx
jmp @f
@@ -612,7 +612,7 @@ exFAT_entry_to_bdfe2:
jnz .utf16
@@:
pop esi edi
add esi, 520
add esi, FILENAME_LEN_UTF
; DEBUGF 1, "K : exFAT_entry_to_bdfe +520 ESI:%x\n", esi
ret
;------------------------------------------------------------------------------
+202 -175
View File
@@ -5,6 +5,8 @@
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
prologue@proc equ omit_frame_pointer_prologue
epilogue@proc equ omit_frame_pointer_epilogue
; EXT external functions
; in:
@@ -767,6 +769,7 @@ extfsExtentAlloc:
extfsGetExtent:
; in: ecx = starting file block
; [ebp+EXTFS.inodeBuffer]
; out: eax = first block number, ecx = extent size
push ebx edx esi
lea esi, [ebp+EXTFS.inodeBuffer]
@@ -993,9 +996,11 @@ writeInode:
stc
jmp .ret
readInode:
; in: eax = inode number, ebx -> inode buffer
push edx edi esi ecx ebx
proc readInode uses ecx edx ebx esi edi
; in: eax = inode number
; ebx = inode buffer
; ebp = PARTITION pointer
; out: cf = success / CF = fail
mov edi, ebx
call getInodeLocation
mov ebx, [ebp+EXTFS.tempBlockBuffer]
@@ -1026,8 +1031,8 @@ readInode:
.zero_rest:
xor eax, eax
rep stosb
pop ebx ecx esi edi edx
ret
endp
indirectBlockAlloc:
; in:
@@ -1784,136 +1789,181 @@ unlinkInode:
pop eax
ret
findInode:
; in: esi -> path string in UTF-8
; out:
; edi -> file name in UTF-8
; esi = last inode number
; [ebp+EXTFS.inodeBuffer] = last inode
; ecx = parent inode number
; CF=1 -> file not found, edi=0 -> error
; ebp = PARTITION pointer
; out:
; edi -> file name in UTF-8
; esi = last inode number
; [ebp+EXTFS.inodeBuffer] = last inode
; ecx = parent inode number
; CF=1 -> file not found, edi=0 -> error
proc findInode uses ebx, _at_inode
locals
.cur_inode dd ?
.last_component_name dd ?
endl
mov [ebp+EXTFS.symlink_depth], SYMLINK_MAX_DEPTH
push esi
lea esi, [ebp+EXTFS.rootInodeBuffer]
lea edi, [ebp+EXTFS.inodeBuffer]
movzx ecx, [ebp+EXTFS.superblock.inodeSize]
mov edx, esi
rep movsb
pop esi
pushd ebx 0 ROOT_INODE
mov edi, esi
cmp [edx+INODE.fileSize], 0
jz .not_found
.skip_root_slashes:
cmp byte [esi], '/'
jne @f
inc esi
jmp .skip_root_slashes
@@:
cmp byte [esi], 0
jnz .next_path_part
xor eax, eax
pop esi ecx ebx
ret
@@:
pop esi esi
.error:
pop esi ecx ebx
xor edi, edi
stc
ret
.next_path_part:
push [edx+INODE.fileSize]
xor ecx, ecx
.folder_block_cycle:
push ecx
call extfsGetExtent
jc @b
mov ebx, [ebp+EXTFS.mainBlockBuffer]
call extfsReadBlock
jc @b
push esi edx
mov edx, ebx
add edx, [ebp+EXTFS.bytesPerBlock]
.start_rec:
cmp [ebx+DIRENTRY.inodeNumber], 0
jz .next_rec
push esi
movzx ecx, [ebx+DIRENTRY.nameLength]
lea edi, [ebx+DIRENTRY.name]
repz cmpsb
jz .test_find
@@: ; doesn't match
pop esi
.next_rec:
movzx ecx, [ebx+DIRENTRY.entryLength]
jecxz .stop
add ebx, ecx
cmp ebx, edx
jb .start_rec
jmp .stop
.test_find:
cmp byte [esi], 0
je @f
cmp byte [esi], '/'
jne @b
.skip_slashes:
inc esi
cmp byte [esi], '/'
je .skip_slashes
@@:
pop edx
.stop:
pop edx edi ecx eax
; ebx -> matched directory entry, esi -> name without parent, or not changed
cmp edi, esi
jnz @f
sub eax, [ebp+EXTFS.bytesPerBlock]
jle .not_found
push eax
inc ecx
jmp .folder_block_cycle
@@:
pop eax
mov [esp], eax
mov eax, [ebx+DIRENTRY.inodeNumber]
lea ebx, [ebp+EXTFS.inodeBuffer]
push eax
mov eax, [_at_inode]
mov [.cur_inode], eax
.next_path_part:
.skip_slashes:
cmp byte[esi], '/'
jnz @f
inc esi
jmp .skip_slashes
@@:
cmp byte[esi], 0
jz .found
mov [.last_component_name], esi
stdcall ext._.lookup, [_at_inode]
jc .error
jnz .not_found
mov eax, [edx+DIRENTRY.inodeNumber]
mov [.cur_inode], eax
call readInode
jc .error
movzx eax, [ebx+INODE.accessMode]
and eax, TYPE_MASK
; check if symlink
cmp eax, FLAG_SYMLINK
jz .resolve_symlink
cmp byte [esi], 0
je .ret
mov edx, ebx
jz .symlink
cmp eax, DIRECTORY
jz .next_path_part
xor edi, edi ; path folder is a file
jmp @f
.not_found:
mov esi, edi
call strlen
mov al, '/'
repnz scasb
mov edi, esi
jnz @f
xor edi, edi ; path folder not found
jz .directory
; all other file types: fifo, device, etc
cmp byte[esi], 0
jz .found
jmp .error
.symlink:
stdcall ext._.resolve_symlink
jc .error
test eax, eax
jz @f
mov [_at_inode], eax
@@:
jmp .next_path_part
.directory:
cmp byte[esi], 0
jz .found
mov eax, [.cur_inode]
mov [_at_inode], eax
jmp .next_path_part
.found:
mov eax, [.cur_inode]
call readInode
jc .error
jmp .ret
.not_found:
call ext._.path_strlen
cmp byte[esi+ecx], 0
movi eax, ERROR_FILE_NOT_FOUND
jz .last_component_not_found
.error:
mov [.last_component_name], 0
.last_component_not_found:
stc
.ret:
pop esi ecx ebx
mov edi, [.last_component_name]
mov esi, [.cur_inode]
mov ecx, [_at_inode]
ret
endp
; in: esi -- path
; out: ecx -- length
proc ext._.path_strlen
mov ecx, esi
.next_byte:
cmp byte[ecx], 0
jz .done
cmp byte[ecx], '/'
jz .done
inc ecx
jmp .next_byte
.done:
sub ecx, esi
ret
endp
; in: edx - DIRENTRY pointer
; in: esi -- path
; out: ZF = match / zf = no match
proc ext._.compare_rec uses edi
cmp [edx+DIRENTRY.inodeNumber], 0
jz .no_match
stdcall ext._.path_strlen
cmp cl, [edx+DIRENTRY.nameLength]
jnz .ret
mov eax, esi
lea edi, [edx+DIRENTRY.name]
repz cmpsb
jz .ret
mov esi, eax
.no_match:
test esp, esp ; clear ZF
.ret:
ret
endp
; in: esi -- path
; edx -- directory block pointer
; out: ZF / zf -- found / not found
proc ext._.lookup_block _block_len
.next_rec:
stdcall ext._.compare_rec
jz .found
movzx ecx, [edx+DIRENTRY.entryLength]
jecxz .not_found ; is this possible?
add edx, ecx
sub [_block_len], ecx
ja .next_rec
.not_found:
test esp, esp ; zf
.found:
ret
endp
; in: _at_inode -- lookup dir inode
; esi -- path
; out: CF/cf -- error / no error, ZF/zf -- found / not found
; ebx -- INODE structure
proc ext._.lookup _at_inode
locals
.cur_block dd ?
endl
mov [.cur_block], 0
mov eax, [_at_inode]
lea ebx, [ebp+EXTFS.inodeBuffer]
call readInode
jc .error
.next_block:
mov ecx, [.cur_block]
call extfsGetExtent
jc .error
push ebx
mov ebx, [ebp+EXTFS.mainBlockBuffer]
call extfsReadBlock
pop ebx
jc .error
mov edx, [ebp+EXTFS.mainBlockBuffer]
stdcall ext._.lookup_block, [ebp+EXTFS.bytesPerBlock]
; ebx -> matched directory entry
; esi -> name without parent, or not changed
jz .found
mov eax, [ebp+EXTFS.bytesPerBlock]
sub [ebx+INODE.fileSize], eax
jbe .not_found
inc [.cur_block]
jmp .next_block
.not_found:
test esp, esp ; cf, zf
.found:
.error:
ret
endp
; in: ebp -- EXTFS partition struct
proc ext._.resolve_symlink
.resolve_symlink:
dec [ebp+EXTFS.symlink_depth]
jns @f
@@ -2022,35 +2072,13 @@ findInode:
; The target path starts with '/', it is absolute.
inc esi
mov dword [esp], ROOT_INODE
mov dword [esp+4], ROOT_INODE
push esi
lea esi, [ebp+EXTFS.rootInodeBuffer]
lea edi, [ebp+EXTFS.inodeBuffer]
movzx ecx, [ebp+EXTFS.superblock.inodeSize]
rep movsb
pop esi
lea edx, [ebp+EXTFS.inodeBuffer]
cmp byte [esi], 0
jz .ret
jmp .next_path_part
movi eax, ROOT_INODE
jmp .done
; The target path does not start with '/', it is relative to the current directory.
.relative_symlink:
mov eax, [esp+4]
mov [esp], eax
lea ebx, [ebp+EXTFS.inodeBuffer]
push eax
call readInode
add esp, 4
jc .error
mov edx, ebx
jmp .next_path_part
xor eax, eax
jmp .done
.error_nested:
pop eax ecx edi
@@ -2060,6 +2088,14 @@ findInode:
add esp, 12
pop esi
jmp .error
.error:
.ret:
stc
ret
.done:
clc
ret
endp
writeSuperblock:
push ebx
@@ -2215,24 +2251,11 @@ endp
;----------------------------------------------------------------
ext_ReadFolder:
call ext_lock
cmp byte [esi], 0
jz .root_folder
call findInode
stdcall findInode, ROOT_INODE
jc .error_ret
lea esi, [ebp+EXTFS.inodeBuffer]
test [esi+INODE.accessMode], FLAG_FILE
jnz .error_not_found
jmp @f
.root_folder:
lea esi, [ebp+EXTFS.rootInodeBuffer]
lea edi, [ebp+EXTFS.inodeBuffer]
movzx ecx, [ebp+EXTFS.superblock.inodeSize]
shr ecx, 2
push edi
rep movsd
pop esi
@@:
cmp [esi+INODE.fileSize], 0
je .error_empty_dir
mov edx, [ebx+16]
@@ -2333,10 +2356,10 @@ ext_ReadFolder:
or byte [edx], KOS_HIDDEN
@@:
lea edi, [edx+40]
cmp byte [edx+4], 3
cmp byte [edx+4], ENC_UTF8
jz .utf8
add ecx, esi
cmp byte [edx+4], 2
cmp byte [edx+4], ENC_UTF16
jz .utf16
@@:
call utf8to16
@@ -2345,7 +2368,7 @@ ext_ReadFolder:
cmp esi, ecx
jc @b
and byte [edi], 0
add edx, 40+264
add edx, sizeof.bdfe_cp866
@@:
pop esi ecx edi ebx
dec ecx
@@ -2365,7 +2388,7 @@ ext_ReadFolder:
.utf8:
rep movsb
mov byte [edi], 0
add edx, 40+520
add edx, sizeof.bdfe_utf
jmp @b
.utf16:
@@ -2374,7 +2397,7 @@ ext_ReadFolder:
cmp esi, ecx
jc .utf16
and word [edi], 0
add edx, 40+520
add edx, sizeof.bdfe_utf
jmp @b
.end_dir:
@@ -2420,7 +2443,7 @@ ext_ReadFolder:
;----------------------------------------------------------------
ext_ReadFile:
call ext_lock
call findInode
stdcall findInode, ROOT_INODE
pushd 0 eax
jc .ret
lea esi, [ebp+EXTFS.inodeBuffer]
@@ -2529,7 +2552,7 @@ ext_GetFileInfo:
cmp byte [esi], 0
jz .volume
call ext_lock
call findInode
stdcall findInode, ROOT_INODE
jc .ret
lea esi, [ebp+EXTFS.inodeBuffer]
mov edx, [ebx+16]
@@ -2577,10 +2600,10 @@ ext_GetFileInfo:
lea esi, [ebp+EXTFS.superblock.volumeLabel]
mov ecx, 16
add edi, 40
cmp eax, 3
cmp eax, ENC_UTF8
jz .utf8
add ecx, esi
cmp eax, 2
cmp eax, ENC_UTF16
jz .utf16
@@:
call utf8to16
@@ -2629,7 +2652,7 @@ endp
;----------------------------------------------------------------
ext_SetFileInfo:
call extfsWritingInit
call findInode
stdcall findInode, ROOT_INODE
jc @f
lea edi, [ebp+EXTFS.inodeBuffer]
test [edi+INODE.featureFlags], EXT4_IMMUTABLE_FL
@@ -2670,7 +2693,7 @@ ext_SetFileInfo:
;----------------------------------------------------------------
ext_Delete:
call extfsWritingInit
call findInode
stdcall findInode, ROOT_INODE
jc .error
lea eax, [ebp+EXTFS.inodeBuffer]
test [eax+INODE.featureFlags], EXT4_IMMUTABLE_FL
@@ -2858,7 +2881,7 @@ initializeTimeFields:
;----------------------------------------------------------------
ext_CreateFolder:
call extfsWritingInit
call findInode
stdcall findInode, ROOT_INODE
jnc .success ; exist
test edi, edi
jz .error
@@ -2932,14 +2955,16 @@ ext_CreateFolder:
pop eax
ret
iglobal
self_link db ".", 0
parent_link db "..", 0
endg
;----------------------------------------------------------------
ext_CreateFile:
call extfsWritingInit
pushd 0 0 ebx
call findInode
stdcall findInode, ROOT_INODE
jnc .exist
test edi, edi
jz .error
@@ -2999,7 +3024,7 @@ ext_CreateFile:
;----------------------------------------------------------------
ext_WriteFile:
call extfsWritingInit
call findInode
stdcall findInode, ROOT_INODE
pushd 0 eax
jc .ret
mov dword [esp], ERROR_ACCESS_DENIED
@@ -3138,7 +3163,7 @@ ext_WriteFile:
;----------------------------------------------------------------
ext_SetFileEnd:
call extfsWritingInit
call findInode
stdcall findInode, ROOT_INODE
jc .error2
lea edi, [ebp+EXTFS.inodeBuffer]
movi eax, ERROR_ACCESS_DENIED
@@ -3226,7 +3251,7 @@ ext_Rename:
call extfsWritingInit
push esi
mov esi, edi
call findInode
stdcall findInode, ROOT_INODE
jnc .error
test edi, edi
jz .error
@@ -3237,7 +3262,7 @@ ext_Rename:
jnz .error_denied
xchg [esp], esi
push edi
call findInode
stdcall findInode, ROOT_INODE
pop edi
jc .error
xor edx, edx
@@ -3286,3 +3311,5 @@ ext_Rename:
call ext_unlock
pop eax ebx
ret
restore prologue@proc,epilogue@proc
+5 -5
View File
@@ -1163,9 +1163,9 @@ fat_entry_to_bdfe2:
push edi esi
mov edi, esi
mov esi, ebp
cmp byte [ebp-4], 2
cmp byte [ebp-4], ENC_UTF16
jz .utf16
cmp byte [ebp-4], 3
cmp byte [ebp-4], ENC_UTF8
jz .utf8
@@:
lodsw
@@ -1174,13 +1174,13 @@ fat_entry_to_bdfe2:
test al, al
jnz @b
pop esi edi
add esi, 264
add esi, FILENAME_LEN_CP866
.ret:
ret
.utf8:
push ecx
mov ecx, 519
mov ecx, FILENAME_LEN_UTF - 1
call UTF16to8_string
pop ecx
jmp @f
@@ -1192,7 +1192,7 @@ fat_entry_to_bdfe2:
jnz .utf16
@@:
pop esi edi
add esi, 520
add esi, FILENAME_LEN_UTF
ret
bdfe_to_fat_entry:
+100 -46
View File
@@ -1,13 +1,12 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2024. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2004-2026. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License. ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
UNIXTIME_TO_KOS_OFFSET = (365*31+8)*24*60*60 ; 01.01.1970 to 01.01.2001
ERROR_SUCCESS = 0
ERROR_DISK_BASE = 1
ERROR_UNSUPPORTED_FS = 2
@@ -24,8 +23,63 @@ ERROR_TOO_MANY_LINKS = 40
maxPathLength = 1000h
image_of_eax EQU esp+32
image_of_ebx EQU esp+20
macro omit_frame_pointer_prologue procname,flag,parmbytes,localbytes,reglist {
local loc
loc = (localbytes+3) and (not 3)
if localbytes
sub esp, loc
end if
irps reg, reglist \{ push reg \}
counter = 0
irps reg, reglist \{counter = counter+1 \}
parmbase@proc equ esp+counter*4+loc+4
localbase@proc equ esp+counter*4
}
macro omit_frame_pointer_epilogue procname,flag,parmbytes,localbytes,reglist {
local loc
loc = (localbytes+3) and (not 3)
irps reg, reglist \{ reverse pop reg \}
if localbytes
lea esp, [esp+loc]
end if
if flag and 10000b
retn
else
retn parmbytes
end if
}
struct bdfe_hdr
version dd ?
read_cnt dd ?
total_cnt dd ?
zeroed rd 5
ends
struct bdfe
attr dd ?
nameenc dd ?
ctime dd ?
cdate dd ?
atime dd ?
adate dd ?
mtime dd ?
mdate dd ?
size DQ ?
name rb 0
ends
FILENAME_LEN_CP866 = 264
FILENAME_LEN_UTF = 520
struct bdfe_cp866 bdfe
rb FILENAME_LEN_CP866
ends
struct bdfe_utf bdfe
rb FILENAME_LEN_UTF
ends
; fs api for drivers
struct FileSystem
@@ -70,7 +124,7 @@ fs_add:
; check all disks
mov esi, [disk_list]
.new_disk:
cmp dword[esi], disk_list
cmp [esi + LHEAD.next], disk_list
jz .end
push edx
@@ -157,14 +211,14 @@ proc file_system_is_operation_safe stdcall, inf_struct_ptr: dword
cmp dword [ebx], 1 ; if 70.1
jnz .case2_3
;mov ecx, 32
cmp dword [ebx + 8], 1 ; check encoding
cmp dword [ebx + 8], ENC_CP866
jbe .case1_304 ; if encdoing <= 1 i.e cpp866
mov ecx, 560 ; if unicode then bdvk block len is 560 bytes
mov ecx, sizeof.bdfe_utf
jmp .case1_end
.case1_304:
mov ecx, 304 ; if cp866 then bdvk block len is 304 bytes
mov ecx, sizeof.bdfe_cp866
.case1_end:
imul ecx, dword [ebx + 12] ; multiply bdvk length by their count
imul ecx, dword [ebx + 12] ; multiply bdfe length by their count
add ecx, 32 ; add result header len
jmp .end_switch
@@ -203,7 +257,7 @@ sys_fileSystemUnicode: ; with user pointer correctness checking
jz @f
DEBUGF 1, "sysfn80 addr error\n"
mov dword [image_of_eax], ERROR_MEMORY_POINTER
mov [esp+SYSCALL_STACK.eax], ERROR_MEMORY_POINTER
ret
@@:
jmp fileSystemUnicode
@@ -215,7 +269,7 @@ sys_file_system_lfn: ; with user pointer correctness checking
jz @f
DEBUGF 1, "sysfn70 addr error\n"
mov dword [image_of_eax], ERROR_MEMORY_POINTER
mov [esp+SYSCALL_STACK.eax], ERROR_MEMORY_POINTER
ret
@@:
jmp file_system_lfn
@@ -234,8 +288,8 @@ file_system_lfn_protected:
call file_system_lfn
call unprotect_from_terminate
popad
mov [image_of_eax], eax
mov [image_of_ebx], ebx
mov [esp+SYSCALL_STACK.eax], eax
mov [esp+SYSCALL_STACK.ebx], ebx
ret
fileSystemUnicode:
@@ -272,7 +326,7 @@ file_system_lfn:
mov ecx, [ebx+8]
mov ebx, ebp
call fs_execute
mov [image_of_eax], eax
mov [esp+SYSCALL_STACK.eax], eax
ret
@@:
@@ -284,7 +338,7 @@ file_system_lfn:
call dyndisk_handler ; not returns if success
.notfound:
stdcall kernel_free, ebp
mov dword[image_of_eax], ERROR_FILE_NOT_FOUND
mov [esp+SYSCALL_STACK.eax], ERROR_FILE_NOT_FOUND
ret
.CD:
@@ -325,21 +379,21 @@ file_system_lfn:
shl eax, 1
inc eax
shr edi, 2
mov dword[image_of_eax], ERROR_FILE_NOT_FOUND
mov [esp+SYSCALL_STACK.eax], ERROR_FILE_NOT_FOUND
bt [edi*5+DRIVE_DATA+1], ax
jnc @f
mov ecx, [ebx+12]
mov edx, [ebx+16]
mov eax, [ebx]
mov dword[image_of_eax], ERROR_UNSUPPORTED_FS
mov [esp+SYSCALL_STACK.eax], ERROR_UNSUPPORTED_FS
cmp eax, fs_NumCdServices
jae @f
add ebx, 4
push ebp
call dword[fs_CdServices + eax*4]
pop ebp
mov [image_of_eax], eax
mov [image_of_ebx], ebx
mov [esp+SYSCALL_STACK.eax], eax
mov [esp+SYSCALL_STACK.ebx], ebx
@@:
call free_cd_channel
and [cd_status], 0
@@ -404,7 +458,7 @@ file_system_lfn:
push edx
test eax, eax
jnz @b
cmp ebx, 2
cmp ebx, ENC_UTF16
jz .uni
@@:
pop eax
@@ -413,9 +467,9 @@ file_system_lfn:
test eax, eax
jnz @b
pop edi edx eax
cmp ebx, 3
cmp ebx, ENC_UTF8
jz @f
add edi, 264
add edi, FILENAME_LEN_CP866
jmp .maindir_loop
.uni:
@@ -426,7 +480,7 @@ file_system_lfn:
jnz .uni
pop edi edx eax
@@:
add edi, 520
add edi, FILENAME_LEN_UTF
jmp .maindir_loop
.maindir_done:
@@ -437,12 +491,12 @@ file_system_lfn:
js @f
mov al, ERROR_END_OF_FILE
@@:
mov [image_of_eax], eax
mov [image_of_ebx], ebx
mov [esp+SYSCALL_STACK.eax], eax
mov [esp+SYSCALL_STACK.ebx], ebx
ret
.access_denied:
mov dword[image_of_eax], ERROR_ACCESS_DENIED
mov [esp+SYSCALL_STACK.eax], ERROR_ACCESS_DENIED
ret
.deviceInfo:
@@ -451,7 +505,7 @@ file_system_lfn:
mov ecx, 40/4
rep stosd
pop edi
mov dword [edi], 0x10 ; attributes: folder
mov [edi+bdfe.attr], 0x10 ; attributes: folder
test ebp, ebp
jz @f
mov eax, dword[ebp+DISK.MediaInfo.Capacity]
@@ -460,10 +514,10 @@ file_system_lfn:
bsf ecx, ecx
shld edx, eax, cl
shl eax, cl
mov [edi+36], edx
mov [edi+32], eax
mov [edi+bdfe.size.hi], edx
mov [edi+bdfe.size.lo], eax
@@:
and dword[image_of_eax], 0
mov [esp+SYSCALL_STACK.eax], 0
ret
.rootdir: ; / - virtual root folder
@@ -475,8 +529,8 @@ file_system_lfn:
mov ecx, 40/4
rep stosd
pop edi
mov dword [edi], 0x10 ; attributes: folder
and dword[image_of_eax], 0
mov [edi+bdfe.attr], 0x10 ; attributes: folder
mov [esp+SYSCALL_STACK.eax], 0
ret
.rootdir_readfolder:
cmp byte [ebx], 1 ; read folder?
@@ -504,8 +558,8 @@ file_system_lfn:
dec ebp
js .rootdir_loop
inc dword[edx+4]
mov dword[edi], 16 ; attributes: folder
mov dword[edi+4], ebx ; name encoding
mov [edi+bdfe.attr], 0x10 ; attributes: folder
mov [edi+bdfe.nameenc], ebx ; name encoding
push eax
mov ecx, 32/4
add edi, 8
@@ -513,7 +567,7 @@ file_system_lfn:
rep stosd
push edi
lea esi, [esp+8]
cmp ebx, 2
cmp ebx, ENC_UTF16
jz .uni2
@@:
lodsb
@@ -521,9 +575,9 @@ file_system_lfn:
test eax, eax
jnz @b
pop edi eax
cmp ebx, 3
cmp ebx, ENC_UTF8
jz @f
add edi, 264
add edi, FILENAME_LEN_CP866
jmp .rootdir_loop
.uni2:
@@ -533,7 +587,7 @@ file_system_lfn:
jnz .uni2
pop edi eax
@@:
add edi, 520
add edi, FILENAME_LEN_UTF
jmp .rootdir_loop
.rootdirCD:
@@ -558,8 +612,8 @@ file_system_lfn:
dec ebp
js .rootdirCD_loop
inc dword[edx+4]
mov dword[edi], 16 ; attributes: folder
mov dword[edi+4], ebx ; name encoding
mov [edi+bdfe.attr], 0x10 ; attributes: folder
mov [edi+bdfe.nameenc], ebx ; name encoding
mov ecx, 32/4
add edi, 8
xor eax, eax
@@ -570,13 +624,13 @@ file_system_lfn:
jz @f
mov word [edi], 'cd'
mov [edi+2], ax
add edi, 264
add edi, FILENAME_LEN_CP866
jmp .rootdirCD_loop
@@:
mov dword[edi], 640063h
mov [edi+4], eax
add edi, 520
add edi, FILENAME_LEN_UTF
jmp .rootdirCD_loop
.rootdir_done:
@@ -587,8 +641,8 @@ file_system_lfn:
js @f
mov al, ERROR_END_OF_FILE
@@:
mov [image_of_eax], eax
mov [image_of_ebx], ebx
mov [esp+SYSCALL_STACK.eax], eax
mov [esp+SYSCALL_STACK.ebx], ebx
ret
;-----------------------------------------------------------------------------
@@ -790,9 +844,9 @@ getFullPath:
mov esi, ebp
dec edi
.absolute:
cmp byte [esp+4], 2
cmp byte [esp+4], ENC_UTF16
jz .utf16
cmp byte [esp+4], 3
cmp byte [esp+4], ENC_UTF8
jz .utf8
call cp866toUTF8_string
jns .end
+17 -17
View File
@@ -333,9 +333,9 @@ fs_CdReadFolder:
call cd_get_parameters_of_file
add edi, 40
mov ax, '.'
cmp dword[ebx+4], 2
cmp dword[ebx+4], ENC_UTF16
jz .utf16
cmp dword[ebx+4], 3
cmp dword[ebx+4], ENC_UTF8
jz .utf8
cmp [cd_counter_block], 2
jbe .parentDirectory
@@ -348,7 +348,7 @@ fs_CdReadFolder:
jc @b
@@:
mov [edi], byte 0
add [cd_mem_location], 304
add [cd_mem_location], sizeof.bdfe_cp866
jmp .get_names_from_buffer
.parentDirectory:
@@ -374,7 +374,7 @@ fs_CdReadFolder:
@@:
pop ecx
mov [edi], byte 0
add [cd_mem_location], 304
add [cd_mem_location], sizeof.bdfe_cp866
jmp .get_names_from_buffer
.checkForEnd:
@@ -405,7 +405,7 @@ fs_CdReadFolder:
jc @b
@@:
mov [edi], word 0
add [cd_mem_location], 560
add [cd_mem_location], sizeof.bdfe_utf
jmp .get_names_from_buffer
.utf16ParentDirectory:
@@ -503,9 +503,9 @@ fs_CdGetFileInfo:
mov ecx, 16
mov esi, CDDataBuf+40
add edi, 40
cmp eax, 2
cmp eax, ENC_UTF16
jz .utf16
cmp eax, 3
cmp eax, ENC_UTF8
jz .utf8
@@:
lodsw
@@ -742,7 +742,7 @@ cd_compare_name:
DESCRIPTOR_TYPE_BOOT = 0x00 ; not used
DESCRIPTOR_TYPE_PRIMARY = 0x01
DESCRIPTOR_TYPE_SUPPLEMENTARY = 0x02
; DESCRIPTOR_TYPE_PRIMARY for Juliet(UTF-16)
; DESCRIPTOR_TYPE_PRIMARY for Joliet(UTF-16)
DESCRIPTOR_TYPE_PARTITION = 0x02
DESCRIPTOR_TYPE_TERMANATOR = 0xff ; end scan descriptors
@@ -1235,7 +1235,7 @@ end virtual
movzx ecx, byte[ebx - 1]
cmp [ebp + ISO9660.type_encoding], 0
jnz .ucs2
cmp eax, 2
cmp eax, ENC_UTF16
je .ascii2utf16
@@:
sub ecx, 1 ; CF
@@ -1276,7 +1276,7 @@ end virtual
jmp .end_copy
;-----------------------------------------------------------------------------
.ucs2utf16:
cmp edx, 2 ; utf16 encoding
cmp edx, ENC_UTF16
jne .ucs2utf8
; convert ucs2 to utf16LE
@@:
@@ -1312,7 +1312,7 @@ end virtual
add edi, 264
cmp eax, 2
jb .skip
add edi, 520-264
add edi, FILENAME_LEN_UTF - FILENAME_LEN_CP866
.skip:
movzx ecx, byte[ebx]
add ebx, ecx
@@ -1736,13 +1736,13 @@ iso9660_copy_name:
cmp [ebp + ISO9660.type_encoding], 0
jnz .ucs2
cmp edx, 1 ; cp866 encoding
cmp edx, ENC_CP866
jne @f
; no convert chars
rep movsb
jmp .end_copy_name
@@:
cmp edx, 2 ; utf16 encoding
cmp edx, ENC_UTF16
jne .ascii2utf8
; convert ascii to utf16LE
@@:
@@ -1753,7 +1753,7 @@ iso9660_copy_name:
jmp .end_copy_name
.ascii2utf8:
cmp edx, 3 ; utf8 encoding
cmp edx, ENC_UTF8
jne .end_copy_name
; convert ascii to utf8
call cp866toUTF8_string
@@ -1761,7 +1761,7 @@ iso9660_copy_name:
.ucs2:
shr ecx, 1 ; ecx/2 - ucs2 chars
cmp edx, 1 ; cp866 encoding
cmp edx, ENC_CP866
jne .ucs2utf16
; convert ucs2 to ascii
@@:
@@ -1773,7 +1773,7 @@ iso9660_copy_name:
jmp .end_copy_name
.ucs2utf16:
cmp edx, 2 ; utf16 encoding
cmp edx, ENC_UTF16
jne .ucs2utf8
; convert ucs2 to utf16LE
@@:
@@ -1784,7 +1784,7 @@ iso9660_copy_name:
jmp .end_copy_name
.ucs2utf8:
cmp edx, 3 ; utf8 encoding
cmp edx, ENC_UTF8
jne .end_copy_name
; convert ucs2 to utf8
mov ebx, ecx
+9 -9
View File
@@ -1638,14 +1638,14 @@ ntfs_ReadFolder:
mov al, '.'
push edi ecx
lea ecx, [esi+1]
cmp dword[edi-36], 2
cmp dword[edi-36], ENC_UTF16
jz .utf16sp
rep stosb
mov byte [edi], 0
pop ecx edi
cmp dword[edi-36], 3
cmp dword[edi-36], ENC_UTF8
jz @f
add edi, 264
add edi, FILENAME_LEN_CP866
ret
.utf16sp:
@@ -1653,7 +1653,7 @@ ntfs_ReadFolder:
mov word [edi], 0
pop ecx edi
@@:
add edi, 520
add edi, FILENAME_LEN_UTF
.ret:
ret
@@ -1678,9 +1678,9 @@ ntfs_ReadFolder:
push ecx esi edi
movzx ecx, byte [esi+fileNameLength]
add esi, fileName
cmp dword[edi-36], 2
cmp dword[edi-36], ENC_UTF16
jz .utf16
cmp dword[edi-36], 3
cmp dword[edi-36], ENC_UTF8
jz .utf8
@@:
lodsw
@@ -1689,12 +1689,12 @@ ntfs_ReadFolder:
loop @b
mov byte [edi], 0
pop edi esi ecx
add edi, 264
add edi, FILENAME_LEN_CP866
ret
.utf8:
push ecx
mov cx, 519
mov cx, FILENAME_LEN_UTF - 1
@@:
lodsw
call UTF16to8
@@ -1706,7 +1706,7 @@ ntfs_ReadFolder:
pop edi
@@:
pop edi esi ecx
add edi, 520
add edi, FILENAME_LEN_UTF
ret
.utf16:
+25 -43
View File
@@ -8,33 +8,6 @@
include 'xfs.inc'
macro omit_frame_pointer_prologue procname,flag,parmbytes,localbytes,reglist {
local loc
loc = (localbytes+3) and (not 3)
if localbytes
sub esp, loc
end if
irps reg, reglist \{ push reg \}
counter = 0
irps reg, reglist \{counter = counter+1 \}
parmbase@proc equ esp+counter*4+loc+4
localbase@proc equ esp
}
macro omit_frame_pointer_epilogue procname,flag,parmbytes,localbytes,reglist {
local loc
loc = (localbytes+3) and (not 3)
irps reg, reglist \{ reverse pop reg \}
if localbytes
lea esp, [esp+loc]
end if
if flag and 10000b
retn
else
retn parmbytes
end if
}
prologue@proc equ omit_frame_pointer_prologue
epilogue@proc equ omit_frame_pointer_epilogue
@@ -642,7 +615,8 @@ proc xfs._.readdir_block _literal_area, _out_buf
mov eax, ebx
mov ebx, [ebp+XFS.cur_dirblock]
stdcall xfs._.extent_unpack, eax
stdcall xfs._.read_dirblock, [ebp+XFS.extent.br_startblock.lo], [ebp+XFS.extent.br_startblock.hi], ebx
stdcall xfs._.read_dirblock, [ebp+XFS.extent.br_startblock.lo], \
[ebp+XFS.extent.br_startblock.hi], ebx
mov edx, [_out_buf]
jnz .error
mov eax, [ebp+XFS.dir_block_magic]
@@ -691,7 +665,8 @@ proc xfs._.readdir_leaf_node uses esi, _inode_data, _out_buf
mov [ebp+XFS.offset_end.lo], ecx
mov ecx, [ebp+XFS.dir2_free_offset_blocks.hi]
mov [ebp+XFS.offset_end.hi], ecx
stdcall xfs._.walk_extent_list, edx, eax, xfs._.extent_iterate_dirblocks, xfs._.leafn_calc_entries, 0
stdcall xfs._.walk_extent_list, edx, eax, \
xfs._.extent_iterate_dirblocks, xfs._.leafn_calc_entries, 0
jnz .error
mov eax, [ebp+XFS.entries_read]
mov edx, [_out_buf]
@@ -712,7 +687,8 @@ proc xfs._.readdir_leaf_node uses esi, _inode_data, _out_buf
mov ecx, [ebp+XFS.dir2_leaf_offset_blocks.hi]
mov [ebp+XFS.offset_end.hi], ecx
pop ecx
stdcall xfs._.walk_extent_list, edx, eax, xfs._.extent_iterate_dirblocks, xfs._.dir_btree_skip_read, ecx
stdcall xfs._.walk_extent_list, edx, eax, \
xfs._.extent_iterate_dirblocks, xfs._.dir_btree_skip_read, ecx
; jnz .error
.error:
.quit:
@@ -820,7 +796,8 @@ proc xfs._.readdir_btree uses esi, _inode_data, _out_buf
mov [ebp+XFS.offset_end.lo], ecx
mov ecx, [ebp+XFS.dir2_free_offset_blocks.hi]
mov [ebp+XFS.offset_end.hi], ecx
stdcall xfs._.walk_btree, edx, eax, xfs._.extent_iterate_dirblocks, xfs._.leafn_calc_entries, 0, 1
stdcall xfs._.walk_btree, edx, eax, xfs._.extent_iterate_dirblocks, \
xfs._.leafn_calc_entries, 0, 1
mov eax, [ebp+XFS.entries_read]
mov edx, [_out_buf]
mov [edx+bdfe_hdr.total_cnt], eax
@@ -845,7 +822,8 @@ proc xfs._.readdir_btree uses esi, _inode_data, _out_buf
mov ecx, [_out_buf]
push ecx
mov ecx, esp
stdcall xfs._.walk_btree, edx, eax, xfs._.extent_iterate_dirblocks, xfs._.dir_btree_skip_read, ecx, 1
stdcall xfs._.walk_btree, edx, eax, xfs._.extent_iterate_dirblocks, \
xfs._.dir_btree_skip_read, ecx, 1
pop ecx
.error:
.quit:
@@ -855,9 +833,9 @@ endp
proc xfs._.copy_filename uses eax
mov eax, [ebp+XFS.bdfe_nameenc]
cmp eax, 3
cmp eax, ENC_UTF8
jz .utf8
cmp eax, 2
cmp eax, ENC_UTF16
jz .utf16
.cp866:
call unicode.utf8.decode
@@ -898,10 +876,10 @@ proc xfs._.readdir uses ebx esi edi, _start_number, _entries_to_read, _dst, _src
mov [ebp+XFS.requested_cnt], eax
mov eax, [_encoding]
mov [ebp+XFS.bdfe_nameenc], eax
mov ecx, 304
cmp eax, 1 ; CP866
mov ecx, sizeof.bdfe_cp866
cmp eax, ENC_CP866
jbe @f
mov ecx, 560
mov ecx, sizeof.bdfe_utf
@@:
mov [ebp+XFS.bdfe_len], ecx
mov edx, [_dst]
@@ -1064,7 +1042,8 @@ proc xfs._.get_inode_by_addr uses ebx esi edi, _inode_buf
mov [ebp+XFS.offset_begin.lo], eax
mov [ebp+XFS.offset_begin.hi], edx
stdcall xfs._.extent_list.seek, ecx
stdcall xfs._.read_dirblock, [ebp+XFS.extent.br_startblock.lo], [ebp+XFS.extent.br_startblock.hi], [ebp+XFS.cur_dirblock]
stdcall xfs._.read_dirblock, [ebp+XFS.extent.br_startblock.lo], \
[ebp+XFS.extent.br_startblock.hi], [ebp+XFS.cur_dirblock]
jnz .error
jmp .common
.btree:
@@ -1150,7 +1129,8 @@ endl
mov [ebp+XFS.offset_begin.lo], esi
mov [ebp+XFS.offset_begin.hi], 0
stdcall xfs._.extent_list.seek, edx
stdcall xfs._.read_dirblock, [ebp+XFS.extent.br_startblock.lo], [ebp+XFS.extent.br_startblock.hi], [ebp+XFS.cur_dirblock]
stdcall xfs._.read_dirblock, [ebp+XFS.extent.br_startblock.lo], \
[ebp+XFS.extent.br_startblock.hi], [ebp+XFS.cur_dirblock]
jnz .error
mov ebx, [ebp+XFS.cur_dirblock]
movzx eax, [ebp+XFS.da_node_magic]
@@ -1363,7 +1343,8 @@ proc xfs_ReadFolder uses esi edi
stdcall xfs_read_inode, eax, edx, [ebp+XFS.cur_inode]
test eax, eax
jnz .error
stdcall xfs._.readdir, [ebx+f70s1arg.start_idx], [ebx+f70s1arg.count], [ebx+f70s1arg.buf], edx, [ebx+f70s1arg.encoding]
stdcall xfs._.readdir, [ebx+f70s1arg.start_idx], [ebx+f70s1arg.count], \
[ebx+f70s1arg.buf], edx, [ebx+f70s1arg.encoding]
test eax, eax
jnz .error
mov edx, [ebx+f70s1arg.buf]
@@ -1406,7 +1387,6 @@ endp
proc xfs._.conv_bigtime_to_kos_epoch
NANOSEC_PER_SEC = 1_000_000_000
BIGTIME_TO_UNIX_OFFSET = 0x80000000 ; int32 min
UNIXTIME_TO_KOS_OFFSET = (365*31+8)*24*60*60 ; 01.01.1970--01.01.2001
BIGTIME_TO_KOS_OFFSET = BIGTIME_TO_UNIX_OFFSET + UNIXTIME_TO_KOS_OFFSET
BIGTIME_TO_KOS_OFFSET_NS = BIGTIME_TO_KOS_OFFSET * NANOSEC_PER_SEC
movbe edx, [ecx+DQ.hi_be]
@@ -1993,7 +1973,8 @@ proc xfs._.walk_btree uses ebx esi edi, _ptr, _size, _callback_extent, _callback
movzx ecx, [ebx+xfs_bmbt_block.bb_numrecs]
xchg cl, ch
add ebx, [ebp+XFS.bmbt_block_size]
stdcall xfs._.walk_extent_list, ecx, ebx, [_callback_extent+8], [_callback_block+4], [_callback_data]
stdcall xfs._.walk_extent_list, ecx, ebx, [_callback_extent+8], \
[_callback_block+4], [_callback_data]
jnz .error
mov esi, [ebp+XFS.offset_begin.lo]
mov edi, [ebp+XFS.offset_begin.hi]
@@ -2094,7 +2075,8 @@ proc xfs._.extent_iterate_dirblocks _callback, _callback_data
cmp esi, [ebp+XFS.offset_end.lo]
jae .quit
.read_dirblock:
stdcall xfs._.read_dirblock, [ebp+XFS.extent.br_startblock.lo], [ebp+XFS.extent.br_startblock.hi], [ebp+XFS.cur_dirblock]
stdcall xfs._.read_dirblock, [ebp+XFS.extent.br_startblock.lo], \
[ebp+XFS.extent.br_startblock.hi], [ebp+XFS.cur_dirblock]
mov edx, [ebp+XFS.cur_dirblock]
mov eax, [_callback]
stdcall eax, edx, esi, edi, [_callback_data]
-20
View File
@@ -598,23 +598,3 @@ struct f70s5arg
zero db ?
path dd ?
ends
struct bdfe_hdr
version dd ?
read_cnt dd ?
total_cnt dd ?
zeroed rd 5
ends
struct bdfe
attr dd ?
nameenc dd ?
ctime dd ?
cdate dd ?
atime dd ?
adate dd ?
mtime dd ?
mdate dd ?
size DQ ?
name db ?
ends