forked from KolibriOS/kolibrios
ext fs optimizing
git-svn-id: svn://kolibrios.org@6848 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
9a9304d04f
commit
1ab6d8bc4e
@ -164,6 +164,8 @@ dwordsPerBlock dd ?
|
|||||||
dwordsPerBranch dd ? ; dwordsPerBlock ^ 2
|
dwordsPerBranch dd ? ; dwordsPerBlock ^ 2
|
||||||
mainBlockBuffer dd ?
|
mainBlockBuffer dd ?
|
||||||
tempBlockBuffer dd ?
|
tempBlockBuffer dd ?
|
||||||
|
descriptorTable dd ?
|
||||||
|
descriptorTableEnd dd ?
|
||||||
align0 rb 200h-EXTFS.align0
|
align0 rb 200h-EXTFS.align0
|
||||||
superblock SUPERBLOCK
|
superblock SUPERBLOCK
|
||||||
align1 rb 400h-EXTFS.align1
|
align1 rb 400h-EXTFS.align1
|
||||||
@ -254,9 +256,33 @@ ext2_create_partition:
|
|||||||
jz @f
|
jz @f
|
||||||
.read_only:
|
.read_only:
|
||||||
or [ebp+EXTFS.mountType], READ_ONLY
|
or [ebp+EXTFS.mountType], READ_ONLY
|
||||||
@@: ; read root inode
|
@@:
|
||||||
|
mov eax, [ebx+SUPERBLOCK.inodesTotal]
|
||||||
|
dec eax
|
||||||
|
xor edx, edx
|
||||||
|
div [ebx+SUPERBLOCK.inodesPerGroup]
|
||||||
|
inc eax
|
||||||
|
shl eax, 5
|
||||||
|
push eax eax
|
||||||
|
call kernel_alloc
|
||||||
|
pop ecx
|
||||||
|
test eax, eax
|
||||||
|
jz .error2
|
||||||
|
mov [ebp+EXTFS.descriptorTable], eax
|
||||||
|
mov ebx, eax
|
||||||
|
add eax, ecx
|
||||||
|
mov [ebp+EXTFS.descriptorTableEnd], eax
|
||||||
|
mov eax, [ebp+EXTFS.superblock.firstGroupBlock]
|
||||||
|
inc eax
|
||||||
|
mul [ebp+EXTFS.sectorsPerBlock]
|
||||||
|
dec ecx
|
||||||
|
shr ecx, 9
|
||||||
|
inc ecx
|
||||||
|
call fs_read64_sys
|
||||||
|
test eax, eax
|
||||||
|
jnz @f
|
||||||
|
mov al, ROOT_INODE
|
||||||
lea ebx, [ebp+EXTFS.rootInodeBuffer]
|
lea ebx, [ebp+EXTFS.rootInodeBuffer]
|
||||||
mov eax, ROOT_INODE
|
|
||||||
call readInode
|
call readInode
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jnz @f
|
jnz @f
|
||||||
@ -265,6 +291,8 @@ ext2_create_partition:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
@@:
|
@@:
|
||||||
|
stdcall kernel_free, [ebp+EXTFS.descriptorTable]
|
||||||
|
.error2:
|
||||||
stdcall kernel_free, [ebp+EXTFS.mainBlockBuffer]
|
stdcall kernel_free, [ebp+EXTFS.mainBlockBuffer]
|
||||||
.error:
|
.error:
|
||||||
mov eax, ebp
|
mov eax, ebp
|
||||||
@ -278,8 +306,9 @@ ext2_create_partition:
|
|||||||
; unmount EXT partition
|
; unmount EXT partition
|
||||||
ext_free:
|
ext_free:
|
||||||
; in: eax -> EXTFS structure
|
; in: eax -> EXTFS structure
|
||||||
push eax
|
push eax [eax+EXTFS.mainBlockBuffer]
|
||||||
stdcall kernel_free, [eax+EXTFS.mainBlockBuffer]
|
stdcall kernel_free, [eax+EXTFS.descriptorTable]
|
||||||
|
call kernel_free
|
||||||
pop eax
|
pop eax
|
||||||
jmp free
|
jmp free
|
||||||
|
|
||||||
@ -303,44 +332,17 @@ extfsReadBlock:
|
|||||||
@@:
|
@@:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
extfsReadDescriptor:
|
|
||||||
; in: eax = block group number
|
|
||||||
; out: ebx -> block group descriptor
|
|
||||||
push ecx edx
|
|
||||||
mov edx, [ebp+EXTFS.superblock.firstGroupBlock]
|
|
||||||
inc edx
|
|
||||||
mov ecx, [ebp+EXTFS.sectorsPerBlockLog]
|
|
||||||
shl edx, cl
|
|
||||||
shl eax, 5
|
|
||||||
mov ecx, eax
|
|
||||||
and ecx, 511
|
|
||||||
shr eax, 9
|
|
||||||
add eax, edx
|
|
||||||
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
|
||||||
push ecx
|
|
||||||
call fs_read32_sys
|
|
||||||
pop ecx
|
|
||||||
add ebx, ecx
|
|
||||||
test eax, eax
|
|
||||||
jz @f
|
|
||||||
movi eax, ERROR_DEVICE
|
|
||||||
stc
|
|
||||||
@@:
|
|
||||||
pop edx ecx
|
|
||||||
ret
|
|
||||||
|
|
||||||
extfsWriteDescriptor:
|
extfsWriteDescriptor:
|
||||||
; in: eax = block group number
|
; in: ebx = block group descriptor
|
||||||
push ebx ecx edx
|
mov eax, [ebp+EXTFS.superblock.firstGroupBlock]
|
||||||
mov edx, [ebp+EXTFS.superblock.firstGroupBlock]
|
inc eax
|
||||||
inc edx
|
mul [ebp+EXTFS.sectorsPerBlock]
|
||||||
mov ecx, [ebp+EXTFS.sectorsPerBlockLog]
|
sub ebx, [ebp+EXTFS.descriptorTable]
|
||||||
shl edx, cl
|
shr ebx, 9
|
||||||
shr eax, 9-5
|
add eax, ebx
|
||||||
add eax, edx
|
shl ebx, 9
|
||||||
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
add ebx, [ebp+EXTFS.descriptorTable]
|
||||||
call fs_write32_sys
|
call fs_write32_sys
|
||||||
pop edx ecx ebx
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
extfsExtentFree:
|
extfsExtentFree:
|
||||||
@ -353,19 +355,24 @@ extfsExtentFree:
|
|||||||
sub ebx, edx
|
sub ebx, edx
|
||||||
sub ebx, ecx
|
sub ebx, ecx
|
||||||
jc .ret
|
jc .ret
|
||||||
push edx eax
|
push edx
|
||||||
call extfsReadDescriptor
|
mov ebx, [ebp+EXTFS.descriptorTable]
|
||||||
jc .fail2
|
shl eax, 5
|
||||||
|
add ebx, eax
|
||||||
|
mov eax, ecx
|
||||||
|
mul [ebp+EXTFS.sectorsPerBlock]
|
||||||
add [ebx+BGDESCR.blocksFree], cx
|
add [ebx+BGDESCR.blocksFree], cx
|
||||||
mov edx, [ebx+BGDESCR.blockBitmap]
|
add [ebp+EXTFS.superblock.blocksFree], ecx
|
||||||
pop eax
|
sub [ebp+EXTFS.inodeBuffer.sectorsUsed], eax
|
||||||
|
push [ebx+BGDESCR.blockBitmap]
|
||||||
call extfsWriteDescriptor
|
call extfsWriteDescriptor
|
||||||
mov eax, edx
|
|
||||||
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
|
||||||
call extfsReadBlock
|
|
||||||
jc .fail
|
|
||||||
pop eax
|
pop eax
|
||||||
push ecx ebx edx
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
||||||
|
mov edx, eax
|
||||||
|
call extfsReadBlock
|
||||||
|
pop eax
|
||||||
|
jc .ret
|
||||||
|
push ebx edx
|
||||||
mov edi, eax
|
mov edi, eax
|
||||||
shr edi, 5
|
shr edi, 5
|
||||||
shl edi, 2
|
shl edi, 2
|
||||||
@ -402,43 +409,35 @@ extfsExtentFree:
|
|||||||
@@:
|
@@:
|
||||||
pop eax ebx
|
pop eax ebx
|
||||||
call extfsWriteBlock
|
call extfsWriteBlock
|
||||||
pop ecx
|
|
||||||
mov eax, ecx
|
|
||||||
add [ebp+EXTFS.superblock.blocksFree], ecx
|
|
||||||
mul [ebp+EXTFS.sectorsPerBlock]
|
|
||||||
sub [ebp+EXTFS.inodeBuffer.sectorsUsed], eax
|
|
||||||
.ret:
|
.ret:
|
||||||
pop edi edx ebx
|
pop edi edx ebx
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.fail2:
|
|
||||||
pop eax
|
|
||||||
.fail:
|
|
||||||
pop eax
|
|
||||||
jmp .ret
|
|
||||||
|
|
||||||
extfsInodeAlloc:
|
extfsInodeAlloc:
|
||||||
; in: eax = parent inode number
|
; in: eax = parent inode number
|
||||||
; out: ebx = allocated inode number
|
; out: ebx = allocated inode number
|
||||||
push ecx edx esi edi
|
push ecx edx edi
|
||||||
dec eax
|
dec eax
|
||||||
xor edx, edx
|
xor edx, edx
|
||||||
div [ebp+EXTFS.superblock.inodesPerGroup]
|
div [ebp+EXTFS.superblock.inodesPerGroup]
|
||||||
push eax eax
|
mov ebx, [ebp+EXTFS.descriptorTable]
|
||||||
mov esi, .forward ; search forward, then backward
|
shl eax, 5
|
||||||
|
add ebx, eax
|
||||||
|
push ebx
|
||||||
.test_block_group:
|
.test_block_group:
|
||||||
call extfsReadDescriptor
|
push ebx
|
||||||
jc .fail
|
|
||||||
cmp [ebx+BGDESCR.blocksFree], 0
|
cmp [ebx+BGDESCR.blocksFree], 0
|
||||||
jz .next
|
jz .next
|
||||||
|
cmp [ebx+BGDESCR.inodesFree], 0
|
||||||
|
jz .next
|
||||||
dec [ebx+BGDESCR.inodesFree]
|
dec [ebx+BGDESCR.inodesFree]
|
||||||
js .next
|
dec [ebp+EXTFS.superblock.inodesFree]
|
||||||
mov edx, [ebx+BGDESCR.inodeBitmap]
|
push [ebx+BGDESCR.inodeBitmap]
|
||||||
mov eax, [esp]
|
|
||||||
call extfsWriteDescriptor
|
call extfsWriteDescriptor
|
||||||
mov eax, edx
|
pop eax
|
||||||
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
||||||
|
mov edx, eax
|
||||||
mov edi, ebx
|
mov edi, ebx
|
||||||
call extfsReadBlock
|
call extfsReadBlock
|
||||||
jc .fail
|
jc .fail
|
||||||
@ -459,35 +458,29 @@ extfsInodeAlloc:
|
|||||||
mov eax, edx
|
mov eax, edx
|
||||||
call extfsWriteBlock
|
call extfsWriteBlock
|
||||||
pop eax
|
pop eax
|
||||||
|
sub eax, [ebp+EXTFS.descriptorTable]
|
||||||
|
shr eax, 5
|
||||||
mul [ebp+EXTFS.superblock.inodesPerGroup]
|
mul [ebp+EXTFS.superblock.inodesPerGroup]
|
||||||
dec [ebp+EXTFS.superblock.inodesFree]
|
|
||||||
lea ebx, [eax+ecx+1]
|
lea ebx, [eax+ecx+1]
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
.ret:
|
.ret:
|
||||||
pop edi edi esi edx ecx
|
pop edi edi edx ecx
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.next:
|
.next: ; search forward, then backward
|
||||||
jmp esi
|
pop ebx
|
||||||
|
cmp ebx, [esp]
|
||||||
.forward:
|
jc .backward
|
||||||
inc dword[esp]
|
add ebx, 32
|
||||||
mov eax, [esp]
|
cmp ebx, [ebp+EXTFS.descriptorTableEnd]
|
||||||
mul [ebp+EXTFS.superblock.inodesPerGroup]
|
jc .test_block_group
|
||||||
cmp eax, [ebp+EXTFS.superblock.inodesTotal]
|
mov ebx, [esp]
|
||||||
ja @f
|
|
||||||
mov eax, [esp]
|
|
||||||
jmp .test_block_group
|
|
||||||
|
|
||||||
@@:
|
|
||||||
mov eax, [esp+4]
|
|
||||||
mov [esp], eax
|
|
||||||
mov esi, .backward
|
|
||||||
.backward:
|
.backward:
|
||||||
sub dword[esp], 1
|
sub ebx, 32
|
||||||
mov eax, [esp]
|
cmp ebx, [ebp+EXTFS.descriptorTable]
|
||||||
jnc .test_block_group
|
jnc .test_block_group
|
||||||
movi eax, ERROR_DISK_FULL
|
movi eax, ERROR_DISK_FULL
|
||||||
|
push eax
|
||||||
.fail:
|
.fail:
|
||||||
pop edi
|
pop edi
|
||||||
jmp .ret
|
jmp .ret
|
||||||
@ -499,12 +492,14 @@ extfsExtentAlloc:
|
|||||||
dec eax
|
dec eax
|
||||||
xor edx, edx
|
xor edx, edx
|
||||||
div [ebp+EXTFS.superblock.inodesPerGroup]
|
div [ebp+EXTFS.superblock.inodesPerGroup]
|
||||||
push eax eax
|
mov ebx, [ebp+EXTFS.descriptorTable]
|
||||||
|
shl eax, 5
|
||||||
|
add ebx, eax
|
||||||
|
push ebx
|
||||||
.test_block_group:
|
.test_block_group:
|
||||||
call extfsReadDescriptor
|
push ebx
|
||||||
jc .fail
|
cmp [ebx+BGDESCR.blocksFree], 0
|
||||||
dec [ebx+BGDESCR.blocksFree]
|
jz .next
|
||||||
js .next
|
|
||||||
mov eax, [ebx+BGDESCR.blockBitmap]
|
mov eax, [ebx+BGDESCR.blockBitmap]
|
||||||
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
||||||
mov edx, eax
|
mov edx, eax
|
||||||
@ -601,16 +596,17 @@ extfsExtentAlloc:
|
|||||||
pop eax
|
pop eax
|
||||||
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
||||||
call extfsWriteBlock
|
call extfsWriteBlock
|
||||||
mov eax, [esp]
|
mov ebx, [esp]
|
||||||
call extfsReadDescriptor
|
|
||||||
jc .fail
|
|
||||||
mov ecx, [esp+8]
|
mov ecx, [esp+8]
|
||||||
sub [ebx+BGDESCR.blocksFree], cx
|
sub [ebx+BGDESCR.blocksFree], cx
|
||||||
jc .fail
|
jnc @f
|
||||||
|
mov [ebx+BGDESCR.blocksFree], 0
|
||||||
|
@@:
|
||||||
sub [ebp+EXTFS.superblock.blocksFree], ecx
|
sub [ebp+EXTFS.superblock.blocksFree], ecx
|
||||||
mov eax, [esp]
|
|
||||||
call extfsWriteDescriptor
|
call extfsWriteDescriptor
|
||||||
pop eax ebx
|
pop eax ebx
|
||||||
|
sub eax, [ebp+EXTFS.descriptorTable]
|
||||||
|
shr eax, 5
|
||||||
mul [ebp+EXTFS.superblock.blocksPerGroup]
|
mul [ebp+EXTFS.superblock.blocksPerGroup]
|
||||||
mov ebx, eax
|
mov ebx, eax
|
||||||
add ebx, esi
|
add ebx, esi
|
||||||
@ -625,25 +621,19 @@ extfsExtentAlloc:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
.next: ; search forward, then backward
|
.next: ; search forward, then backward
|
||||||
pop eax
|
pop ebx
|
||||||
cmp eax, [esp]
|
cmp ebx, [esp]
|
||||||
jc .backward
|
jc .backward
|
||||||
inc eax
|
add ebx, 32
|
||||||
push eax
|
cmp ebx, [ebp+EXTFS.descriptorTableEnd]
|
||||||
mul [ebp+EXTFS.superblock.blocksPerGroup]
|
jc .test_block_group
|
||||||
cmp eax, [ebp+EXTFS.superblock.blocksTotal]
|
mov ebx, [esp]
|
||||||
ja @f
|
|
||||||
mov eax, [esp]
|
|
||||||
jmp .test_block_group
|
|
||||||
|
|
||||||
@@:
|
|
||||||
pop eax eax
|
|
||||||
push eax
|
|
||||||
.backward:
|
.backward:
|
||||||
dec eax
|
sub ebx, 32
|
||||||
push eax
|
cmp ebx, [ebp+EXTFS.descriptorTable]
|
||||||
jns .test_block_group
|
jnc .test_block_group
|
||||||
movi eax, ERROR_DISK_FULL
|
movi eax, ERROR_DISK_FULL
|
||||||
|
push eax
|
||||||
.fail:
|
.fail:
|
||||||
add esp, 12
|
add esp, 12
|
||||||
xor ecx, ecx
|
xor ecx, ecx
|
||||||
@ -804,18 +794,16 @@ getInodeLocation:
|
|||||||
dec eax
|
dec eax
|
||||||
xor edx, edx
|
xor edx, edx
|
||||||
div [ebp+EXTFS.superblock.inodesPerGroup]
|
div [ebp+EXTFS.superblock.inodesPerGroup]
|
||||||
call extfsReadDescriptor
|
shl eax, 5
|
||||||
jc @f
|
add eax, [ebp+EXTFS.descriptorTable]
|
||||||
mov ebx, [ebx+BGDESCR.inodeTable]
|
mov ebx, [eax+BGDESCR.inodeTable]
|
||||||
mov ecx, [ebp+EXTFS.sectorsPerBlockLog]
|
imul ebx, [ebp+EXTFS.sectorsPerBlock]
|
||||||
shl ebx, cl
|
|
||||||
movzx eax, [ebp+EXTFS.superblock.inodeSize]
|
movzx eax, [ebp+EXTFS.superblock.inodeSize]
|
||||||
mul edx
|
mul edx
|
||||||
mov edx, eax
|
mov edx, eax
|
||||||
shr eax, 9
|
shr eax, 9
|
||||||
and edx, 511
|
and edx, 511
|
||||||
add eax, ebx
|
add eax, ebx
|
||||||
@@:
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
writeInode:
|
writeInode:
|
||||||
@ -2266,19 +2254,20 @@ ext_Delete:
|
|||||||
dec eax
|
dec eax
|
||||||
xor edx, edx
|
xor edx, edx
|
||||||
div [ebp+EXTFS.superblock.inodesPerGroup]
|
div [ebp+EXTFS.superblock.inodesPerGroup]
|
||||||
push edx eax
|
push edx
|
||||||
call extfsReadDescriptor
|
mov ebx, [ebp+EXTFS.descriptorTable]
|
||||||
jc .error_stack8_eax
|
shl eax, 5
|
||||||
|
add ebx, eax
|
||||||
cmp ecx, DIRECTORY
|
cmp ecx, DIRECTORY
|
||||||
jnz @f
|
jnz @f
|
||||||
dec [ebx+BGDESCR.directoriesCount]
|
dec [ebx+BGDESCR.directoriesCount]
|
||||||
@@:
|
@@:
|
||||||
inc [ebx+BGDESCR.inodesFree]
|
inc [ebx+BGDESCR.inodesFree]
|
||||||
mov ecx, [ebx+BGDESCR.inodeBitmap]
|
push [ebx+BGDESCR.inodeBitmap]
|
||||||
pop eax
|
|
||||||
call extfsWriteDescriptor
|
call extfsWriteDescriptor
|
||||||
mov eax, ecx
|
pop eax
|
||||||
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
||||||
|
mov ecx, eax
|
||||||
call extfsReadBlock
|
call extfsReadBlock
|
||||||
jc .error_stack4_eax
|
jc .error_stack4_eax
|
||||||
pop eax
|
pop eax
|
||||||
@ -2303,9 +2292,7 @@ ext_Delete:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
.not_empty_eax:
|
.not_empty_eax:
|
||||||
pop ebx ebx
|
add esp, 12
|
||||||
.error_stack8_eax:
|
|
||||||
pop ebx
|
|
||||||
.error_stack4_eax:
|
.error_stack4_eax:
|
||||||
pop ebx
|
pop ebx
|
||||||
push eax
|
push eax
|
||||||
@ -2367,11 +2354,10 @@ ext_CreateFolder:
|
|||||||
dec eax
|
dec eax
|
||||||
xor edx, edx
|
xor edx, edx
|
||||||
div [ebp+EXTFS.superblock.inodesPerGroup]
|
div [ebp+EXTFS.superblock.inodesPerGroup]
|
||||||
mov edx, eax
|
mov ebx, [ebp+EXTFS.descriptorTable]
|
||||||
call extfsReadDescriptor
|
shl eax, 5
|
||||||
jc .error
|
add ebx, eax
|
||||||
inc [ebx+BGDESCR.directoriesCount]
|
inc [ebx+BGDESCR.directoriesCount]
|
||||||
mov eax, edx
|
|
||||||
call extfsWriteDescriptor
|
call extfsWriteDescriptor
|
||||||
.success:
|
.success:
|
||||||
.error:
|
.error:
|
||||||
|
Loading…
Reference in New Issue
Block a user