ext fs optimizing

git-svn-id: svn://kolibrios.org@6756 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
pathoswithin 2016-11-24 17:29:52 +00:00
parent cca1343075
commit 69d1122a04

View File

@ -305,87 +305,117 @@ extfsReadBlock:
extfsReadDescriptor: extfsReadDescriptor:
; in: eax = block group number ; in: eax = block group number
; out: ; out: ebx -> block group descriptor
; [ebp+EXTFS.tempBlockBuffer] -> relevant block push ecx edx
; eax -> block group descriptor, 0 = error mov edx, [ebp+EXTFS.superblock.firstGroupBlock]
push edx ebx inc edx
mov ecx, [ebp+EXTFS.sectorsPerBlockLog]
shl edx, cl
shl eax, 5 shl eax, 5
xor edx, edx mov ecx, eax
div [ebp+EXTFS.bytesPerBlock] and ecx, 511
add eax, [ebp+EXTFS.superblock.firstGroupBlock] shr eax, 9
inc eax
mov ebx, [ebp+EXTFS.tempBlockBuffer]
call extfsReadBlock
jc .fail
mov eax, ebx
add eax, edx add eax, edx
@@: mov ebx, [ebp+EXTFS.tempBlockBuffer]
pop ebx edx push ecx
ret call fs_read32_sys
pop ecx
.fail: add ebx, ecx
xor eax, eax test eax, eax
jz @f
movi eax, ERROR_DEVICE
stc stc
jmp @b @@:
pop edx ecx
ret
extfsWriteDescriptor: extfsWriteDescriptor:
; in: ; in: eax = block group number
; eax = block group number push ebx ecx edx
; [ebp+EXTFS.tempBlockBuffer] -> relevant block mov edx, [ebp+EXTFS.superblock.firstGroupBlock]
push edx ebx inc edx
shl eax, 5 mov ecx, [ebp+EXTFS.sectorsPerBlockLog]
xor edx, edx shl edx, cl
div [ebp+EXTFS.bytesPerBlock] shr eax, 9-5
add eax, [ebp+EXTFS.superblock.firstGroupBlock] add eax, edx
inc eax
mov ebx, [ebp+EXTFS.tempBlockBuffer] mov ebx, [ebp+EXTFS.tempBlockBuffer]
call extfsWriteBlock call fs_write32_sys
pop ebx edx pop edx ecx ebx
ret ret
extfsResourceFree: extfsExtentFree:
; in: ; in: eax = first block number, ecx = extent size
; ecx=0 -> block, ecx=1 -> inode push ebx edx edi
; eax = block/inode number
push ebx edx
sub eax, [ebp+EXTFS.superblock.firstGroupBlock] sub eax, [ebp+EXTFS.superblock.firstGroupBlock]
xor edx, edx xor edx, edx
div [ebp+EXTFS.superblock.blocksPerGroup] mov ebx, [ebp+EXTFS.superblock.blocksPerGroup]
div ebx
sub ebx, edx
sub ebx, ecx
jc .ret
push edx eax push edx eax
call extfsReadDescriptor call extfsReadDescriptor
jc .fail2 jc .fail2
inc [eax+BGDESCR.blocksFree+ecx*2] add [ebx+BGDESCR.blocksFree], cx
mov edx, [eax+BGDESCR.blockBitmap+ecx*4] mov edx, [ebx+BGDESCR.blockBitmap]
pop eax pop eax
call extfsWriteDescriptor call extfsWriteDescriptor
jc .fail
mov eax, edx mov eax, edx
mov ebx, [ebp+EXTFS.tempBlockBuffer] mov ebx, [ebp+EXTFS.tempBlockBuffer]
call extfsReadBlock call extfsReadBlock
jc .fail jc .fail
pop eax pop eax
push edx push ecx ebx edx
mov edx, eax add [ebp+EXTFS.superblock.blocksFree], ecx
and edx, 31 mov edi, eax
shr eax, 5 shr edi, 5
shl eax, 2 shl edi, 2
add eax, [ebp+EXTFS.tempBlockBuffer] add edi, ebx
btr [eax], edx and eax, 31
pop eax mov edx, ecx
mov ebx, [ebp+EXTFS.tempBlockBuffer] mov ecx, 32
call extfsWriteBlock sub ecx, eax
jc @f sub edx, ecx
inc [ebp+EXTFS.superblock.blocksFree+ecx*4] jnc @f
add ecx, edx
xor edx, edx
@@: @@:
or ebx, -1
shl ebx, cl
not ebx
mov ecx, eax
shl ebx, cl
not ebx
and [edi], ebx
mov ecx, edx
jecxz @f
shr ecx, 5
add edi, 4
xor eax, eax
rep stosd
and edx, 31
mov ecx, edx
jecxz @f
not eax
shl eax, cl
and [edi], eax
@@:
pop eax ebx
call extfsWriteBlock
pop ecx
mov eax, ecx
mul [ebp+EXTFS.sectorsPerBlock]
sub [ebp+EXTFS.inodeBuffer.sectorsUsed], eax
.ret:
pop edi edx ebx
xor eax, eax xor eax, eax
pop edx ebx
ret ret
.fail2: .fail2:
pop eax pop eax
.fail: .fail:
pop eax pop eax
jmp @b jmp .ret
extfsInodeAlloc: extfsInodeAlloc:
; in: eax = parent inode number ; in: eax = parent inode number
@ -399,12 +429,11 @@ extfsInodeAlloc:
.test_block_group: .test_block_group:
call extfsReadDescriptor call extfsReadDescriptor
jc .fail jc .fail
dec [eax+BGDESCR.inodesFree] dec [ebx+BGDESCR.inodesFree]
js .next js .next
mov edx, [eax+BGDESCR.inodeBitmap] mov edx, [ebx+BGDESCR.inodeBitmap]
mov eax, [esp] mov eax, [esp]
call extfsWriteDescriptor call extfsWriteDescriptor
jc .fail
mov eax, edx mov eax, edx
mov ebx, [ebp+EXTFS.tempBlockBuffer] mov ebx, [ebp+EXTFS.tempBlockBuffer]
mov edi, ebx mov edi, ebx
@ -426,23 +455,15 @@ extfsInodeAlloc:
mov ecx, eax mov ecx, eax
mov eax, edx mov eax, edx
call extfsWriteBlock call extfsWriteBlock
jc .fail
pop eax pop eax
mul [ebp+EXTFS.superblock.inodesPerGroup] mul [ebp+EXTFS.superblock.inodesPerGroup]
add eax, ecx
dec [ebp+EXTFS.superblock.inodesFree] dec [ebp+EXTFS.superblock.inodesFree]
mov ebx, eax lea ebx, [eax+ecx+1]
pop eax
xor eax, eax xor eax, eax
@@: .ret:
pop edi esi edx ecx pop edi edi esi edx ecx
ret ret
.fail:
pop eax eax
movi eax, ERROR_DEVICE
jmp @b
.next: .next:
jmp esi jmp esi
@ -461,17 +482,16 @@ extfsInodeAlloc:
mov esi, .backward mov esi, .backward
.backward: .backward:
sub dword[esp], 1 sub dword[esp], 1
jc .fail
mov eax, [esp] mov eax, [esp]
jmp .test_block_group jnc .test_block_group
movi eax, ERROR_DISK_FULL
.fail:
pop edi
jmp .ret
extfsExtentAlloc: extfsExtentAlloc:
; in: ; in: eax = parent inode number, ecx = blocks max
; eax = parent inode number ; out: ebx = first block number, ecx = blocks allocated
; ecx = blocks max
; out:
; ebx = first block number
; ecx = blocks allocated
push edx esi edi ecx push edx esi edi ecx
dec eax dec eax
xor edx, edx xor edx, edx
@ -480,9 +500,9 @@ extfsExtentAlloc:
.test_block_group: .test_block_group:
call extfsReadDescriptor call extfsReadDescriptor
jc .fail jc .fail
dec [eax+BGDESCR.blocksFree] dec [ebx+BGDESCR.blocksFree]
js .next js .next
mov eax, [eax+BGDESCR.blockBitmap] mov eax, [ebx+BGDESCR.blockBitmap]
mov ebx, [ebp+EXTFS.tempBlockBuffer] mov ebx, [ebp+EXTFS.tempBlockBuffer]
mov edx, eax mov edx, eax
mov edi, ebx mov edi, ebx
@ -502,8 +522,10 @@ extfsExtentAlloc:
not eax not eax
shr eax, cl shr eax, cl
shl eax, cl shl eax, cl
mov ebx, 32
bsf ebx, eax bsf ebx, eax
jnz @f
mov ebx, 32
@@:
sub ebx, ecx sub ebx, ecx
mov eax, [esp+16] mov eax, [esp+16]
cmp ebx, eax cmp ebx, eax
@ -574,33 +596,29 @@ extfsExtentAlloc:
pop eax pop eax
mov ebx, [ebp+EXTFS.tempBlockBuffer] mov ebx, [ebp+EXTFS.tempBlockBuffer]
call extfsWriteBlock call extfsWriteBlock
jc .fail
mov eax, [esp] mov eax, [esp]
call extfsReadDescriptor call extfsReadDescriptor
jc .fail jc .fail
mov ecx, [esp+8] mov ecx, [esp+8]
sub [eax+BGDESCR.blocksFree], cx sub [ebx+BGDESCR.blocksFree], cx
jc .fail jc .fail
sub [ebp+EXTFS.superblock.blocksFree], ecx sub [ebp+EXTFS.superblock.blocksFree], ecx
mov eax, [esp] mov eax, [esp]
call extfsWriteDescriptor call extfsWriteDescriptor
jc .fail
pop eax ebx pop eax ebx
mul [ebp+EXTFS.superblock.blocksPerGroup] mul [ebp+EXTFS.superblock.blocksPerGroup]
mov ebx, eax mov ebx, eax
add ebx, esi add ebx, esi
xor eax, eax add ebx, [ebp+EXTFS.superblock.firstGroupBlock]
pop ecx pop ecx
mov eax, ecx
mul [ebp+EXTFS.sectorsPerBlock]
add [ebp+EXTFS.inodeBuffer.sectorsUsed], eax
xor eax, eax
.ret: .ret:
pop edi esi edx pop edi esi edx
ret ret
.fail:
pop eax eax
movi eax, ERROR_DEVICE
xor ecx, ecx
jmp .ret
.next: ; search forward, then backward .next: ; search forward, then backward
pop eax pop eax
cmp eax, [esp] cmp eax, [esp]
@ -620,9 +638,11 @@ extfsExtentAlloc:
dec eax dec eax
push eax push eax
jns .test_block_group jns .test_block_group
pop eax eax
movi eax, ERROR_DISK_FULL movi eax, ERROR_DISK_FULL
.fail:
add esp, 12
xor ecx, ecx xor ecx, ecx
stc
jmp .ret jmp .ret
extfsGetExtent: extfsGetExtent:
@ -753,6 +773,8 @@ extfsGetExtent:
.calculateExtent: .calculateExtent:
lea esi, [ebx+edx*4] lea esi, [ebx+edx*4]
lodsd lodsd
test eax, eax
jz .noBlock
mov ebx, eax mov ebx, eax
sub ecx, edx sub ecx, edx
xor edx, edx xor edx, edx
@ -773,30 +795,21 @@ extfsGetExtent:
getInodeLocation: getInodeLocation:
; in: eax = inode number ; in: eax = inode number
; out: ebx = inode sector, edx = offset in sector ; out: eax = inode sector, edx = offset in sector
dec eax dec eax
xor edx, edx xor edx, edx
div [ebp+EXTFS.superblock.inodesPerGroup] div [ebp+EXTFS.superblock.inodesPerGroup]
mov ecx, edx call extfsReadDescriptor
shl eax, 5
xor edx, edx
div [ebp+EXTFS.bytesPerBlock]
add eax, [ebp+EXTFS.superblock.firstGroupBlock]
inc eax
mov ebx, [ebp+EXTFS.tempBlockBuffer]
call extfsReadBlock
jc @f jc @f
add ebx, edx
mov ebx, [ebx+BGDESCR.inodeTable] mov ebx, [ebx+BGDESCR.inodeTable]
mov eax, ecx
mov ecx, [ebp+EXTFS.sectorsPerBlockLog] mov ecx, [ebp+EXTFS.sectorsPerBlockLog]
shl ebx, cl shl ebx, cl
mov eax, edx
mul [ebp+EXTFS.superblock.inodeSize] mul [ebp+EXTFS.superblock.inodeSize]
mov edx, eax mov edx, eax
shr eax, 9 shr eax, 9
and edx, 511 and edx, 511
add ebx, eax add eax, ebx
xor eax, eax
@@: @@:
ret ret
@ -810,7 +823,6 @@ writeInode:
pop eax pop eax
call getInodeLocation call getInodeLocation
jc .ret jc .ret
mov eax, ebx
mov ebx, [ebp+EXTFS.tempBlockBuffer] mov ebx, [ebp+EXTFS.tempBlockBuffer]
mov ecx, eax mov ecx, eax
call fs_read32_sys call fs_read32_sys
@ -838,7 +850,6 @@ readInode:
mov edi, ebx mov edi, ebx
call getInodeLocation call getInodeLocation
jc @f jc @f
mov eax, ebx
mov ebx, [ebp+EXTFS.tempBlockBuffer] mov ebx, [ebp+EXTFS.tempBlockBuffer]
call fs_read32_sys call fs_read32_sys
test eax, eax test eax, eax
@ -1002,9 +1013,6 @@ doublyIndirectBlockAlloc:
call extfsExtentAlloc call extfsExtentAlloc
jc .end jc .end
sub [esp+12], ecx sub [esp+12], ecx
mov eax, ecx
imul eax, [ebp+EXTFS.sectorsPerBlock]
add [ebp+EXTFS.inodeBuffer.sectorsUsed], eax
jmp @b jmp @b
extfsExtendFile: extfsExtendFile:
@ -1040,9 +1048,6 @@ extfsExtendFile:
call extfsExtentAlloc call extfsExtentAlloc
jc .errDone jc .errDone
sub [esp], ecx sub [esp], ecx
mov eax, ecx
imul eax, [ebp+EXTFS.sectorsPerBlock]
add [esi+INODE.sectorsUsed], eax
cmp edx, 12 cmp edx, 12
jc .directBlocks jc .directBlocks
sub edx, 12 sub edx, 12
@ -1168,9 +1173,6 @@ extfsExtendFile:
call extfsExtentAlloc call extfsExtentAlloc
jc .errSave jc .errSave
sub [esp], ecx sub [esp], ecx
mov eax, ecx
imul eax, [ebp+EXTFS.sectorsPerBlock]
add [ebp+EXTFS.inodeBuffer.sectorsUsed], eax
jmp @b jmp @b
@@: @@:
@ -1206,26 +1208,40 @@ freeIndirectBlock:
lea edi, [ebx+edx*4] lea edi, [ebx+edx*4]
neg edx neg edx
add edx, [ebp+EXTFS.dwordsPerBlock] add edx, [ebp+EXTFS.dwordsPerBlock]
.freeExtent:
mov ebx, [edi]
test ebx, ebx
jz .end
xor eax, eax
xor ecx, ecx xor ecx, ecx
@@: @@:
mov eax, [edi]
test eax, eax
jz .end
call extfsResourceFree
stosd stosd
inc ecx
dec edx dec edx
jnz @b jz @f
mov eax, [edi]
sub eax, ebx
sub eax, ecx
jz @b
@@:
mov eax, ebx
call extfsExtentFree
test edx, edx
jnz .freeExtent
dec dword[esp+8] dec dword[esp+8]
.end: .end:
pop edx edi pop edx edi
mov eax, [edi] mov eax, [edi]
test edx, edx test edx, edx
jnz @f jnz @f
call extfsResourceFree xor ecx, ecx
inc ecx
call extfsExtentFree
stosd stosd
jmp .done jmp .done
@@: @@:
mov ebx, [ebp+EXTFS.mainBlockBuffer]
call extfsWriteBlock call extfsWriteBlock
add edi, 4 add edi, 4
.done: .done:
@ -1270,7 +1286,8 @@ freeDoublyIndirectBlock:
test edx, edx test edx, edx
jnz @f jnz @f
xor ecx, ecx xor ecx, ecx
call extfsResourceFree inc ecx
call extfsExtentFree
stosd stosd
jmp .done jmp .done
@ -1291,9 +1308,7 @@ freeDoublyIndirectBlock:
ret ret
extfsTruncateFile: extfsTruncateFile:
; in: ; in: ecx = new size, [ebp+EXTFS.inodeBuffer] = inode
; [ebp+EXTFS.inodeBuffer] = inode
; ecx = new size
push ebx ecx edx esi edi push ebx ecx edx esi edi
lea esi, [ebp+EXTFS.inodeBuffer] lea esi, [ebp+EXTFS.inodeBuffer]
cmp ecx, [esi+INODE.fileSize] cmp ecx, [esi+INODE.fileSize]
@ -1322,11 +1337,12 @@ extfsTruncateFile:
neg edx neg edx
add edx, 12 add edx, 12
xor ecx, ecx xor ecx, ecx
inc ecx
@@: @@:
mov eax, [edi] mov eax, [edi]
test eax, eax test eax, eax
jz .ret jz .ret
call extfsResourceFree call extfsExtentFree
stosd stosd
dec edx dec edx
jnz @b jnz @b
@ -1368,7 +1384,8 @@ extfsTruncateFile:
test edx, edx test edx, edx
jnz @f jnz @f
xor ecx, ecx xor ecx, ecx
call extfsResourceFree inc ecx
call extfsExtentFree
mov [esi+INODE.tripleAddress], eax mov [esi+INODE.tripleAddress], eax
jmp .done jmp .done
@ -1462,7 +1479,6 @@ linkInode:
pop eax pop eax
mov ebx, [ebp+EXTFS.tempBlockBuffer] mov ebx, [ebp+EXTFS.tempBlockBuffer]
call extfsWriteBlock call extfsWriteBlock
jc .error_get_inode_block
pop ecx pop ecx
inc ecx inc ecx
cmp ecx, [esp] cmp ecx, [esp]
@ -1502,7 +1518,6 @@ linkInode:
mov eax, edx mov eax, edx
mov ebx, [ebp+EXTFS.tempBlockBuffer] mov ebx, [ebp+EXTFS.tempBlockBuffer]
call extfsWriteBlock call extfsWriteBlock
jc .error_block_write
mov eax, [esp] mov eax, [esp]
lea ebx, [ebp+EXTFS.inodeBuffer] lea ebx, [ebp+EXTFS.inodeBuffer]
call readInode call readInode
@ -1527,11 +1542,8 @@ linkInode:
jmp @b jmp @b
unlinkInode: unlinkInode:
; in: ; in: eax = inode from which to unlink, ebx = inode to unlink
; eax = inode from which to unlink ; out: eax = current number of links to inode, -1 = error
; ebx = inode to unlink
; out:
; eax = current number of links to inode, -1 = error
push edx ebx push edx ebx
lea ebx, [ebp+EXTFS.inodeBuffer] lea ebx, [ebp+EXTFS.inodeBuffer]
call readInode call readInode
@ -1593,7 +1605,6 @@ unlinkInode:
mov eax, edi mov eax, edi
mov ebx, [ebp+EXTFS.tempBlockBuffer] mov ebx, [ebp+EXTFS.tempBlockBuffer]
call extfsWriteBlock call extfsWriteBlock
jc .fail
mov eax, [esp] mov eax, [esp]
lea ebx, [ebp+EXTFS.inodeBuffer] lea ebx, [ebp+EXTFS.inodeBuffer]
call readInode call readInode
@ -1624,7 +1635,7 @@ findInode:
pop esi pop esi
pushd 0 ROOT_INODE pushd 0 ROOT_INODE
mov edi, esi mov edi, esi
cmp [edx+INODE.sectorsUsed], 0 cmp [edx+INODE.fileSize], 0
jz .not_found jz .not_found
cmp byte [esi], 0 cmp byte [esi], 0
jnz .next_path_part jnz .next_path_part
@ -1641,7 +1652,7 @@ findInode:
ret ret
.next_path_part: .next_path_part:
push [edx+INODE.sectorsUsed] push [edx+INODE.fileSize]
xor ecx, ecx xor ecx, ecx
.folder_block_cycle: .folder_block_cycle:
push ecx push ecx
@ -1682,7 +1693,7 @@ findInode:
; 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
jnz @f jnz @f
sub eax, [ebp+EXTFS.sectorsPerBlock] sub eax, [ebp+EXTFS.bytesPerBlock]
jle .not_found jle .not_found
push eax push eax
inc ecx inc ecx
@ -2193,6 +2204,13 @@ ext_Delete:
inc ecx inc ecx
jmp .checkDirectory jmp .checkDirectory
.not_empty:
pop eax eax
.error_stack8:
pop eax eax
push ERROR_ACCESS_DENIED
jmp .ret
.empty: .empty:
cmp eax, ERROR_END_OF_FILE cmp eax, ERROR_END_OF_FILE
jnz .not_empty_eax jnz .not_empty_eax
@ -2231,24 +2249,36 @@ ext_Delete:
mov ebx, edi mov ebx, edi
call writeInode call writeInode
jc .error_stack4_eax jc .error_stack4_eax
cmp edx, DIRECTORY pop eax
jne @f
mov eax, [esp]
dec eax dec eax
mov ecx, edx
xor edx, edx xor edx, edx
div [ebp+EXTFS.superblock.inodesPerGroup] div [ebp+EXTFS.superblock.inodesPerGroup]
push eax push edx eax
call extfsReadDescriptor call extfsReadDescriptor
jc .error_stack8 jc .error_stack8_eax
dec [eax+BGDESCR.directoriesCount] cmp ecx, DIRECTORY
jnz @f
dec [ebx+BGDESCR.directoriesCount]
@@:
inc [ebx+BGDESCR.inodesFree]
mov ecx, [ebx+BGDESCR.inodeBitmap]
pop eax pop eax
call extfsWriteDescriptor call extfsWriteDescriptor
@@: ; free inode mov eax, ecx
mov ebx, [ebp+EXTFS.tempBlockBuffer]
call extfsReadBlock
jc .error_stack4_eax
pop eax pop eax
dec eax mov edx, eax
xor ecx, ecx and edx, 31
inc ecx shr eax, 5
call extfsResourceFree shl eax, 2
add eax, ebx
btr [eax], edx
mov eax, ecx
call extfsWriteBlock
inc [ebp+EXTFS.superblock.inodesFree]
push eax push eax
.disk_sync: .disk_sync:
call writeSuperblock call writeSuperblock
@ -2260,15 +2290,10 @@ ext_Delete:
pop eax pop eax
ret ret
.not_empty:
pop eax eax
.error_stack8:
pop eax eax
push ERROR_ACCESS_DENIED
jmp .disk_sync
.not_empty_eax: .not_empty_eax:
add esp, 12 pop ebx ebx
.error_stack8_eax:
pop ebx
.error_stack4_eax: .error_stack4_eax:
pop ebx pop ebx
push eax push eax
@ -2284,7 +2309,6 @@ ext_CreateFolder:
mov eax, esi mov eax, esi
call extfsInodeAlloc call extfsInodeAlloc
jc .error jc .error
inc ebx
push ebx esi edi push ebx esi edi
xor al, al xor al, al
lea edi, [ebp+EXTFS.inodeBuffer] lea edi, [ebp+EXTFS.inodeBuffer]
@ -2333,8 +2357,8 @@ ext_CreateFolder:
div [ebp+EXTFS.superblock.inodesPerGroup] div [ebp+EXTFS.superblock.inodesPerGroup]
mov edx, eax mov edx, eax
call extfsReadDescriptor call extfsReadDescriptor
jc @f jc .error
inc [eax+BGDESCR.directoriesCount] inc [ebx+BGDESCR.directoriesCount]
mov eax, edx mov eax, edx
call extfsWriteDescriptor call extfsWriteDescriptor
.success: .success:
@ -2347,10 +2371,6 @@ ext_CreateFolder:
pop eax pop eax
ret ret
@@:
movi eax, ERROR_DEVICE
jmp .error
self_link db ".", 0 self_link db ".", 0
parent_link db "..", 0 parent_link db "..", 0
@ -2365,7 +2385,6 @@ ext_CreateFile:
mov eax, esi mov eax, esi
call extfsInodeAlloc call extfsInodeAlloc
jc .error jc .error
inc ebx
push ebx ebx esi edi push ebx ebx esi edi
xor al, al xor al, al
lea edi, [ebp+EXTFS.inodeBuffer] lea edi, [ebp+EXTFS.inodeBuffer]