Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 6522 → Rev 6521

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