Rev 40 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ha | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; System service for filesystem call ;; |
||
4 | ;; (C) 2004 Ville Turjanmaa, License: GPL ;; |
||
5 | ;; ;; |
||
6 | ;; 15.01.2005 get file size/attr/date, file_append (only for hd) - ATV ;; |
||
7 | ;; 23.11.2004 test if hd/partition is set - ATV ;; |
||
8 | ;; 18.11.2004 get_disk_info and more error codes - ATV ;; |
||
9 | ;; 08.11.2004 expand_pathz and rename (only for hd) - ATV ;; |
||
10 | ;; 20.10.2004 Makedir/Removedir (only for hd) - ATV ;; |
||
11 | ;; ;; |
||
12 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
13 | |||
14 | iglobal |
||
15 | dir0: db 'HARDDISK ' |
||
16 | db 'RAMDISK ' |
||
17 | db 'FLOPPYDISK ' |
||
18 | db 0 |
||
19 | |||
20 | dir1: db 'FIRST ' |
||
21 | db 'SECOND ' |
||
22 | db 'THIRD ' |
||
23 | db 'FOURTH ' |
||
24 | db 0 |
||
25 | |||
26 | not_select_IDE db 0 |
||
27 | |||
28 | hd_address_table: dd 0x1f0,0x00,0x1f0,0x10 |
||
29 | dd 0x170,0x00,0x170,0x10 |
||
30 | endg |
||
31 | |||
32 | file_system: |
||
33 | ; IN: |
||
34 | ; |
||
35 | ; eax = 0 ; read file /RamDisk/First 6 /HardDisk/First 30 |
||
36 | ; eax = 1 ; write file /RamDisk/First 33 /HardDisk/First 56 |
||
37 | ; eax = 2 ; delete file /RamDisk/First 32 /HardDisk/First 57 |
||
38 | ; eax = 3 ; append to a file /RamDisk/First ?? /HardDisk/First ?? |
||
39 | ; eax = 4 ; makedir |
||
40 | ; eax = 5 ; rename file/directory |
||
41 | ; eax = 8 ; lba read |
||
42 | ; eax = 12 ; get_filesize |
||
43 | ; eax = 13 ; get_fileattr |
||
44 | ; eax = 14 ; get_filedate |
||
45 | ; eax = 15 ; get_disk_info |
||
46 | ; eax = 16 ; start application |
||
47 | ; |
||
48 | ; OUT: |
||
49 | ; |
||
50 | ; eax = 0 : read ok |
||
61 | halyavin | 51 | ; eax = 1 : no hd base and/or partition defined |
1 | ha | 52 | ; eax = 2 : yet unsupported FS |
53 | ; eax = 3 : unknown FS |
||
54 | ; eax = 4 : partition not defined at hd |
||
55 | ; eax = 5 : file not found |
||
56 | ; eax = 6 : end of file |
||
57 | ; eax = 7 : memory pointer not in application area |
||
58 | ; eax = 8 : disk full |
||
59 | ; eax = 9 : fat table corrupted |
||
60 | ; eax = 10 : access denied |
||
61 | ; |
||
62 | ; ebx = size |
||
63 | |||
61 | halyavin | 64 | ; \begin{diamond}[18.03.2006] |
65 | ; for subfunction 16 (start application) error codes must be negative |
||
66 | ; because positive values are valid PIDs |
||
67 | ; so possible return values are: |
||
68 | ; eax > 0 : process created, eax=PID |
||
69 | |||
70 | ; -0x10 <= eax < 0 : -eax is filesystem error code: |
||
71 | ; eax = -1 = 0xFFFFFFFF : no hd base and/or partition defined |
||
72 | ; eax = -3 = 0xFFFFFFFD : unknown FS |
||
73 | ; eax = -5 = 0xFFFFFFFB : file not found |
||
74 | ; eax = -6 = 0xFFFFFFFA : unexpected end of file (probably not executable file) |
||
75 | ; eax = -9 = 0xFFFFFFF7 : fat table corrupted |
||
76 | ; eax = -10 = 0xFFFFFFF6 : access denied |
||
77 | |||
78 | ; -0x20 <= eax < -0x10: eax is process creation error code: |
||
79 | ; eax = -0x20 = 0xFFFFFFE0 : too many processes |
||
80 | ; eax = -0x1F = 0xFFFFFFE1 : not Menuet/Kolibri executable |
||
81 | ; eax = -0x1E = 0xFFFFFFE2 : no memory |
||
82 | |||
83 | ; ebx is not changed |
||
84 | |||
85 | ; \end{diamond}[18.03.2006] |
||
86 | |||
1 | ha | 87 | ; Extract parameters |
61 | halyavin | 88 | add eax, std_application_base_address ; abs start of info block |
1 | ha | 89 | |
90 | cmp dword [eax+0],12 ; Get file size |
||
91 | je fs_read |
||
92 | cmp dword [eax+0],13 ; Get file attribute |
||
93 | je fs_read |
||
94 | cmp dword [eax+0],14 ; Get file date/time |
||
95 | je fs_read |
||
96 | cmp dword [eax+0],15 ; GET_DISK_INFO |
||
97 | je fs_info |
||
98 | cmp dword [eax+0],16 ; RUN - dont care about read&write blocks |
||
99 | je fs_read |
||
100 | cmp dword [eax+0],5 ; RENAME - dont care about read&write blocks |
||
101 | je fs_read |
||
102 | cmp dword [eax+0],4 ; MAKEDIR - dont care about read&write blocks |
||
103 | je fs_read |
||
104 | cmp dword [eax+0],2 ; DELETE - dont care about read&write blocks |
||
105 | je fs_read |
||
106 | |||
107 | cmp dword [0x3000],1 ; no memory checks for kernel requests |
||
108 | jz no_checks_for_kernel |
||
109 | mov edx,eax |
||
110 | cmp dword [eax+0],1 |
||
111 | jz .check_for_write_op |
||
112 | cmp dword [eax+0],3 |
||
113 | jnz .usual_check |
||
114 | .check_for_write_op: |
||
115 | mov ebx,[eax+12] |
||
116 | add ebx,std_application_base_address |
||
117 | mov ecx,[eax+8] |
||
118 | call check_region |
||
119 | test eax,eax |
||
120 | jnz area_in_app_mem |
||
121 | |||
122 | .error_output: |
||
123 | mov esi,buffer_failed |
||
124 | call sys_msg_board_str |
||
61 | halyavin | 125 | ; mov eax,7 |
1 | ha | 126 | mov dword [esp+36],7 |
127 | ret |
||
128 | iglobal |
||
61 | halyavin | 129 | buffer_failed db 'K : Buffer check failed',13,10,0 |
1 | ha | 130 | endg |
131 | .usual_check: |
||
132 | cmp dword [eax+0],0 |
||
133 | mov ecx,512 |
||
134 | jnz .small_size |
||
135 | mov ecx,[eax+8] |
||
136 | shl ecx,9 |
||
137 | .small_size: |
||
138 | mov ebx,[eax+12] |
||
139 | add ebx,std_application_base_address |
||
140 | call check_region |
||
141 | test eax,eax |
||
142 | jz .error_output |
||
143 | area_in_app_mem: |
||
144 | mov eax,edx |
||
145 | no_checks_for_kernel: |
||
146 | |||
147 | |||
148 | cmp dword [eax+0],3 ; APPEND - allow write 0 bytes (truncate) |
||
149 | je fs_read |
||
150 | cmp dword [eax+8],0 ; read or write 0 blocks/bytes ? |
||
151 | jne fs_read |
||
61 | halyavin | 152 | and dword [esp+36],0 |
1 | ha | 153 | ret |
154 | fs_read: |
||
155 | |||
156 | mov ebx,[eax+20] ; program wants root directory ? |
||
157 | test bl,bl |
||
158 | je fs_getroot |
||
159 | test bh,bh |
||
160 | jne fs_noroot |
||
161 | fs_getroot: |
||
61 | halyavin | 162 | ; \begin{diamond}[18.03.2006] |
163 | ; root - only read is allowed |
||
164 | ; other operations return "access denied", eax=10 |
||
165 | ; (execute operation returns eax=-10) |
||
166 | cmp dword [eax], 0 |
||
167 | jz .read_root |
||
168 | mov ecx, 10 |
||
169 | cmp dword [eax], 16 |
||
170 | jnz @f |
||
171 | neg ecx |
||
172 | @@: mov [esp+36], ecx |
||
173 | ret |
||
174 | .read_root: |
||
175 | ; \end{diamond}[18.03.2006] |
||
1 | ha | 176 | mov esi,dir0 |
177 | mov edi,[eax+12] |
||
61 | halyavin | 178 | add edi,std_application_base_address |
1 | ha | 179 | mov ecx,11 |
61 | halyavin | 180 | push ecx |
181 | ; cld ; already is |
||
1 | ha | 182 | rep movsb |
61 | halyavin | 183 | mov al,0x10 |
1 | ha | 184 | stosb |
185 | add edi,32-11-1 |
||
61 | halyavin | 186 | pop ecx |
1 | ha | 187 | rep movsb |
188 | stosb |
||
61 | halyavin | 189 | and dword [esp+36],0 ; ok read |
1 | ha | 190 | mov dword [esp+24],32*2 ; size of root |
191 | ret |
||
192 | |||
193 | fs_info: ;start of code - Mihasik |
||
61 | halyavin | 194 | push eax |
1 | ha | 195 | cmp [eax+21],byte 'h' |
196 | je fs_info_h |
||
197 | cmp [eax+21],byte 'H' |
||
198 | je fs_info_h |
||
199 | cmp [eax+21],byte 'r' |
||
200 | je fs_info_r |
||
201 | cmp [eax+21],byte 'R' |
||
202 | je fs_info_r |
||
203 | mov eax,3 ;if unknown disk |
||
204 | xor ebx,ebx |
||
205 | xor ecx,ecx |
||
206 | xor edx,edx |
||
207 | jmp fs_info1 |
||
208 | fs_info_r: |
||
209 | call ramdisk_free_space ;if ramdisk |
||
210 | mov ecx,edi ;free space in ecx |
||
211 | shr ecx,9 ;free clusters |
||
212 | mov ebx,2847 ;total clusters |
||
213 | mov edx,512 ;cluster size |
||
214 | xor eax,eax ;always 0 |
||
215 | jmp fs_info1 |
||
216 | fs_info_h: ;if harddisk |
||
217 | call get_hd_info |
||
218 | fs_info1: |
||
219 | pop edi |
||
220 | mov [esp+36],eax |
||
221 | mov [esp+24],ebx ; total clusters on disk |
||
222 | mov [esp+32],ecx ; free clusters on disk |
||
223 | mov [edi],edx ; cluster size in bytes |
||
224 | ret ;end of code - Mihasik |
||
225 | |||
226 | fs_noroot: |
||
227 | |||
61 | halyavin | 228 | push dword [eax+0] ; read/write/delete/.../makedir/rename/lba/run |
229 | push dword [eax+4] ; 512 block number to read |
||
230 | push dword [eax+8] ; bytes to write/append or 512 blocks to read |
||
1 | ha | 231 | mov ebx,[eax+12] |
61 | halyavin | 232 | add ebx,std_application_base_address |
1 | ha | 233 | push ebx ; abs start of return/save area |
234 | |||
235 | lea esi,[eax+20] ; abs start of dir + filename |
||
61 | halyavin | 236 | mov edi,[eax+16] |
237 | add edi,std_application_base_address ; abs start of work area |
||
1 | ha | 238 | |
239 | call expand_pathz |
||
240 | |||
241 | push edi ; dir start |
||
242 | push ebx ; name of file start |
||
243 | |||
244 | mov eax,[edi+1] |
||