Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 74 → Rev 75

/kernel/trunk/fs/fat12.inc
1091,6 → 1091,7
pusha
sub esp, 262*2 ; reserve place for LFN
mov ebp, esp
push 0 ; for fat_get_name: read ASCII name
call read_flp_fat
cmp [FDC_Status], 0
jnz .error
1121,13 → 1122,13
js @f
jnz .20_1
.error:
add esp, 262*2
add esp, 262*2+4
popa
stc
ret
@@:
; read next sector from FAT
mov eax, [(eax-31)*2+0x282000]
mov eax, [(eax-31-1)*2+0x282000]
and eax, 0xFFF
cmp eax, 0xFF8
jae .error
1158,7 → 1159,7
mov dh, 0
jmp .main_loop
.done:
add esp, 262*2+4
add esp, 262*2+4+4
push edi
popad
ret
1178,7 → 1179,7
;
;--------------------------------------------------------------
fs_FloppyRead:
mov [save_flag], 0
call read_flp_fat
cmp byte [esi], 0
jnz @f
or ebx, -1
1261,4 → 1262,139
mov eax, 5 ; may be other error code?
pop edx ecx ebx ebx edi
ret
 
;----------------------------------------------------------------
;
; fs_FloppyReadFolder - LFN variant for reading floppy folders
;
; esi points to filename
; ebx pointer to 32-bit number = first wanted block, 0+
; ecx number of blocks to read, 0+
; edx mem location to return data
;
; ret ebx = size or 0xffffffff folder not found
; eax = 0 ok read or other = errormsg
;
;--------------------------------------------------------------
fs_FloppyReadFolder:
call read_flp_fat
mov ebx, [ebx]
push edi
cmp byte [esi], 0
jz .root
call fd_find_lfn
jnc .found
pop edi
or ebx, -1
mov eax, ERROR_FILE_NOT_FOUND
ret
.found:
test byte [edi+11], 0x10 ; do not allow read files
jnz .found_dir
pop edi
or ebx, -1
mov eax, ERROR_ACCESS_DENIED
ret
.found_dir:
movzx eax, word [edi+26]
add eax, 31
push 0
jmp .doit
.root:
mov eax, 19
push 14
.doit:
push ecx ebp
sub esp, 262*2 ; reserve space for LFN
mov ebp, esp
push 1 ; for fat_get_name: read UNICODE names
; init header
push eax ecx
mov edi, edx
mov ecx, 32/4
xor eax, eax
rep stosd
pop ecx eax
mov byte [edx], 1 ; version
mov esi, edi ; esi points to BDFE
.main_loop:
pusha
call read_chs_sector
popa
cmp [FDC_Status], 0
jnz .error
mov edi, 0xD000
push eax
.l1:
call fat_get_name
jc .l2
cmp byte [edi+11], 0xF
jnz .do_bdfe
add edi, 0x20
cmp edi, 0xD200
jb .do_bdfe
pop eax
inc eax
dec byte [esp+262*2+12]
jz .done
jns @f
; read next sector from FAT
mov eax, [(eax-31-1)*2+0x282000]
and eax, 0xFFF
cmp eax, 0xFF8
jae .done
add eax, 31
mov byte [esp+262*2+12], 0
@@:
pusha
call read_chs_sector
popa
cmp [FDC_Status], 0
jnz .error
mov edi, 0xD000
push eax
.do_bdfe:
inc dword [edx+8] ; new file found
dec ebx
jns .l2
dec ecx
js .l2
inc dword [edx+4] ; new file block copied
call fat_entry_to_bdfe
.l2:
add edi, 0x20
cmp edi, 0xD200
jb .l1
pop eax
inc eax
dec byte [esp+262*2+12]
jz .done
jns @f
; read next sector from FAT
mov eax, [(eax-31-1)*2+0x282000]
and eax, 0xFFF
cmp eax, 0xFF8
jae .done
add eax, 31
mov byte [esp+262*2+12], 0
@@:
jmp .main_loop
.error:
add esp, 262*2+4
pop ebp ecx edi edi
or ebx, -1
mov eax, ERROR_FILE_NOT_FOUND
ret
.done:
add esp, 262*2+4
pop ebp
mov ebx, [edx+8]
xor eax, eax
dec ecx
js @f
mov al, ERROR_END_OF_FILE
@@:
pop ecx edi edi
ret
 
; \end{diamond}
/kernel/trunk/fs/fat32.inc
7,9 → 7,10
;; Copyright 2002 Paolo Minazzi, paolo.minazzi@inwind.it ;;
;; ;;
;; See file COPYING for details ;;
;; 04.05.2006 LFN read folder - diamond ;;
;; 29.04.2006 Elimination of hangup after the ;;
;; expiration hd_wait_timeout - Mario79 ;;
;; 23.04.2006 LFN read - diamond ;;
;; 23.04.2006 LFN read file - diamond ;;
;; 28.01.2006 find all Fat16/32 partition in all input point ;;
;; to MBR, see file part_set.inc - Mario79 ;;
;; 15.01.2005 get file size/attr/date, file_append - ATV ;;
2936,6 → 2937,7
pusha
sub esp, 262*2 ; allocate space for LFN
mov ebp, esp
push 0 ; for fat_get_name: read ASCII name
mov eax, [ROOT_CLUSTER] ; start from root
.mainloop:
.new_cluster:
2990,7 → 2992,7
cmp eax, [fatRESERVED]
jb .new_cluster
.notfound:
add esp, 262*2
add esp, 262*2+4
popa
stc
ret
3036,7 → 3038,7
mov ax, [edi+26]
jmp .mainloop
.done:
add esp, 262*2+4 ; CF=0
add esp, 262*2+4+4 ; CF=0
push edi
popad
ret
3197,4 → 3199,172
.eof:
pop ebx edx ecx ebx
jmp .reteof
 
;----------------------------------------------------------------
;
; fs_HdReadFolder - LFN variant for reading hard disk folder
;
; esi points to filename
; ebx pointer to 32-bit number = first wanted block, 0+
; ecx number of blocks to read, 0+
; edx mem location to return data
;
; ret ebx = size or 0xffffffff folder not found
; eax = 0 ok read or other = errormsg
;
;--------------------------------------------------------------
fs_HdReadFolder:
mov ebx, [ebx]
mov eax, [ROOT_CLUSTER]
push edi
cmp byte [esi], 0
jz .doit
call hd_find_lfn
jnc .found
pop edi
or ebx, -1
mov eax, ERROR_FILE_NOT_FOUND
ret
.found:
test byte [edi+11], 0x10 ; do not allow read files
jnz .found_dir
pop edi
or ebx, -1
mov eax, ERROR_ACCESS_DENIED
ret
.found_dir:
mov eax, [edi+20-2]
mov ax, [edi+26] ; eax=cluster
.doit:
push esi ecx
push ebp
sub esp, 262*2 ; reserve space for LFN
mov ebp, esp
push 1 ; for fat_get_name: read UNICODE name
; init header
push eax ecx
mov edi, edx
mov ecx, 32/4
xor eax, eax
rep stosd
pop ecx eax
mov byte [edx], 1 ; version
mov esi, edi ; esi points to BDFE
.new_cluster:
mov [cluster_tmp], eax
test eax, eax
jnz @f
cmp [fat_type], 32
jz .notfound
mov eax, [ROOT_START]
push [ROOT_SECTORS]
push ebx
jmp .new_sector
@@:
dec eax
dec eax
imul eax, [SECTORS_PER_CLUSTER]
push [SECTORS_PER_CLUSTER]
add eax, [DATA_START]
push ebx
.new_sector:
mov ebx, buffer
mov edi, ebx
call hd_read
cmp [hd_error], 0
jnz .notfound2
add ebx, 512
push eax
.l1:
call fat_get_name
jc .l2
cmp byte [edi+11], 0xF
jnz .do_bdfe
add edi, 0x20
cmp edi, ebx
jb .do_bdfe
pop eax
inc eax
dec dword [esp+4]
jnz @f
mov eax, [cluster_tmp]
test eax, eax
jz .done
call get_FAT
cmp [hd_error], 0
jnz .notfound2
cmp eax, 2
jb .done
cmp eax, [fatRESERVED]
jae .done
push eax
mov eax, [SECTORS_PER_CLUSTER]
mov [esp+8], eax
pop eax
mov [cluster_tmp], eax
dec eax
dec eax
imul eax, [SECTORS_PER_CLUSTER]
add eax, [DATA_START]
@@:
mov ebx, buffer
mov edi, ebx
call hd_read
cmp [hd_error], 0
jnz .notfound2
add ebx, 512
push eax
.do_bdfe:
inc dword [edx+8] ; new file found
dec dword [esp+4]
jns .l2
dec ecx
js .l2
inc dword [edx+4] ; new file block copied
call fat_entry_to_bdfe
.l2:
add edi, 0x20
cmp edi, ebx
jb .l1
pop eax
inc eax
dec dword [esp+4]
jnz .new_sector
mov eax, [cluster_tmp]
test eax, eax
jz .done
call get_FAT
cmp [hd_error], 0
jnz .notfound2
cmp eax, 2
jb .done
cmp eax, [fatRESERVED]
jae .done
push eax
mov eax, [SECTORS_PER_CLUSTER]
mov [esp+8], eax
pop eax
pop ebx
add esp, 4
jmp .new_cluster
.notfound2:
add esp, 8
.notfound:
add esp, 262*2+4
pop ebp ecx esi edi
mov eax, ERROR_FILE_NOT_FOUND
or ebx, -1
ret
.done:
add esp, 262*2+4+8
pop ebp
mov ebx, [edx+8]
xor eax, eax
dec ecx
js @f
mov al, ERROR_END_OF_FILE
@@:
pop ecx esi edi
ret
 
; \end{diamond}
/kernel/trunk/fs/fs_lfn.inc
6,21 → 6,44
rootdirs:
db 2,'rd'
dd fs_OnRamdisk
dd fs_NextRamdisk
db 7,'ramdisk'
dd fs_OnRamdisk
dd fs_NextRamdisk
db 2,'fd'
dd fs_OnFloppy
dd fs_NextFloppy
db 10,'floppydisk'
dd fs_OnFloppy
dd fs_NextFloppy
db 3,'hd0'
dd fs_OnHd0
dd fs_NextHd0
db 3,'hd1'
dd fs_OnHd1
dd fs_NextHd1
db 3,'hd2'
dd fs_OnHd2
dd fs_NextHd2
db 3,'hd3'
dd fs_OnHd3
dd fs_NextHd3
db 0
 
virtual_root_query:
dd fs_HasRamdisk
du 'rd',0
dd fs_HasFloppy
du 'fd',0
dd fs_HasHd0
du 'hd0',0
dd fs_HasHd1
du 'hd1',0
dd fs_HasHd2
du 'hd2',0
dd fs_HasHd3
du 'hd3',0
dd 0
endg
 
file_system_lfn:
27,15 → 50,16
; in: eax->fileinfo block
; operation codes:
; 0 : read file
; 1 : rewrite file - not implemented yet
; 2 : delete file - not implemented yet
; 1 : read folder
; 2 : rewrite file - not implemented yet
; 3 : write/append to file - not implemented yet
; 4 : create directory - not implemented yet
; 5 : rename file/directory - not implemented yet
; 6 : get file attributes structure - not implemented yet
; 7 : start application - not implemented yet
; 8 : find file with mask - not implemented yet
; 4 : start application - not implemented yet
; 5 : delete file - not implemented yet
; 6 : create directory - not implemented yet
; 7 : rename file/directory - not implemented yet
; 8 : get file attributes structure - not implemented yet
 
add eax, std_application_base_address
; parse file name
xchg ebx, eax
lea esi, [ebx+20]
48,7 → 72,7
@@:
cmp byte [esi], 0
jz .rootdir
mov edi, rootdirs-4
mov edi, rootdirs-8
xor ecx, ecx
push esi
.scan1:
55,6 → 79,7
pop esi
add edi, ecx
scasd
scasd
mov cl, byte [edi]
jecxz .notfound
inc edi
65,23 → 90,146
scasb
loopz @b
jnz .scan1
pop eax
lodsb
cmp al, '/'
jz .found1
test al, al
jnz .scan1
pop eax
; directory /xxx
.maindir:
cmp dword [ebx], 1
jnz .access_denied
xor eax, eax
mov ebp, [ebx+12]
mov edx, [ebx+16]
add edx, std_application_base_address
mov ebx, [ebx+4]
mov esi, [edi+4]
; ebx=first block, ebp=number of blocks, edx=return area, esi='Next' handler
mov edi, edx
mov ecx, 32/4
rep stosd
mov byte [edx], 1 ; version
.maindir_loop:
call esi
jc .maindir_done
inc dword [edx+8]
dec ebx
jns .maindir_loop
dec ebp
js .maindir_loop
inc dword [edx+4]
mov dword [edi], 0x10 ; attributes: folder
mov dword [edi+4], 1 ; name type: UNICODE
push eax
xor eax, eax
add edi, 8
mov ecx, 40/4-2
rep stosd
pop eax
push eax edx
; convert number in eax to decimal UNICODE string
push edi
push -'0'
mov cl, 10
@@:
xor edx, edx
div ecx
push edx
test eax, eax
jnz @b
@@:
pop eax
add al, '0'
stosw
jnz @b
mov byte [edi-1], 0
pop edi
add edi, 520
pop edx eax
jmp .maindir_loop
.maindir_done:
mov ebx, [edx+8]
xor eax, eax
dec ebp
js @f
mov al, ERROR_END_OF_FILE
@@:
mov [esp+36], eax
mov [esp+24], ebx
ret
; directory /
.rootdir:
cmp dword [ebx], 1 ; read folder?
jz .readroot
.access_denied:
mov dword [esp+36], 10 ; access denied
ret
 
.readroot:
; virtual root folder - special handler
mov esi, virtual_root_query
mov ebp, [ebx+12]
mov edx, [ebx+16]
add edx, std_application_base_address
mov ebx, [ebx+4]
xor eax, eax
; eax=0, ebx=first block, ebp=number of blocks, edx=return area
mov edi, edx
mov ecx, 32/4
rep stosd
mov byte [edx], 1 ; version
.readroot_loop:
cmp dword [esi], eax
jz .readroot_done
call dword [esi]
add esi, 4
test eax, eax
jnz @f
.readroot_next:
or ecx, -1
xchg esi, edi
repnz scasw
xchg esi, edi
jmp .readroot_loop
@@:
xor eax, eax
inc dword [edx+8]
dec ebx
jns .readroot_next
dec ebp
js .readroot_next
inc dword [edx+4]
mov dword [edi], 0x10 ; attributes: folder
mov dword [edi+4], 1 ; name type: UNICODE
add edi, 8
mov ecx, 40/4-2
rep stosd
push edi
@@:
lodsw
stosw
test eax, eax
jnz @b
pop edi
add edi, 520
jmp .readroot_loop
.readroot_done:
mov ebx, [edx+8]
xor eax, eax
dec ebp
js @f
mov al, ERROR_END_OF_FILE
@@:
mov [esp+36], eax
mov [esp+24], ebx
ret
 
.found1:
pop eax
cmp byte [esi], 0
jz .maindir
mov ebp, dword [edi] ; handler for this device
; read partition number
xor ecx, ecx
xor eax, eax
104,10 → 252,12
jnz @f
dec esi
@@:
; now ebp contains handler address, ecx - partition number, esi points to ASCIIZ string - rest of name
jmp ebp
; now [edi] contains handler address, ecx - partition number,
; esi points to ASCIIZ string - rest of name
jmp dword [edi]
 
; handlers for devices
; in: ecx = 0 => query virtual directory /xxx
; in: ecx = partition number
; esi -> relative (for device) name
; ebx -> fileinfo
116,9 → 266,9
fs_OnRamdisk:
cmp ecx, 1
jnz file_system_lfn.notfound
movzx eax, byte [ebx]
test eax, eax
jnz .not_impl
mov eax, [ebx]
cmp eax, 1
ja .not_impl
mov ecx, [ebx+12]
mov edx, [ebx+16]
add edx, std_application_base_address
133,13 → 283,14
 
fs_RamdiskServices:
dd fs_RamdiskRead
dd fs_RamdiskReadFolder
 
fs_OnFloppy:
cmp ecx, 2
ja file_system_lfn.notfound
movzx eax, byte [ebx]
test eax, eax
jnz fs_OnRamdisk.not_impl
mov eax, [ebx]
cmp eax, 1
ja fs_OnRamdisk.not_impl
call reserve_flp
mov [flp_number], cl
mov ecx, [ebx+12]
154,6 → 305,7
 
fs_FloppyServices:
dd fs_FloppyRead
dd fs_FloppyReadFolder
 
fs_OnHd0:
call reserve_hd1
181,8 → 333,11
fs_OnHd:
pop eax
mov [hdpos], eax
cmp ecx, [0x40001+eax]
cmp ecx, 0x100
jae .nf
cmp cl, [0x40001+eax]
jbe @f
.nf:
and [hd1_status], 0
mov dword [esp+36], 5 ; not found
ret
194,7 → 349,9
mov ecx, [ebx+12]
mov edx, [ebx+16]
add edx, std_application_base_address
movzx eax, byte [ebx]
mov eax, [ebx]
cmp eax, 1
ja .not_impl
add ebx, 4
call dword [fs_HdServices + eax*4]
and [hd1_status], 0
201,6 → 358,101
mov [esp+36], eax
mov [esp+24], ebx
ret
.not_impl:
and [hd1_status], 0
mov dword [esp+36], 2 ; not implemented
ret
 
fs_HdServices:
dd fs_HdRead
dd fs_HdReadFolder
 
fs_HasRamdisk:
mov al, 1 ; we always have ramdisk
ret
 
fs_HasFloppy:
cmp byte [0x40000], 0
setnz al
ret
 
fs_HasHd0:
mov al, [0x40001]
and al, 11000000b
cmp al, 01000000b
setz al
ret
fs_HasHd1:
mov al, [0x40001]
and al, 00110000b
cmp al, 00010000b
setz al
ret
fs_HasHd2:
mov al, [0x40001]
and al, 00001100b
cmp al, 00000100b
setz al
ret
fs_HasHd3:
mov al, [0x40001]
and al, 00000011b
cmp al, 00000001b
setz al
ret
 
; fs_NextXXX functions:
; in: eax = partition number, from which start to scan
; out: CF=1 => no more partitions
; CF=0 => eax=next partition number
 
fs_NextRamdisk:
; we always have /rd/1
test eax, eax
stc
jnz @f
mov al, 1
clc
@@:
ret
 
fs_NextFloppy:
; we have /fd/1 iff (([0x40000] and 0xF0) != 0) and /fd/2 iff (([0x40000] and 0x0F) != 0)
test byte [0x40000], 0xF0
jz .no1
test eax, eax
jnz .no1
inc eax
ret ; CF cleared
.no1:
test byte [0x40000], 0x0F
jz .no2
cmp al, 2
jae .no2
mov al, 2
clc
ret
.no2:
stc
ret
 
; on hdx, we have partitions from 1 to [0x40002+x]
fs_NextHd0:
push 0
jmp fs_NextHd
fs_NextHd1:
push 1
jmp fs_NextHd
fs_NextHd2:
push 2
jmp fs_NextHd
fs_NextHd3:
push 3
fs_NextHd:
pop ecx
movzx ecx, byte [0x40002+ecx]
cmp eax, ecx
jae fs_NextFloppy.no2
inc eax
clc
ret