我們程式最前面的部分是每一次讀取都要檢查的部分,包括有沒有超出檔案大小,讀取是否結束等等。接下來我們透過判斷大小的方式,因為間接存取有256個塊,雙重間接存取有65536個,三重則有16777216個塊。透過判斷數字大小的方法,我們可以把程式分流給各個程式區塊來執行。
在這個程式中,我們使用了SysV ABI的32位元呼叫規定,利用堆疊傳遞參數,保護某些暫存器,並且把我們讀取的區塊數量當作回傳值放在EAX暫存器回傳。
此函式程式碼如下:(在最上方有個EBX和堆疊的狀態示意,可以參考)
# readInodeBlock
# protect:
# EBX EDI EBP
# STACK:
# +24 No. zero block LBA
# +20 read block count
# +16 block number (start from zero)
# +12 inode pos
# +8 address to put
# +4 return address
# +0 ebp
# Number Zero Block is at LBA 33
#
readInodeBlock:
pushl %ebp
movl %esp, %ebp
pushl %edi
pushl %ebx
movl 12(%ebp), %ebx
movl 16(%ebp), %edx
movl 20(%ebp), %ecx
movl 28(%ebx), %eax
shr %eax
.riblock_loop:
test %ecx, %ecx
jz .riblock_ret_val
cmp %eax, %edx
jge .riblock_ret_val
cmp $12, %edx
jl .riblock_directBlocks
cmp $268, %edx
jl .riblock_indirect
cmp $65804, %edx
jl .riblock_db_indirect
cmp $16843020, %edx
jl .riblock_tp_indirect
jge .riblock_ret_val
# Current Register Status
# EAX 512 bytes block count
# EBX INODE POS
# ECX Counter
# EDX CURRENT BLOCK NO.
.riblock_directBlocks:
pushl %eax
pushl %ebx
pushl %ecx
pushl %edx
movl 40(%ebx, %edx, 4), %edx
movl 24(%ebp), %ebx
shll %edx
addl %edx, %ebx
movl $2, %ecx
movl 8(%ebp), %edi
call readATA
movl %edi, 8(%ebp)
jmp .riblock_loop_end
.riblock_indirect:
pushl %eax
pushl %ebx
pushl %ecx
pushl %edx
# ======================= STAGE I ==============================
movl 88(%ebx), %edx
movl 24(%ebp), %ebx
shll %edx
addl %edx, %ebx
movl $2, %ecx
movl 8(%ebp), %edi
call readATA
movl (%esp), %edx
movl 4(%esp), %ecx
movl 8(%esp), %ebx
movl 12(%esp), %eax
# ======================= STAGE II ==============================
movl 8(%ebp), %edi
subl $12, %edx
movl (%edi, %edx, 4), %edx
movl 24(%ebp), %ebx
shll %edx
addl %edx, %ebx
movl $2, %ecx
call readATA
movl %edi, 8(%ebp)
jmp .riblock_loop_end
.riblock_db_indirect:
pushl %eax
pushl %ebx
pushl %ecx
pushl %edx
# ======================= STAGE I ==============================
movl 92(%ebx), %edx
movl 24(%ebp), %ebx
shll %edx
addl %edx, %ebx
movl $2, %ecx
movl 8(%ebp), %edi
call readATA
movl (%esp), %edx
movl 4(%esp), %ecx
movl 8(%esp), %ebx
movl 12(%esp), %eax
# ======================= STAGE II ==============================
movl 8(%ebp), %edi
subl $268, %edx
shrl $8, %edx
movl (%edi, %edx, 4), %edx
movl 24(%ebp), %ebx
shll %edx
addl %edx, %ebx
movl $2, %ecx
call readATA
movl (%esp), %edx
movl 4(%esp), %ecx
movl 8(%esp), %ebx
movl 12(%esp), %eax
# ======================= STAGE III ==============================
movl 8(%ebp), %edi
subl $268, %edx
andl $256, %edx
movl (%edi, %edx, 4), %edx
movl 24(%ebp), %ebx
shl %edx
addl %edx, %ebx
movl $2, %ecx
call readATA
movl %edi, 8(%ebp)
jmp .riblock_loop_end
.riblock_tp_indirect:
pushl %eax
pushl %ebx
pushl %ecx
pushl %edx
# ======================= STAGE I ==============================
movl 96(%ebx), %edx
movl 24(%ebp), %ebx
shll %edx
addl %edx, %ebx
movl $2, %ecx
movl 8(%ebp), %edi
call readATA
movl (%esp), %edx
movl 4(%esp), %ecx
movl 8(%esp), %ebx
movl 12(%esp), %eax
# ======================= STAGE II ==============================
movl 8(%ebp), %edi
subl $65804, %edx
shrl $16, %edx
movl (%edi, %edx, 4), %edx
movl 24(%ebp), %ebx
shll %edx
addl %edx, %ebx
movl $2, %ecx
call readATA
movl (%esp), %edx
movl 4(%esp), %ecx
movl 8(%esp), %ebx
movl 12(%esp), %eax
# ======================= STAGE III ==============================
movl 8(%ebp), %edi
subl $65804, %edx
shrl $8, %edx
andl $256, %edx
movl (%edi, %edx, 4), %edx
movl 24(%ebp), %ebx
shll %edx
addl %edx, %ebx
movl $2, %ecx
call readATA
movl (%esp), %edx
movl 4(%esp), %ecx
movl 8(%esp), %ebx
movl 12(%esp), %eax
# ======================= STAGE IV ==============================
movl 8(%ebp), %edi
subl $65804, %edx
andl $256, %edx
movl (%edi, %edx, 4), %edx
movl 24(%ebp), %ebx
shl %edx
addl %edx, %ebx
movl $2, %ecx
call readATA
movl %edi, 8(%ebp)
jmp .riblock_loop_end
.riblock_loop_end:
popl %edx
popl %ecx
popl %ebx
popl %eax
decl %ecx
incl %edx
jmp .riblock_loop
.riblock_ret_val:
movl 20(%ebp), %eax
subl %ecx, %eax
.riblock_leave:
popl %ebx
popl %edi
leave
ret
下一次我們就要正式來讀取核心了
👉【幫我們一個忙!】👈
👋如果您喜歡這篇文章,請在下方按5個Like!
❤您的支持是我們最大的動力!
您只要登入帳號(Facebook、Google),在下方按5個Like,我們就會收到來自LikeCoin基金會的贊助。
您只需要支持我們,完全不會花到錢!