ext fs debugging and optimizing

git-svn-id: svn://kolibrios.org@6575 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
pathoswithin 2016-10-07 12:10:45 +00:00
parent 726024dfe0
commit 56c4a442eb

View File

@ -286,9 +286,7 @@ ext_free:
extfsWriteBlock: extfsWriteBlock:
push fs_write64_sys push fs_write64_sys
jmp @f jmp @f
; in: ; in: eax = block number, ebx -> buffer
; eax = block number
; ebx -> buffer
extfsReadBlock: extfsReadBlock:
push fs_read64_sys push fs_read64_sys
@@: @@:
@ -353,13 +351,16 @@ extfsResourceFree:
sub eax, [ebp+EXTFS.superblock.firstGroupBlock] sub eax, [ebp+EXTFS.superblock.firstGroupBlock]
xor edx, edx xor edx, edx
div [ebp+EXTFS.superblock.blocksPerGroup] div [ebp+EXTFS.superblock.blocksPerGroup]
push eax edx push edx eax
call extfsReadDescriptor call extfsReadDescriptor
jc .fail jc .fail2
inc [eax+BGDESCR.blocksFree+ecx*2] inc [eax+BGDESCR.blocksFree+ecx*2]
mov eax, [eax+BGDESCR.blockBitmap+ecx*4] mov edx, [eax+BGDESCR.blockBitmap+ecx*4]
mov ebx, [ebp+EXTFS.mainBlockBuffer] pop eax
mov edx, eax call extfsWriteDescriptor
jc .fail
mov eax, edx
mov ebx, [ebp+EXTFS.tempBlockBuffer]
call extfsReadBlock call extfsReadBlock
jc .fail jc .fail
pop eax pop eax
@ -368,25 +369,23 @@ extfsResourceFree:
and edx, 31 and edx, 31
shr eax, 5 shr eax, 5
shl eax, 2 shl eax, 2
add eax, [ebp+EXTFS.mainBlockBuffer] add eax, [ebp+EXTFS.tempBlockBuffer]
btr [eax], edx btr [eax], edx
pop eax pop eax
mov ebx, [ebp+EXTFS.mainBlockBuffer] mov ebx, [ebp+EXTFS.tempBlockBuffer]
call extfsWriteBlock call extfsWriteBlock
jc @f jc @f
inc [ebp+EXTFS.superblock.blocksFree+ecx*4] inc [ebp+EXTFS.superblock.blocksFree+ecx*4]
pop eax @@:
call extfsWriteDescriptor
.ret:
pop edx ebx pop edx ebx
ret ret
.fail2:
pop eax
.fail: .fail:
pop eax pop eax
@@:
pop eax
movi eax, ERROR_DEVICE movi eax, ERROR_DEVICE
jmp .ret jmp @b
freeDoublyIndirectBlock: freeDoublyIndirectBlock:
; in: eax = doubly-indirect block number ; in: eax = doubly-indirect block number
@ -394,7 +393,7 @@ freeDoublyIndirectBlock:
test eax, eax test eax, eax
jz .complete jz .complete
push eax push eax
mov ebx, [ebp+EXTFS.tempBlockBuffer] mov ebx, [ebp+EXTFS.mainBlockBuffer]
call extfsReadBlock call extfsReadBlock
pop eax pop eax
jc .ret jc .ret
@ -418,19 +417,8 @@ freeDoublyIndirectBlock:
inc eax inc eax
ret ret
inodeBlockAlloc: inodeBlockAlloc: ; also erases
; in: esi -> inode, eax = inode number ; in: esi -> inode, eax = inode number
; out: ebx = block number
call extfsBlockAlloc
jc @f
mov eax, [ebp+EXTFS.sectorsPerBlock]
add [esi+INODE.sectorsUsed], eax
xor eax, eax
@@:
ret
extfsBlockAlloc: ; also erases
; in: eax = inode number
; out: ebx = block number ; out: ebx = block number
xor ebx, ebx xor ebx, ebx
call extfsResourceAlloc call extfsResourceAlloc
@ -441,10 +429,14 @@ extfsBlockAlloc: ; also erases
mov ebx, edi mov ebx, edi
xor eax, eax xor eax, eax
rep stosd rep stosd
pop edi ecx pop edi ecx eax
mov eax, [esp] push eax
call extfsWriteBlock call extfsWriteBlock
pop ebx pop ebx
jc @f
mov eax, [ebp+EXTFS.sectorsPerBlock]
add [esi+INODE.sectorsUsed], eax
xor eax, eax
@@: @@:
ret ret
@ -464,10 +456,14 @@ extfsResourceAlloc:
call extfsReadDescriptor call extfsReadDescriptor
jc .fail jc .fail
dec [eax+BGDESCR.blocksFree+ebx*2] dec [eax+BGDESCR.blocksFree+ebx*2]
mov eax, [eax+BGDESCR.blockBitmap+ebx*4] js .next
mov edx, [eax+BGDESCR.blockBitmap+ebx*4]
mov eax, [esp]
call extfsWriteDescriptor
jc .fail
push ebx push ebx
mov ebx, [ebp+EXTFS.mainBlockBuffer] mov eax, edx
mov edx, eax mov ebx, [ebp+EXTFS.tempBlockBuffer]
mov edi, ebx mov edi, ebx
call extfsReadBlock call extfsReadBlock
pop ebx pop ebx
@ -483,24 +479,23 @@ extfsResourceAlloc:
not eax not eax
bsf eax, eax bsf eax, eax
bts [edi], eax bts [edi], eax
sub edi, [ebp+EXTFS.mainBlockBuffer] sub edi, [ebp+EXTFS.tempBlockBuffer]
shl edi, 3 shl edi, 3
add eax, edi add eax, edi
mov ecx, eax mov ecx, eax
mov eax, edx mov eax, edx
push ebx push ebx
mov ebx, [ebp+EXTFS.mainBlockBuffer] mov ebx, [ebp+EXTFS.tempBlockBuffer]
call extfsWriteBlock call extfsWriteBlock
pop ebx pop ebx
jc .fail jc .fail
mov eax, [esp] pop eax
mul [ebp+EXTFS.superblock.blocksPerGroup+ebx*8] mul [ebp+EXTFS.superblock.blocksPerGroup+ebx*8]
add eax, ecx add eax, ecx
dec [ebp+EXTFS.superblock.blocksFree+ebx*4] dec [ebp+EXTFS.superblock.blocksFree+ebx*4]
mov ebx, eax mov ebx, eax
pop eax pop eax
add esp, 4 xor eax, eax
call extfsWriteDescriptor
@@: @@:
pop edi esi edx ecx pop edi esi edx ecx
ret ret
@ -536,11 +531,8 @@ extfsResourceAlloc:
jmp .test_block_group jmp .test_block_group
extfsGetFileBlock: extfsGetFileBlock:
; in: ; in: esi -> inode, ecx = file block number
; ecx = file block number ; out: ecx = block number
; esi -> inode
; out:
; ecx = block number
test [esi+INODE.featureFlags], EXTENTS_USED test [esi+INODE.featureFlags], EXTENTS_USED
jz .listTreeSearch jz .listTreeSearch
pushad pushad
@ -701,7 +693,7 @@ extfsSetFileBlock:
mov eax, ebx mov eax, ebx
@@: @@:
push eax push eax
mov ebx, [ebp+EXTFS.tempBlockBuffer] mov ebx, [ebp+EXTFS.mainBlockBuffer]
call extfsReadBlock call extfsReadBlock
jc .fail_alloc_4 jc .fail_alloc_4
xor edx, edx xor edx, edx
@ -717,7 +709,7 @@ extfsSetFileBlock:
jc .fail_alloc_4 jc .fail_alloc_4
mov [ecx], ebx mov [ecx], ebx
mov eax, [esp] mov eax, [esp]
mov ebx, [ebp+EXTFS.tempBlockBuffer] mov ebx, [ebp+EXTFS.mainBlockBuffer]
call extfsWriteBlock call extfsWriteBlock
jc .fail_alloc_4 jc .fail_alloc_4
mov eax, [ecx] mov eax, [ecx]
@ -739,7 +731,7 @@ extfsSetFileBlock:
mov eax, ebx mov eax, ebx
.double_indirect_present: .double_indirect_present:
push eax push eax
mov ebx, [ebp+EXTFS.tempBlockBuffer] mov ebx, [ebp+EXTFS.mainBlockBuffer]
call extfsReadBlock call extfsReadBlock
jc .fail_alloc_4 jc .fail_alloc_4
mov eax, ecx mov eax, ecx
@ -757,7 +749,7 @@ extfsSetFileBlock:
jc .fail_alloc_8 jc .fail_alloc_8
mov [ecx], ebx mov [ecx], ebx
mov eax, [esp+4] mov eax, [esp+4]
mov ebx, [ebp+EXTFS.tempBlockBuffer] mov ebx, [ebp+EXTFS.mainBlockBuffer]
call extfsWriteBlock call extfsWriteBlock
jc .fail_alloc_8 jc .fail_alloc_8
@@: @@:
@ -781,7 +773,7 @@ extfsSetFileBlock:
mov eax, ebx mov eax, ebx
@@: @@:
push eax push eax
mov ebx, [ebp+EXTFS.tempBlockBuffer] mov ebx, [ebp+EXTFS.mainBlockBuffer]
call extfsReadBlock call extfsReadBlock
jc .fail_alloc_4 jc .fail_alloc_4
mov [ebx+ecx*4], edi mov [ebx+ecx*4], edi
@ -804,70 +796,27 @@ extfsSetFileBlock:
pop ebx pop ebx
jmp .ret jmp .ret
extfsEraseFileBlock: ; also allocates extfsFileBlockAlloc:
; in: ; in:
; esi -> inode
; edx = inode number ; edx = inode number
; eax = file block number ; eax = file block number
; [ebp+EXTFS.inodeBuffer] = inode ; out:
push ebx ecx edx edi esi ; edi = allocated block number
mov edi, eax push ebx ecx
mov ecx, eax mov ecx, eax
lea esi, [ebp+EXTFS.inodeBuffer]
call extfsGetFileBlock
jc @f
test ecx, ecx
jz .allocate
mov edx, ecx
mov ecx, [ebp+EXTFS.bytesPerBlock]
mov edi, [ebp+EXTFS.tempBlockBuffer]
xor eax, eax
rep stosb
mov eax, edx mov eax, edx
mov ebx, [ebp+EXTFS.tempBlockBuffer] xor ebx, ebx
call extfsWriteBlock call extfsResourceAlloc
jmp @f
.allocate:
mov eax, edx
call extfsBlockAlloc
jc @f jc @f
mov ecx, edi
mov edi, ebx mov edi, ebx
lea esi, [ebp+EXTFS.inodeBuffer]
call extfsSetFileBlock call extfsSetFileBlock
jc @f jc @f
mov eax, [ebp+EXTFS.sectorsPerBlock] mov eax, [ebp+EXTFS.sectorsPerBlock]
add [esi+INODE.sectorsUsed], eax add [esi+INODE.sectorsUsed], eax
xor eax, eax xor eax, eax
@@: @@:
pop esi edi edx ecx ebx pop ecx ebx
ret
extfsFreeFileBlock:
; in:
; eax = file block number
; [ebp+EXTFS.inodeBuffer] = inode
push ebx ecx edx edi esi
mov edi, eax
mov ecx, eax
lea esi, [ebp+EXTFS.inodeBuffer]
call extfsGetFileBlock
jc @f
test ecx, ecx
jz @f
mov eax, ecx
xor ecx, ecx
call extfsResourceFree
mov ecx, edi
xor edi, edi
movi edx, ROOT_INODE
lea esi, [ebp+EXTFS.inodeBuffer]
call extfsSetFileBlock
mov eax, [ebp+EXTFS.sectorsPerBlock]
sub [esi+INODE.sectorsUsed], eax
xor eax, eax
@@:
pop esi edi edx ecx ebx
ret ret
extfsReadFileBlock: extfsReadFileBlock:
@ -898,9 +847,9 @@ extfsReadFileBlock:
extfsWriteFileBlock: extfsWriteFileBlock:
; in: ; in:
; eax = file block number ; eax = file block number
; ebx -> data
; [ebp+EXTFS.inodeBuffer] = inode ; [ebp+EXTFS.inodeBuffer] = inode
; [ebp+EXTFS.mainBlockBuffer] -> block to write push ecx edx esi
push ebx ecx edx esi
mov ecx, eax mov ecx, eax
lea esi, [ebp+EXTFS.inodeBuffer] lea esi, [ebp+EXTFS.inodeBuffer]
call extfsGetFileBlock call extfsGetFileBlock
@ -908,17 +857,14 @@ extfsWriteFileBlock:
test ecx, ecx test ecx, ecx
jz @b jz @b
mov eax, ecx mov eax, ecx
mov ebx, [ebp+EXTFS.mainBlockBuffer]
call extfsWriteBlock call extfsWriteBlock
@@: @@:
pop esi edx ecx ebx pop esi edx ecx
ret ret
getInodeLocation: getInodeLocation:
; in: eax = inode number ; in: eax = inode number
; out: ; out: ebx = inode sector, edx = offset in sector
; ebx = 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]
@ -946,9 +892,7 @@ getInodeLocation:
ret ret
writeInode: writeInode:
; in: ; in: eax = inode number, ebx -> inode data
; eax = inode number
; ebx -> inode data
push edx edi esi ecx ebx eax push edx edi esi ecx ebx eax
mov edi, ebx mov edi, ebx
call fsGetTime call fsGetTime
@ -980,9 +924,7 @@ writeInode:
jmp .ret jmp .ret
readInode: readInode:
; in: ; in: eax = inode number, ebx -> inode buffer
; eax = inode number
; ebx -> inode buffer
push edx edi esi ecx ebx push edx edi esi ecx ebx
mov edi, ebx mov edi, ebx
call getInodeLocation call getInodeLocation
@ -1007,67 +949,40 @@ extfsExtendFile:
; eax = inode number ; eax = inode number
; ecx = new size ; ecx = new size
push ebx ecx edx esi edi eax push ebx ecx edx esi edi eax
lea ebx, [ebp+EXTFS.inodeBuffer] lea esi, [ebp+EXTFS.inodeBuffer]
cmp [ebx+INODE.fileSize], ecx mov eax, [esi+INODE.fileSize]
jnc .ret
mov eax, [ebx+INODE.fileSize]
push eax
sub ecx, eax sub ecx, eax
jna .ret
mov ebx, eax
xor edx, edx xor edx, edx
div [ebp+EXTFS.bytesPerBlock] div [ebp+EXTFS.bytesPerBlock]
test edx, edx test edx, edx
jz .start_aligned jz .start_aligned
mov esi, [ebp+EXTFS.bytesPerBlock] mov eax, [ebp+EXTFS.bytesPerBlock]
sub esi, edx sub eax, edx
cmp esi, ecx cmp eax, ecx
jbe @f jbe @f
mov esi, ecx mov eax, ecx
@@: ; clear esi trailing bytes in block number eax @@:
push eax add ebx, eax
call extfsReadFileBlock sub ecx, eax
pop edi
jc .error_inode_size
push edi ecx
xor eax, eax
mov ecx, esi
mov edi, ebx
add edi, edx
rep stosb
pop ecx eax
call extfsWriteFileBlock
jc .error_inode_size
add [esp], esi
sub ecx, esi
jz .done jz .done
.start_aligned: .start_aligned:
cmp ecx, [ebp+EXTFS.bytesPerBlock] mov eax, ebx
jb @f
mov eax, [esp]
xor edx, edx xor edx, edx
div [ebp+EXTFS.bytesPerBlock] div [ebp+EXTFS.bytesPerBlock]
mov edx, [esp+4] mov edx, [esp]
call extfsEraseFileBlock call extfsFileBlockAlloc
jc .error_inode_size jc .error
mov eax, [ebp+EXTFS.bytesPerBlock] mov eax, [ebp+EXTFS.bytesPerBlock]
add ebx, eax
sub ecx, eax sub ecx, eax
add [esp], eax ja .start_aligned
jmp .start_aligned add ebx, ecx
@@: ; handle the remaining bytes
test ecx, ecx
jz .done
mov eax, [esp]
xor edx, edx
div [ebp+EXTFS.bytesPerBlock]
mov edx, [esp+4]
call extfsEraseFileBlock
jc .error_inode_size
add [esp], ecx
.done: .done:
xor eax, eax xor eax, eax
.error_inode_size: .error:
lea ebx, [ebp+EXTFS.inodeBuffer] mov [esi+INODE.fileSize], ebx
pop [ebx+INODE.fileSize]
.ret: .ret:
pop edi edi esi edx ecx ebx pop edi edi esi edx ecx ebx
ret ret
@ -1077,88 +992,63 @@ extfsTruncateFile:
; [ebp+EXTFS.inodeBuffer] = inode ; [ebp+EXTFS.inodeBuffer] = inode
; ecx = new size ; ecx = new size
push ebx ecx edx esi edi push ebx ecx edx esi edi
lea ebx, [ebp+EXTFS.inodeBuffer] lea esi, [ebp+EXTFS.inodeBuffer]
cmp ecx, [ebx+INODE.fileSize] mov eax, [esi+INODE.fileSize]
jnc .ret
mov eax, [ebx+INODE.fileSize]
push eax
sub ecx, eax sub ecx, eax
not ecx jnc .ret
inc ecx neg ecx
mov ebx, eax
xor edx, edx xor edx, edx
div [ebp+EXTFS.bytesPerBlock] div [ebp+EXTFS.bytesPerBlock]
test edx, edx test edx, edx
jz .start_aligned jnz @f
mov esi, edx
cmp esi, ecx
jbe @f
; if the size to truncate is smaller than the unaligned bytes
; we're going to clear neccessary bytes from the EOF
push eax
call extfsReadFileBlock
pop edi
jc .error_inode_size
push edi ecx
mov edi, [ebp+EXTFS.mainBlockBuffer]
sub edx, ecx
add edi, edx
xor eax, eax
rep stosb
pop ecx eax
call extfsWriteFileBlock
jc .error_inode_size
sub [esp], ecx
jmp .done
@@:
call extfsFreeFileBlock
sub [esp], esi
sub ecx, esi
jz .done
.start_aligned: .start_aligned:
cmp ecx, [ebp+EXTFS.bytesPerBlock] mov edx, [ebp+EXTFS.bytesPerBlock]
jb @f dec eax
mov eax, [esp] @@:
cmp ecx, edx
jc .tail
push ecx edx
mov edi, eax
mov ecx, eax
call extfsGetFileBlock
jc .error
test ecx, ecx
jz @f
mov eax, ecx
xor ecx, ecx
call extfsResourceFree
mov ecx, edi
xor edi, edi
movi edx, ROOT_INODE
call extfsSetFileBlock
mov eax, [ebp+EXTFS.sectorsPerBlock]
sub [esi+INODE.sectorsUsed], eax
@@:
pop edx ecx
sub ebx, edx
sub ecx, edx
jz .done
mov eax, ebx
xor edx, edx xor edx, edx
div [ebp+EXTFS.bytesPerBlock] div [ebp+EXTFS.bytesPerBlock]
dec eax
call extfsFreeFileBlock
mov eax, [ebp+EXTFS.bytesPerBlock]
sub ecx, eax
sub [esp], eax
jmp .start_aligned jmp .start_aligned
@@: ; handle the remaining bytes .tail: ; handle the remaining bytes
test ecx, ecx sub ebx, ecx
jz .done
mov eax, [esp]
xor edx, edx
div [ebp+EXTFS.bytesPerBlock]
dec eax
push eax
call extfsReadFileBlock
pop edi
jc .error_inode_size
push edi ecx
mov edi, [ebp+EXTFS.mainBlockBuffer]
mov edx, [ebp+EXTFS.bytesPerBlock]
sub edx, ecx
add edi, edx
xor eax, eax
rep stosb
pop ecx eax
call extfsWriteFileBlock
jc .error_inode_size
sub [esp], ecx
.done: .done:
xor eax, eax xor eax, eax
.error_inode_size: @@:
lea ebx, [ebp+EXTFS.inodeBuffer] mov [esi+INODE.fileSize], ebx
pop [ebx+INODE.fileSize]
.ret: .ret:
pop edi esi edx ecx ebx pop edi esi edx ecx ebx
ret ret
.error:
pop edx ecx
jmp @b
linkInode: linkInode:
; in: ; in:
; eax = inode on which to link ; eax = inode on which to link
@ -1249,42 +1139,32 @@ linkInode:
jmp .prepare_block jmp .prepare_block
.alloc_block: .alloc_block:
mov eax, [esp+24] mov eax, [esp]
mov edx, eax mov edx, [esp+24]
call extfsBlockAlloc call extfsFileBlockAlloc
jc .error_get_inode_block
mov ecx, [esp]
mov edi, ebx
call extfsSetFileBlock
jc .error_get_inode_block jc .error_get_inode_block
mov eax, [ebp+EXTFS.bytesPerBlock] mov eax, [ebp+EXTFS.bytesPerBlock]
add [esi+INODE.fileSize], eax add [esi+INODE.fileSize], eax
mov eax, [ebp+EXTFS.sectorsPerBlock]
add [esi+INODE.sectorsUsed], eax
mov eax, [esp+24] mov eax, [esp+24]
mov ebx, esi mov ebx, esi
call writeInode call writeInode
jc .error_get_inode_block jc .error_get_inode_block
push edi ; save the block we just allocated push edi ; save the block we just allocated
.prepare_block: .prepare_block:
mov eax, [esp] mov edi, [ebp+EXTFS.tempBlockBuffer]
mov ebx, [ebp+EXTFS.tempBlockBuffer]
call extfsReadBlock
jc .error_block_read
mov edi, ebx
mov eax, [ebp+EXTFS.bytesPerBlock] mov eax, [ebp+EXTFS.bytesPerBlock]
mov [edi+DIRENTRY.entryLength], ax mov [edi+DIRENTRY.entryLength], ax
.found: .found:
pop edx ecx ecx ecx ebx esi pop edx ecx ecx ecx ebx esi
push ebx push ebx
mov [edi], ebx ; save inode mov [edi+DIRENTRY.inodeNumber], ebx
mov eax, [esp+4] sub ecx, 8
mov word [edi+DIRENTRY.nameLength], cx
cmp [ebp+EXTFS.superblock.dynamicVersionFlag], 0 cmp [ebp+EXTFS.superblock.dynamicVersionFlag], 0
je .name je .name
mov eax, [esp+4]
mov [edi+DIRENTRY.fileType], al mov [edi+DIRENTRY.fileType], al
.name: .name:
sub ecx, 8
mov [edi+DIRENTRY.nameLength], cl
add edi, 8 add edi, 8
rep movsb rep movsb
mov eax, edx mov eax, edx
@ -2065,28 +1945,28 @@ ext_Delete:
mov eax, [edi+INODE.tripleAddress] mov eax, [edi+INODE.tripleAddress]
test eax, eax test eax, eax
jz .success jz .success
push eax xor edx, edx
mov ebx, [ebp+EXTFS.tempBlockBuffer] mov ecx, eax
@@:
mov eax, ecx
mov ebx, [ebp+EXTFS.mainBlockBuffer]
call extfsReadBlock call extfsReadBlock
pop ecx
jc .error_stack8_eax jc .error_stack8_eax
mov eax, [ebx+edx]
test eax, eax
jz @f
push ecx edx
call freeDoublyIndirectBlock
pop edx ecx
cmp eax, 1
je @f
add edx, 4
cmp edx, [ebp+EXTFS.bytesPerBlock]
jb @b
@@:
mov eax, ecx mov eax, ecx
xor ecx, ecx xor ecx, ecx
call extfsResourceFree call extfsResourceFree
mov edx, ebx
add edx, [ebp+EXTFS.bytesPerBlock]
@@:
mov eax, [ebx]
test eax, eax
jz .success
push ebx edx
call freeDoublyIndirectBlock
pop edx ebx
cmp eax, 1
je .success
add ebx, 4
cmp ebx, edx
jb @b
.success: ; clear the inode, and add deletion time .success: ; clear the inode, and add deletion time
xor eax, eax xor eax, eax
movzx ecx, [ebp+EXTFS.superblock.inodeSize] movzx ecx, [ebp+EXTFS.superblock.inodeSize]
@ -2310,33 +2190,36 @@ ext_WriteFile:
jc .error jc .error
mov eax, [ebx+4] mov eax, [ebx+4]
mov ecx, [ebx+12] mov ecx, [ebx+12]
mov esi, [ebx+16] mov ebx, [ebx+16]
push eax push eax
xor edx, edx xor edx, edx
div [ebp+EXTFS.bytesPerBlock] div [ebp+EXTFS.bytesPerBlock]
test edx, edx test edx, edx
jz .start_aligned jz .start_aligned
mov ebx, [ebp+EXTFS.bytesPerBlock] mov esi, [ebp+EXTFS.bytesPerBlock]
sub ebx, edx sub esi, edx
cmp ebx, ecx cmp esi, ecx
jbe @f jbe @f
mov ebx, ecx mov esi, ecx
@@: @@:
push eax mov edi, eax
call extfsReadFileBlock call extfsReadFileBlock
pop edi
jc .error_inode_size jc .error_inode_size
mov eax, edi mov eax, edi
push ecx push ebx ecx
mov ecx, ebx mov ecx, esi
mov edi, ebx mov edi, [ebp+EXTFS.mainBlockBuffer]
mov esi, ebx
mov ebx, edi
add edi, edx add edi, edx
mov edx, ecx
rep movsb rep movsb
pop ecx
call extfsWriteFileBlock call extfsWriteFileBlock
pop ecx ebx
jc .error_inode_size jc .error_inode_size
add [esp], ebx add [esp], edx
sub ecx, ebx add ebx, edx
sub ecx, edx
jz .write_inode jz .write_inode
.start_aligned: .start_aligned:
cmp ecx, [ebp+EXTFS.bytesPerBlock] cmp ecx, [ebp+EXTFS.bytesPerBlock]
@ -2344,47 +2227,28 @@ ext_WriteFile:
mov eax, [esp] mov eax, [esp]
xor edx, edx xor edx, edx
div [ebp+EXTFS.bytesPerBlock] div [ebp+EXTFS.bytesPerBlock]
mov edx, [esp+4]
push eax
call extfsEraseFileBlock
pop edi
jc .error_inode_size
mov eax, edi
push ecx
mov ecx, [ebp+EXTFS.bytesPerBlock]
mov edi, [ebp+EXTFS.mainBlockBuffer]
rep movsb
pop ecx
call extfsWriteFileBlock call extfsWriteFileBlock
jc .error_inode_size jc .error_inode_size
mov eax, [ebp+EXTFS.bytesPerBlock] mov eax, [ebp+EXTFS.bytesPerBlock]
sub ecx, eax sub ecx, eax
add ebx, eax
add [esp], eax add [esp], eax
jmp .start_aligned jmp .start_aligned
@@: ; Handle the remaining bytes.
@@: ; handle the remaining bytes
test ecx, ecx test ecx, ecx
jz .write_inode jz .write_inode
mov eax, [esp] mov eax, [esp]
xor edx, edx xor edx, edx
div [ebp+EXTFS.bytesPerBlock] div [ebp+EXTFS.bytesPerBlock]
push eax
call extfsReadFileBlock
pop eax
jnc @f
mov edx, [esp+4]
push eax
call extfsEraseFileBlock
pop edi
jc .error_inode_size
mov eax, edi
@@:
push ecx push ecx
mov esi, ebx
mov edi, [ebp+EXTFS.mainBlockBuffer] mov edi, [ebp+EXTFS.mainBlockBuffer]
mov ebx, edi
rep movsb rep movsb
pop ecx pop ecx
call extfsWriteFileBlock call extfsWriteFileBlock
jc .error_inode_size jc .error_inode_size
add [esp], ecx
xor ecx, ecx xor ecx, ecx
.error_inode_size: .error_inode_size:
mov [esp+12], eax mov [esp+12], eax
@ -2417,25 +2281,84 @@ ext_SetFileEnd:
call extfsWritingInit call extfsWritingInit
pushd [ebx+4] pushd [ebx+4]
call findInode call findInode
pop ecx jc .error
jc @f lea edi, [ebp+EXTFS.inodeBuffer]
lea edx, [ebp+EXTFS.inodeBuffer]
movi eax, ERROR_ACCESS_DENIED movi eax, ERROR_ACCESS_DENIED
cmp [edx+INODE.accessMode], FLAG_FILE cmp [edi+INODE.accessMode], FLAG_FILE
jnz @f ; not a file jnz .error ; not a file
pop ecx
push esi
mov ebx, [edi+INODE.fileSize]
mov eax, esi mov eax, esi
call extfsExtendFile cmp ebx, ecx
jc @f jc @f
call extfsTruncateFile call extfsTruncateFile
jc @f jc .error
mov eax, esi jmp .done
@@:
call extfsExtendFile
jc .error
sub ecx, ebx
mov eax, ebx
xor edx, edx
div [ebp+EXTFS.bytesPerBlock]
mov edi, eax
test edx, edx
jz .start_aligned
call extfsReadFileBlock
jc .error
mov eax, [ebp+EXTFS.bytesPerBlock]
sub eax, edx
cmp eax, ecx
jbe @f
mov eax, ecx
@@:
mov ebx, [ebp+EXTFS.mainBlockBuffer]
push edi ecx
mov ecx, eax
mov edi, ebx
add edi, edx
xor eax, eax
mov edx, ecx
rep stosb
pop ecx edi
mov eax, edi
call extfsWriteFileBlock
jc .error
sub ecx, edx
jz .done
inc edi
.start_aligned:
mov eax, ecx
mov ecx, [ebp+EXTFS.bytesPerBlock]
dec eax
xor edx, edx
div ecx
inc eax
mov ebx, [ebp+EXTFS.mainBlockBuffer]
push eax edi
mov edi, ebx
xor eax, eax
rep stosb
pop edi ecx
@@:
mov eax, edi
call extfsWriteFileBlock
jc .error
inc edi
loop @b
.done:
mov eax, [esp]
lea ebx, [ebp+EXTFS.inodeBuffer] lea ebx, [ebp+EXTFS.inodeBuffer]
call writeInode call writeInode
@@: jc .error
push eax
call writeSuperblock call writeSuperblock
mov esi, [ebp+PARTITION.Disk] mov esi, [ebp+PARTITION.Disk]
call disk_sync call disk_sync
xor eax, eax
.error:
mov [esp], eax
call ext_unlock call ext_unlock
pop eax pop eax
ret ret