[KERNEL] Added the "FsAdd" function for drivers on file systems.

TODO: added functions for lock\unlock partition and read\write sectors for user programs 

git-svn-id: svn://kolibrios.org@9894 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Doczom 2023-01-21 18:07:32 +00:00
parent a1909c89a2
commit 2160c0e6f7
3 changed files with 140 additions and 1 deletions

View File

@ -1241,7 +1241,7 @@ end virtual
add ebp, 8 ; ebp points to part of PARTITION structure
xor eax, eax ; first sector of the partition
call fs_read32_sys
push eax
;push eax
; 2. Run tests for all supported filesystems. If at least one test succeeded,
; go to 4.
; For tests:
@ -1249,6 +1249,22 @@ end virtual
; [esp] = error code after bootsector read: 0 = ok, otherwise = failed,
; ebx points to the buffer for bootsector,
; ebx+[esi+DISK.MediaInfo.SectorSize] points to sector-sized buffer that can be used for anything.
mov ecx, [fs_list]
@@:
cmp ecx, fs_list
jz @f
push ecx eax
call dword[ecx + FileSystem.Creat_part]
pop ecx
test eax, eax
jnz .success
pop eax
mov ecx, [ecx]
jmp @b
@@:
push eax
call fat_create_partition
test eax, eax
jnz .success

View File

@ -18,6 +18,21 @@ __exports:
disk_add, 'DiskAdd', \ ;stdcall
disk_del, 'DiskDel', \
disk_media_changed, 'DiskMediaChanged', \ ;stdcall
\
fs_read32_sys, 'FsRead32Sys', \
fs_read32_app, 'FsRead32App', \
fs_read64_sys, 'FsRead64Sys', \
fs_read64_app, 'FsRead64App', \
\
fs_write32_sys, 'FsWrite32Sys', \
fs_write32_app, 'FsWrite32App', \
fs_write64_sys, 'FsWrite64Sys', \
fs_write64_app, 'FsWrite64App', \
\
fs_add, 'FsAdd', \
\ ;fs_del, 'FsDel', \
\
disk_sync, 'DiskSync', \
\
create_event, 'CreateEvent', \ ; ecx, esi
destroy_event, 'DestroyEvent', \ ;

View File

@ -25,6 +25,114 @@ maxPathLength = 1000h
image_of_eax EQU esp+32
image_of_ebx EQU esp+20
; fs api for drivers
struct FileSystem
Next dd ?
Prev dd ?
Creat_part dd ? ; %FSNAME%_create_partition
UserFuncs dd ? ; for fs_del
Name rd 16 ;ascii string + \n
ends
fs_list:
dd fs_list
dd fs_list
;.look: dd 0
; IN: ecx = %FSNAME%_create_partition
; edx = ptr to UserFuncs
; [esp] = fs name
;OUT: eax = list item
fs_add:
push ecx edx
; add in fs_list
mov eax, sizeof.FileSystem
call malloc
pop edx ecx
test eax, eax
jz .err
mov [eax + FileSystem.Creat_part], ecx
mov [eax + FileSystem.UserFuncs], edx
mov edx, [esp + 4]
mov [eax + FileSystem.Name], edx
mov edx, eax
cli ; DELETE
list_add_tail edx, fs_list
sti ; DELETE
mov edx, ecx ; save function
;DEBUGF 1, 'K : FS: find partition\n'
; check all disks
mov esi, [disk_list]
.new_disk:
cmp dword[esi], disk_list
jz .end
push edx
mov eax, [esi + DISK.MediaInfo.SectorSize]
shl eax, 2
stdcall kernel_alloc, eax ;get buffer
test eax, eax
pop edx
jz .end ; no memory
mov ebx, eax
mov ecx, [esi + DISK.NumPartitions]
dec ecx
shl ecx, 2 ; to dword
add ecx, [esi + DISK.Partitions]
@@:
mov ebp, [ecx]
cmp [ebp + PARTITION.FSUserFunctions], default_fs_functions
jnz .no_fs
;DEBUGF 1, 'K : FS: found partition\n'
push ecx edx
xor eax, eax ; first sector of the partition
call fs_read32_sys
push eax
;DEBUGF 1, 'K : FS: call driver func = %x\n', edx
call edx ; creat_partition
add esp, 4
;DEBUGF 1, 'K : FS: end call\n'
pop edx ecx
test eax, eax
jz .no_fs
; save and delete old struct
xchg [ecx], eax
push ecx edx
call free
pop edx ecx
;DEBUGF 1, 'K : FS: set fs for partition\n'
.no_fs:
;sub ecx, 4
cmp ecx, [esi + DISK.Partitions]
lea ecx, [ecx - 4]
jnz @b
push edx
stdcall kernel_free, ebx
pop edx
mov esi, [esi]
jmp .new_disk
.end:
.err:
ret
; IN: ecx = list item
;OUT: -
;fs_del:
;
; ret
; System function 70 security check
align 4
proc file_system_is_operation_safe stdcall, inf_struct_ptr: dword