1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;; Copyright (C) KolibriOS team 2004-2024. All rights reserved. ;;
4 ;; Distributed under terms of the GNU General Public License. ;;
6 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11 ERROR_UNSUPPORTED_FS = 2
14 ERROR_FILE_NOT_FOUND = 5
16 ERROR_MEMORY_POINTER = 7
19 ERROR_ACCESS_DENIED = 10
24 image_of_eax EQU esp+32
25 image_of_ebx EQU esp+20
31 Creat_part dd ? ; %FSNAME%_create_partition
32 UserFuncs dd ? ; for fs_del
33 Name rd 16 ;ascii string + \n
42 ; IN: ecx = %FSNAME%_create_partition
43 ; edx = ptr to UserFuncs
49 mov eax, sizeof.FileSystem
55 mov [eax + FileSystem.Creat_part], ecx
56 mov [eax + FileSystem.UserFuncs], edx
58 mov [eax + FileSystem.Name], edx
62 list_add_tail edx, fs_list
64 mov edx, ecx ; save function
66 ;DEBUGF 1, 'K : FS: find partition\n'
70 cmp dword[esi], disk_list
74 mov eax, [esi + DISK.MediaInfo.SectorSize]
76 stdcall kernel_alloc, eax ;get buffer
82 mov ecx, [esi + DISK.NumPartitions]
85 add ecx, [esi + DISK.Partitions]
88 cmp [ebp + PARTITION.FSUserFunctions], default_fs_functions
91 ;DEBUGF 1, 'K : FS: found partition\n'
94 xor eax, eax ; first sector of the partition
97 ;DEBUGF 1, 'K : FS: call driver func = %x\n', edx
99 call edx ; creat_partition
101 ;DEBUGF 1, 'K : FS: end call\n'
106 ; save and delete old struct
111 ;DEBUGF 1, 'K : FS: set fs for partition\n'
114 cmp ecx, [esi + DISK.Partitions]
119 stdcall kernel_free, ebx
127 ; IN: ecx = list item
135 ; System function 70 security check
137 proc file_system_is_operation_safe stdcall, inf_struct_ptr: dword
139 ; inf_struct_ptr = pointer to information structure was given to sysfn70
140 ; out: ZF = 1 if operation is safe
141 ; ZF = 0 if operation can cause kernel crash
143 xor ecx, ecx ; ecx - length of target buffer
145 mov ebx, [inf_struct_ptr]
146 mov edx, [ebx + 16] ; base of target buffer
148 cmp dword [ebx], 0 ; if 70.0
150 mov ecx, dword [ebx + 12]
154 cmp dword [ebx], 1 ; if 70.1
157 cmp dword [ebx + 8], 1 ; check encoding
158 jbe .case1_304 ; if encdoing <= 1 i.e cpp866
159 mov ecx, 560 ; if unicode then bdvk block len is 560 bytes
162 mov ecx, 304 ; if cp866 then bdvk block len is 304 bytes
164 imul ecx, dword [ebx + 12] ; multiply bdvk length by their count
165 add ecx, 32 ; add result header len
170 ja .case5 ; if subfn > 3
171 mov ecx, dword [ebx + 12]
191 stdcall is_region_userspace, edx, ecx
197 sys_fileSystemUnicode: ; with user pointer correctness checking
198 ; in: ebx -> f.80 parameter structure
199 stdcall file_system_is_operation_safe, ebx
202 DEBUGF 1, "sysfn80 addr error\n"
203 mov dword [image_of_eax], ERROR_MEMORY_POINTER
206 jmp fileSystemUnicode
209 sys_file_system_lfn: ; with user pointer correctness checking
210 ; in: ebx -> f.70 parameter structure
211 stdcall file_system_is_operation_safe, ebx
214 DEBUGF 1, "sysfn70 addr error\n"
215 mov dword [image_of_eax], ERROR_MEMORY_POINTER
220 ;file_system_lfn_protected returns values not in registers, but in their images
221 ;on stack. Make a short wrapper to actually return values in registers.
222 file_system_lfn_protected_registers:
224 call file_system_lfn_protected
228 file_system_lfn_protected:
230 call protect_from_terminate
232 call unprotect_from_terminate
234 mov [image_of_eax], eax
235 mov [image_of_ebx], ebx
239 ; in: ebx -> f.80 parameter structure
245 ; in: ebx -> f.70 parameter structure
259 stdcall kernel_alloc, maxPathLength
266 cmp dword[ebx], 7 ; start application
272 mov [image_of_eax], eax
281 call dyndisk_handler ; not returns if success
283 stdcall kernel_free, ebp
284 mov dword[image_of_eax], ERROR_FILE_NOT_FOUND
300 lodsb ; partition number
318 call reserve_cd_channel
325 mov dword[image_of_eax], ERROR_FILE_NOT_FOUND
326 bt [edi*5+DRIVE_DATA+1], ax
331 mov dword[image_of_eax], ERROR_UNSUPPORTED_FS
332 cmp eax, fs_NumCdServices
336 call dword[fs_CdServices + eax*4]
338 mov [image_of_eax], eax
339 mov [image_of_ebx], ebx
343 stdcall kernel_free, ebp
347 test eax, eax ; partition number
356 .maindir: ; list partitions
359 .maindir_noesi: ; backjump from dyndisk_handler
363 mov edi, [ebx+16] ; buffer
366 cmp byte [ebx], 1 ; read folder?
369 pushd [ebx+4] ; first block
370 mov ebp, [ebx+12] ; the number of blocks to read
371 mov ebx, [ebx+8] ; flags
376 mov byte [edx], 1 ; version
386 mov dword[edi], 16 ; attributes: folder
387 mov dword[edi+4], ebx ; name encoding
395 ; convert number in eax to decimal string
435 mov al, ERROR_END_OF_FILE
437 mov [image_of_eax], eax
438 mov [image_of_ebx], ebx
442 mov dword[image_of_eax], ERROR_ACCESS_DENIED
448 mov eax, dword[ebp+DISK.MediaInfo.Capacity]
449 mov edx, dword[ebp+DISK.MediaInfo.Capacity+4]
450 mov ecx, [ebp + DISK.MediaInfo.SectorSize]
457 and dword[image_of_eax], 0
460 .rootdir: ; / - virtual root folder
463 cmp byte [ebx], 1 ; read folder?
465 mov ebp, [ebx+12] ; number of blocks
466 mov edx, [ebx+16] ; return area
467 push dword[ebx+4] ; first block
468 mov ebx, [ebx+8] ; flags
473 mov byte [edx], 1 ; version
478 call dyndisk_enum_root
488 mov dword[edi], 16 ; attributes: folder
489 mov dword[edi+4], ebx ; name encoding
534 bt [ecx*5+DRIVE_DATA+1], ax
542 mov dword[edi], 16 ; attributes: folder
543 mov dword[edi+4], ebx ; name encoding
558 mov dword[edi], 640063h
569 mov al, ERROR_END_OF_FILE
571 mov [image_of_eax], eax
572 mov [image_of_ebx], ebx
575 ;-----------------------------------------------------------------------------
576 process_replace_file_name:
577 ; in: [esi] = virtual path
578 ; out: [esi]+[ebp] = physical path
582 cmp edi, [full_file_name_table.size]
586 add edi, [full_file_name_table]
611 add edi, [full_file_name_table]
617 ;-----------------------------------------------------------------------------
622 sys_current_directory: ; sysfunction 30
623 mov eax, [current_slot]
624 mov edi, [eax+APPDATA.cur_dir]
631 jz .mount_additional_directory
641 .mount_additional_directory:
642 ; in: ecx -> dir name+dir path (128)
644 xchg [addDirSeal], al
648 mov edi, sysdir_name1
650 rep movsb ; copying fake directory name
653 call cp866toUTF8_string
655 mov [full_file_name_table.size], 2
659 ; in: ecx -> buffer, edx = length, eax = encoding
660 stdcall is_region_userspace, ecx, edx
663 ; if illegal buffer given
671 cmp edx, maxPathLength
673 mov edx, maxPathLength
726 ; in: esi -> file path, eax = string encoding, edi -> destination
727 ; out: UTF-8 string (with marker), eax = length, 0 -> error
756 call process_replace_file_name
758 mov ecx, maxPathLength
778 call cp866toUTF8_string
803 mov edi, [current_slot]
804 mov edi, [edi+APPDATA.cur_dir]
806 mov ecx, maxPathLength
815 cmp edx, edi ; is destination equal to cur_dir?
829 add ecx, maxPathLength
834 cmp edx, edi ; is destination equal to cur_dir?
896 include "parse_fn.inc"
897 include "fs_common.inc"
898 include "iso9660.inc" ; read for CD filesystem