ext fs debugging

git-svn-id: svn://kolibrios.org@6522 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
pathoswithin 2016-09-14 12:33:51 +00:00
parent 9b003c7938
commit 5ac41a2dfc

View File

@ -1334,7 +1334,7 @@ unlinkInode:
; ebx = inode to unlink ; ebx = inode to unlink
; out: ; out:
; eax = current number of links to inode, -1 = error ; eax = current number of links to inode, -1 = error
push edx esi edi ebx push edx ebx
lea ebx, [ebp+EXTFS.tempInodeBuffer] lea ebx, [ebp+EXTFS.tempInodeBuffer]
call readInode call readInode
jc .fail jc .fail
@ -1410,65 +1410,40 @@ unlinkInode:
jc .fail jc .fail
movzx eax, word [ebx+INODE.linksCount] movzx eax, word [ebx+INODE.linksCount]
@@: @@:
pop ebx edi esi edx pop ebx edx
ret
findInode_parent:
; in: esi -> path string in UTF-8
; out:
; edi -> file name in UTF-8
; esi = inode
push esi
xor edi, edi
.loop:
cmp byte [esi], '/'
jne @f
mov edi, esi
inc esi
jmp .loop
@@:
inc esi
cmp byte [esi-1], 0
jne .loop
cmp edi, 0
jne @f
; parent is root
pop edi
dec esi
jmp .get_inode
@@: ; parent is folder
mov byte [edi], 0
inc edi
pop esi
.get_inode:
push ebx edx
call findInode
pop edx ebx
ret ret
findInode: findInode:
; in: esi -> path string in UTF-8 ; in: esi -> path string in UTF-8
; out: ; out:
; [ebp+EXTFS.mainInodeBuffer] = inode ; edi -> file name in UTF-8
; esi = inode number ; esi = last inode number
; dl = first byte of file/folder name ; [ebp+EXTFS.mainInodeBuffer] = last inode
lea edx, [ebp+EXTFS.rootInodeBuffer] ; ecx = parent inode number
cmp [edx+INODE.sectorsUsed], 0 ; CF=1 -> file not found, edi=0 -> error
je .not_found push esi
cmp byte [esi], 0
jne .next_path_part
; root
push edi ecx
lea esi, [ebp+EXTFS.rootInodeBuffer] lea esi, [ebp+EXTFS.rootInodeBuffer]
lea edi, [ebp+EXTFS.mainInodeBuffer] lea edi, [ebp+EXTFS.mainInodeBuffer]
movzx ecx, [ebp+EXTFS.superblock.inodeSize] movzx ecx, [ebp+EXTFS.superblock.inodeSize]
mov edx, esi
rep movsb rep movsb
pop ecx edi pop esi
pushd 0 ROOT_INODE
cmp [edx+INODE.sectorsUsed], 0
jz .not_found
cmp byte [esi], 0
jnz .next_path_part
xor eax, eax xor eax, eax
xor dl, dl mov edi, esi
mov esi, ROOT_INODE pop esi ecx
ret
@@:
pop esi esi
.error:
pop esi ecx
xor edi, edi
stc
ret ret
.next_path_part: .next_path_part:
@ -1478,12 +1453,12 @@ findInode:
push ecx push ecx
xchg esi, edx xchg esi, edx
call extfsGetFileBlock call extfsGetFileBlock
jc .error_get_block jc @b
xchg esi, edx xchg esi, edx
mov eax, ecx mov eax, ecx
mov ebx, [ebp+EXTFS.mainBlockBuffer] mov ebx, [ebp+EXTFS.mainBlockBuffer]
call extfsReadBlock call extfsReadBlock
jc .error_get_block jc @b
push esi edx push esi edx
mov edx, ebx mov edx, ebx
add edx, [ebp+EXTFS.bytesPerBlock] add edx, [ebp+EXTFS.bytesPerBlock]
@ -1512,50 +1487,37 @@ findInode:
jne @b jne @b
inc esi inc esi
@@: @@:
pop edx edx edi ecx pop edx edx edi ecx eax
; ebx -> matched directory entry, esi -> name without parent, or not changed ; ebx -> matched directory entry, esi -> name without parent, or not changed
cmp edi, esi cmp edi, esi
je .next_folder_block jnz @f
cmp byte [esi], 0
je .get_inode_ret
mov eax, [ebx+DIRENTRY.inodeNumber]
lea ebx, [ebp+EXTFS.mainInodeBuffer]
call readInode
jc .error_get_inode
movzx eax, [ebx+INODE.accessMode]
and eax, TYPE_MASK
cmp eax, DIRECTORY
jne .not_found ; path folder is a file
pop ecx
mov edx, ebx
jmp .next_path_part
.next_folder_block:
pop eax
sub eax, [ebp+EXTFS.sectorsPerBlock] sub eax, [ebp+EXTFS.sectorsPerBlock]
jle .not_found jle .not_found
push eax push eax
inc ecx inc ecx
jmp .folder_block_cycle jmp .folder_block_cycle
.get_inode_ret: @@:
pop eax pop eax
mov dl, [ebx+DIRENTRY.name] mov [esp], eax
mov eax, [ebx+DIRENTRY.inodeNumber] mov eax, [ebx+DIRENTRY.inodeNumber]
lea ebx, [ebp+EXTFS.mainInodeBuffer] lea ebx, [ebp+EXTFS.mainInodeBuffer]
mov esi, eax push eax
call readInode call readInode
ret jc .error
cmp byte [esi], 0
je .ret
mov edx, ebx
movzx eax, [ebx+INODE.accessMode]
and eax, TYPE_MASK
cmp eax, DIRECTORY
jz .next_path_part
xor edi, edi ; path folder is a file
.not_found: .not_found:
movi eax, ERROR_FILE_NOT_FOUND movi eax, ERROR_FILE_NOT_FOUND
stc stc
ret .ret:
pop esi ecx
.error_get_block:
pop ebx
.error_get_inode:
pop ebx
ret ret
writeSuperblock: writeSuperblock:
@ -1596,8 +1558,8 @@ ext_ReadFolder:
pop ebx pop ebx
jc .error_ret jc .error_ret
lea esi, [ebp+EXTFS.mainInodeBuffer] lea esi, [ebp+EXTFS.mainInodeBuffer]
test [esi+INODE.accessMode], DIRECTORY test [esi+INODE.accessMode], FLAG_FILE
jz .error_not_found jnz .error_not_found
jmp @f jmp @f
.root_folder: .root_folder:
@ -1705,8 +1667,8 @@ ext_ReadFolder:
call fsTime2bdfe call fsTime2bdfe
pop edx pop edx
or dword [edx], KOS_DIRECTORY or dword [edx], KOS_DIRECTORY
test [esi+INODE.accessMode], DIRECTORY test [esi+INODE.accessMode], FLAG_FILE
jnz @f jz @f
xor dword [edx], KOS_DIRECTORY ; mark as file xor dword [edx], KOS_DIRECTORY ; mark as file
mov eax, [esi+INODE.fileSize] mov eax, [esi+INODE.fileSize]
stosd stosd
@ -1930,7 +1892,6 @@ ext_GetFileInfo:
jz .is_root jz .is_root
push edx push edx
call findInode call findInode
mov ebx, edx
pop edx pop edx
lea esi, [ebp+EXTFS.mainInodeBuffer] lea esi, [ebp+EXTFS.mainInodeBuffer]
jnc @f jnc @f
@ -1940,9 +1901,10 @@ ext_GetFileInfo:
ret ret
.is_root: .is_root:
xor ebx, ebx mov edi, esi
lea esi, [ebp+EXTFS.rootInodeBuffer] lea esi, [ebp+EXTFS.rootInodeBuffer]
@@: @@:
mov bl, [edi]
xor eax, eax xor eax, eax
mov edi, edx mov edi, edx
mov ecx, 40/4 mov ecx, 40/4
@ -1952,8 +1914,8 @@ ext_GetFileInfo:
or dword [edx], KOS_HIDDEN or dword [edx], KOS_HIDDEN
@@: @@:
or dword [edx], KOS_DIRECTORY or dword [edx], KOS_DIRECTORY
test [esi+INODE.accessMode], DIRECTORY test [esi+INODE.accessMode], FLAG_FILE
jnz @f jz @f
xor dword [edx], KOS_DIRECTORY ; mark as file xor dword [edx], KOS_DIRECTORY ; mark as file
mov eax, [esi+INODE.fileSize] mov eax, [esi+INODE.fileSize]
mov ebx, [esi+INODE.fileSizeHigh] mov ebx, [esi+INODE.fileSizeHigh]
@ -2011,10 +1973,8 @@ ext_SetFileInfo:
;---------------------------------------------------------------- ;----------------------------------------------------------------
ext_Delete: ext_Delete:
call extfsWritingInit call extfsWritingInit
push esi
call findInode call findInode
mov ebx, esi mov ebx, esi
pop esi
push eax push eax
jc .ret jc .ret
pop eax pop eax
@ -2023,7 +1983,7 @@ ext_Delete:
and edx, TYPE_MASK and edx, TYPE_MASK
cmp edx, DIRECTORY cmp edx, DIRECTORY
jne .file jne .file
push esi ebx edx 0 push ebx ecx edx 0
lea esi, [ebp+EXTFS.mainInodeBuffer] lea esi, [ebp+EXTFS.mainInodeBuffer]
.checkDirectory: .checkDirectory:
mov ecx, [esp] mov ecx, [esp]
@ -2057,39 +2017,21 @@ ext_Delete:
jmp .checkDirectory jmp .checkDirectory
.empty: .empty:
pop edx edx ebx esi pop edx edx ecx ebx
.file: .file:
call findInode_parent mov eax, ecx
jc .error push ebx ecx
mov eax, esi
; save file/folder's and parent's inode
push ebx eax
cmp edx, DIRECTORY
jne @f
; Unlink '.'
mov eax, [esp+4]
call unlinkInode call unlinkInode
cmp eax, -1 cmp eax, -1
je .error_stack8 je .error_stack8
; Unlink '..' pop ebx
mov eax, [esp+4]
mov ebx, [esp]
call unlinkInode
cmp eax, -1
je .error_stack8
@@:
pop eax
mov ebx, [esp]
call unlinkInode
cmp eax, -1
je .error_stack4
test eax, eax test eax, eax
jz @f jz @f
; has hardlinks
xor eax, eax xor eax, eax
mov [esp], eax cmp edx, DIRECTORY
jmp .disk_sync jnz .error_stack4_eax ; hardlinks
mov eax, [esp]
call unlinkInode
@@: @@:
mov eax, [esp] mov eax, [esp]
lea ebx, [ebp+EXTFS.mainInodeBuffer] lea ebx, [ebp+EXTFS.mainInodeBuffer]
@ -2194,9 +2136,7 @@ ext_Delete:
.not_empty: .not_empty:
pop eax pop eax
.error_stack8: .error_stack8:
pop eax pop eax eax
.error_stack4:
pop eax
push ERROR_ACCESS_DENIED push ERROR_ACCESS_DENIED
jmp .disk_sync jmp .disk_sync
@ -2213,12 +2153,10 @@ ext_Delete:
;---------------------------------------------------------------- ;----------------------------------------------------------------
ext_CreateFolder: ext_CreateFolder:
call extfsWritingInit call extfsWritingInit
push esi
call findInode call findInode
pop esi
jnc .success ; exist jnc .success ; exist
call findInode_parent test edi, edi
jc .error jz .error
mov eax, esi mov eax, esi
xor ebx, ebx xor ebx, ebx
inc ebx inc ebx
@ -2297,28 +2235,18 @@ parent_link db "..", 0
;---------------------------------------------------------------- ;----------------------------------------------------------------
ext_CreateFile: ext_CreateFile:
call extfsWritingInit call extfsWritingInit
push ebx esi push 0 ebx
call findInode call findInode
mov esi, [esp] jnc .exist
jc @f test edi, edi
call ext_unlock jz .error
call ext_Delete
push eax
call ext_lock
pop eax
test eax, eax
jnz .error
mov esi, [esp]
@@:
call findInode_parent
jc .error
mov eax, esi mov eax, esi
xor ebx, ebx xor ebx, ebx
inc ebx inc ebx
call extfsResourceAlloc call extfsResourceAlloc
jc .error jc .error
inc ebx inc ebx
push ebx esi edi push ebx ebx esi edi
xor al, al xor al, al
lea edi, [ebp+EXTFS.tempInodeBuffer] lea edi, [ebp+EXTFS.tempInodeBuffer]
movzx ecx, [ebp+EXTFS.superblock.inodeSize] movzx ecx, [ebp+EXTFS.superblock.inodeSize]
@ -2334,18 +2262,32 @@ ext_CreateFile:
mov [ebx+INODE.accessMode], FLAG_FILE or PERMISSIONS mov [ebx+INODE.accessMode], FLAG_FILE or PERMISSIONS
mov eax, edx mov eax, edx
call writeInode call writeInode
jc .error jc .error2
; link parent to child ; link parent to child
mov eax, esi mov eax, esi
mov ebx, edx mov ebx, edx
mov esi, edi mov esi, edi
mov dl, DIR_FLAG_FILE mov dl, DIR_FLAG_FILE
call linkInode call linkInode
jc .error jc .error2
pop esi ebx pop esi ebx
call ext_unlock push ebx esi
jmp ext_WriteFile mov ecx, [ebx+12]
jmp ext_WriteFile.start
.exist:
lea edx, [ebp+EXTFS.mainInodeBuffer]
movi eax, ERROR_ACCESS_DENIED
test [edx+INODE.accessMode], FLAG_FILE
jz .error ; not a file
pop ebx
push ebx esi
mov eax, esi
mov ecx, [ebx+12]
call extfsTruncateFile
jnc ext_WriteFile.start
.error2:
pop ebx
.error: .error:
push eax push eax
call ext_unlock call ext_unlock
@ -2358,20 +2300,22 @@ ext_WriteFile:
call extfsWritingInit call extfsWritingInit
push 0 ebx push 0 ebx
call findInode call findInode
pop ebx
push ebx esi
jc .error jc .error
lea edx, [ebp+EXTFS.mainInodeBuffer] lea edx, [ebp+EXTFS.mainInodeBuffer]
movi eax, ERROR_ACCESS_DENIED movi eax, ERROR_ACCESS_DENIED
test [edx+INODE.accessMode], FLAG_FILE test [edx+INODE.accessMode], FLAG_FILE
jz .error ; not a file jz .error ; not a file
mov ebx, [esp]
push esi ; inode number
mov eax, esi
mov ecx, [ebx+4] mov ecx, [ebx+4]
add ecx, [ebx+12]
.start:
mov eax, esi
call extfsExtendFile call extfsExtendFile
jc .error2 jc .error
mov eax, [ebx+4]
mov ecx, [ebx+12] mov ecx, [ebx+12]
mov esi, [ebx+16] mov esi, [ebx+16]
mov eax, [edx+INODE.fileSize]
push eax push eax
xor edx, edx xor edx, edx
div [ebp+EXTFS.bytesPerBlock] div [ebp+EXTFS.bytesPerBlock]
@ -2451,8 +2395,7 @@ ext_WriteFile:
mov [esp+12], eax mov [esp+12], eax
.write_inode: .write_inode:
lea ebx, [ebp+EXTFS.tempInodeBuffer] lea ebx, [ebp+EXTFS.tempInodeBuffer]
pop [ebx+INODE.fileSize] pop eax eax
pop eax
call writeInode call writeInode
pop ebx pop ebx
mov ebx, [ebx+12] mov ebx, [ebx+12]
@ -2469,10 +2412,8 @@ ext_WriteFile:
pop eax pop eax
ret ret
.error2:
pop ebx
.error: .error:
pop ebx ebx pop ebx ebx ebx
push eax push eax
jmp @b jmp @b