2024-09-02 13:12:19 +00:00
|
|
|
;; File: stpdfs.inc
|
2024-08-31 12:40:07 +00:00
|
|
|
|
2024-09-02 13:12:19 +00:00
|
|
|
STPDFS_BLOCK_SIZE = 512
|
|
|
|
STPDFS_NAME_MAX = 28
|
|
|
|
|
|
|
|
;; Struct: Inode
|
2024-09-01 09:53:44 +00:00
|
|
|
struc Inode {
|
2024-08-31 12:40:07 +00:00
|
|
|
.inode dw ?
|
|
|
|
.nlink dw ?
|
|
|
|
.uid dw ?
|
|
|
|
.gid dw ?
|
|
|
|
.flags dw ?
|
|
|
|
.size dd ?
|
|
|
|
.zones dd 10 dup(?)
|
|
|
|
.actime dq ?
|
|
|
|
.modtime dq ?
|
|
|
|
}
|
2024-09-01 09:53:44 +00:00
|
|
|
DEFN Inode
|
2024-08-31 12:40:07 +00:00
|
|
|
|
2024-09-02 13:12:19 +00:00
|
|
|
STPDFS_INODE_PER_BLOCK equ STPDFS_BLOCK_SIZE / sizeof.Inode
|
|
|
|
|
|
|
|
;; Struct: DirEntry
|
|
|
|
struc DirEntry {
|
2024-08-31 12:40:07 +00:00
|
|
|
.inum dd ?
|
|
|
|
.name db STPDFS_NAME_MAX dup(?)
|
|
|
|
}
|
2024-09-02 13:12:19 +00:00
|
|
|
DEFN DirEntry
|
2024-08-31 12:40:07 +00:00
|
|
|
|
|
|
|
;; Function: stpdfs_load_rootdir
|
|
|
|
;;
|
|
|
|
;; Out:
|
2024-09-02 13:12:19 +00:00
|
|
|
;;
|
2024-08-31 12:40:07 +00:00
|
|
|
stpdfs_load_rootdir:
|
|
|
|
; read first inode
|
|
|
|
mov ax, DISK_BUFFER/0x10
|
|
|
|
mov es, ax
|
|
|
|
mov ax, 2
|
|
|
|
mov cx, 1
|
|
|
|
xor bx, bx
|
2024-09-01 09:53:44 +00:00
|
|
|
|
2024-08-31 12:40:07 +00:00
|
|
|
call disk_read_sectors
|
2024-09-01 09:53:44 +00:00
|
|
|
|
2024-08-31 12:40:07 +00:00
|
|
|
; root dir is inode 1
|
2024-09-01 09:53:44 +00:00
|
|
|
xor ax, ax
|
|
|
|
mov es, ax
|
|
|
|
mov ecx, sizeof.Inode
|
|
|
|
mov esi, DISK_BUFFER + sizeof.Inode
|
|
|
|
mov edi, inode_cache
|
|
|
|
rep movsb
|
2024-08-31 12:40:07 +00:00
|
|
|
|
2024-09-01 09:53:44 +00:00
|
|
|
mov ax, DISK_BUFFER/0x10
|
|
|
|
mov es, ax
|
2024-09-02 13:12:19 +00:00
|
|
|
xor bx, bx
|
2024-09-01 09:53:44 +00:00
|
|
|
call stpdfs_copy_data
|
|
|
|
|
2024-09-02 13:12:19 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
;; Function: stpdfs_read_inode
|
|
|
|
;;
|
|
|
|
;; copy selected inode from file system to `inode_cache`
|
|
|
|
;;
|
|
|
|
;; In:
|
|
|
|
;; EAX - inum
|
|
|
|
;;
|
|
|
|
stpdfs_read_inode:
|
|
|
|
; get block where inode is located
|
|
|
|
xor edx, edx
|
|
|
|
mov ecx, STPDFS_INODE_PER_BLOCK
|
|
|
|
div ecx
|
|
|
|
add eax, 2
|
|
|
|
|
|
|
|
; read block
|
|
|
|
push edx
|
|
|
|
push eax
|
|
|
|
mov ax, DISK_BUFFER/0x10
|
|
|
|
mov es, ax
|
|
|
|
pop eax
|
|
|
|
mov cx, 1
|
|
|
|
xor bx, bx
|
|
|
|
call disk_read_sectors
|
|
|
|
pop edx
|
|
|
|
|
|
|
|
; copy to inode cache
|
|
|
|
mov eax, edx
|
|
|
|
mov cl, sizeof.Inode
|
|
|
|
mul cl
|
|
|
|
movzx esi, ax
|
|
|
|
add esi, DISK_BUFFER
|
|
|
|
|
|
|
|
xor ax, ax
|
|
|
|
mov es, ax
|
|
|
|
mov ecx, sizeof.Inode
|
|
|
|
mov edi, inode_cache
|
|
|
|
rep movsb
|
2024-08-31 12:40:07 +00:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
;; Function: stpdfs_search
|
|
|
|
;;
|
|
|
|
;; In:
|
|
|
|
;; SI - filename
|
|
|
|
;;
|
2024-09-02 13:12:19 +00:00
|
|
|
;; Out:
|
|
|
|
;; EAX - kernel inode
|
2024-08-31 12:40:07 +00:00
|
|
|
stpdfs_search:
|
|
|
|
clc ; clear carry flag
|
2024-09-02 13:12:19 +00:00
|
|
|
|
|
|
|
xor ax, ax
|
|
|
|
mov es, ax
|
2024-08-31 12:40:07 +00:00
|
|
|
|
2024-09-02 13:12:19 +00:00
|
|
|
xor ecx, ecx
|
|
|
|
.search_loop:
|
|
|
|
cmp ecx, dword [inode_cache + Inode.size]
|
|
|
|
jge .search_end
|
|
|
|
|
|
|
|
push ecx
|
|
|
|
|
|
|
|
; check if inum != 0
|
|
|
|
mov eax, DISK_BUFFER
|
|
|
|
add eax, ecx
|
|
|
|
mov edx, [eax]
|
|
|
|
|
|
|
|
or edx, edx
|
|
|
|
jz .search_next
|
|
|
|
|
|
|
|
; compare filename
|
|
|
|
mov edi, eax
|
|
|
|
add edi, 4
|
|
|
|
|
|
|
|
push si
|
|
|
|
.strcmp:
|
|
|
|
mov al, [si]
|
|
|
|
cmpsb
|
|
|
|
jne .strcmp_not_equal
|
|
|
|
or al, al
|
|
|
|
jz .kernel_found
|
|
|
|
jmp .strcmp
|
|
|
|
.strcmp_not_equal:
|
|
|
|
pop si
|
|
|
|
.search_next:
|
|
|
|
pop ecx
|
|
|
|
add ecx, sizeof.DirEntry
|
|
|
|
jmp .search_loop
|
|
|
|
.search_end:
|
|
|
|
stc
|
|
|
|
ret
|
|
|
|
.kernel_found:
|
|
|
|
pop si
|
|
|
|
pop ecx
|
|
|
|
|
|
|
|
mov eax, edx
|
2024-08-31 12:40:07 +00:00
|
|
|
|
2024-09-02 13:12:19 +00:00
|
|
|
clc
|
2024-08-31 12:40:07 +00:00
|
|
|
ret
|
|
|
|
|
2024-09-01 09:53:44 +00:00
|
|
|
;; Function: stpdfs_copy_data
|
|
|
|
;;
|
|
|
|
;; In:
|
2024-09-02 13:12:19 +00:00
|
|
|
;; ES:BX - buffer
|
|
|
|
;;
|
2024-08-31 12:40:07 +00:00
|
|
|
stpdfs_copy_data:
|
2024-09-01 09:53:44 +00:00
|
|
|
xor edx, edx
|
|
|
|
movzx ebx, bx
|
2024-09-02 13:12:19 +00:00
|
|
|
|
|
|
|
;; read direct
|
2024-09-01 09:53:44 +00:00
|
|
|
@@:
|
2024-09-02 13:12:19 +00:00
|
|
|
cmp ebx, dword [inode_cache + Inode.size]
|
2024-09-01 09:53:44 +00:00
|
|
|
jg .all_read
|
|
|
|
mov eax, edx
|
|
|
|
shl eax, 2
|
2024-09-02 13:12:19 +00:00
|
|
|
add eax, inode_cache + Inode.zones
|
|
|
|
mov eax, [eax]
|
2024-09-01 09:53:44 +00:00
|
|
|
|
|
|
|
push edx
|
|
|
|
push ebx
|
|
|
|
mov cx, 1
|
|
|
|
call disk_read_sectors
|
|
|
|
pop ebx
|
|
|
|
pop edx
|
|
|
|
|
2024-09-02 13:12:19 +00:00
|
|
|
add ebx, STPDFS_BLOCK_SIZE
|
2024-09-01 09:53:44 +00:00
|
|
|
inc edx
|
2024-09-02 13:12:19 +00:00
|
|
|
cmp edx, 7
|
|
|
|
jb @b
|
2024-09-01 09:53:44 +00:00
|
|
|
|
|
|
|
.indirect_read:
|
2024-09-02 13:12:19 +00:00
|
|
|
push ebx
|
|
|
|
mov ax, es
|
|
|
|
push ax
|
|
|
|
|
|
|
|
mov ax, DISK_BUFFER/0x10
|
|
|
|
mov es, ax
|
|
|
|
|
|
|
|
mov eax, dword [inode_cache + Inode.zones + 28]
|
|
|
|
mov cx, 1
|
|
|
|
xor bx, bx
|
|
|
|
call disk_read_sectors
|
2024-09-01 09:53:44 +00:00
|
|
|
|
2024-09-02 13:12:19 +00:00
|
|
|
pop ax
|
|
|
|
mov es, ax
|
|
|
|
|
|
|
|
pop ebx
|
|
|
|
xor edx, edx
|
|
|
|
@@:
|
|
|
|
cmp ebx, dword [inode_cache + Inode.size]
|
|
|
|
jg .all_read
|
|
|
|
mov eax, edx
|
|
|
|
shl eax, 2
|
|
|
|
add eax, DISK_BUFFER
|
|
|
|
mov eax, [eax]
|
|
|
|
|
|
|
|
mov cx, 1
|
|
|
|
push edx
|
|
|
|
call disk_read_sectors
|
|
|
|
pop edx
|
|
|
|
|
|
|
|
add ebx, STPDFS_BLOCK_SIZE
|
|
|
|
inc edx
|
|
|
|
cmp edx, 128
|
|
|
|
jbe @b
|
2024-09-01 09:53:44 +00:00
|
|
|
.all_read:
|
2024-08-31 12:40:07 +00:00
|
|
|
ret
|