Rev 1 | 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 |
||
51 | ; eax = 1 : no fd base and/or partition defined |
||
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 | |||
64 | ; Extract parameters |
||
65 | |||
66 | mov edi,[0x3010] |
||
67 | add eax,[edi+0x10] ; abs start of info block |
||
68 | |||
69 | cmp dword [eax+0],12 ; Get file size |
||
70 | je fs_read |
||
71 | cmp dword [eax+0],13 ; Get file attribute |
||
72 | je fs_read |
||
73 | cmp dword [eax+0],14 ; Get file date/time |
||
74 | je fs_read |
||
75 | cmp dword [eax+0],15 ; GET_DISK_INFO |
||
76 | je fs_info |
||
77 | cmp dword [eax+0],16 ; RUN - dont care about read&write blocks |
||
78 | je fs_read |
||
79 | cmp dword [eax+0],5 ; RENAME - dont care about read&write blocks |
||
80 | je fs_read |
||
81 | cmp dword [eax+0],4 ; MAKEDIR - dont care about read&write blocks |
||
82 | je fs_read |
||
83 | cmp dword [eax+0],2 ; DELETE - dont care about read&write blocks |
||
84 | je fs_read |
||
85 | |||
86 | cmp dword [0x3000],1 ; no memory checks for kernel requests |
||
87 | jz no_checks_for_kernel |
||
88 | ;iglobal |
||
89 | ; buffer_failed db 'Buffer check failed',13,10,0 |
||
90 | ;endg |
||
91 | mov edx,eax |
||
92 | cmp dword [eax+0],1 |
||
93 | jz .check_for_write_op |
||
94 | cmp dword [eax+0],3 |
||
95 | jnz .usual_check |
||
96 | .check_for_write_op: |
||
97 | mov ebx,[eax+12] |
||
98 | add ebx,std_application_base_address |
||
99 | mov ecx,[eax+8] |
||
100 | call check_region |
||
101 | test eax,eax |
||
102 | jnz area_in_app_mem |
||
103 | |||
104 | .error_output: |
||
105 | mov esi,buffer_failed |
||
106 | call sys_msg_board_str |
||
107 | mov eax,7 |
||
108 | mov dword [esp+36],7 |
||
109 | ret |
||
110 | iglobal |
||
111 | buffer_failed db 'Buffer check failed',13,10,0 |
||
112 | endg |
||
113 | .usual_check: |
||
114 | cmp dword [eax+0],0 |
||
115 | mov ecx,512 |
||
116 | jnz .small_size |
||
117 | mov ecx,[eax+8] |
||
118 | shl ecx,9 |
||
119 | .small_size: |
||
120 | mov ebx,[eax+12] |
||
121 | add ebx,std_application_base_address |
||
122 | call check_region |
||
123 | test eax,eax |
||
124 | jz .error_output |
||
125 | jmp area_in_app_mem |
||
126 | ; mov ebx,[0x3000] ; pointer in application memory ? |
||
127 | ; shl ebx,8 |
||
128 | ; mov ebx,[ebx+0x80000+0x8c] |
||
129 | |||
130 | ; mov ebp,ebx ; save for checking at stack save |
||
131 | ; sub ebp,[eax+12] |
||
132 | ; shr ebp,9 |
||
133 | |||
134 | ; sub ebx,512 ; need atleast one block |
||
135 | |||
136 | ; cmp ebx,[eax+12] |
||
137 | ; ja area_in_app_mem |
||
138 | ; mov eax,7 |
||
139 | ; mov dword [esp+36],7 |
||
140 | ; ret |
||
141 | area_in_app_mem: |
||
142 | mov eax,edx |
||
143 | no_checks_for_kernel: |
||
144 | |||
145 | |||
146 | cmp dword [eax+0],3 ; APPEND - allow write 0 bytes (truncate) |
||
147 | je fs_read |
||
148 | cmp dword [eax+8],0 ; read or write 0 blocks/bytes ? |
||
149 | jne fs_read |
||
150 | mov dword [esp+36],0 |
||
151 | ret |
||
152 | fs_read: |
||
153 | |||
154 | mov ebx,[eax+20] ; program wants root directory ? |
||
155 | test bl,bl |
||
156 | je fs_getroot |
||
157 | test bh,bh |
||
158 | jne fs_noroot |
||
159 | fs_getroot: |
||
160 | mov edx,[edi+0x10] |
||
161 | mov esi,dir0 |
||
162 | mov edi,[eax+12] |
||
163 | add edi,edx |
||
164 | mov ecx,11 |
||
165 | cld |
||
166 | rep movsb |
||
167 | mov eax,0x10 |
||
168 | stosb |
||
169 | add edi,32-11-1 |
||
170 | mov ecx,11 |
||
171 | rep movsb |
||
172 | stosb |
||
173 | mov dword [esp+36],0 ; ok read |
||
174 | mov dword [esp+24],32*2 ; size of root |
||
175 | ret |
||
176 | |||
177 | fs_info: ;start of code - Mihasik |
||
178 | mov edi,eax |
||
179 | push edi |
||
180 | cmp [eax+21],byte 'h' |
||
181 | je fs_info_h |
||
182 | cmp [eax+21],byte 'H' |
||
183 | je fs_info_h |
||
184 | cmp [eax+21],byte 'r' |
||
185 | je fs_info_r |
||
186 | cmp [eax+21],byte 'R' |
||
187 | je fs_info_r |
||
188 | mov eax,3 ;if unknown disk |
||
189 | xor ebx,ebx |
||
190 | xor ecx,ecx |
||
191 | xor edx,edx |
||
192 | jmp fs_info1 |
||
193 | fs_info_r: |
||
194 | call ramdisk_free_space ;if ramdisk |
||
195 | mov ecx,edi ;free space in ecx |
||
196 | shr ecx,9 ;free clusters |
||
197 | mov ebx,2847 ;total clusters |
||
198 | mov edx,512 ;cluster size |
||
199 | xor eax,eax ;always 0 |
||
200 | jmp fs_info1 |
||
201 | fs_info_h: ;if harddisk |
||
202 | call get_hd_info |
||
203 | fs_info1: |
||
204 | pop edi |
||
205 | mov [esp+36],eax |
||
206 | mov [esp+24],ebx ; total clusters on disk |
||
207 | mov [esp+32],ecx ; free clusters on disk |
||
208 | mov [edi],edx ; cluster size in bytes |
||
209 | ret ;end of code - Mihasik |
||
210 | |||
211 | fs_noroot: |
||
212 | |||
213 | mov ebx,[eax+0] |
||
214 | push ebx ; read/write/delete/.../makedir/rename/lba/run |
||
215 | mov ebx,[eax+4] |
||
216 | push ebx ; 512 block number to read |
||
217 | mov ebx,[eax+8] |
||
218 | |||
219 | ; cmp dword [eax+0],0 ; if read, check that the data stays at |
||
220 | ; jne ret_size_fine ; application memory |
||
221 | ; cmp ebx,ebp |
||
222 | ; jbe ret_size_fine |
||
223 | ; mov ebx,ebp |
||
224 | ; ret_size_fine: |
||
225 | |||
226 | push ebx ; bytes to write/append or 512 blocks to read |
||
227 | mov ebx,[eax+12] |
||
228 | add ebx,[edi+0x10] |
||
229 | push ebx ; abs start of return/save area |
||
230 | |||
231 | lea esi,[eax+20] ; abs start of dir + filename |
||
232 | mov edi,[edi+0x10] ; abs start of work area |
||
233 | add edi,[eax+16] |
||
234 | |||
235 | call expand_pathz |
||
236 | |||
237 | push edi ; dir start |
||
238 | push ebx ; name of file start |
||
239 | |||
240 | mov ebx,[dir0+11] ; /RAMDISK |
||
241 | mov eax,[edi+1] |
||
242 | cmp eax,'RD ' |
||
243 | je fs_yesramdisk |
||
244 | cmp eax,ebx |
||
245 | jne fs_noramdisk |
||
246 | |||
247 | fs_yesramdisk: |
||
248 | |||
249 | cmp byte [edi+1+11],0 |
||
250 | je fs_give_dir1 |
||
251 | |||
252 | mov ebx,[dir1] ; /FIRST |
||
253 | mov eax,[edi+1+12] |
||
254 | cmp eax,'1 ' |
||
255 | je fs_yesramdisk_first |
||
256 | cmp eax,ebx |
||
257 | jne fs_noramdisk |
||
258 | |||
259 | fs_yesramdisk_first: |
||
260 | |||
261 | cmp dword [esp+20],8 ; LBA read ramdisk |
||
262 | jne fs_no_LBA_read_ramdisk |
||
263 | |||
264 | mov eax,[esp+16] ; LBA block to read |
||
265 | mov ecx,[esp+8] ; abs pointer to return area |
||
266 | |||
267 | call LBA_read_ramdisk |
||
268 | jmp file_system_return |
||
269 | |||
270 | |||
271 | fs_no_LBA_read_ramdisk: |
||
272 | |||
273 | cmp dword [esp+20],0 ; READ |
||
274 | jne fs_noramdisk_read |
||
275 | |||
276 | mov eax,[esp+4] ; fname |
||
277 | add eax,2*12+1 |
||
278 | mov ebx,[esp+16] ; block start |
||
279 | inc ebx |
||
280 | mov ecx,[esp+12] ; block count |
||
281 | mov edx,[esp+8] ; return |
||
282 | mov esi,[esp+0] |
||
283 | sub esi,eax |
||
284 | add esi,12+1 ; file name length |
||
285 | call fileread |
||
286 | |||
287 | jmp file_system_return |
||
288 | |||
289 | |||
290 | fs_noramdisk_read: |
||
291 | |||
292 | cmp dword [esp+20],1 ; WRITE |
||
293 | jne fs_noramdisk_write |
||
294 | |||
295 | mov eax,[esp+4] ; fname |
||
296 | add eax,2*12+1 |
||
297 | mov ebx,[esp+8] ; buffer |
||
298 | mov ecx,[esp+12] ; count to write |
||
299 | mov edx,0 ; create new |
||
300 | call filesave |
||
301 | |||
302 | ; eax=0 ok - eax=1 not enough free space |
||
303 | |||
304 | jmp file_system_return |
||
305 | |||
306 | fs_noramdisk_write: |
||
307 | |||
308 | cmp dword [esp+20],16 ; START APPLICATION |
||
309 | jne fs_noramdisk_start_application |
||
310 | |||
311 | mov eax,[esp+4] ; fname |
||
312 | add eax,2*12+1 |
||
313 | |||
314 | xor ebx,ebx ; parameters to pass |
||
315 | cmp dword [esp+12],0 |
||
316 | je no_fl_start_param |
||
317 | mov ebx,[0x3010] |
||
318 | mov ebx,[ebx+0x10] |
||
319 | add ebx,[esp+12] |
||
320 | no_fl_start_param: |
||
321 | |||
322 | call start_application_fl |
||
323 | |||
324 | jmp file_system_return |
||
325 | |||
326 | fs_noramdisk_start_application: ;there's new code - Mihasik |
||
327 | cmp dword [esp+20],2 ;DELETE |
||
328 | jne fs_noramdisk_delete |
||
329 | mov eax,[esp+4] ; fname |
||
330 | add eax,2*12+1 |
||
331 | call filedelete |
||
332 | jmp file_system_return |
||
333 | |||
334 | fs_noramdisk_delete: |
||
335 | cmp dword [esp+20],12 ;GET TIME,DATE,SIZE AND ATTRS |
||
336 | jb fs_noramdisk_getinfo |
||
337 | cmp dword [esp+20],14 |
||
338 | ja fs_noramdisk_getinfo |
||
339 | mov eax,[esp+4] ; fname |
||
340 | add eax,2*12+1 |
||
341 | mov ebx,[esp+20] |
||
342 | mov ecx,[esp+0] |
||
343 | sub ecx,eax |
||
344 | add ecx,12+1 ; file name length |
||
345 | call rd_getfileinfo |
||
346 | jmp file_system_return |
||
347 | fs_noramdisk_getinfo: ;End of code - Mihasik |
||
348 | |||
349 | fs_noramdisk: |
||
350 | |||
351 | ;******************************************************************** |
||
352 | mov ebx,[dir0+22] ; /FLOPPYDISK |
||
353 | mov eax,[edi+1] |
||
354 | cmp eax,'FD ' |
||
355 | je fs_yesflpdisk |
||
356 | cmp eax,ebx |
||
357 | jne fs_noflpdisk |
||
358 | |||
359 | fs_yesflpdisk: |
||
360 | call reserve_flp |
||
361 | |||
362 | cmp byte [edi+1+11],0 |
||
363 | je fs_give_dir1 |
||
364 | |||
365 | mov ebx,[dir1] ; /FIRST |
||
366 | mov eax,[edi+1+12] |
||
367 | cmp eax,'1 ' |
||
368 | je fs_yesflpdisk_first |
||
369 | cmp eax,ebx |
||
370 | je fs_yesflpdisk_first |
||
371 | mov ebx,[dir1+11] ; /SECOND |
||
372 | cmp eax,'2 ' |
||
373 | je fs_yesflpdisk_second |
||
374 | cmp eax,ebx |
||
375 | jne fs_noflpdisk |
||
376 | jmp fs_yesflpdisk_second |
||
377 | |||
378 | fs_yesflpdisk_first: |
||
379 | mov [flp_number],1 |
||
380 | jmp fs_yesflpdisk_start |
||
381 | fs_yesflpdisk_second: |
||
382 | mov [flp_number],2 |
||
383 | fs_yesflpdisk_start: |
||
384 | cmp dword [esp+20],0 ; READ |
||
385 | jne fs_noflpdisk_read |
||
386 | |||
387 | mov eax,[esp+4] ; fname |
||
388 | add eax,2*12+1 |
||
389 | mov ebx,[esp+16] ; block start |
||
390 | inc ebx |
||
391 | mov ecx,[esp+12] ; block count |
||
392 | mov edx,[esp+8] ; return |
||
393 | mov esi,[esp+0] |
||
394 | sub esi,eax |
||
395 | add esi,12+1 ; file name length |
||
396 | call floppy_fileread |
||
397 | |||
398 | jmp file_system_return |
||
399 | |||
400 | |||
401 | fs_noflpdisk_read: |
||
402 | |||
403 | cmp dword [esp+20],1 ; WRITE |
||
404 | jne fs_noflpdisk_write |
||
405 | |||
406 | mov eax,[esp+4] ; fname |
||
407 | add eax,2*12+1 |
||
408 | mov ebx,[esp+8] ; buffer |
||
409 | mov ecx,[esp+12] ; count to write |
||
410 | mov edx,0 ; create new |
||
411 | call floppy_filesave |
||
412 | |||
413 | ; eax=0 ok - eax=1 not enough free space |
||
414 | |||
415 | jmp file_system_return |
||
416 | |||
417 | fs_noflpdisk_write: |
||
418 | |||
419 | cmp dword [esp+20],2 ; DELETE |
||
420 | jne fs_noflpdisk_delete |
||
421 | |||
422 | mov eax,[esp+4] ; fname |
||
423 | add eax,2*12+1 |
||
424 | call floppy_filedelete |
||
425 | mov [flp_status],0 |
||
426 | jmp file_system_return |
||
427 | |||
428 | fs_noflpdisk_delete: |
||
429 | cmp dword [esp+20],16 ; START APPLICATION |
||
430 | jne fs_noflpdisk_start_application |
||
431 | |||
432 | mov eax,[esp+4] ; fname |
||
433 | add eax,2*12+1 |
||
434 | |||
435 | xor ebx,ebx ; parameters to pass |
||
436 | cmp dword [esp+12],0 |
||
437 | je no_flp_start_param |
||
438 | mov ebx,[0x3010] |
||
439 | mov ebx,[ebx+0x10] |
||
440 | add ebx,[esp+12] |
||
441 | |||
442 | no_flp_start_param: |
||
443 | |||
444 | call start_application_floppy |
||
445 | |||
446 | jmp file_system_return |
||
447 | |||
448 | fs_noflpdisk_start_application: |
||
449 | |||
450 | fs_noflpdisk: |
||
451 | ;***************************************************************** |
||
452 | |||
453 | mov eax,[edi+1] |
||
454 | cmp eax,'HD0 ' |
||
455 | je fs_yesharddisk_IDE0 |
||
456 | cmp eax,'HD1 ' |
||
457 | je fs_yesharddisk_IDE1 |
||
458 | cmp eax,'HD2 ' |
||
459 | je fs_yesharddisk_IDE2 |
||
460 | cmp eax,'HD3 ' |
||
461 | je fs_yesharddisk_IDE3 |
||
462 | jmp old_path_harddisk |
||
463 | fs_yesharddisk_IDE0: |
||
464 | call reserve_hd1 |
||
465 | mov [hdbase],0x1f0 |
||
466 | mov [hdid],0x0 |
||
467 | mov [hdpos],1 |
||
468 | jmp fs_yesharddisk_partition |
||
469 | fs_yesharddisk_IDE1: |
||
470 | call reserve_hd1 |
||
471 | mov [hdbase],0x1f0 |
||
472 | mov [hdid],0x10 |
||
473 | mov [hdpos],2 |
||
474 | jmp fs_yesharddisk_partition |
||
475 | fs_yesharddisk_IDE2: |
||
476 | call reserve_hd1 |
||
477 | mov [hdbase],0x170 |
||
478 | mov [hdid],0x0 |
||
479 | mov [hdpos],3 |
||
480 | jmp fs_yesharddisk_partition |
||
481 | fs_yesharddisk_IDE3: |
||
482 | call reserve_hd1 |
||
483 | mov [hdbase],0x170 |
||
484 | mov [hdid],0x10 |
||
485 | mov [hdpos],4 |
||
486 | fs_yesharddisk_partition: |
||
487 | ; call choice_necessity_partition |
||
488 | ; jmp fs_yesharddisk_all |
||
489 | jmp fs_for_new_semantic |
||
490 | |||
491 | choice_necessity_partition: |
||
492 | mov eax,[edi+1+12] |
||
493 | call StringToNumber |
||
494 | mov [fat32part],eax |
||
495 | choice_necessity_partition_1: |
||
496 | mov [0xfe10],dword 0 ; entries in hd cache |
||
497 | mov ecx,[hdpos] |
||
498 | xor eax,eax |
||
499 | mov edx,0x40002 |
||
500 | search_partition_array: |
||
501 | mov bl,[edx] |
||
502 | movzx ebx,bl |
||
503 | add eax,ebx |
||
504 | inc edx |
||
505 | loop search_partition_array |
||
506 | sub eax,ebx |
||
507 | add eax,[fat32part] |
||
508 | dec eax |
||
509 | xor edx,edx |
||
510 | imul eax,100 |
||
511 | add eax,0x4000a |
||
512 | mov [transfer_adress],eax |
||
513 | call partition_data_transfer_1 |
||
514 | ret |
||
515 | |||
516 | old_path_harddisk: |
||
517 | mov ebx,[dir0] ; /HARDDISK |
||
518 | mov eax,[edi+1] |
||
519 | cmp eax,'HD ' |
||
520 | je fs_yesharddisk |
||
521 | cmp eax,ebx |
||
522 | jne fs_noharddisk |
||
523 | |||
524 | fs_yesharddisk: |
||
525 | call reserve_hd1 |
||
526 | |||
527 | cmp dword [esp+20],8 ; LBA read |
||
528 | jne fs_no_LBA_read |
||
529 | mov eax,[esp+16] ; LBA block to read |
||
530 | lea ebx,[edi+1+12] ; pointer to FIRST/SECOND/THIRD/FOURTH |
||
531 | mov ecx,[esp+8] ; abs pointer to return area |
||
532 | call LBA_read |
||
533 | jmp file_system_return |
||
534 | |||
535 | fs_no_LBA_read: |
||
536 | |||
537 | cmp byte [edi+1+11],0 ; directory read |
||
538 | je fs_give_dir1 |
||
539 | fs_for_new_semantic: |
||
540 | call choice_necessity_partition |
||
541 | |||
542 | fs_yesharddisk_all: |
||
543 | mov eax,1 |
||
544 | cmp [hdpos],0 ; is hd base set? |
||
545 | jz file_system_return ; no |
||
546 | cmp [fat32part],0 ; is partition set? |
||
547 | jz file_system_return ; no |
||
548 | |||
549 | cmp dword [esp+20],0 ; READ |
||
550 | jne fs_noharddisk_read |
||
551 | |||
552 | mov eax,[esp+0] ; /fname |
||
553 | lea edi,[eax+12] |
||
554 | mov byte [eax],0 ; path to asciiz |
||
555 | inc eax ; filename start |
||
556 | |||
557 | mov ebx,[esp+12] ; count to read |
||
558 | mov ecx,[esp+8] ; buffer |
||
559 | mov edx,[esp+4] |
||
560 | add edx,12*2 ; dir start |
||
561 | sub edi,edx ; path length |
||
562 | mov esi,[esp+16] ; blocks to read |
||
563 | |||
564 | call file_read |
||
565 | |||
566 | mov edi,[esp+0] |
||
567 | mov byte [edi],'/' |
||
568 | |||
569 | jmp file_system_return |
||
570 | |||
571 | fs_noharddisk_read: |
||
572 | |||
573 | |||
574 | cmp dword [esp+20],1 ; WRITE |
||
575 | jne fs_noharddisk_write |
||
576 | |||
577 | mov eax,[esp+0] ; /fname |
||
578 | mov byte [eax],0 ; path to asciiz |
||
579 | inc eax ; filename start |
||
580 | |||
581 | mov ebx,[esp+12] ; count to write |
||
582 | mov ecx,[esp+8] ; buffer |
||
583 | mov edx,[esp+4] |
||
584 | add edx,12*2 ; path start |
||
585 | |||
586 | call file_write |
||
587 | |||
588 | mov edi,[esp+0] |
||
589 | mov byte [edi],'/' |
||
590 | |||
591 | ; eax=0 ok - eax=1 not enough free space |
||
592 | |||
593 | jmp file_system_return |
||
594 | |||
595 | |||
596 | fs_noharddisk_write: |
||
597 | |||
598 | cmp dword [esp+20],2 ; DELETE |
||
599 | jne fs_noharddisk_delete |
||
600 | |||
601 | mov eax,[esp+0] ; /dirname or /filename |
||
602 | mov byte [eax],0 ; path to asciiz |
||
603 | inc eax ; filename start |
||
604 | mov edx,[esp+4] |
||
605 | add edx,12*2 ; path start |
||
606 | |||
607 | call removedir |
||
608 | |||
609 | mov edi,[esp+0] |
||
610 | mov byte [edi],'/' |
||
611 | |||
612 | jmp file_system_return |
||
613 | |||
614 | fs_noharddisk_delete: |
||
615 | |||
616 | cmp dword [esp+20],3 ; APPEND |
||
617 | jne fs_noharddisk_append |
||
618 | |||
619 | mov eax,[esp+0] ; /dirname or /filename |
||
620 | mov byte [eax],0 ; path to asciiz |
||
621 | inc eax ; filename start |
||
622 | mov edx,[esp+4] |
||
623 | add edx,12*2 ; path start |
||
624 | mov ecx,[esp+8] ; buffer |
||
625 | mov ebx,[esp+12] ; count to write |
||
626 | mov esi,[esp+16] ; bytes to skip over |
||
627 | |||
628 | call file_append |
||
629 | |||
630 | mov edi,[esp+0] |
||
631 | mov byte [edi],'/' |
||
632 | |||
633 | jmp file_system_return |
||
634 | |||
635 | fs_noharddisk_append: |
||
636 | |||
637 | cmp dword [esp+20],4 ; MAKEDIR |
||
638 | jne fs_noharddisk_makedir |
||
639 | |||
640 | mov eax,[esp+0] ; /dirname |
||
641 | mov byte [eax],0 ; path to asciiz |
||
642 | inc eax ; filename start |
||
643 | mov edx,[esp+4] |
||
644 | add edx,12*2 ; path start |
||
645 | |||
646 | call makedir |
||
647 | |||
648 | mov edi,[esp+0] |
||
649 | mov byte [edi],'/' |
||
650 | |||
651 | jmp file_system_return |
||
652 | |||
653 | fs_noharddisk_makedir: |
||
654 | |||
655 | cmp dword [esp+20],5 ; RENAME |
||
656 | jne fs_noharddisk_rename |
||
657 | |||
658 | mov edi,[esp+0] ; start of source file name |
||
659 | add edi,12+1 ; continue after name |
||
660 | call expand_pathz ; convert destination name |
||
661 | |||
662 | mov edx,[dir0] ; /HARDDISK |
||
663 | mov eax,[edi+1] |
||
664 | cmp eax,'HD ' |
||
665 | je fs_rename_test1 |
||
666 | cmp eax,edx |
||
667 | jne fs_rename_error |
||
668 | |||
669 | fs_rename_test1: |
||
670 | mov edx,[dir1] ; /FIRST |
||
671 | mov eax,[edi+1+12] |
||
672 | cmp eax,'1 ' |
||
673 | je fs_rename_start |
||
674 | cmp eax,edx |
||
675 | jne fs_rename_error |
||
676 | |||
677 | fs_rename_start: |
||
678 | mov byte [ebx],0 ; path to asciiz |
||
679 | inc ebx ; filename start |
||
680 | add edi,12*2 ; path start |
||
681 | cmp byte [ebx],0 |
||
682 | je fs_rename_error |
||
683 | cmp byte [ebx],32 |
||
684 | je fs_rename_error |
||
685 | |||
686 | mov eax,[esp+0] ; /filename |
||
687 | mov byte [eax],0 ; path to asciiz |
||
688 | inc eax ; filename start |
||
689 | mov edx,[esp+4] |
||
690 | add edx,12*2 ; path start |
||
691 | |||
692 | call rename |
||
693 | |||
694 | mov edi,[esp+0] |
||
695 | mov byte [edi],'/' |
||
696 | |||
697 | jmp file_system_return |
||
698 | |||
699 | fs_rename_error: |
||
700 | mov eax,4 ; partition not defined at hd |
||
701 | jmp file_system_return |
||
702 | |||
703 | fs_noharddisk_rename: |
||
704 | |||
705 | cmp dword [esp+20],12 ; get FILESIZE |
||
706 | jne fs_noharddisk_get_filesize |
||
707 | |||
708 | mov eax,[esp+0] ; /fname |
||
709 | lea edi,[eax+12] |
||
710 | mov byte [eax],0 ; path to asciiz |
||
711 | inc eax ; filename start |
||
712 | mov edx,[esp+4] |
||
713 | add edx,12*2 ; path start |
||
714 | sub edi,edx ; path length |
||
715 | |||
716 | call get_filesize |
||
717 | |||
718 | mov edi,[esp+0] |
||
719 | mov byte [edi],'/' |
||
720 | |||
721 | jmp file_system_return |
||
722 | |||
723 | fs_noharddisk_get_filesize: |
||
724 | |||
725 | cmp dword [esp+20],13 ; get FILEATTR |
||
726 | jne fs_noharddisk_get_fileattr |
||
727 | |||
728 | mov eax,[esp+0] ; /dirname |
||
729 | mov byte [eax],0 ; path to asciiz |
||
730 | inc eax ; filename start |
||
731 | mov edx,[esp+4] |
||
732 | add edx,12*2 ; path start |
||
733 | |||
734 | call get_fileattr |
||
735 | |||
736 | mov edi,[esp+0] |
||
737 | mov byte [edi],'/' |
||
738 | |||
739 | jmp file_system_return |
||
740 | |||
741 | fs_noharddisk_get_fileattr: |
||
742 | |||
743 | cmp dword [esp+20],14 ; get FILEDATE |
||
744 | jne fs_noharddisk_get_filedate |
||
745 | |||
746 | mov eax,[esp+0] ; /dirname |
||
747 | mov byte [eax],0 ; path to asciiz |
||
748 | inc eax ; filename start |
||
749 | mov edx,[esp+4] |
||
750 | add edx,12*2 ; path start |
||
751 | |||
752 | call get_filedate |
||
753 | |||
754 | mov edi,[esp+0] |
||
755 | mov byte [edi],'/' |
||
756 | |||
757 | jmp file_system_return |
||
758 | |||
759 | fs_noharddisk_get_filedate: |
||
760 | |||
761 | cmp dword [esp+20],16 ; START APPLICATION |
||
762 | jne fs_noharddisk_start_application |
||
763 | |||
764 | mov eax,[esp+4] ; fname |
||
765 | add eax,12*2 |
||
766 | |||
767 | mov ebx,[esp+0] ; length |
||
768 | sub ebx,eax |
||
769 | add ebx,12 |
||
770 | |||
771 | mov ecx,[esp+4] ; work area |
||
772 | add ecx,512 |
||
773 | |||
774 | xor ebp,ebp ; parameters to pass |
||
775 | cmp dword [esp+12],0 |
||
776 | je no_hd_start_param |
||
777 | mov ebp,[0x3010] |
||
778 | mov ebp,[ebp+0x10] |
||
779 | add ebp,[esp+12] |
||
780 | no_hd_start_param: |
||
781 | |||
782 | call start_application_hd |
||
783 | |||
784 | jmp file_system_return |
||
785 | |||
786 | fs_noharddisk_start_application: |
||
787 | |||
788 | fs_noharddisk: |
||
789 | |||
790 | file_system_return: |
||
791 | |||
792 | add esp,24 |
||
793 | |||
794 | mov [esp+36],eax |
||
795 | mov [esp+24],ebx |
||
796 | ret |
||
797 | |||
798 | |||
799 | fs_give_dir1: |
||
800 | |||
801 | mov eax,0x10 |
||
802 | mov ebx,1 |
||
803 | mov edi,[esp+8] |
||
804 | mov esi,dir1 |
||
805 | fs_d1_new: |
||
806 | mov ecx,11 |
||
807 | cld |
||
808 | rep movsb |
||
809 | stosb |
||
810 | add edi,32-11-1 |
||
811 | dec ebx |
||
812 | jne fs_d1_new |
||
813 | |||
814 | add esp,24 |
||
815 | |||
816 | mov dword [esp+36],0 ; ok read |
||
817 | mov dword [esp+24],32*1 ; dir/data size |
||
818 | ret |
||
819 | |||
820 | |||
821 | |||
822 | LBA_read_ramdisk: |
||
823 | |||
824 | cmp [lba_read_enabled],1 |
||
825 | je lbarrl1 |
||
826 | |||
827 | xor ebx,ebx |
||
828 | mov eax,2 |
||
829 | ret |
||
830 | |||
831 | lbarrl1: |
||
832 | |||
833 | cmp eax,18*2*80 |
||
834 | jb lbarrl2 |
||
835 | xor ebx,ebx |
||
836 | mov eax,3 |
||
837 | ret |
||
838 | |||
839 | lbarrl2: |
||
840 | |||
841 | pushad |
||
842 | |||
843 | call restorefatchain |
||
844 | |||
845 | mov edi,ecx |
||
846 | mov esi,eax |
||
847 | |||
848 | shl esi,9 |
||
849 | add esi,0x100000 |
||
850 | mov ecx,512/4 |
||
851 | cld |
||
852 | rep movsd |
||
853 | |||
854 | popad |
||
855 | |||
856 | xor ebx,ebx |
||
857 | xor eax,eax |
||
858 | ret |
||
859 | |||
860 | LBA_read: |
||
861 | |||
862 | ; IN: |
||
863 | ; |
||
864 | ; eax = LBA block to read |
||
865 | ; ebx = pointer to FIRST/SECOND/THIRD/FOURTH |
||
866 | ; ecx = abs pointer to return area |
||
867 | |||
868 | cmp [lba_read_enabled],1 |
||
869 | je lbarl1 |
||
870 | mov eax,2 |
||
871 | ret |
||
872 | |||
873 | lbarl1: |
||
874 | |||
875 | ; call reserve_hd1 |
||
876 | |||
877 | push eax |
||
878 | push ecx |
||
879 | |||
880 | mov edi,hd_address_table |
||
881 | mov esi,dir1 |
||
882 | mov eax,[ebx] |
||
883 | mov edx,'1 ' |
||
884 | mov ecx,4 |
||
885 | blar0: |
||
886 | cmp eax,[esi] |
||
887 | je blar2 |
||
888 | cmp eax,edx |
||
889 | je blar2 |
||
890 | inc edx |
||
891 | add edi,8 |
||
892 | add esi,11 |
||
893 | dec ecx |
||
894 | jnz blar0 |
||
895 | |||
896 | mov eax,1 |
||
897 | mov ebx,1 |
||
898 | jmp LBA_read_ret |
||
899 | |||
900 | blar2: |
||
901 | mov eax,[edi+0] |
||
902 | mov ebx,[edi+4] |
||
903 | |||
904 | call wait_for_hd_idle |
||
905 | |||
906 | ; eax = hd port |
||
907 | ; ebx = set for primary (0x00) or slave (0x10) |
||
908 | |||
909 | cli |
||
910 | |||
911 | mov edx,eax |
||
912 | inc edx |
||
913 | xor eax,eax |
||
914 | out dx,al |
||
915 | inc edx |
||
916 | inc eax |
||
917 | out dx,al |
||
918 | inc edx |
||
919 | mov eax,[esp+4] |
||
920 | out dx,al |
||
921 | shr eax,8 |
||
922 | inc edx |
||
923 | out dx,al |
||
924 | shr eax,8 |
||
925 | inc edx |
||
926 | out dx,al |
||
927 | shr eax,8 |
||
928 | inc edx |
||
929 | and al,1+2+4+8 |
||
930 | add al,bl |
||
931 | add al,128+64+32 |
||
932 | out dx,al |
||
933 | |||
934 | inc edx |
||
935 | mov al,20h |
||
936 | out dx,al |
||
937 | |||
938 | sti |
||
939 | |||
940 | call wait_for_sector_buffer |
||
941 | |||
942 | cli |
||
943 | |||
944 | mov edi,[esp+0] |
||
945 | mov ecx,256 |
||
946 | sub edx,7 |
||
947 | cld |
||
948 | rep insw |
||
949 | |||
950 | sti |
||
951 | |||
952 | xor eax,eax |
||
953 | xor ebx,ebx |
||
954 | |||
955 | LBA_read_ret: |
||
956 | |||
957 | mov [hd1_status],0 |
||
958 | add esp,2*4 |
||
959 | |||
960 | ret |
||
961 | |||
962 | |||
963 | expand_pathz: |
||
964 | ; IN: |
||
965 | ; esi = asciiz path & file |
||
966 | ; edi = buffer for path & file name |
||
967 | ; OUT: |
||
968 | ; edi = directory & file : / 11 + / 11 + / 11 - zero terminated |
||
969 | ; ebx = /file name - zero terminated |
||
970 | ; esi = pointer after source |
||
971 | |||
972 | push eax |
||
973 | push ecx |
||
974 | push edi ;[esp+0] |
||
975 | |||
976 | pathz_start: |
||
977 | mov byte [edi],'/' |
||
978 | inc edi |
||
979 | mov al,32 |
||
980 | mov ecx,11 |
||
981 | cld |
||
982 | rep stosb ; clear filename area |
||
983 | sub edi,11 |
||
984 | mov ebx,edi ; start of dir/file name |
||
985 | |||
986 | pathz_new_char: |
||
987 | mov al,[esi] |
||
988 | inc esi |
||
989 | cmp al,0 |
||
990 | je pathz_end |
||
991 | |||
992 | cmp al,'/' |
||
993 | jne pathz_not_path |
||
994 | cmp edi,ebx ; skip first '/' |
||
995 | jz pathz_new_char |
||
996 | lea edi,[ebx+11] ; start of next directory |
||
997 | jmp pathz_start |
||
998 | |||
999 | pathz_not_path: |
||
1000 | cmp al,'.' |
||
1001 | jne pathz_not_ext |
||
1002 | lea edi,[ebx+8] ; start of extension |
||
1003 | jmp pathz_new_char |
||
1004 | |||
1005 | pathz_not_ext: |
||
1006 | cmp al,'a' |
||
1007 | jb pathz_not_low |
||
1008 | cmp al,'z' |
||
1009 | ja pathz_not_low |
||
1010 | sub al,0x20 ; char to uppercase |
||
1011 | |||
1012 | pathz_not_low: |
||
1013 | mov [edi],al |
||
1014 | inc edi |
||
1015 | mov eax,[esp+0] ; start_of_dest_path |
||
1016 | add eax,512 ; keep maximum path under 512 bytes |
||
1017 | cmp edi,eax |
||
1018 | jb pathz_new_char |
||
1019 | |||
1020 | pathz_end: |
||
1021 | cmp ebx,edi ; if path end with '/' |
||
1022 | jnz pathz_put_zero ; go back 1 level |
||
1023 | sub ebx,12 |
||
1024 | |||
1025 | pathz_put_zero: |
||
1026 | mov byte [ebx+11],0 |
||
1027 | dec ebx ; include '/' char into file name |
||
1028 | pop edi |
||
1029 | pop ecx |
||
1030 | pop eax |
||
1031 | ret |
||
1032 | |||
1033 | ;******************************************* |
||
1034 | ;* string to number |
||
1035 | ;* input eax - 4 byte string |
||
1036 | ;* output eax - number |
||
1037 | ;******************************************* |
||
1038 | StringToNumber: |
||
1039 | ; ÏÅÐÅÂÎÄ ÑÒÐÎÊÎÂÎÃÎ ×ÈÑËÀ  ×ÈÑËÎÂÎÉ ÂÈÄ |
||
1040 | ; Âõîä: |
||
1041 | ; EDI - àäðåñ ñòðîêè ñ ÷èñëîì. Êîíåö ÷èñëà îòìå÷åí êîäîì 0Dh |
||
1042 | ; Âûõîä: |
||
1043 | ; CF - èíäèêàòîð îøèáîê: |
||
1044 | ; 0 - îøèáîê íåò; |
||
1045 | ; 1 - îøèáêà |
||
1046 | ; Åñëè CF=0, òî AX - ÷èñëî. |
||
1047 | |||
1048 | push bx |
||
1049 | push cx |
||
1050 | push dx |
||
1051 | push edi |
||
1052 | mov [partition_string],eax |
||
1053 | mov edi,partition_string |
||
1054 | xor cx,cx |
||
1055 | i1: |
||
1056 | mov al,[edi] |
||
1057 | cmp al,32 ;13 |
||
1058 | je i_exit |
||
1059 | ; cmp al,'0' |
||
1060 | ; jb err |
||
1061 | ; cmp al,'9' |
||
1062 | ; ja err |
||
1063 | sub al,48 |
||
1064 | shl cx,1 |
||
1065 | jc err |
||
1066 | mov bx,cx |
||
1067 | shl cx,1 |
||
1068 | jc err |
||
1069 | shl cx,1 |
||
1070 | jc err |
||
1071 | add cx,bx |
||
1072 | jc err |
||
1073 | cbw |
||
1074 | add cx,ax |
||
1075 | jc err |
||
1076 | i3: |
||
1077 | inc edi |
||
1078 | jmp i1 |
||
1079 | i_exit: |
||
1080 | mov ax,cx |
||
1081 | clc |
||
1082 | i4: |
||
1083 | movzx eax,ax |
||
1084 | pop edi |
||
1085 | pop dx |
||
1086 | pop cx |
||
1087 | pop bx |
||
1088 | ret |
||
1089 | |||
1090 | err: |
||
1091 | stc |
||
1092 | jmp i4 |
||
1093 | |||
1094 | partition_string: dd 0 |
||
1095 | db 32 |