one-string path for filesystems, some cleaning

git-svn-id: svn://kolibrios.org@6468 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
pathoswithin 2016-08-02 20:28:34 +00:00
parent 25b23034ea
commit 1048443a57
6 changed files with 376 additions and 587 deletions

View File

@ -1045,8 +1045,7 @@ endg
; This function is called from file_system_lfn. ; This function is called from file_system_lfn.
; This handler gets the control each time when fn 70 is called ; This handler gets the control each time when fn 70 is called
; with unknown item of root subdirectory. ; with unknown item of root subdirectory.
; in: esi -> name ; in: esi = ebp -> path string
; ebp = 0 or rest of name relative to esi
; out: if the handler processes path, it must not return in file_system_lfn, ; out: if the handler processes path, it must not return in file_system_lfn,
; but instead pop return address and return directly to the caller ; but instead pop return address and return directly to the caller
; otherwise simply return ; otherwise simply return
@ -1142,6 +1141,25 @@ dyndisk_handler:
@@: @@:
; 11c. Let the procedure from fs_lfn.inc do the job. ; 11c. Let the procedure from fs_lfn.inc do the job.
jmp file_system_lfn.maindir_noesi jmp file_system_lfn.maindir_noesi
.access_denied:
mov dword [esp+32], ERROR_ACCESS_DENIED
mov esi, ecx ; disk*dereference assume that esi points to DISK
.cleanup_esi:
test edx, edx ; if there are no media, we didn't reference it
jz @f
call disk_media_dereference
@@:
call disk_dereference
stdcall kernel_free, ebp
ret
.dyndisk_cleanup:
pop esi
pop edx
mov dword [esp+32], ERROR_FILE_NOT_FOUND
jmp .cleanup_esi
.haspartition: .haspartition:
; 12. The fs operation has specified some partition. ; 12. The fs operation has specified some partition.
push edx push edx
@ -1160,36 +1178,84 @@ dyndisk_handler:
jnz .dyndisk_cleanup jnz .dyndisk_cleanup
dec esi dec esi
@@: @@:
cmp byte [esi], 0 dec ecx ; convert to zero-based partition index
jnz @f pop edx ; edx = pointer to DISK, dword [esp] = NULL or edx
test ebp, ebp ; If the driver does not support insert notifications and we are the only fs
jz @f ; operation with this disk, ask the driver whether the media
mov esi, ebp ; was inserted/removed/changed. Otherwise, assume that media status is valid.
xor ebp, ebp test byte [edx+DISK.DriverFlags], DISK_NO_INSERT_NOTIFICATION
@@: jz .media_accurate
jmp fs_dyndisk push ecx esi
mov esi, edx
.dyndisk_cleanup: cmp dword [esp+8], 0
pop esi jz .test_no_media
cmp [esi+DISK.MediaRefCount], 2
jnz .media_accurate_pop
lea edx, [esi+DISK.MediaInfo]
and [edx+DISKMEDIAINFO.Flags], 0
mov al, DISKFUNC.querymedia
stdcall disk_call_driver, edx
test eax, eax
jz .media_accurate_pop
stdcall disk_media_dereference ; drop our reference so that disk_media_changed could close the media
stdcall disk_media_changed, esi, 0
and dword [esp+8], 0 ; no media
.test_no_media:
stdcall disk_media_changed, esi, 1 ; issue fake notification
; if querymedia() inside disk_media_changed returns error, the notification is ignored
cmp [esi+DISK.MediaInserted], 0
jz .media_accurate_pop
lock inc [esi+DISK.MediaRefCount]
mov dword [esp+8], esi
.media_accurate_pop:
mov edx, esi
pop esi ecx
.media_accurate:
pop eax
test eax, eax
jz .nomedia
cmp ecx, [edx+DISK.NumPartitions]
jae .notfound2
mov eax, [edx+DISK.Partitions]
mov eax, [eax+ecx*4]
mov edi, [eax+PARTITION.FSUserFunctions]
mov ecx, [ebx]
cmp [edi+4], ecx
jbe .unsupported
push edx
push ebp
mov ebp, eax
call dword [edi+8+ecx*4]
pop ebp
pop edx pop edx
mov dword [esp+32], ERROR_FILE_NOT_FOUND mov dword [esp+32], eax
jmp .cleanup_esi mov dword [esp+20], ebx
.access_denied:
; 13. Fail the operation with the appropriate code.
mov dword [esp+32], ERROR_ACCESS_DENIED
.cleanup: .cleanup:
; 14. Cleanup. mov esi, edx
mov esi, ecx ; disk*dereference assume that esi points to DISK
.cleanup_esi:
test edx, edx ; if there are no media, we didn't reference it
jz @f
call disk_media_dereference call disk_media_dereference
@@: @@:
call disk_dereference call disk_dereference
; 15. Return. stdcall kernel_free, ebp
ret ret
.unsupported:
mov dword [esp+32], ERROR_UNKNOWN_FS
cmp edi, default_fs_functions
jz .cleanup
mov dword [esp+32], ERROR_UNSUPPORTED_FS
jmp .cleanup
.notfound2:
mov dword [esp+32], ERROR_FILE_NOT_FOUND
jmp .cleanup
.nomedia:
test ecx, ecx
jnz .notfound2
mov dword [esp+32], ERROR_DEVICE
mov esi, edx
jmp @b
; This is a callback for enumerating partitions called from ; This is a callback for enumerating partitions called from
; file_system_lfn.maindir in the case of inserted media. ; file_system_lfn.maindir in the case of inserted media.
; It just increments eax until DISK.NumPartitions reached and then ; It just increments eax until DISK.NumPartitions reached and then
@ -1228,86 +1294,6 @@ fs_dyndisk_next_nomedia:
stc stc
ret ret
; esp -> {dd pointer to DISK, dd media object}
; ecx = partition number, esi+ebp = ASCIIZ name
fs_dyndisk:
dec ecx ; convert to zero-based partition index
pop edx ; edx = pointer to DISK, dword [esp] = NULL or edx
; If the driver does not support insert notifications and we are the only fs
; operation with this disk, ask the driver whether the media
; was inserted/removed/changed. Otherwise, assume that media status is valid.
test byte [edx+DISK.DriverFlags], DISK_NO_INSERT_NOTIFICATION
jz .media_accurate
push ecx esi
mov esi, edx
cmp dword [esp+8], 0
jz .test_no_media
cmp [esi+DISK.MediaRefCount], 2
jnz .media_accurate_pop
lea edx, [esi+DISK.MediaInfo]
and [edx+DISKMEDIAINFO.Flags], 0
mov al, DISKFUNC.querymedia
stdcall disk_call_driver, edx
test eax, eax
jz .media_accurate_pop
stdcall disk_media_dereference ; drop our reference so that disk_media_changed could close the media
stdcall disk_media_changed, esi, 0
and dword [esp+8], 0 ; no media
.test_no_media:
stdcall disk_media_changed, esi, 1 ; issue fake notification
; if querymedia() inside disk_media_changed returns error, the notification is ignored
cmp [esi+DISK.MediaInserted], 0
jz .media_accurate_pop
lock inc [esi+DISK.MediaRefCount]
mov dword [esp+8], esi
.media_accurate_pop:
mov edx, esi
pop esi ecx
.media_accurate:
pop eax
test eax, eax
jz .nomedia
.main:
cmp ecx, [edx+DISK.NumPartitions]
jae .notfound
mov eax, [edx+DISK.Partitions]
mov eax, [eax+ecx*4]
mov edi, [eax+PARTITION.FSUserFunctions]
mov ecx, [ebx]
cmp [edi+4], ecx
jbe .unsupported
push edx
push ebp
mov ebp, eax
call dword [edi+8+ecx*4]
pop ebp
pop edx
mov dword [esp+32], eax
mov dword [esp+20], ebx
.cleanup:
mov esi, edx
call disk_media_dereference
call disk_dereference
ret
.nofs:
mov dword [esp+32], ERROR_UNKNOWN_FS
jmp .cleanup
.notfound:
mov dword [esp+32], ERROR_FILE_NOT_FOUND
jmp .cleanup
.unsupported:
cmp edi, default_fs_functions
jz .nofs
mov dword [esp+32], ERROR_UNSUPPORTED_FS
jmp .cleanup
.nomedia:
test ecx, ecx
jnz .notfound
mov dword [esp+32], ERROR_DEVICE
mov esi, edx
call disk_dereference
ret
; This function is called from file_system_lfn. ; This function is called from file_system_lfn.
; This handler is called when virtual root is enumerated ; This handler is called when virtual root is enumerated
; and must return all items which can be handled by this. ; and must return all items which can be handled by this.

View File

@ -11,7 +11,7 @@ $Revision$
; in: ; in:
; ebx -> parameter structure of sysfunc 70 ; ebx -> parameter structure of sysfunc 70
; ebp -> EXTFS structure ; ebp -> EXTFS structure
; [esi]+[[esp+4]] = name ; esi -> path string
; out: ; out:
; eax, ebx = return values for sysfunc 70 ; eax, ebx = return values for sysfunc 70
iglobal iglobal
@ -1444,12 +1444,12 @@ findInode_parent:
pop esi pop esi
.get_inode: .get_inode:
push ebx edx push ebx edx
stdcall findInode, 0 call findInode
pop edx ebx pop edx ebx
ret ret
findInode: findInode:
; in: [esi]+[[esp+4]] = name ; in: esi -> path string
; out: ; out:
; [ebp+EXTFS.mainInodeBuffer] = inode ; [ebp+EXTFS.mainInodeBuffer] = inode
; esi = inode number ; esi = inode number
@ -1469,7 +1469,7 @@ findInode:
xor eax, eax xor eax, eax
xor dl, dl xor dl, dl
mov esi, ROOT_INODE mov esi, ROOT_INODE
ret 4 ret
.next_path_part: .next_path_part:
push [edx+INODE.sectorsUsed] push [edx+INODE.sectorsUsed]
@ -1534,12 +1534,7 @@ findInode:
cmp edi, esi cmp edi, esi
je .next_folder_block je .next_folder_block
cmp byte [esi], 0 cmp byte [esi], 0
jnz @f
cmp dword[esp+8], 0
je .get_inode_ret je .get_inode_ret
mov esi, [esp+8]
mov dword[esp+8], 0
@@:
mov eax, [ebx+DIRENTRY.inodeNumber] mov eax, [ebx+DIRENTRY.inodeNumber]
lea ebx, [ebp+EXTFS.mainInodeBuffer] lea ebx, [ebp+EXTFS.mainInodeBuffer]
call readInode call readInode
@ -1567,18 +1562,18 @@ findInode:
lea ebx, [ebp+EXTFS.mainInodeBuffer] lea ebx, [ebp+EXTFS.mainInodeBuffer]
mov esi, eax mov esi, eax
call readInode call readInode
ret 4 ret
.not_found: .not_found:
movi eax, ERROR_FILE_NOT_FOUND movi eax, ERROR_FILE_NOT_FOUND
stc stc
ret 4 ret
.error_get_block: .error_get_block:
pop ebx pop ebx
.error_get_inode: .error_get_inode:
pop ebx pop ebx
ret 4 ret
writeSuperblock: writeSuperblock:
push ebx push ebx
@ -1614,7 +1609,7 @@ ext_ReadFolder:
cmp byte [esi], 0 cmp byte [esi], 0
jz .root_folder jz .root_folder
push ebx push ebx
stdcall findInode, [esp+4+4] call findInode
pop ebx pop ebx
jc .error_ret jc .error_ret
lea esi, [ebp+EXTFS.mainInodeBuffer] lea esi, [ebp+EXTFS.mainInodeBuffer]
@ -1801,7 +1796,7 @@ ext_ReadFile:
cmp byte [esi], 0 cmp byte [esi], 0
jz .error ; root jz .error ; root
mov [esp], ebx mov [esp], ebx
stdcall findInode, [esp+4+4] call findInode
pop ebx pop ebx
jc .error_eax jc .error_eax
push ERROR_ACCESS_DENIED push ERROR_ACCESS_DENIED
@ -1931,7 +1926,7 @@ ext_GetFileInfo:
cmp byte [esi], 0 cmp byte [esi], 0
jz .is_root jz .is_root
push edx push edx
stdcall findInode, [esp+4+4] call findInode
mov ebx, edx mov ebx, edx
pop edx pop edx
lea esi, [ebp+EXTFS.mainInodeBuffer] lea esi, [ebp+EXTFS.mainInodeBuffer]
@ -1982,7 +1977,7 @@ ext_GetFileInfo:
ext_SetFileInfo: ext_SetFileInfo:
call extfsWritingInit call extfsWritingInit
pushd [ebx+16] pushd [ebx+16]
stdcall findInode, [esp+4+4] call findInode
pop edx pop edx
jc @f jc @f
push esi ; inode number push esi ; inode number
@ -2014,7 +2009,7 @@ ext_SetFileInfo:
ext_Delete: ext_Delete:
call extfsWritingInit call extfsWritingInit
push esi push esi
stdcall findInode, [esp+4+4] call findInode
mov ebx, esi mov ebx, esi
pop esi pop esi
push eax push eax
@ -2216,7 +2211,7 @@ ext_Delete:
ext_CreateFolder: ext_CreateFolder:
call extfsWritingInit call extfsWritingInit
push esi push esi
stdcall findInode, [esp+4+4] call findInode
pop esi pop esi
jnc .success ; exist jnc .success ; exist
call findInode_parent call findInode_parent
@ -2300,12 +2295,12 @@ parent_link db "..", 0
ext_CreateFile: ext_CreateFile:
call extfsWritingInit call extfsWritingInit
push ebx esi push ebx esi
stdcall findInode, [esp+8+4] call findInode
mov esi, [esp] mov esi, [esp]
jc @f jc @f
call ext_unlock call ext_unlock
stdcall ext_Delete, [esp+8+4] call ext_Delete
mov [esp], eax push eax
call ext_lock call ext_lock
pop eax pop eax
test eax, eax test eax, eax
@ -2359,7 +2354,7 @@ ext_CreateFile:
ext_WriteFile: ext_WriteFile:
call extfsWritingInit call extfsWritingInit
push 0 ebx push 0 ebx
stdcall findInode, [esp+8+4] call findInode
jc .error jc .error
lea edx, [ebp+EXTFS.mainInodeBuffer] lea edx, [ebp+EXTFS.mainInodeBuffer]
movi eax, ERROR_ACCESS_DENIED movi eax, ERROR_ACCESS_DENIED
@ -2482,7 +2477,7 @@ ext_WriteFile:
ext_SetFileEnd: ext_SetFileEnd:
call extfsWritingInit call extfsWritingInit
pushd [ebx+4] pushd [ebx+4]
stdcall findInode, [esp+4+4] call findInode
pop ecx pop ecx
jc @f jc @f
lea edx, [ebp+EXTFS.mainInodeBuffer] lea edx, [ebp+EXTFS.mainInodeBuffer]

View File

@ -1,50 +1,37 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License. ;;
;; ;;
;; FAT functions for KolibriOS ;;
;; ;;
;; Copyright 2002 Paolo Minazzi, paolo.minazzi@inwind.it ;;
;; ;;
;; See file COPYING for details ;;
;; 06.2015 fs_read64 - pathoswithin ;;
;; 04.02.2007 LFN create folder - diamond ;;
;; 08.10.2006 LFN delete file/folder - diamond ;;
;; 20.08.2006 LFN set file size (truncate/extend) - diamond ;;
;; 17.08.2006 LFN write/append to file - diamond ;;
;; 23.06.2006 LFN start application - diamond ;;
;; 15.06.2006 LFN get/set file/folder info - diamond ;;
;; 27.05.2006 LFN create/rewrite file - diamond ;;
;; 04.05.2006 LFN read folder - diamond ;;
;; 29.04.2006 Elimination of hangup after the ;;
;; expiration hd_wait_timeout - Mario79 ;;
;; 23.04.2006 LFN read file - diamond ;;
;; 28.01.2006 find all Fat16/32 partition in all input point ;;
;; to MBR, see file part_set.inc - Mario79 ;;
;; 15.01.2005 get file size/attr/date, file_append - ATV ;;
;; 04.12.2004 skip volume label, file delete bug fixed - ATV ;;
;; 29.11.2004 get_free_FAT changed, append dir bug fixed - ATV ;;
;; 23.11.2004 don't allow overwrite dir with file - ATV ;;
;; 18.11.2004 get_disk_info and more error codes - ATV ;;
;; 17.11.2004 set_FAT/get_FAT and disk cache rewritten - ATV ;;
;; 10.11.2004 removedir clear whole directory structure - ATV ;;
;; 08.11.2004 rename - ATV ;;
;; 30.10.2004 file_read return also dirsize in bytes - ATV ;;
;; 20.10.2004 Makedir/Removedir - ATV ;;
;; 14.10.2004 Partition chain/Fat16 - ATV (thanks drh3xx) ;;
;; 06.09.2004 Fix free space - Mario79 ;;
;; 24.05.2004 Write back buffer for File_write - VT ;;
;; 20.05.2004 File_read function to work with syscall 58 - VT ;;
;; 30.03.2004 Error parameters at function return - VT ;;
;; 29.06.2002 Improved fat32 verification - VT ;;
;; 20.05.2002 Hd status check - VT ;;
;; 01.05.2002 Bugfix in device write - VT ;;
;; ;; ;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$Revision$ $Revision$
; FAT external functions
; in:
; ebx -> parameter structure of sysfunc 70
; ebp -> FAT structure
; esi -> path string
; out:
; eax, ebx = return values for sysfunc 70
iglobal
align 4
fat_user_functions:
dd fat_free
dd (fat_user_functions_end - fat_user_functions - 4) / 4
dd fat_Read
dd fat_ReadFolder
dd fat_CreateFile
dd fat_Write
dd fat_SetFileEnd
dd fat_GetFileInfo
dd fat_SetFileInfo
dd 0
dd fat_Delete
dd fat_CreateFolder
fat_user_functions_end:
endg
cache_max equ 1919 ; max. is 1919*512+0x610000=0x6ffe00 cache_max equ 1919 ; max. is 1919*512+0x610000=0x6ffe00
PUSHAD_EAX equ [esp+28] PUSHAD_EAX equ [esp+28]
@ -57,84 +44,56 @@ PUSHAD_EDI equ [esp+0]
; Internal data for every FAT partition. ; Internal data for every FAT partition.
struct FAT PARTITION struct FAT PARTITION
fs_type db ? fs_type db ?
fat16_root db 0 ; flag for fat16 rootdir fat_change db ? ; 1=fat has changed
fat_change db 0 ; 1=fat has changed rb 2
rb 1 Lock MUTEX ; currently operations with one partition
Lock MUTEX ? ; currently operations with one partition
; can not be executed in parallel since the legacy code is not ready ; can not be executed in parallel since the legacy code is not ready
SECTORS_PER_FAT dd 0x1f3a SECTORS_PER_FAT dd ?
NUMBER_OF_FATS dd 0x2 NUMBER_OF_FATS dd ?
SECTORS_PER_CLUSTER dd 0x8 SECTORS_PER_CLUSTER dd ?
BYTES_PER_SECTOR dd 0x200 ; Note: if BPS <> 512 need lots of changes BYTES_PER_SECTOR dd ? ; Note: if BPS <> 512 need lots of changes
ROOT_CLUSTER dd 2 ; first rootdir cluster ROOT_CLUSTER dd ? ; first rootdir cluster
FAT_START dd 0 ; start of fat table FAT_START dd ? ; start of fat table
ROOT_START dd 0 ; start of rootdir (only fat16) ROOT_START dd ? ; start of rootdir (only fat16)
ROOT_SECTORS dd 0 ; count of rootdir sectors (only fat16) ROOT_SECTORS dd ? ; count of rootdir sectors (only fat16)
DATA_START dd 0 ; start of data area (=first cluster 2) DATA_START dd ? ; start of data area (=first cluster 2)
LAST_CLUSTER dd 0 ; last availabe cluster LAST_CLUSTER dd ? ; last availabe cluster
ADR_FSINFO dd 0 ; used only by fat32 ADR_FSINFO dd ? ; used only by fat32
fatRESERVED dd ?
fatRESERVED dd 0x0FFFFFF6 fatBAD dd ?
fatBAD dd 0x0FFFFFF7 fatEND dd ?
fatEND dd 0x0FFFFFF8 fatMASK dd ?
fatMASK dd 0x0FFFFFFF fatStartScan dd ?
cluster_tmp dd ? ; used by analyze_directory and analyze_directory_to_write
fatStartScan dd 2 longname_sec1 dd ? ; used by analyze_directory to save 2 previous
cluster_tmp dd 0 ; used by analyze_directory longname_sec2 dd ? ; directory sectors for delete long filename
; and analyze_directory_to_write fat_in_cache dd ?
longname_sec1 dd 0 ; used by analyze_directory to save 2 previous
longname_sec2 dd 0 ; directory sectors for delete long filename
fat_in_cache dd -1
; For FAT16/FAT32, this points to 512-byte buffer for the current sector of FAT. ; For FAT16/FAT32, this points to 512-byte buffer for the current sector of FAT.
; For FAT12, the entire FAT structure is read ; For FAT12, the entire FAT structure is read
; and unpacked from 12bit per cluster to word per cluster. ; and unpacked from 12bit per cluster to word per cluster.
; Note: work with unpacked copy of FAT12 means ; Note: work with unpacked copy of FAT12 means
; additional memory and additional code for packing/unpacking. ; additional memory and additional code for packing/unpacking.
; I'm not sure that the economy justifies the cost, but anyway, ; I'm not sure that the economy justifies the cost, but anyway,
; there is how work was done before my edits, and I'm just keeping the principle. ; there is how work was done before my edits, and I'm just keeping the principle.
fat_cache_ptr dd ? fat_cache_ptr dd ?
fat12_unpacked_ptr dd ? fat12_unpacked_ptr dd ?
buffer rb 512 buffer rb 512
fsinfo_buffer rb 512 fsinfo_buffer rb 512
ends ends
uglobal uglobal
align 4 align 4
partition_count dd 0 ; partitions found by set_FAT32_variables partition_count dd ? ; partitions found by set_FAT32_variables
hd_error dd 0 hd_error dd ?
hd_setup dd 0 hd_setup dd ?
hd_wait_timeout dd 0 hd_wait_timeout dd ?
cache_search_start dd 0 ; used by find_empty_slot cache_search_start dd ? ; used by find_empty_slot
endg
uglobal
align 4
Sector512: ; label for dev_hdcd.inc Sector512: ; label for dev_hdcd.inc
buffer: buffer:
rb 512 rb 512
endg endg
iglobal
align 4
fat_user_functions:
dd fat_free
dd (fat_user_functions_end - fat_user_functions - 4) / 4
dd fat_Read
dd fat_ReadFolder
dd fat_Rewrite
dd fat_Write
dd fat_SetFileEnd
dd fat_GetFileInfo
dd fat_SetFileInfo
dd 0
dd fat_Delete
dd fat_CreateFolder
fat_user_functions_end:
endg
; these labels are located before the main function to make ; these labels are located before the main function to make
; most of jumps to these be short ; most of jumps to these be short
fat_create_partition.free_return0: fat_create_partition.free_return0:
@ -1598,11 +1557,9 @@ bdfe_to_fat_entry:
ret ret
hd_find_lfn: hd_find_lfn:
; in: ebp -> FAT structure ; in: esi -> path string
; in: esi+[esp+4] -> name
; out: CF=1 - file not found, eax=error code ; out: CF=1 - file not found, eax=error code
; else CF=0 and edi->direntry, eax=sector ; else CF=0 and edi->direntry, eax=sector
; destroys eax
push esi edi push esi edi
push 0 push 0
push 0 push 0
@ -1618,7 +1575,6 @@ hd_find_lfn:
jc .notfound jc .notfound
cmp byte [esi], 0 cmp byte [esi], 0
jz .found jz .found
.continue:
test byte [edi+11], 10h test byte [edi+11], 10h
jz .notfound jz .notfound
and dword [esp+12], 0 and dword [esp+12], 0
@ -1629,38 +1585,28 @@ hd_find_lfn:
mov dword [esp+4], fat_notroot_first mov dword [esp+4], fat_notroot_first
mov dword [esp], fat_notroot_next mov dword [esp], fat_notroot_next
jmp .loop jmp .loop
.notfound: .notfound:
add esp, 16 add esp, 16
pop edi esi pop edi esi
stc stc
ret 4 ret
.found: .found:
lea eax, [esp+4+24]
cmp dword [eax], 0
jz @f
mov esi, [eax]
and dword [eax], 0
jmp .continue
@@:
lea eax, [esp+8] lea eax, [esp+8]
cmp dword [eax], 0 cmp dword [eax], 0
jz .root jz .root
call fat_get_sector call fat_get_sector
jmp .cmn jmp .cmn
.root: .root:
mov eax, [eax+4] mov eax, [eax+4]
add eax, [ebp+FAT.ROOT_START] add eax, [ebp+FAT.ROOT_START]
.cmn: .cmn:
add esp, 20 ; CF=0 add esp, 20 ; CF=0
pop esi pop esi
ret 4 ret
;----------------------------------------------------------------
; fat_Read - FAT implementation of reading a file
; in: ebp = pointer to FAT structure
; in: esi+[esp+4] = name
; in: ebx = pointer to parameters from sysfunc 70
; out: eax, ebx = return values for sysfunc 70
;---------------------------------------------------------------- ;----------------------------------------------------------------
fat_Read: fat_Read:
call fat_lock call fat_lock
@ -1674,7 +1620,7 @@ fat_Read:
mov eax, ERROR_ACCESS_DENIED mov eax, ERROR_ACCESS_DENIED
ret ret
@@: @@:
stdcall hd_find_lfn, [esp+8] call hd_find_lfn
jnc .found jnc .found
pop edi pop edi
push eax push eax
@ -1850,12 +1796,6 @@ fat_Read:
xor ecx, ecx xor ecx, ecx
jmp .fragmentEnd jmp .fragmentEnd
;----------------------------------------------------------------
; fat_ReadFolder - FAT implementation of reading a folder
; in: ebp = pointer to FAT structure
; in: esi+[esp+4] = name
; in: ebx = pointer to parameters from sysfunc 70
; out: eax, ebx = return values for sysfunc 70
;---------------------------------------------------------------- ;----------------------------------------------------------------
fat_ReadFolder: fat_ReadFolder:
call fat_lock call fat_lock
@ -1863,7 +1803,7 @@ fat_ReadFolder:
push edi push edi
cmp byte [esi], 0 cmp byte [esi], 0
jz .doit jz .doit
stdcall hd_find_lfn, [esp+4+4] call hd_find_lfn
jnc .found jnc .found
pop edi pop edi
push eax push eax
@ -2253,27 +2193,14 @@ fshrad:
xor ebx, ebx xor ebx, ebx
ret ret
;----------------------------------------------------------------
; fat_CreateFolder - FAT implementation of creating a folder
; in: ebp = pointer to FAT structure
; in: esi+[esp+4] = name
; in: ebx = pointer to parameters from sysfunc 70
; out: eax, ebx = return values for sysfunc 70
;---------------------------------------------------------------- ;----------------------------------------------------------------
fat_CreateFolder: fat_CreateFolder:
push 1 push 1
jmp fat_Rewrite.common jmp @f
;---------------------------------------------------------------- fat_CreateFile:
; fat_Rewrite - FAT implementation of creating a new file
; in: ebp = pointer to FAT structure
; in: esi+[esp+4] = name
; in: ebx = pointer to parameters from sysfunc 70
; out: eax, ebx = return values for sysfunc 70
;----------------------------------------------------------------
fat_Rewrite:
push 0 push 0
.common: @@:
call fat_lock call fat_lock
pop eax pop eax
cmp byte [esi], 0 cmp byte [esi], 0
@ -2282,11 +2209,7 @@ fat_Rewrite:
mov edx, [ebx+16] mov edx, [ebx+16]
pushad pushad
xor edi, edi xor edi, edi
mov edx, [esp+4+20h]
push esi push esi
test edx, edx
jz @f
mov esi, edx
@@: @@:
lodsb lodsb
test al, al test al, al
@ -2295,12 +2218,11 @@ fat_Rewrite:
jnz @b jnz @b
lea edi, [esi-1] lea edi, [esi-1]
jmp @b jmp @b
@@: @@:
pop esi pop esi
test edi, edi test edi, edi
jnz .noroot jnz .noroot
test edx, edx
jnz .hasebp
mov edx, [ebp+FAT.ROOT_CLUSTER] mov edx, [ebp+FAT.ROOT_CLUSTER]
cmp [ebp+FAT.fs_type], 32 cmp [ebp+FAT.fs_type], 32
jz .pushnotroot jz .pushnotroot
@ -2315,14 +2237,7 @@ fat_Rewrite:
push fat1x_root_first push fat1x_root_first
push fat1x_root_next push fat1x_root_next
jmp .common1 jmp .common1
.hasebp:
mov eax, ERROR_ACCESS_DENIED
cmp byte [edx], 0
jz .ret1
stdcall hd_find_lfn, 0
mov esi, [esp+4+20h]
jc .ret1
jmp .common0
.noroot: .noroot:
mov eax, ERROR_ACCESS_DENIED mov eax, ERROR_ACCESS_DENIED
cmp byte [edi+1], 0 cmp byte [edi+1], 0
@ -2330,7 +2245,7 @@ fat_Rewrite:
; check existence ; check existence
mov byte [edi], 0 mov byte [edi], 0
push edi push edi
stdcall hd_find_lfn, [esp+4+24h] call hd_find_lfn
pop esi pop esi
mov byte [esi], '/' mov byte [esi], '/'
jnc @f jnc @f
@ -2342,15 +2257,15 @@ fat_Rewrite:
popad popad
xor ebx, ebx xor ebx, ebx
ret ret
@@: @@:
inc esi inc esi
.common0:
test byte [edi+11], 0x10 ; must be directory test byte [edi+11], 0x10 ; must be directory
mov eax, ERROR_ACCESS_DENIED mov eax, ERROR_ACCESS_DENIED
jz .ret1 jz .ret1
mov edx, [edi+20-2] mov edx, [edi+20-2]
mov dx, [edi+26] ; ebp=cluster mov dx, [edi+26] ; ebp=cluster
mov eax, ERROR_FAT_TABLE mov eax, ERROR_FS_FAIL
cmp edx, 2 cmp edx, 2
jb .ret1 jb .ret1
.pushnotroot: .pushnotroot:
@ -2366,11 +2281,9 @@ fat_Rewrite:
.common1: .common1:
call fat_find_lfn call fat_find_lfn
jc .notfound jc .notfound
; found
test byte [edi+11], 10h test byte [edi+11], 10h
jz .exists_file jz .exists_file
; found directory; if we are creating directory, return OK, ; found directory
; if we are creating file, say "access denied"
add esp, 36 add esp, 36
call fat_unlock call fat_unlock
popad popad
@ -2381,9 +2294,8 @@ fat_Rewrite:
@@: @@:
xor ebx, ebx xor ebx, ebx
ret ret
.exists_file: .exists_file:
; found file; if we are creating directory, return "access denied",
; if we are creating file, delete existing file and continue
cmp byte [esp+36+28], 0 cmp byte [esp+36+28], 0
jz @f jz @f
add esp, 36 add esp, 36
@ -2392,8 +2304,8 @@ fat_Rewrite:
mov eax, ERROR_ACCESS_DENIED mov eax, ERROR_ACCESS_DENIED
xor ebx, ebx xor ebx, ebx
ret ret
@@:
; delete FAT chain @@: ; delete FAT chain
push edi push edi
xor eax, eax xor eax, eax
mov dword [edi+28], eax ; zero size mov dword [edi+28], eax ; zero size
@ -2415,17 +2327,20 @@ fat_Rewrite:
jc .done1 jc .done1
inc ecx inc ecx
jmp @b jmp @b
.done1:
pop edi .short_name_found:
call get_time_for_file pop ecx edi esi
mov [edi+22], ax call fat_next_short_name
call get_date_for_file jnc .test_short_name_loop
mov [edi+24], ax .disk_full:
mov [edi+18], ax add esp, 12+36
or byte [edi+11], 20h ; set 'archive' attribute call fat_unlock
jmp .doit popa
.notfound: mov eax, ERROR_DISK_FULL
; file is not found; generate short name xor ebx, ebx
ret
.notfound: ; generate short name
call fat_name_is_legal call fat_name_is_legal
jc @f jc @f
add esp, 36 add esp, 36
@ -2434,6 +2349,7 @@ fat_Rewrite:
mov eax, ERROR_FILE_NOT_FOUND mov eax, ERROR_FILE_NOT_FOUND
xor ebx, ebx xor ebx, ebx
ret ret
@@: @@:
sub esp, 12 sub esp, 12
mov edi, esp mov edi, esp
@ -2459,18 +2375,6 @@ fat_Rewrite:
lea eax, [esp+12+12+8] lea eax, [esp+12+12+8]
call dword [eax-8] call dword [eax-8]
jnc .test_short_name_entry jnc .test_short_name_entry
jmp .found
.short_name_found:
pop ecx edi esi
call fat_next_short_name
jnc .test_short_name_loop
.disk_full:
add esp, 12+36
call fat_unlock
popa
mov eax, ERROR_DISK_FULL
xor ebx, ebx
ret
.found: .found:
pop ecx edi esi pop ecx edi esi
; now find space in directory ; now find space in directory
@ -2489,6 +2393,7 @@ fat_Rewrite:
inc esi inc esi
inc eax inc eax
jmp @b jmp @b
@@: @@:
sub esi, eax sub esi, eax
add eax, 12+13 add eax, 12+13
@ -2518,6 +2423,7 @@ fat_Rewrite:
mov eax, ERROR_DEVICE mov eax, ERROR_DEVICE
xor ebx, ebx xor ebx, ebx
ret ret
.scan_dir: .scan_dir:
cmp byte [edi], 0 cmp byte [edi], 0
jz .free jz .free
@ -2544,6 +2450,7 @@ fat_Rewrite:
mov eax, ERROR_DISK_FULL mov eax, ERROR_DISK_FULL
xor ebx, ebx xor ebx, ebx
ret ret
.free: .free:
test ecx, ecx test ecx, ecx
jnz @f jnz @f
@ -2564,17 +2471,17 @@ fat_Rewrite:
; on a full disk. ; on a full disk.
; yup, the argument is quite non-intuitive... but what should I do if ; yup, the argument is quite non-intuitive... but what should I do if
; the entire function uses such arguments? BTW, it refers to al from pushad, ; the entire function uses such arguments? BTW, it refers to al from pushad,
; which in turn is filled with 0 in fat_Rewrite and 1 in fat_CreateFolder. ; which in turn is filled with 0 in fat_CreateFile and 1 in fat_CreateFolder.
cmp byte [esp+8+12+8+12+36+28], 0 cmp byte [esp+8+12+8+12+36+28], 0
jz .no.preallocate.folder.data jz .no.preallocate.folder.data
call get_free_FAT call get_free_FAT
jnc @f jnc @f
add esp, 8+12+8 add esp, 8+12+8
jmp .disk_full jmp .disk_full
@@: @@:
mov [esp+8+12+8+12+36+20], eax ; store the cluster somewhere mov [esp+8+12+8+12+36+20], eax ; store the cluster somewhere
.no.preallocate.folder.data: .no.preallocate.folder.data: ; calculate name checksum
; calculate name checksum
mov esi, [esp+8+12] mov esi, [esp+8+12]
mov ecx, 11 mov ecx, 11
xor eax, eax xor eax, eax
@ -2622,8 +2529,6 @@ fat_Rewrite:
loop .writelfn loop .writelfn
pop eax pop eax
pop esi pop esi
; lea eax, [esp+8+12+8]
; call dword [eax+16] ; end write
.nolfn: .nolfn:
xchg esi, [esp] xchg esi, [esp]
mov ecx, 11 mov ecx, 11
@ -2659,6 +2564,15 @@ fat_Rewrite:
push ecx push ecx
push edi push edi
jmp .doit2 jmp .doit2
.done1:
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
.doit: .doit:
mov esi, [esp+36+20] mov esi, [esp+36+20]
lea eax, [esp+8] lea eax, [esp+8]
@ -2690,7 +2604,6 @@ fat_Rewrite:
imul eax, [ebp+FAT.SECTORS_PER_CLUSTER] imul eax, [ebp+FAT.SECTORS_PER_CLUSTER]
add eax, [ebp+FAT.DATA_START] add eax, [ebp+FAT.DATA_START]
push [ebp+FAT.SECTORS_PER_CLUSTER] push [ebp+FAT.SECTORS_PER_CLUSTER]
; write data
.write_sector: .write_sector:
cmp byte [esp+20+36+28], 0 cmp byte [esp+20+36+28], 0
jnz .writedir jnz .writedir
@ -2701,6 +2614,7 @@ fat_Rewrite:
mov ebx, esi mov ebx, esi
add esi, ecx add esi, ecx
jmp .writecommon jmp .writecommon
.writeshort: .writeshort:
mov ecx, [esp+12] mov ecx, [esp+12]
push ecx push ecx
@ -2741,14 +2655,17 @@ fat_Rewrite:
pop edx pop edx
xchg eax, ecx xchg eax, ecx
jmp .write_cluster jmp .write_cluster
.diskfull: .diskfull:
mov eax, ERROR_DISK_FULL mov eax, ERROR_DISK_FULL
jmp .ret jmp .ret
.writeerr: .writeerr:
pop eax eax pop eax eax
sub esi, ecx sub esi, ecx
mov eax, ERROR_DEVICE mov eax, ERROR_DEVICE
jmp .ret jmp .ret
.writedone: .writedone:
pop eax eax pop eax eax
.done: .done:
@ -2777,6 +2694,7 @@ fat_Rewrite:
call fat_unlock call fat_unlock
popad popad
ret ret
.writedir: .writedir:
push 512 push 512
lea edi, [ebp+FAT.buffer] lea edi, [ebp+FAT.buffer]
@ -2830,38 +2748,27 @@ fat_read_symbols:
loop fat_read_symbols loop fat_read_symbols
ret ret
fat_Write.access_denied:
push ERROR_ACCESS_DENIED
fat_Write.ret0:
pop eax
xor ebx, ebx
ret
fat_Write.ret11:
push ERROR_DEVICE
jmp fat_Write.ret0
;----------------------------------------------------------------
; fat_Write - FAT implementation of writing to file
; in: ebp = pointer to FAT structure
; in: esi+[esp+4] = name
; in: ebx = pointer to parameters from sysfunc 70
; out: eax, ebx = return values for sysfunc 70
;---------------------------------------------------------------- ;----------------------------------------------------------------
fat_Write: fat_Write:
cmp byte [esi], 0 cmp byte [esi], 0
jz .access_denied jz .access_denied
call fat_lock call fat_lock
push edi push edi
stdcall hd_find_lfn, [esp+4+4] call hd_find_lfn
jnc .found jnc .found
pop edi pop edi
push eax push eax
call fat_unlock call fat_unlock
.ret0:
pop eax
xor ebx, ebx
ret
.access_denied:
push ERROR_ACCESS_DENIED
jmp .ret0 jmp .ret0
.found:
; FAT does not support files larger than 4GB .found: ; FAT does not support files larger than 4GB
cmp dword [ebx+8], 0 cmp dword [ebx+8], 0
jz @f jz @f
.eof: .eof:
@ -2875,20 +2782,17 @@ fat_Write:
mov ebx, [ebx+4] mov ebx, [ebx+4]
; now edi points to direntry, ebx=start byte to write, ; now edi points to direntry, ebx=start byte to write,
; ecx=number of bytes to write, edx=data pointer ; ecx=number of bytes to write, edx=data pointer
; extend file if needed ; extend file if needed
add ecx, ebx add ecx, ebx
jc .eof ; FAT does not support files larger than 4GB jc .eof ; FAT does not support files larger than 4GB
push edx push edx
push eax ; save directory sector push eax ; save directory sector
push 0 ; return value=0 push 0 ; return value=0
call get_time_for_file call get_time_for_file
mov [edi+22], ax ; last write time mov [edi+22], ax ; last write time
call get_date_for_file call get_date_for_file
mov [edi+24], ax ; last write date mov [edi+24], ax ; last write date
mov [edi+18], ax ; last access date mov [edi+18], ax ; last access date
push dword [edi+28] ; save current file size push dword [edi+28] ; save current file size
cmp ecx, [edi+28] cmp ecx, [edi+28]
jbe .length_ok jbe .length_ok
@ -2949,7 +2853,7 @@ fat_Write:
mov byte [esp+8], ERROR_DEVICE mov byte [esp+8], ERROR_DEVICE
jmp .ret jmp .ret
.fat_err: .fat_err:
mov byte [esp+8], ERROR_FAT_TABLE mov byte [esp+8], ERROR_FS_FAIL
jmp .ret jmp .ret
@@: @@:
@ -3074,7 +2978,7 @@ hd_extend_file.zero_size:
; extends file on hd to given size (new data area is undefined) ; extends file on hd to given size (new data area is undefined)
; in: edi->direntry, ecx=new size ; in: edi->direntry, ecx=new size
; out: CF=0 => OK, eax=0 ; out: CF=0 => OK, eax=0
; CF=1 => error, eax=code (ERROR_FAT_TABLE or ERROR_DISK_FULL or ERROR_DEVICE) ; CF=1 => error, eax=code (ERROR_FS_FAIL or ERROR_DISK_FULL or ERROR_DEVICE)
hd_extend_file: hd_extend_file:
push esi push esi
mov esi, [ebp+FAT.SECTORS_PER_CLUSTER] mov esi, [ebp+FAT.SECTORS_PER_CLUSTER]
@ -3106,7 +3010,7 @@ hd_extend_file:
jb .last_loop jb .last_loop
.fat_err: .fat_err:
pop ecx esi pop ecx esi
push ERROR_FAT_TABLE push ERROR_FS_FAIL
jmp .ret_err jmp .ret_err
.last_found: .last_found:
push eax push eax
@ -3177,13 +3081,6 @@ fat_update_datetime:
mov [edi+18], ax ; last access date mov [edi+18], ax ; last access date
ret ret
;----------------------------------------------------------------
; fat_SetFileEnd - FAT implementation of setting end-of-file
; in: ebp = pointer to FAT structure
; in: esi+[esp+4] = name
; in: ebx = pointer to parameters from sysfunc 70
; out: eax, ebx = return values for sysfunc 70
;---------------------------------------------------------------- ;----------------------------------------------------------------
fat_SetFileEnd: fat_SetFileEnd:
call fat_lock call fat_lock
@ -3198,7 +3095,7 @@ fat_SetFileEnd:
pop edi pop edi
ret ret
@@: @@:
stdcall hd_find_lfn, [esp+4+4] call hd_find_lfn
jnc @f jnc @f
.reteax: .reteax:
push eax push eax
@ -3409,21 +3306,15 @@ fat_SetFileEnd:
ret ret
.error_fat: .error_fat:
pop eax pop eax
mov byte [esp], ERROR_FAT_TABLE mov byte [esp], ERROR_FS_FAIL
jmp .pop_ret jmp .pop_ret
.error_fat2: .error_fat2:
pop eax ecx eax edi pop eax ecx eax edi
call update_disk call update_disk
call fat_unlock call fat_unlock
movi eax, ERROR_FAT_TABLE movi eax, ERROR_FS_FAIL
ret ret
;----------------------------------------------------------------
; fat_GetFileInfo - FAT implementation of getting file info
; in: ebp = pointer to FAT structure
; in: esi+[esp+4] = name
; in: ebx = pointer to parameters from sysfunc 70
; out: eax, ebx = return values for sysfunc 70
;---------------------------------------------------------------- ;----------------------------------------------------------------
fat_GetFileInfo: fat_GetFileInfo:
cmp byte [esi], 0 cmp byte [esi], 0
@ -3433,7 +3324,7 @@ fat_GetFileInfo:
@@: @@:
push edi push edi
call fat_lock call fat_lock
stdcall hd_find_lfn, [esp+4+4] call hd_find_lfn
jc .error jc .error
push ebp push ebp
xor ebp, ebp xor ebp, ebp
@ -3452,12 +3343,6 @@ fat_GetFileInfo:
pop edi pop edi
ret ret
;----------------------------------------------------------------
; fat_SetFileInfo - FAT implementation of setting file info
; in: ebp = pointer to FAT structure
; in: esi+[esp+4] = name
; in: ebx = pointer to parameters from sysfunc 70
; out: eax, ebx = return values for sysfunc 70
;---------------------------------------------------------------- ;----------------------------------------------------------------
fat_SetFileInfo: fat_SetFileInfo:
cmp byte [esi], 0 cmp byte [esi], 0
@ -3467,7 +3352,7 @@ fat_SetFileInfo:
@@: @@:
push edi push edi
call fat_lock call fat_lock
stdcall hd_find_lfn, [esp+4+4] call hd_find_lfn
jc .error jc .error
push eax push eax
mov edx, [ebx+16] mov edx, [ebx+16]
@ -3487,12 +3372,6 @@ fat_SetFileInfo:
pop edi pop edi
ret ret
;----------------------------------------------------------------
; fat_Delete - FAT implementation of deleting a file/folder
; in: ebp = pointer to FAT structure
; in: esi+[esp+4] = name
; in: ebx = pointer to parameters from sysfunc 70
; out: eax, ebx = return values for sysfunc 70
;---------------------------------------------------------------- ;----------------------------------------------------------------
fat_Delete: fat_Delete:
call fat_lock call fat_lock
@ -3510,7 +3389,7 @@ fat_Delete:
and [ebp+FAT.longname_sec1], 0 and [ebp+FAT.longname_sec1], 0
and [ebp+FAT.longname_sec2], 0 and [ebp+FAT.longname_sec2], 0
push edi push edi
stdcall hd_find_lfn, [esp+4+4] call hd_find_lfn
jnc .found jnc .found
pop edi pop edi
push ERROR_FILE_NOT_FOUND push ERROR_FILE_NOT_FOUND
@ -3577,7 +3456,7 @@ fat_Delete:
popad popad
pop edi pop edi
call fat_unlock call fat_unlock
movi eax, ERROR_FAT_TABLE movi eax, ERROR_FS_FAIL
ret ret
.notempty: .notempty:
popad popad

View File

@ -16,12 +16,13 @@ ERROR_FILE_NOT_FOUND = 5
ERROR_END_OF_FILE = 6 ERROR_END_OF_FILE = 6
ERROR_MEMORY_POINTER = 7 ERROR_MEMORY_POINTER = 7
ERROR_DISK_FULL = 8 ERROR_DISK_FULL = 8
ERROR_FAT_TABLE = 9 ;deprecated
ERROR_FS_FAIL = 9 ERROR_FS_FAIL = 9
ERROR_ACCESS_DENIED = 10 ERROR_ACCESS_DENIED = 10
ERROR_DEVICE = 11 ERROR_DEVICE = 11
ERROR_OUT_OF_MEMORY = 12 ERROR_OUT_OF_MEMORY = 12
maxPathLength = 1000h
image_of_eax EQU esp+32 image_of_eax EQU esp+32
image_of_ebx EQU esp+20 image_of_ebx EQU esp+20
@ -50,25 +51,11 @@ file_system_lfn:
; start application ; start application
; 8 = delete file/folder ; 8 = delete file/folder
; 9 = create folder ; 9 = create folder
lea esi, [ebx+20] lea ebp, [ebx+20]
lodsb cmp byte [ebp], 0
test al, al
jnz @f jnz @f
mov esi, [esi] mov ebp, [ebx+21]
lodsb
@@: @@:
lea ebp, [esi-1]
if 0
cmp [ebx], dword 0
jne .1
DEBUGF 1,'read file %s\n',ebp
jmp @f
.1:
cmp [ebx], dword 5
jne @f
DEBUGF 1,'get file attributes %s\n',ebp
@@:
end if
cmp dword[ebx], 7 ; start application cmp dword[ebx], 7 ; start application
jne @f jne @f
mov edx, [ebx+4] mov edx, [ebx+4]
@ -78,29 +65,24 @@ end if
ret ret
@@: @@:
cmp al, '/' cmp word [ebp], '/'
jz .notcurdir
dec esi
mov ebp, esi
test al, al
jnz @f
xor ebp, ebp
@@:
mov esi, [current_slot]
mov esi, [esi+APPDATA.cur_dir]
jmp .parse_normal
.notcurdir:
cmp byte [esi], 0
jz .rootdir jz .rootdir
call process_replace_file_name stdcall kernel_alloc, maxPathLength
.parse_normal: push ebx
mov ax, [esi] mov ebx, ebp
mov ebp, eax
push maxPathLength
push eax
call get_full_file_name
pop ebx
mov esi, ebp
mov ax, [ebp]
or ax, 2020h or ax, 2020h
cmp ax, 'cd' cmp ax, 'cd'
jz .CD jz .CD
call dyndisk_handler ; not returns if success call dyndisk_handler ; not returns if success
.notfound: .notfound:
stdcall kernel_free, ebp
mov dword[image_of_eax], ERROR_FILE_NOT_FOUND mov dword[image_of_eax], ERROR_FILE_NOT_FOUND
ret ret
@ -125,13 +107,6 @@ end if
cmp byte [esi], '/' cmp byte [esi], '/'
jnz @f jnz @f
inc esi inc esi
@@:
cmp byte [esi], 0
jnz @f
test ebp, ebp
jz @f
mov esi, ebp
xor ebp, ebp
@@: @@:
call reserve_cd call reserve_cd
mov eax, edi mov eax, edi
@ -160,15 +135,12 @@ end if
jae @f jae @f
add ebx, 4 add ebx, 4
call dword[fs_CdServices + eax*4] call dword[fs_CdServices + eax*4]
call free_cd_channel
and [cd_status], 0
mov [image_of_eax], eax mov [image_of_eax], eax
mov [image_of_ebx], ebx mov [image_of_ebx], ebx
ret
@@: @@:
call free_cd_channel call free_cd_channel
and [cd_status], 0 and [cd_status], 0
stdcall kernel_free, ebp
ret ret
.nextCD: .nextCD:
@ -183,12 +155,15 @@ end if
.maindir: ; list partitions .maindir: ; list partitions
mov esi, .nextCD mov esi, .nextCD
.maindir_noesi: ; backjump from dyndisk_handler .maindir_noesi: ; backjump from dyndisk_handler
push ebp
mov ebp, ecx
call kernel_free
cmp dword[ebx], 1 cmp dword[ebx], 1
jnz .access_denied ; read folder? jnz .access_denied ; read folder?
push ecx push ebp
pushd [ebx+4] ; first block
mov ebp, [ebx+12] ; the number of blocks to read mov ebp, [ebx+12] ; the number of blocks to read
mov edx, [ebx+16] ; where to write the result mov edx, [ebx+16] ; buffer
push dword[ebx+4] ; first block
mov ebx, [ebx+8] ; flags mov ebx, [ebx+8] ; flags
mov ecx, 32/4 mov ecx, 32/4
mov edi, edx mov edi, edx
@ -293,8 +268,8 @@ end if
add edi, 8 add edi, 8
xor eax, eax xor eax, eax
rep stosd rep stosd
push esi edi push edi
lea esi, [esp+12] lea esi, [esp+8]
cmp ebx, 1 cmp ebx, 1
jz .uni2 jz .uni2
@@: @@:
@ -302,7 +277,7 @@ end if
stosb stosb
test eax, eax test eax, eax
jnz @b jnz @b
pop edi esi eax pop edi eax
add edi, 264 add edi, 264
jmp .rootdir_loop jmp .rootdir_loop
@ -311,7 +286,7 @@ end if
stosw stosw
test eax, eax test eax, eax
jnz .uni2 jnz .uni2
pop edi esi eax pop edi eax
add edi, 520 add edi, 520
jmp .rootdir_loop jmp .rootdir_loop
@ -370,23 +345,6 @@ end if
mov [image_of_ebx], ebx mov [image_of_ebx], ebx
ret ret
fs_NotImplemented:
mov eax, 2
ret
;-----------------------------------------------------------------------------
fs_CdServices:
dd fs_CdRead
dd fs_CdReadFolder
dd fs_NotImplemented
dd fs_NotImplemented
dd fs_NotImplemented
dd fs_CdGetFileInfo
dd fs_NotImplemented
dd 0
dd fs_NotImplemented
dd fs_NotImplemented
fs_NumCdServices = ($ - fs_CdServices)/4
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
process_replace_file_name: process_replace_file_name:
; in: [esi] = virtual path ; in: [esi] = virtual path
@ -476,14 +434,12 @@ sys_current_directory: ; sysfunction 30
@@: @@:
ret ret
max_cur_dir equ 0x1000 ; length
.get: ; in: ecx -> buffer, edx = length .get: ; in: ecx -> buffer, edx = length
mov ebx, edi ; buffer mov ebx, edi ; buffer
push ecx push ecx
push edi push edi
xor eax, eax xor eax, eax
mov ecx, max_cur_dir mov ecx, maxPathLength
repne scasb repne scasb
jnz .error jnz .error
sub edi, ebx sub edi, ebx
@ -511,7 +467,7 @@ max_cur_dir equ 0x1000 ; length
.set: .set:
pop eax pop eax
push max_cur_dir push maxPathLength
push edi push edi
push eax push eax
mov ebx, ecx mov ebx, ecx
@ -519,17 +475,48 @@ get_full_file_name:
; in: ebx -> file name, [esp+4] -> destination, [esp+8] = max length ; in: ebx -> file name, [esp+4] -> destination, [esp+8] = max length
; destroys all registers ; destroys all registers
push ebp push ebp
mov esi, [current_slot]
mov esi, [esi+APPDATA.cur_dir]
mov edx, esi
@@:
inc esi
cmp byte [esi-1], 0
jnz @b
dec esi
cmp byte [ebx], '/' cmp byte [ebx], '/'
jz .set_absolute jnz .set_relative
lea esi, [ebx+1]
call process_replace_file_name
mov edi, [esp+8] mov edi, [esp+8]
mov edx, [esp+12]
add edx, edi
.set_copy:
lodsb
stosb
test al, al
jz .set_part2
.set_copy_cont:
cmp edi, edx
jb .set_copy
.overflow:
dec edi
.fail:
mov byte [edi], 0
xor eax, eax
pop ebp
ret 8
.set_part2:
mov esi, ebp
xor ebp, ebp
test esi, esi
jz .ret.ok
mov byte [edi-1], '/'
jmp .set_copy_cont
.set_relative:
mov edi, [current_slot]
mov edi, [edi+APPDATA.cur_dir]
mov edx, edi
mov ecx, [esp+12]
xor eax, eax
repnz scasb
mov esi, edi
dec esi
mov edi, [esp+8]
jecxz .fail
.relative: .relative:
cmp byte [ebx], 0 cmp byte [ebx], 0
jz .set_ok jz .set_ok
@ -556,18 +543,9 @@ get_full_file_name:
.set_ok: .set_ok:
cmp edx, edi ; is destination equal to APPDATA.cur_dir? cmp edx, edi ; is destination equal to APPDATA.cur_dir?
jz .set_ok.cur_dir jz @f
sub esi, edx
cmp esi, [esp+12]
jb .set_ok.copy
.fail:
mov byte [edi], 0
xor eax, eax
pop ebp
ret 8
.set_ok.copy:
mov ecx, esi mov ecx, esi
sub ecx, edx
mov esi, edx mov esi, edx
rep movsb rep movsb
mov byte [edi], 0 mov byte [edi], 0
@ -576,17 +554,15 @@ get_full_file_name:
pop ebp pop ebp
ret 8 ret 8
.set_ok.cur_dir: @@:
mov byte [esi], 0 mov byte [esi], 0
jmp .ret.ok jmp .ret.ok
.doset_relative: .doset_relative:
cmp edx, edi cmp edx, edi
jz .doset_relative.cur_dir jz .doset_relative.cur_dir
sub esi, edx
cmp esi, [esp+12]
jae .fail
mov ecx, esi mov ecx, esi
sub ecx, edx
mov esi, edx mov esi, edx
mov edx, edi mov edx, edi
rep movsb rep movsb
@ -608,34 +584,8 @@ get_full_file_name:
jz .ret.ok jz .ret.ok
cmp edi, edx cmp edi, edx
jb @b jb @b
.overflow:
dec edi
jmp .fail
.set_absolute:
lea esi, [ebx+1]
call process_replace_file_name
mov edi, [esp+8]
mov edx, [esp+12]
add edx, edi
.set_copy:
lodsb
stosb
test al, al
jz .set_part2
.set_copy_cont:
cmp edi, edx
jb .set_copy
jmp .overflow jmp .overflow
.set_part2:
mov esi, ebp
xor ebp, ebp
test esi, esi
jz .ret.ok
mov byte [edi-1], '/'
jmp .set_copy_cont
include "parse_fn.inc" include "parse_fn.inc"
include "fs_common.inc" include "fs_common.inc"
include "iso9660.inc" ; read for CD filesystem include "iso9660.inc" ; read for CD filesystem

View File

@ -1,19 +1,49 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License. ;;
;; ;; ;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$Revision$ $Revision$
;----------------------------------------------------------------------------- ; CD external functions
uglobal ; in:
cd_current_pointer_of_input dd 0 ; esi -> path string
cd_current_pointer_of_input_2 dd 0 ; ebx -> offset in file (qword)
cd_mem_location dd 0 ; ecx = bytes to read
cd_counter_block dd 0 ; edx -> buffer
; out:
; eax, ebx = return values for sysfunc 70
iglobal
align 4
fs_CdServices:
dd fs_CdRead
dd fs_CdReadFolder
dd fs_NotImplemented
dd fs_NotImplemented
dd fs_NotImplemented
dd fs_CdGetFileInfo
dd fs_NotImplemented
dd 0
dd fs_NotImplemented
dd fs_NotImplemented
fs_NumCdServices = ($ - fs_CdServices)/4
endg endg
uglobal
align 4
cd_current_pointer_of_input dd 0
cd_current_pointer_of_input_2 dd 0
cd_mem_location dd 0
cd_counter_block dd 0
cd_status dd 0
endg
;-----------------------------------------------------------------------------
fs_NotImplemented:
movi eax, ERROR_UNSUPPORTED_FS
ret
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
reserve_cd: reserve_cd:
cli cli
@ -127,23 +157,7 @@ free_cd_channel:
call mutex_unlock call mutex_unlock
popad popad
ret ret
;-----------------------------------------------------------------------------
uglobal
cd_status dd 0
endg
;-----------------------------------------------------------------------------
;
; fs_CdRead - LFN variant for reading CD disk
;
; esi points to filename /dir1/dir2/.../dirn/file,0
; 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
;
; ret ebx = bytes read or 0xffffffff file not found
; eax = 0 ok read or other = errormsg
;
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
fs_CdRead: fs_CdRead:
push edi push edi
@ -277,20 +291,7 @@ fs_CdRead:
pop eax edx ecx pop eax edx ecx
sub ebx, edx sub ebx, edx
jmp .reteof jmp .reteof
;-----------------------------------------------------------------------------
;
; fs_CdReadFolder - LFN variant for reading CD disk folder
;
; esi points to filename /dir1/dir2/.../dirn/file,0
; ebx pointer to structure 32-bit number = first wanted block, 0+
; & flags (bitfields)
; flags: bit 0: 0=ANSI names, 1=UNICODE names
; ecx number of blocks to read, 0+
; edx mem location to return data
;
; ret ebx = blocks read or 0xffffffff folder not found
; eax = 0 ok read or other = errormsg
;
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
fs_CdReadFolder: fs_CdReadFolder:
push edi push edi
@ -559,11 +560,7 @@ cd_get_parameters_of_file_1:
mov eax, [ebp-23] mov eax, [ebp-23]
mov [edi+32], eax mov [edi+32], eax
ret ret
;-----------------------------------------------------------------------------
;
; fs_CdGetFileInfo - LFN variant for CD
; get file/directory attributes structure
;
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
fs_CdGetFileInfo: fs_CdGetFileInfo:
cmp byte [esi], 0 cmp byte [esi], 0
@ -607,7 +604,7 @@ fs_CdGetFileInfo:
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
cd_find_lfn: cd_find_lfn:
mov [cd_appl_data], 0 mov [cd_appl_data], 0
; in: esi+ebp -> name ; in: esi -> path string
; out: CF=1 - file not found ; out: CF=1 - file not found
; else CF=0 and [cd_current_pointer_of_input] direntry ; else CF=0 and [cd_current_pointer_of_input] direntry
push eax esi push eax esi
@ -684,12 +681,8 @@ cd_find_lfn:
call ReadCDWRetr ; read sector of directory call ReadCDWRetr ; read sector of directory
cmp [DevErrorCode], 0 cmp [DevErrorCode], 0
jne .access_denied jne .access_denied
push ebp
call cd_find_name_in_buffer call cd_find_name_in_buffer
pop ebp
jnc .found jnc .found
sub eax, 2048 sub eax, 2048
; directory is over? ; directory is over?
cmp eax, 0 cmp eax, 0
@ -706,7 +699,6 @@ cd_find_lfn:
; the end of the file path ; the end of the file path
cmp byte [esi-1], 0 cmp byte [esi-1], 0
jz .done jz .done
.nested:
mov eax, [cd_current_pointer_of_input] mov eax, [cd_current_pointer_of_input]
push dword [eax+2] push dword [eax+2]
pop dword [CDSectorAddress] ; beginning of the directory pop dword [CDSectorAddress] ; beginning of the directory
@ -715,14 +707,6 @@ cd_find_lfn:
;-------------------------------------- ;--------------------------------------
; file pointer found ; file pointer found
.done: .done:
test ebp, ebp
jz @f
mov esi, ebp
xor ebp, ebp
jmp .nested
;--------------------------------------
@@:
pop esi eax pop esi eax
mov [cd_appl_data], 1 mov [cd_appl_data], 1
clc clc

View File

@ -11,7 +11,7 @@ $Revision$
; in: ; in:
; ebx -> parameter structure of sysfunc 70 ; ebx -> parameter structure of sysfunc 70
; ebp -> NTFS structure ; ebp -> NTFS structure
; [esi]+[[esp+4]] = name ; esi -> path string
; out: ; out:
; eax, ebx = return values for sysfunc 70 ; eax, ebx = return values for sysfunc 70
iglobal iglobal
@ -1174,7 +1174,7 @@ unichar_toupper:
ret ret
ntfs_find_lfn: ntfs_find_lfn:
; in: [esi]+[esp+4] = name ; in: esi -> path string
; out: ; out:
; [ebp+NTFS.cur_iRecord] = target fileRecord ; [ebp+NTFS.cur_iRecord] = target fileRecord
; eax -> target index in the node ; eax -> target index in the node
@ -1280,7 +1280,7 @@ ntfs_find_lfn:
.ret2: .ret2:
pop esi pop esi
.ret: .ret:
ret 4 ret
.slash: .slash:
pop eax pop eax
@ -1337,14 +1337,9 @@ ntfs_find_lfn:
mov [esp+1Ch], esi mov [esp+1Ch], esi
mov [esp+4], edi mov [esp+4], edi
popad popad
inc esi cmp byte [esi], 0
cmp byte [esi-1], 0
jnz @f
cmp dword [esp+8], 0
jz .ret2 jz .ret2
mov esi, [esp+8] inc esi
mov dword [esp+8], 0
@@:
pop eax pop eax
jmp .doit2 jmp .doit2
@ -1358,7 +1353,7 @@ ntfs_ReadFile:
@@: @@:
call ntfs_lock call ntfs_lock
stdcall ntfs_find_lfn, [esp+4] call ntfs_find_lfn
jnc .found jnc .found
call ntfs_unlock call ntfs_unlock
or ebx, -1 or ebx, -1
@ -1493,7 +1488,7 @@ ntfs_ReadFolder:
mov [ebp+NTFS.cur_iRecord], 5 ; root directory mov [ebp+NTFS.cur_iRecord], 5 ; root directory
cmp byte [esi], 0 cmp byte [esi], 0
jz @f jz @f
stdcall ntfs_find_lfn, [esp+4] call ntfs_find_lfn
jc ntfsNotFound jc ntfsNotFound
@@: @@:
mov [ebp+NTFS.cur_attr], 0x10 ; $STANDARD_INFORMATION mov [ebp+NTFS.cur_attr], 0x10 ; $STANDARD_INFORMATION
@ -1820,7 +1815,7 @@ ntfs_GetFileInfo:
mov edi, [ebx+16] mov edi, [ebx+16]
cmp byte [esi], 0 cmp byte [esi], 0
jz .volume jz .volume
stdcall ntfs_find_lfn, [esp+4] call ntfs_find_lfn
jnc .found jnc .found
test eax, eax test eax, eax
jz ntfsFail jz ntfsFail
@ -1885,7 +1880,7 @@ ntfs_CreateFile:
@@: ; 1. Search file @@: ; 1. Search file
call ntfs_lock call ntfs_lock
stdcall ntfs_find_lfn, [esp+4] call ntfs_find_lfn
jc .notFound jc .notFound
; found, rewrite ; found, rewrite
cmp [ebp+NTFS.cur_iRecord], 16 cmp [ebp+NTFS.cur_iRecord], 16
@ -2172,7 +2167,7 @@ ntfs_CreateFile:
mov edx, [ebp+NTFS.rootLastRead] mov edx, [ebp+NTFS.rootLastRead]
call writeRecord call writeRecord
mov esi, [esp+4] mov esi, [esp+4]
stdcall ntfs_find_lfn.doit2, 0 call ntfs_find_lfn.doit2
test eax, eax test eax, eax
jz .errorPop3 jz .errorPop3
mov edi, [ebp+NTFS.cur_index_buf] mov edi, [ebp+NTFS.cur_index_buf]
@ -3510,7 +3505,7 @@ ntfs_WriteFile:
ret ret
@@: @@:
call ntfs_lock call ntfs_lock
stdcall ntfs_find_lfn, [esp+4] call ntfs_find_lfn
jc ntfsNotFound jc ntfsNotFound
cmp [ebp+NTFS.cur_iRecord], 16 cmp [ebp+NTFS.cur_iRecord], 16
jc ntfsDenied jc ntfsDenied
@ -3690,7 +3685,7 @@ ntfs_Delete:
@@: @@:
call ntfs_lock call ntfs_lock
stdcall ntfs_find_lfn, [esp+4] call ntfs_find_lfn
jc ntfsNotFound jc ntfsNotFound
cmp [ebp+NTFS.cur_iRecord], 16 cmp [ebp+NTFS.cur_iRecord], 16
jc ntfsDenied jc ntfsDenied
@ -3783,7 +3778,7 @@ ntfs_Delete:
mov eax, [ebp+NTFS.newRecord] mov eax, [ebp+NTFS.newRecord]
mov [ebp+NTFS.cur_iRecord], eax mov [ebp+NTFS.cur_iRecord], eax
mov esi, [ebp+NTFS.indexPointer] mov esi, [ebp+NTFS.indexPointer]
stdcall ntfs_find_lfn.doit2, 0 call ntfs_find_lfn.doit2
jc ntfsFail jc ntfsFail
mov ebx, [ebp+NTFS.secondIndexBuffer] mov ebx, [ebp+NTFS.secondIndexBuffer]
mov byte [ebx], 0 mov byte [ebx], 0
@ -4008,7 +4003,7 @@ ntfs_SetFileEnd:
ret ret
@@: @@:
call ntfs_lock call ntfs_lock
stdcall ntfs_find_lfn, [esp+4] call ntfs_find_lfn
jc ntfsNotFound jc ntfsNotFound
cmp [ebp+NTFS.cur_iRecord], 16 cmp [ebp+NTFS.cur_iRecord], 16
jc ntfsDenied jc ntfsDenied
@ -4142,7 +4137,7 @@ ntfs_SetFileInfo:
ret ret
@@: @@:
call ntfs_lock call ntfs_lock
stdcall ntfs_find_lfn, [esp+4] call ntfs_find_lfn
jnc @f jnc @f
test eax, eax test eax, eax
jz ntfsFail jz ntfsFail