Rev 2 | 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: |
||
40 | halyavin | 321 | mov edx,[esp+16] ; flags |
1 | ha | 322 | |
323 | call start_application_fl |
||
324 | |||
325 | jmp file_system_return |
||
326 | |||
327 | fs_noramdisk_start_application: ;there's new code - Mihasik |
||
328 | cmp dword [esp+20],2 ;DELETE |
||
329 | jne fs_noramdisk_delete |
||
330 | mov eax,[esp+4] ; fname |
||
331 | add eax,2*12+1 |
||
332 | call filedelete |
||
333 | jmp file_system_return |
||
334 | |||
335 | fs_noramdisk_delete: |
||
336 | cmp dword [esp+20],12 ;GET TIME,DATE,SIZE AND ATTRS |
||
337 | jb fs_noramdisk_getinfo |
||
338 | cmp dword [esp+20],14 |
||
339 | ja fs_noramdisk_getinfo |
||
340 | mov eax,[esp+4] ; fname |
||
341 | add eax,2*12+1 |
||
342 | mov ebx,[esp+20] |
||
343 | mov ecx,[esp+0] |
||
344 | sub ecx,eax |
||
345 | add ecx,12+1 ; file name length |
||
346 | call rd_getfileinfo |
||
347 | jmp file_system_return |
||
348 | fs_noramdisk_getinfo: ;End of code - Mihasik |
||
349 | |||
350 | fs_noramdisk: |
||
351 | |||
352 | ;******************************************************************** |
||
353 | mov ebx,[dir0+22] ; /FLOPPYDISK |
||
354 | mov eax,[edi+1] |
||
355 | cmp eax,'FD ' |
||
356 | je fs_yesflpdisk |
||
357 | cmp eax,ebx |
||
358 | jne fs_noflpdisk |
||
359 | |||
360 | fs_yesflpdisk: |
||
361 | call reserve_flp |
||
362 | |||
363 | cmp byte [edi+1+11],0 |
||
364 | je fs_give_dir1 |
||
365 | |||
366 | mov ebx,[dir1] ; /FIRST |
||
367 | mov eax,[edi+1+12] |
||
368 | cmp eax,'1 ' |
||
369 | je fs_yesflpdisk_first |
||
370 | cmp eax,ebx |
||
371 | je fs_yesflpdisk_first |
||
372 | mov ebx,[dir1+11] ; /SECOND |
||
373 | cmp eax,'2 ' |
||
374 | je fs_yesflpdisk_second |
||
375 | cmp eax,ebx |
||
376 | jne fs_noflpdisk |
||
377 | jmp fs_yesflpdisk_second |
||
378 | |||
379 | fs_yesflpdisk_first: |
||
380 | mov [flp_number],1 |
||
381 | jmp fs_yesflpdisk_start |
||
382 | fs_yesflpdisk_second: |
||
383 | mov [flp_number],2 |
||
384 | fs_yesflpdisk_start: |
||
385 | cmp dword [esp+20],0 ; READ |
||
386 | jne fs_noflpdisk_read |
||
387 | |||
388 | mov eax,[esp+4] ; fname |
||
389 | add eax,2*12+1 |
||
390 | mov ebx,[esp+16] ; block start |
||
391 | inc ebx |
||
392 | mov ecx,[esp+12] ; block count |
||
393 | mov edx,[esp+8] ; return |
||
394 | mov esi,[esp+0] |
||
395 | sub esi,eax |
||
396 | add esi,12+1 ; file name length |
||
397 | call floppy_fileread |
||
398 | |||
399 | jmp file_system_return |
||
400 | |||
401 | |||
402 | fs_noflpdisk_read: |
||
403 | |||
404 | cmp dword [esp+20],1 ; WRITE |
||
405 | jne fs_noflpdisk_write |
||
406 | |||
407 | mov eax,[esp+4] ; fname |
||
408 | add eax,2*12+1 |
||
409 | mov ebx,[esp+8] ; buffer |
||
410 | mov ecx,[esp+12] ; count to write |
||
411 | mov edx,0 ; create new |
||
412 | call floppy_filesave |
||
413 | |||
414 | ; eax=0 ok - eax=1 not enough free space |
||
415 | |||
416 | jmp file_system_return |
||
417 | |||
418 | fs_noflpdisk_write: |
||
419 | |||
420 | cmp dword [esp+20],2 ; DELETE |
||
421 | jne fs_noflpdisk_delete |
||
422 | |||
423 | mov eax,[esp+4] ; fname |
||
424 | add eax,2*12+1 |
||
425 | call floppy_filedelete |
||
426 | mov [flp_status],0 |
||
427 | jmp file_system_return |
||
428 | |||
429 | fs_noflpdisk_delete: |
||
430 | cmp dword [esp+20],16 ; START APPLICATION |
||
431 | jne fs_noflpdisk_start_application |
||
432 | |||
433 | mov eax,[esp+4] ; fname |
||
434 | add eax,2*12+1 |
||
435 | |||
436 | xor ebx,ebx ; parameters to pass |
||
437 | cmp dword [esp+12],0 |
||
438 | je no_flp_start_param |
||
439 | mov ebx,[0x3010] |
||
440 | mov ebx,[ebx+0x10] |
||
441 | add ebx,[esp+12] |
||
442 | |||
443 | no_flp_start_param: |
||
40 | halyavin | 444 | mov edx,[esp+16] ; flags |
1 | ha | 445 | |
446 | call start_application_floppy |
||
447 | |||
448 | jmp file_system_return |
||
449 | |||
450 | fs_noflpdisk_start_application: |
||
451 | |||
452 | fs_noflpdisk: |
||
453 | ;***************************************************************** |
||
454 | |||
455 | mov eax,[edi+1] |
||
456 | cmp eax,'HD0 ' |
||
457 | je fs_yesharddisk_IDE0 |
||
458 | cmp eax,'HD1 ' |
||
459 | je fs_yesharddisk_IDE1 |
||
460 | cmp eax,'HD2 ' |
||
461 | je fs_yesharddisk_IDE2 |
||
462 | cmp eax,'HD3 ' |
||
463 | je fs_yesharddisk_IDE3 |
||
464 | jmp old_path_harddisk |
||
465 | fs_yesharddisk_IDE0: |
||
466 | call reserve_hd1 |
||
467 | mov [hdbase],0x1f0 |
||
468 | mov [hdid],0x0 |
||
469 | mov [hdpos],1 |
||
470 | jmp fs_yesharddisk_partition |
||
471 | fs_yesharddisk_IDE1: |
||
472 | call reserve_hd1 |
||
473 | mov [hdbase],0x1f0 |
||
474 | mov [hdid],0x10 |
||
475 | mov [hdpos],2 |
||
476 | jmp fs_yesharddisk_partition |
||
477 | fs_yesharddisk_IDE2: |
||
478 | call reserve_hd1 |
||
479 | mov [hdbase],0x170 |
||
480 | mov [hdid],0x0 |
||
481 | mov [hdpos],3 |
||
482 | jmp fs_yesharddisk_partition |
||
483 | fs_yesharddisk_IDE3: |
||
484 | call reserve_hd1 |
||
485 | mov [hdbase],0x170 |
||
486 | mov [hdid],0x10 |
||
487 | mov [hdpos],4 |
||
488 | fs_yesharddisk_partition: |
||
489 | ; call choice_necessity_partition |
||
490 | ; jmp fs_yesharddisk_all |
||
491 | jmp fs_for_new_semantic |
||
492 | |||
493 | choice_necessity_partition: |
||
494 | mov eax,[edi+1+12] |
||
495 | call StringToNumber |
||
496 | mov [fat32part],eax |
||
497 | choice_necessity_partition_1: |
||
498 | mov [0xfe10],dword 0 ; entries in hd cache |
||
499 | mov ecx,[hdpos] |
||
500 | xor eax,eax |
||
501 | mov edx,0x40002 |
||
502 | search_partition_array: |
||
503 | mov bl,[edx] |
||
504 | movzx ebx,bl |
||
505 | add eax,ebx |
||
506 | inc edx |
||
507 | loop search_partition_array |
||
508 | sub eax,ebx |
||
509 | add eax,[fat32part] |
||
510 | dec eax |
||
511 | xor edx,edx |
||
512 | imul eax,100 |
||
513 | add eax,0x4000a |
||
514 | mov [transfer_adress],eax |
||
515 | call partition_data_transfer_1 |
||
516 | ret |
||
517 | |||
518 | old_path_harddisk: |
||
519 | mov ebx,[dir0] ; /HARDDISK |
||
520 | mov eax,[edi+1] |
||
521 | cmp eax,'HD ' |
||
522 | je fs_yesharddisk |
||
523 | cmp eax,ebx |
||
524 | jne fs_noharddisk |
||
525 | |||
526 | fs_yesharddisk: |
||
527 | call reserve_hd1 |
||
528 | |||
529 | cmp dword [esp+20],8 ; LBA read |
||
530 | jne fs_no_LBA_read |
||
531 | mov eax,[esp+16] ; LBA block to read |
||
532 | lea ebx,[edi+1+12] ; pointer to FIRST/SECOND/THIRD/FOURTH |
||
533 | mov ecx,[esp+8] ; abs pointer to return area |
||
534 | call LBA_read |
||
535 | jmp file_system_return |
||
536 | |||
537 | fs_no_LBA_read: |
||
538 | |||
539 | cmp byte [edi+1+11],0 ; directory read |
||
540 | je fs_give_dir1 |
||
541 | fs_for_new_semantic: |
||
542 | call choice_necessity_partition |
||
543 | |||
544 | fs_yesharddisk_all: |
||
545 | mov eax,1 |
||
546 | cmp [hdpos],0 ; is hd base set? |
||
547 | jz file_system_return ; no |
||
548 | cmp [fat32part],0 ; is partition set? |
||
549 | jz file_system_return ; no |
||
550 | |||
551 | cmp dword [esp+20],0 ; READ |
||
552 | jne fs_noharddisk_read |
||
553 | |||
554 | mov eax,[esp+0] ; /fname |
||
555 | lea edi,[eax+12] |
||
556 | mov byte [eax],0 ; path to asciiz |
||
557 | inc eax ; filename start |
||
558 | |||
559 | mov ebx,[esp+12] ; count to read |
||
560 | mov ecx,[esp+8] ; buffer |
||
561 | mov edx,[esp+4] |
||
562 | add edx,12*2 ; dir start |
||
563 | sub edi,edx ; path length |
||
564 | mov esi,[esp+16] ; blocks to read |
||
565 | |||
566 | call file_read |
||
567 | |||
568 | mov edi,[esp+0] |
||
569 | mov byte [edi],'/' |
||
570 | |||
571 | jmp file_system_return |
||
572 | |||
573 | fs_noharddisk_read: |
||
574 | |||
575 | |||
576 | cmp dword [esp+20],1 ; WRITE |
||
577 | jne fs_noharddisk_write |
||
578 | |||
579 | mov eax,[esp+0] ; /fname |
||
580 | mov byte [eax],0 ; path to asciiz |
||
581 | inc eax ; filename start |
||
582 | |||
583 | mov ebx,[esp+12] ; count to write |
||
584 | mov ecx,[esp+8] ; buffer |
||
585 | mov edx,[esp+4] |
||
586 | add edx,12*2 ; path start |
||
587 | |||
588 | call file_write |
||
589 | |||
590 | mov edi,[esp+0] |
||
591 | mov byte [edi],'/' |
||
592 | |||
593 | ; eax=0 ok - eax=1 not enough free space |
||
594 | |||
595 | jmp file_system_return |
||
596 | |||
597 | |||
598 | fs_noharddisk_write: |
||
599 | |||
600 | cmp dword [esp+20],2 ; DELETE |
||
601 | jne fs_noharddisk_delete |
||
602 | |||
603 | mov eax,[esp+0] ; /dirname or /filename |
||
604 | mov byte [eax],0 ; path to asciiz |
||
605 | inc eax ; filename start |
||
606 | mov edx,[esp+4] |
||
607 | add edx,12*2 ; path start |
||
608 | |||
609 | call removedir |
||
610 | |||
611 | mov edi,[esp+0] |
||
612 | mov byte [edi],'/' |
||
613 | |||
614 | jmp file_system_return |
||
615 | |||
616 | fs_noharddisk_delete: |
||
617 | |||
618 | cmp dword [esp+20],3 ; APPEND |
||
619 | jne fs_noharddisk_append |
||
620 | |||
621 | mov eax,[esp+0] ; /dirname or /filename |
||
622 | mov byte [eax],0 ; path to asciiz |
||
623 | inc eax ; filename start |
||
624 | mov edx,[esp+4] |
||
625 | add edx,12*2 ; path start |
||
626 | mov ecx,[esp+8] ; buffer |
||
627 | mov ebx,[esp+12] ; count to write |
||
628 | mov esi,[esp+16] ; bytes to skip over |
||
629 | |||
630 | call file_append |
||
631 | |||
632 | mov edi,[esp+0] |
||
633 | mov byte [edi],'/' |
||
634 | |||
635 | jmp file_system_return |
||
636 | |||
637 | fs_noharddisk_append: |
||
638 | |||
639 | cmp dword [esp+20],4 ; MAKEDIR |
||
640 | jne fs_noharddisk_makedir |
||
641 | |||
642 | mov eax,[esp+0] ; /dirname |
||
643 | mov byte [eax],0 ; path to asciiz |
||
644 | inc eax ; filename start |
||
645 | mov edx,[esp+4] |
||
646 | add edx,12*2 ; path start |
||
647 | |||
648 | call makedir |
||
649 | |||
650 | mov edi,[esp+0] |
||
651 | mov byte [edi],'/' |
||
652 | |||
653 | jmp file_system_return |
||
654 | |||
655 | fs_noharddisk_makedir: |
||
656 | |||
657 | cmp dword [esp+20],5 ; RENAME |
||
658 | jne fs_noharddisk_rename |
||
659 | |||
660 | mov edi,[esp+0] ; start of source file name |
||
661 | add edi,12+1 ; continue after name |
||
662 | call expand_pathz ; convert destination name |
||
663 | |||
664 | mov edx,[dir0] ; /HARDDISK |
||
665 | mov eax,[edi+1] |
||
666 | cmp eax,'HD ' |
||
667 | je fs_rename_test1 |
||
668 | cmp eax,edx |
||
669 | jne fs_rename_error |
||
670 | |||
671 | fs_rename_test1: |
||
672 | mov edx,[dir1] ; /FIRST |
||
673 | mov eax,[edi+1+12] |
||
674 | cmp eax,'1 ' |
||
675 | je fs_rename_start |
||
676 | cmp eax,edx |
||
677 | jne fs_rename_error |
||
678 | |||
679 | fs_rename_start: |
||
680 | mov byte [ebx],0 ; path to asciiz |
||
681 | inc ebx ; filename start |
||
682 | add edi,12*2 ; path start |
||
683 | cmp byte [ebx],0 |
||
684 | je fs_rename_error |
||
685 | cmp byte [ebx],32 |
||
686 | je fs_rename_error |
||
687 | |||
688 | mov eax,[esp+0] ; /filename |
||
689 | mov byte [eax],0 ; path to asciiz |
||
690 | inc eax ; filename start |
||
691 | mov edx,[esp+4] |
||
692 | add edx,12*2 ; path start |
||
693 | |||
694 | call rename |
||
695 | |||
696 | mov edi,[esp+0] |
||
697 | mov byte [edi],'/' |
||
698 | |||
699 | jmp file_system_return |
||
700 | |||
701 | fs_rename_error: |
||
702 | mov eax,4 ; partition not defined at hd |
||
703 | jmp file_system_return |
||
704 | |||
705 | fs_noharddisk_rename: |
||
706 | |||
707 | cmp dword [esp+20],12 ; get FILESIZE |
||
708 | jne fs_noharddisk_get_filesize |
||
709 | |||
710 | mov eax,[esp+0] ; /fname |
||
711 | lea edi,[eax+12] |
||
712 | mov byte [eax],0 ; path to asciiz |
||
713 | inc eax ; filename start |
||
714 | mov edx,[esp+4] |
||
715 | add edx,12*2 ; path start |
||
716 | sub edi,edx ; path length |
||
717 | |||
718 | call get_filesize |
||
719 | |||
720 | mov edi,[esp+0] |
||
721 | mov byte [edi],'/' |
||
722 | |||
723 | jmp file_system_return |
||
724 | |||
725 | fs_noharddisk_get_filesize: |
||
726 | |||
727 | cmp dword [esp+20],13 ; get FILEATTR |
||
728 | jne fs_noharddisk_get_fileattr |
||
729 | |||
730 | mov eax,[esp+0] ; /dirname |
||
731 | mov byte [eax],0 ; path to asciiz |
||
732 | inc eax ; filename start |
||
733 | mov edx,[esp+4] |
||
734 | add edx,12*2 ; path start |
||
735 | |||
736 | call get_fileattr |
||
737 | |||
738 | mov edi,[esp+0] |
||
739 | mov byte [edi],'/' |
||
740 | |||
741 | jmp file_system_return |
||
742 | |||
743 | fs_noharddisk_get_fileattr: |
||
744 | |||
745 | cmp dword [esp+20],14 ; get FILEDATE |
||
746 | jne fs_noharddisk_get_filedate |
||
747 | |||
748 | mov eax,[esp+0] ; /dirname |
||
749 | mov byte [eax],0 ; path to asciiz |
||
750 | inc eax ; filename start |
||
751 | mov edx,[esp+4] |
||
752 | add edx,12*2 ; path start |
||
753 | |||
754 | call get_filedate |
||
755 | |||
756 | mov edi,[esp+0] |
||
757 | mov byte [edi],'/' |
||
758 | |||
759 | jmp file_system_return |
||
760 | |||
761 | fs_noharddisk_get_filedate: |
||
762 | |||
763 | cmp dword [esp+20],16 ; START APPLICATION |
||
764 | jne fs_noharddisk_start_application |
||
765 | |||
766 | mov eax,[esp+4] ; fname |
||
767 | add eax,12*2 |
||
768 | |||
769 | mov ebx,[esp+0] ; length |
||
770 | sub ebx,eax |
||
771 | add ebx,12 |
||
772 | |||
773 | mov ecx,[esp+4] ; work area |
||
774 | add ecx,512 |
||
775 | |||
776 | xor ebp,ebp ; parameters to pass |
||
777 | cmp dword [esp+12],0 |
||
778 | je no_hd_start_param |
||
779 | mov ebp,[0x3010] |
||
780 | mov ebp,[ebp+0x10] |
||
781 | add ebp,[esp+12] |
||
782 | no_hd_start_param: |
||
40 | halyavin | 783 | mov edx,[esp+16] ; flags |
1 | ha | 784 | |
785 | call start_application_hd |
||
786 | |||
787 | jmp file_system_return |
||
788 | |||
789 | fs_noharddisk_start_application: |
||
790 | |||
791 | fs_noharddisk: |
||
792 | |||
793 | file_system_return: |
||
794 | |||
795 | add esp,24 |
||
796 | |||
797 | mov [esp+36],eax |
||
798 | mov [esp+24],ebx |
||
799 | ret |
||
800 | |||
801 | |||
802 | fs_give_dir1: |
||
803 | |||
804 | mov eax,0x10 |
||
805 | mov ebx,1 |
||
806 | mov edi,[esp+8] |
||
807 | mov esi,dir1 |
||
808 | fs_d1_new: |
||
809 | mov ecx,11 |
||
810 | cld |
||
811 | rep movsb |
||
812 | stosb |
||
813 | add edi,32-11-1 |
||
814 | dec ebx |
||
815 | jne fs_d1_new |
||
816 | |||
817 | add esp,24 |
||
818 | |||
819 | mov dword [esp+36],0 ; ok read |
||
820 | mov dword [esp+24],32*1 ; dir/data size |
||
821 | ret |
||
822 | |||
823 | |||
824 | |||
825 | LBA_read_ramdisk: |
||
826 | |||
827 | cmp [lba_read_enabled],1 |
||
828 | je lbarrl1 |
||
829 | |||
830 | xor ebx,ebx |
||
831 | mov eax,2 |
||
832 | ret |
||
833 | |||
834 | lbarrl1: |
||
835 | |||
836 | cmp eax,18*2*80 |
||
837 | jb lbarrl2 |
||
838 | xor ebx,ebx |
||
839 | mov eax,3 |
||
840 | ret |
||
841 | |||
842 | lbarrl2: |
||
843 | |||
844 | pushad |
||
845 | |||
846 | call restorefatchain |
||
847 | |||
848 | mov edi,ecx |
||
849 | mov esi,eax |
||
850 | |||
851 | shl esi,9 |
||
852 | add esi,0x100000 |
||
853 | mov ecx,512/4 |
||
854 | cld |
||
855 | rep movsd |
||
856 | |||
857 | popad |
||
858 | |||
859 | xor ebx,ebx |
||
860 | xor eax,eax |
||
861 | ret |
||
862 | |||
863 | LBA_read: |
||
864 | |||
865 | ; IN: |
||
866 | ; |
||
867 | ; eax = LBA block to read |
||
868 | ; ebx = pointer to FIRST/SECOND/THIRD/FOURTH |
||
869 | ; ecx = abs pointer to return area |
||
870 | |||
871 | cmp [lba_read_enabled],1 |
||
872 | je lbarl1 |
||
873 | mov eax,2 |
||
874 | ret |
||
875 | |||
876 | lbarl1: |
||
877 | |||
878 | ; call reserve_hd1 |
||
879 | |||
880 | push eax |
||
881 | push ecx |
||
882 | |||
883 | mov edi,hd_address_table |
||
884 | mov esi,dir1 |
||
885 | mov eax,[ebx] |
||
886 | mov edx,'1 ' |
||
887 | mov ecx,4 |
||
888 | blar0: |
||
889 | cmp eax,[esi] |
||
890 | je blar2 |
||
891 | cmp eax,edx |
||
892 | je blar2 |
||
893 | inc edx |
||
894 | add edi,8 |
||
895 | add esi,11 |
||
896 | dec ecx |
||
897 | jnz blar0 |
||
898 | |||
899 | mov eax,1 |
||
900 | mov ebx,1 |
||
901 | jmp LBA_read_ret |
||
902 | |||
903 | blar2: |
||
904 | mov eax,[edi+0] |
||
905 | mov ebx,[edi+4] |
||
906 | |||
907 | call wait_for_hd_idle |
||
908 | |||
909 | ; eax = hd port |
||
910 | ; ebx = set for primary (0x00) or slave (0x10) |
||
911 | |||
912 | cli |
||
913 | |||
914 | mov edx,eax |
||
915 | inc edx |
||
916 | xor eax,eax |
||
917 | out dx,al |
||
918 | inc edx |
||
919 | inc eax |
||
920 | out dx,al |
||
921 | inc edx |
||
922 | mov eax,[esp+4] |
||
923 | out dx,al |
||
924 | shr eax,8 |
||
925 | inc edx |
||
926 | out dx,al |
||
927 | shr eax,8 |
||
928 | inc edx |
||
929 | out dx,al |
||
930 | shr eax,8 |
||
931 | inc edx |
||
932 | and al,1+2+4+8 |
||
933 | add al,bl |
||
934 | add al,128+64+32 |
||
935 | out dx,al |
||
936 | |||
937 | inc edx |
||
938 | mov al,20h |
||
939 | out dx,al |
||
940 | |||
941 | sti |
||
942 | |||
943 | call wait_for_sector_buffer |
||
944 | |||
945 | cli |
||
946 | |||
947 | mov edi,[esp+0] |
||
948 | mov ecx,256 |
||
949 | sub edx,7 |
||
950 | cld |
||
951 | rep insw |
||
952 | |||
953 | sti |
||
954 | |||
955 | xor eax,eax |
||
956 | xor ebx,ebx |
||
957 | |||
958 | LBA_read_ret: |
||
959 | |||
960 | mov [hd1_status],0 |
||
961 | add esp,2*4 |
||
962 | |||
963 | ret |
||
964 | |||
965 | |||
966 | expand_pathz: |
||
967 | ; IN: |
||
968 | ; esi = asciiz path & file |
||
969 | ; edi = buffer for path & file name |
||
970 | ; OUT: |
||
971 | ; edi = directory & file : / 11 + / 11 + / 11 - zero terminated |
||
972 | ; ebx = /file name - zero terminated |
||
973 | ; esi = pointer after source |
||
974 | |||
975 | push eax |
||
976 | push ecx |
||
977 | push edi ;[esp+0] |
||
978 | |||
979 | pathz_start: |
||
980 | mov byte [edi],'/' |
||
981 | inc edi |
||
982 | mov al,32 |
||
983 | mov ecx,11 |
||
984 | cld |
||
985 | rep stosb ; clear filename area |
||
986 | sub edi,11 |
||
987 | mov ebx,edi ; start of dir/file name |
||
988 | |||
989 | pathz_new_char: |
||
990 | mov al,[esi] |
||
991 | inc esi |
||
992 | cmp al,0 |
||
993 | je pathz_end |
||
994 | |||
995 | cmp al,'/' |
||
996 | jne pathz_not_path |
||
997 | cmp edi,ebx ; skip first '/' |
||
998 | jz pathz_new_char |
||
999 | lea edi,[ebx+11] ; start of next directory |
||
1000 | jmp pathz_start |
||
1001 | |||
1002 | pathz_not_path: |
||
1003 | cmp al,'.' |
||
1004 | jne pathz_not_ext |
||
1005 | lea edi,[ebx+8] ; start of extension |
||
1006 | jmp pathz_new_char |
||
1007 | |||
1008 | pathz_not_ext: |
||
1009 | cmp al,'a' |
||
1010 | jb pathz_not_low |
||
1011 | cmp al,'z' |
||
1012 | ja pathz_not_low |
||
1013 | sub al,0x20 ; char to uppercase |
||
1014 | |||
1015 | pathz_not_low: |
||
1016 | mov [edi],al |
||
1017 | inc edi |
||
1018 | mov eax,[esp+0] ; start_of_dest_path |
||
1019 | add eax,512 ; keep maximum path under 512 bytes |
||
1020 | cmp edi,eax |
||
1021 | jb pathz_new_char |
||
1022 | |||
1023 | pathz_end: |
||
1024 | cmp ebx,edi ; if path end with '/' |
||
1025 | jnz pathz_put_zero ; go back 1 level |
||
1026 | sub ebx,12 |
||
1027 | |||
1028 | pathz_put_zero: |
||
1029 | mov byte [ebx+11],0 |
||
1030 | dec ebx ; include '/' char into file name |
||
1031 | pop edi |
||
1032 | pop ecx |
||
1033 | pop eax |
||
1034 | ret |
||
1035 | |||
1036 | ;******************************************* |
||
1037 | ;* string to number |
||
1038 | ;* input eax - 4 byte string |
||
1039 | ;* output eax - number |
||
1040 | ;******************************************* |
||
1041 | StringToNumber: |
||
1042 | ; ÏÅÐÅÂÎÄ ÑÒÐÎÊÎÂÎÃÎ ×ÈÑËÀ  ×ÈÑËÎÂÎÉ ÂÈÄ |
||
1043 | ; Âõîä: |
||
1044 | ; EDI - àäðåñ ñòðîêè ñ ÷èñëîì. Êîíåö ÷èñëà îòìå÷åí êîäîì 0Dh |
||
1045 | ; Âûõîä: |
||
1046 | ; CF - èíäèêàòîð îøèáîê: |
||
1047 | ; 0 - îøèáîê íåò; |
||
1048 | ; 1 - îøèáêà |
||
1049 | ; Åñëè CF=0, òî AX - ÷èñëî. |
||
1050 | |||
1051 | push bx |
||
1052 | push cx |
||
1053 | push dx |
||
1054 | push edi |
||
1055 | mov [partition_string],eax |
||
1056 | mov edi,partition_string |
||
1057 | xor cx,cx |
||
1058 | i1: |
||
1059 | mov al,[edi] |
||
1060 | cmp al,32 ;13 |
||
1061 | je i_exit |
||
1062 | ; cmp al,'0' |
||
1063 | ; jb err |
||
1064 | ; cmp al,'9' |
||
1065 | ; ja err |
||
1066 | sub al,48 |
||
1067 | shl cx,1 |
||
1068 | jc err |
||
1069 | mov bx,cx |
||
1070 | shl cx,1 |
||
1071 | jc err |
||
1072 | shl cx,1 |
||
1073 | jc err |
||
1074 | add cx,bx |
||
1075 | jc err |
||
1076 | cbw |
||
1077 | add cx,ax |
||
1078 | jc err |
||
1079 | i3: |
||
1080 | inc edi |
||
1081 | jmp i1 |
||
1082 | i_exit: |
||
1083 | mov ax,cx |
||
1084 | clc |
||
1085 | i4: |
||
1086 | movzx eax,ax |
||
1087 | pop edi |
||
1088 | pop dx |
||
1089 | pop cx |
||
1090 | pop bx |
||
1091 | ret |
||
1092 | |||
1093 | err: |
||
1094 | stc |
||
1095 | jmp i4 |
||
1096 | |||
1097 | partition_string: dd 0 |
||
1098 | db 32 |