Rev 1376 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
431 | serge | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
527 | diamond | 2 | ;; ;; |
431 | serge | 3 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
527 | diamond | 6 | ;; RAMDISK functions ;; |
7 | ;; (C) 2004 Ville Turjanmaa, License: GPL ;; |
||
8 | ;; Addings by M.Lisovin ;; |
||
9 | ;; LFN support by diamond ;; |
||
431 | serge | 10 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ha | 11 | |
593 | mikedld | 12 | $Revision: 2212 $ |
13 | |||
14 | |||
5 | halyavin | 15 | ; calculate fat chain |
1 | ha | 16 | |
5 | halyavin | 17 | calculatefatchain: |
18 | |||
19 | pushad |
||
20 | |||
766 | Rus | 21 | mov esi,RAMDISK+512 |
22 | mov edi,RAMDISK_FAT |
||
5 | halyavin | 23 | |
24 | fcnew: |
||
766 | Rus | 25 | mov eax,dword [esi] |
26 | mov ebx,dword [esi+4] |
||
27 | mov ecx,dword [esi+8] |
||
28 | mov edx,ecx |
||
29 | shr edx,4 ;8 ok |
||
30 | shr dx,4 ;7 ok |
||
31 | xor ch,ch |
||
5 | halyavin | 32 | shld ecx,ebx,20 ;6 ok |
766 | Rus | 33 | shr cx,4 ;5 ok |
5 | halyavin | 34 | shld ebx,eax,12 |
766 | Rus | 35 | and ebx,0x0fffffff ;4 ok |
36 | shr bx,4 ;3 ok |
||
37 | shl eax,4 |
||
38 | and eax,0x0fffffff ;2 ok |
||
39 | shr ax,4 ;1 ok |
||
40 | mov dword [edi],eax |
||
41 | mov dword [edi+4],ebx |
||
42 | mov dword [edi+8],ecx |
||
43 | mov dword [edi+12],edx |
||
44 | add edi,16 |
||
45 | add esi,12 |
||
5 | halyavin | 46 | |
766 | Rus | 47 | cmp edi,RAMDISK_FAT+2856*2 ;2849 clusters |
48 | jnz fcnew |
||
5 | halyavin | 49 | |
50 | popad |
||
51 | ret |
||
52 | |||
53 | |||
54 | restorefatchain: ; restore fat chain |
||
55 | |||
56 | pushad |
||
57 | |||
766 | Rus | 58 | mov esi,RAMDISK_FAT |
59 | mov edi,RAMDISK+512 |
||
5 | halyavin | 60 | |
61 | fcnew2: |
||
766 | Rus | 62 | mov eax,dword [esi] |
63 | mov ebx,dword [esi+4] |
||
64 | shl ax,4 |
||
65 | shl eax,4 |
||
66 | shl bx,4 |
||
67 | shr ebx,4 |
||
5 | halyavin | 68 | shrd eax,ebx,8 |
766 | Rus | 69 | shr ebx,8 |
70 | mov dword [edi],eax |
||
71 | mov word [edi+4],bx |
||
72 | add edi,6 |
||
73 | add esi,8 |
||
5 | halyavin | 74 | |
766 | Rus | 75 | cmp edi,RAMDISK+512+4278 ;4274 bytes - all used FAT |
76 | jb fcnew2 |
||
5 | halyavin | 77 | |
766 | Rus | 78 | mov esi,RAMDISK+512 ; duplicate fat chain |
79 | mov edi,RAMDISK+512+0x1200 |
||
80 | mov ecx,1069 ;4274/4 |
||
5 | halyavin | 81 | cld |
766 | Rus | 82 | rep movsd |
5 | halyavin | 83 | |
84 | popad |
||
85 | ret |
||
86 | |||
87 | |||
1 | ha | 88 | ramdisk_free_space: |
89 | ;--------------------------------------------- |
||
90 | ; |
||
91 | ; returns free space in edi |
||
92 | ; rewr.by Mihasik |
||
93 | ;--------------------------------------------- |
||
94 | |||
766 | Rus | 95 | push eax ebx ecx |
1 | ha | 96 | |
766 | Rus | 97 | mov edi,RAMDISK_FAT ;start of FAT |
98 | xor ax,ax ;Free cluster=0x0000 in FAT |
||
99 | xor ebx,ebx ;counter |
||
100 | mov ecx,2849 ;2849 clusters |
||
101 | cld |
||
1 | ha | 102 | rdfs1: |
766 | Rus | 103 | repne scasw |
104 | jnz rdfs2 ;if last cluster not 0 |
||
105 | inc ebx |
||
106 | test ecx, ecx |
||
107 | jnz rdfs1 |
||
1 | ha | 108 | rdfs2: |
766 | Rus | 109 | shl ebx,9 ;free clusters*512 |
110 | mov edi,ebx |
||
247 | serge | 111 | |
766 | Rus | 112 | pop ecx ebx eax |
113 | ret |
||
1 | ha | 114 | |
115 | |||
116 | expand_filename: |
||
117 | ;--------------------------------------------- |
||
118 | ; |
||
119 | ; exapand filename with '.' to 11 character |
||
120 | ; eax - pointer to filename |
||
121 | ;--------------------------------------------- |
||
122 | |||
766 | Rus | 123 | push esi edi ebx |
1 | ha | 124 | |
766 | Rus | 125 | mov edi,esp ; check for '.' in the name |
126 | add edi,12+8 |
||
1 | ha | 127 | |
766 | Rus | 128 | mov esi,eax |
1 | ha | 129 | |
766 | Rus | 130 | mov eax,edi |
131 | mov [eax+0],dword ' ' |
||
132 | mov [eax+4],dword ' ' |
||
133 | mov [eax+8],dword ' ' |
||
1 | ha | 134 | |
135 | flr1: |
||
136 | |||
766 | Rus | 137 | cmp [esi],byte '.' |
138 | jne flr2 |
||
139 | mov edi,eax |
||
140 | add edi,7 |
||
141 | jmp flr3 |
||
1 | ha | 142 | |
143 | flr2: |
||
144 | |||
766 | Rus | 145 | mov bl,[esi] |
146 | mov [edi],bl |
||
1 | ha | 147 | |
148 | flr3: |
||
149 | |||
766 | Rus | 150 | inc esi |
151 | inc edi |
||
1 | ha | 152 | |
766 | Rus | 153 | mov ebx,eax |
154 | add ebx,11 |
||
1 | ha | 155 | |
766 | Rus | 156 | cmp edi,ebx |
157 | jbe flr1 |
||
1 | ha | 158 | |
766 | Rus | 159 | pop ebx edi esi |
160 | ret |
||
1 | ha | 161 | |
162 | fileread: |
||
163 | ;---------------------------------------------------------------- |
||
164 | ; |
||
165 | ; fileread - sys floppy |
||
166 | ; |
||
167 | ; eax points to filename 11 chars |
||
168 | ; ebx first wanted block ; 1+ ; if 0 then set to 1 |
||
169 | ; ecx number of blocks to read ; 1+ ; if 0 then set to 1 |
||
170 | ; edx mem location to return data |
||
171 | ; esi length of filename 12*X 0=root |
||
172 | ; |
||
173 | ; ret ebx = size or 0xffffffff file not found |
||
174 | ; eax = 0 ok read or other = errormsg |
||
175 | ; |
||
176 | ;-------------------------------------------------------------- |
||
766 | Rus | 177 | test ebx,ebx ;if ebx=0 - set to 1 |
178 | jnz frfl5 |
||
179 | inc ebx |
||
1 | ha | 180 | frfl5: |
766 | Rus | 181 | test ecx,ecx ;if ecx=0 - set to 1 |
182 | jnz frfl6 |
||
183 | inc ecx |
||
1 | ha | 184 | frfl6: |
766 | Rus | 185 | test esi,esi ; return ramdisk root |
186 | jnz fr_noroot ;if not root |
||
187 | cmp ebx,14 ;14 clusters=root dir |
||
188 | ja oorr |
||
189 | cmp ecx,14 |
||
190 | ja oorr |
||
191 | jmp fr_do |
||
1 | ha | 192 | oorr: |
766 | Rus | 193 | mov eax,5 ;out of root range (fnf) |
194 | xor ebx,ebx |
||
195 | dec ebx ;0xffffffff |
||
196 | ret |
||
1 | ha | 197 | |
766 | Rus | 198 | fr_do: ;reading rootdir |
199 | mov edi,edx |
||
200 | dec ebx |
||
201 | push edx |
||
202 | mov edx,ecx |
||
203 | add edx,ebx |
||
204 | cmp edx,15 ;ebx+ecx=14+1 |
||
205 | pushf |
||
206 | jbe fr_do1 |
||
207 | sub edx,14 |
||
208 | sub ecx,edx |
||
1 | ha | 209 | fr_do1: |
766 | Rus | 210 | shl ebx,9 |
211 | mov esi,RAMDISK+512*19 |
||
212 | add esi,ebx |
||
213 | shl ecx,7 |
||
214 | cld |
||
215 | rep movsd |
||
216 | popf |
||
217 | pop edx |
||
218 | jae fr_do2 |
||
219 | xor eax,eax ; ok read |
||
220 | xor ebx,ebx |
||
221 | ret |
||
222 | fr_do2: ;if last cluster |
||
223 | mov eax,6 ;end of file |
||
224 | xor ebx,ebx |
||
225 | ret |
||
1 | ha | 226 | |
227 | fr_noroot: |
||
228 | |||
766 | Rus | 229 | sub esp,32 |
230 | call expand_filename |
||
1 | ha | 231 | |
766 | Rus | 232 | dec ebx |
1 | ha | 233 | |
766 | Rus | 234 | push eax |
1 | ha | 235 | |
766 | Rus | 236 | push eax ebx ecx edx esi edi |
237 | call rd_findfile |
||
238 | je fifound |
||
239 | add esp,32+28 ;if file not found |
||
240 | ret |
||
1 | ha | 241 | |
242 | fifound: |
||
243 | |||
766 | Rus | 244 | mov ebx,[edi-11+28] ;file size |
245 | mov [esp+20],ebx |
||
246 | mov [esp+24],ebx |
||
247 | add edi,0xf |
||
248 | movzx eax,word [edi] |
||
249 | mov edi,eax ;edi=cluster |
||
1 | ha | 250 | |
251 | frnew: |
||
252 | |||
766 | Rus | 253 | add eax,31 ;bootsector+2*fat+filenames |
254 | shl eax,9 ;*512 |
||
255 | add eax,RAMDISK ;image base |
||
256 | mov ebx,[esp+8] |
||
257 | mov ecx,512 ;[esp+4] |
||
1 | ha | 258 | |
766 | Rus | 259 | cmp [esp+16],dword 0 ; wanted cluster ? |
260 | jne frfl7 |
||
261 | call memmove |
||
262 | add [esp+8],dword 512 |
||
263 | dec dword [esp+12] ; last wanted cluster ? |
||
264 | je frnoread |
||
265 | jmp frfl8 |
||
1 | ha | 266 | frfl7: |
766 | Rus | 267 | dec dword [esp+16] |
1 | ha | 268 | frfl8: |
766 | Rus | 269 | movzx eax,word [edi*2+RAMDISK_FAT] ; find next cluster from FAT |
270 | mov edi,eax |
||
271 | cmp edi,4095 ;eof - cluster |
||
272 | jz frnoread2 |
||
1 | ha | 273 | |
766 | Rus | 274 | cmp [esp+24],dword 512 ;eof - size |
275 | jb frnoread |
||
276 | sub [esp+24],dword 512 |
||
1 | ha | 277 | |
766 | Rus | 278 | jmp frnew |
1 | ha | 279 | |
280 | frnoread2: |
||
281 | |||
766 | Rus | 282 | cmp [esp+16],dword 0 ; eof without read ? |
283 | je frnoread |
||
1 | ha | 284 | |
766 | Rus | 285 | pop edi esi edx ecx |
286 | add esp,4 |
||
287 | pop ebx ; ebx <- eax : size of file |
||
288 | add esp,36 |
||
289 | mov eax,6 ; end of file |
||
290 | ret |
||
1 | ha | 291 | |
292 | frnoread: |
||
293 | |||
766 | Rus | 294 | pop edi esi edx ecx |
295 | add esp,4 |
||
296 | pop ebx ; ebx <- eax : size of file |
||
297 | add esp,36 |
||
298 | xor eax,eax ;read ok |
||
299 | ret |
||
1 | ha | 300 | |
301 | |||
302 | |||
303 | rd_findfile: |
||
304 | ;by Mihasik |
||
305 | ;IN: eax - pointer to filename OUT: filestring+11 in edi or notZero in flags and fnf in eax,ebx |
||
306 | |||
766 | Rus | 307 | mov edi,RAMDISK+512*18+512 ;Point at directory |
308 | cld |
||
1 | ha | 309 | rd_newsearch: |
766 | Rus | 310 | mov esi,eax |
311 | mov ecx,11 |
||
312 | rep cmpsb |
||
313 | je rd_ff |
||
314 | add cl,21 |
||
315 | add edi,ecx |
||
316 | cmp edi,RAMDISK+512*33 |
||
317 | jb rd_newsearch |
||
318 | mov eax,5 ;if file not found - eax=5 |
||
319 | xor ebx,ebx |
||
320 | dec ebx ;ebx=0xffffffff and zf=0 |
||
1 | ha | 321 | rd_ff: |
766 | Rus | 322 | ret |
1 | ha | 323 | |
71 | diamond | 324 | ; \begin{diamond} |
325 | |||
326 | uni2ansi_str: |
||
327 | ; convert UNICODE zero-terminated string to ASCII-string (codepage 866) |
||
328 | ; in: esi->source, edi->buffer (may be esi=edi) |
||
329 | ; destroys: eax,esi,edi |
||
766 | Rus | 330 | lodsw |
331 | test ax, ax |
||
332 | jz .done |
||
333 | cmp ax, 0x80 |
||
334 | jb .ascii |
||
335 | cmp ax, 0x401 |
||
336 | jz .yo1 |
||
337 | cmp ax, 0x451 |
||
338 | jz .yo2 |
||
339 | cmp ax, 0x410 |
||
340 | jb .unk |
||
341 | cmp ax, 0x440 |
||
342 | jb .rus1 |
||
343 | cmp ax, 0x450 |
||
344 | jb .rus2 |
||
71 | diamond | 345 | .unk: |
766 | Rus | 346 | mov al, '_' |
347 | jmp .doit |
||
71 | diamond | 348 | .yo1: |
766 | Rus | 349 | mov al, 'ð' |
350 | jmp .doit |
||
71 | diamond | 351 | .yo2: |
766 | Rus | 352 | mov al, 'ñ' |
353 | jmp .doit |
||
71 | diamond | 354 | .rus1: |
355 | ; 0x410-0x43F -> 0x80-0xAF |
||
766 | Rus | 356 | add al, 0x70 |
357 | jmp .doit |
||
71 | diamond | 358 | .rus2: |
75 | diamond | 359 | ; 0x440-0x44F -> 0xE0-0xEF |
766 | Rus | 360 | add al, 0xA0 |
71 | diamond | 361 | .ascii: |
362 | .doit: |
||
766 | Rus | 363 | stosb |
364 | jmp uni2ansi_str |
||
71 | diamond | 365 | .done: |
766 | Rus | 366 | mov byte [edi], 0 |
367 | ret |
||
71 | diamond | 368 | |
75 | diamond | 369 | ansi2uni_char: |
370 | ; convert ANSI character in al to UNICODE character in ax, using cp866 encoding |
||
766 | Rus | 371 | mov ah, 0 |
75 | diamond | 372 | ; 0x00-0x7F - trivial map |
766 | Rus | 373 | cmp al, 0x80 |
374 | jb .ret |
||
75 | diamond | 375 | ; 0x80-0xAF -> 0x410-0x43F |
766 | Rus | 376 | cmp al, 0xB0 |
377 | jae @f |
||
378 | add ax, 0x410-0x80 |
||
75 | diamond | 379 | .ret: |
766 | Rus | 380 | ret |
75 | diamond | 381 | @@: |
382 | ; 0xE0-0xEF -> 0x440-0x44F |
||
766 | Rus | 383 | cmp al, 0xE0 |
384 | jb .unk |
||
385 | cmp al, 0xF0 |
||
386 | jae @f |
||
387 | add ax, 0x440-0xE0 |
||
388 | ret |
||
75 | diamond | 389 | ; 0xF0 -> 0x401 |
390 | ; 0xF1 -> 0x451 |
||
391 | @@: |
||
766 | Rus | 392 | cmp al, 'ð' |
393 | jz .yo1 |
||
394 | cmp al, 'ñ' |
||
395 | jz .yo2 |
||
75 | diamond | 396 | .unk: |
766 | Rus | 397 | mov al, '_' ; ah=0 |
398 | ret |
||
75 | diamond | 399 | .yo1: |
766 | Rus | 400 | mov ax, 0x401 |
401 | ret |
||
75 | diamond | 402 | .yo2: |
766 | Rus | 403 | mov ax, 0x451 |
404 | ret |
||
75 | diamond | 405 | |
71 | diamond | 406 | char_toupper: |
407 | ; convert character to uppercase, using cp866 encoding |
||
408 | ; in: al=symbol |
||
409 | ; out: al=converted symbol |
||
766 | Rus | 410 | cmp al, 'a' |
411 | jb .ret |
||
412 | cmp al, 'z' |
||
413 | jbe .az |
||
2212 | Serge | 414 | cmp al, 'ñ' |
415 | jz .yo1 |
||
766 | Rus | 416 | cmp al, ' ' |
417 | jb .ret |
||
418 | cmp al, 'à' |
||
419 | jb .rus1 |
||
420 | cmp al, 'ï' |
||
421 | ja .ret |
||
71 | diamond | 422 | ; 0xE0-0xEF -> 0x90-0x9F |
766 | Rus | 423 | sub al, 'à'-'' |
71 | diamond | 424 | .ret: |
766 | Rus | 425 | ret |
71 | diamond | 426 | .rus1: |
427 | ; 0xA0-0xAF -> 0x80-0x8F |
||
428 | .az: |
||
766 | Rus | 429 | and al, not 0x20 |
430 | ret |
||
2212 | Serge | 431 | .yo1: |
432 | ; 0xF1 -> 0xF0 |
||
433 | dec ax |
||
434 | ret |
||
71 | diamond | 435 | |
436 | fat_get_name: |
||
437 | ; in: edi->FAT entry |
||
438 | ; out: CF=1 - no valid entry |
||
439 | ; else CF=0 and ebp->ASCIIZ-name |
||
440 | ; (maximum length of filename is 255 (wide) symbols without trailing 0, |
||
441 | ; but implementation requires buffer 261 words) |
||
442 | ; destroys eax |
||
766 | Rus | 443 | cmp byte [edi], 0 |
444 | jz .no |
||
445 | cmp byte [edi], 0xE5 |
||
446 | jnz @f |
||
71 | diamond | 447 | .no: |
766 | Rus | 448 | stc |
449 | ret |
||
71 | diamond | 450 | @@: |
766 | Rus | 451 | cmp byte [edi+11], 0xF |
452 | jz .longname |
||
453 | test byte [edi+11], 8 |
||
454 | jnz .no |
||
455 | push ecx |
||
456 | push edi ebp |
||
457 | test byte [ebp-4], 1 |
||
458 | jnz .unicode_short |
||
247 | serge | 459 | |
766 | Rus | 460 | mov eax, [edi] |
461 | mov ecx, [edi+4] |
||
462 | mov [ebp], eax |
||
463 | mov [ebp+4], ecx |
||
247 | serge | 464 | |
766 | Rus | 465 | mov ecx, 8 |
71 | diamond | 466 | @@: |
766 | Rus | 467 | cmp byte [ebp+ecx-1], ' ' |
468 | loope @b |
||
247 | serge | 469 | |
766 | Rus | 470 | mov eax, [edi+8] |
471 | cmp al, ' ' |
||
472 | je .done |
||
473 | shl eax, 8 |
||
474 | mov al, '.' |
||
247 | serge | 475 | |
766 | Rus | 476 | lea ebp, [ebp+ecx+1] |
477 | mov [ebp], eax |
||
478 | mov ecx, 3 |
||
71 | diamond | 479 | @@: |
766 | Rus | 480 | rol eax, 8 |
481 | cmp al, ' ' |
||
482 | jne .done |
||
483 | loop @b |
||
484 | dec ebp |
||
247 | serge | 485 | .done: |
766 | Rus | 486 | and byte [ebp+ecx+1], 0 ; CF=0 |
487 | pop ebp edi ecx |
||
488 | ret |
||
75 | diamond | 489 | .unicode_short: |
766 | Rus | 490 | mov ecx, 8 |
491 | push ecx |
||
75 | diamond | 492 | @@: |
766 | Rus | 493 | mov al, [edi] |
494 | inc edi |
||
495 | call ansi2uni_char |
||
496 | mov [ebp], ax |
||
497 | inc ebp |
||
498 | inc ebp |
||
499 | loop @b |
||
500 | pop ecx |
||
75 | diamond | 501 | @@: |
766 | Rus | 502 | cmp word [ebp-2], ' ' |
503 | jnz @f |
||
504 | dec ebp |
||
505 | dec ebp |
||
506 | loop @b |
||
75 | diamond | 507 | @@: |
766 | Rus | 508 | mov word [ebp], '.' |
509 | inc ebp |
||
510 | inc ebp |
||
511 | mov ecx, 3 |
||
512 | push ecx |
||
75 | diamond | 513 | @@: |
766 | Rus | 514 | mov al, [edi] |
515 | inc edi |
||
516 | call ansi2uni_char |
||
517 | mov [ebp], ax |
||
518 | inc ebp |
||
519 | inc ebp |
||
520 | loop @b |
||
521 | pop ecx |
||
75 | diamond | 522 | @@: |
766 | Rus | 523 | cmp word [ebp-2], ' ' |
524 | jnz @f |
||
525 | dec ebp |
||
526 | dec ebp |
||
527 | loop @b |
||
528 | dec ebp |
||
529 | dec ebp |
||
75 | diamond | 530 | @@: |
766 | Rus | 531 | and word [ebp], 0 ; CF=0 |
532 | pop ebp edi ecx |
||
533 | ret |
||
71 | diamond | 534 | .longname: |
535 | ; LFN |
||
766 | Rus | 536 | mov al, byte [edi] |
537 | and eax, 0x3F |
||
538 | dec eax |
||
539 | cmp al, 20 |
||
540 | jae .no ; ignore invalid entries |
||
541 | mov word [ebp+260*2], 0 ; force null-terminating for orphans |
||
542 | imul eax, 13*2 |
||
543 | add ebp, eax |
||
544 | test byte [edi], 0x40 |
||
545 | jz @f |
||
546 | mov word [ebp+13*2], 0 |
||
71 | diamond | 547 | @@: |
766 | Rus | 548 | push eax |
71 | diamond | 549 | ; now copy name from edi to ebp ... |
766 | Rus | 550 | mov eax, [edi+1] |
551 | mov [ebp], eax ; symbols 1,2 |
||
552 | mov eax, [edi+5] |
||
553 | mov [ebp+4], eax ; 3,4 |
||
554 | mov eax, [edi+9] |
||
555 | mov [ebp+8], ax ; 5 |
||
556 | mov eax, [edi+14] |
||
557 | mov [ebp+10], eax ; 6,7 |
||
558 | mov eax, [edi+18] |
||
559 | mov [ebp+14], eax ; 8,9 |
||
560 | mov eax, [edi+22] |
||
561 | mov [ebp+18], eax ; 10,11 |
||
562 | mov eax, [edi+28] |
||
563 | mov [ebp+22], eax ; 12,13 |
||
71 | diamond | 564 | ; ... done |
766 | Rus | 565 | pop eax |
566 | sub ebp, eax |
||
567 | test eax, eax |
||
568 | jz @f |
||
71 | diamond | 569 | ; if this is not first entry, more processing required |
766 | Rus | 570 | stc |
571 | ret |
||
71 | diamond | 572 | @@: |
573 | ; if this is first entry: |
||
766 | Rus | 574 | test byte [ebp-4], 1 |
575 | jnz .ret |
||
71 | diamond | 576 | ; buffer at ebp contains UNICODE name, convert it to ANSI |
766 | Rus | 577 | push esi edi |
578 | mov esi, ebp |
||
579 | mov edi, ebp |
||
580 | call uni2ansi_str |
||
581 | pop edi esi |
||
75 | diamond | 582 | .ret: |
766 | Rus | 583 | clc |
584 | ret |
||
71 | diamond | 585 | |
586 | fat_compare_name: |
||
587 | ; compares ASCIIZ-names, case-insensitive (cp866 encoding) |
||
588 | ; in: esi->name, ebp->name |
||
589 | ; out: if names match: ZF=1 and esi->next component of name |
||
590 | ; else: ZF=0, esi is not changed |
||
591 | ; destroys eax |
||
766 | Rus | 592 | push ebp esi |
71 | diamond | 593 | .loop: |
766 | Rus | 594 | mov al, [ebp] |
595 | inc ebp |
||
596 | call char_toupper |
||
597 | push eax |
||
598 | lodsb |
||
599 | call char_toupper |
||
600 | cmp al, [esp] |
||
601 | jnz .done |
||
602 | pop eax |
||
603 | test al, al |
||
604 | jnz .loop |
||
605 | dec esi |
||
606 | pop eax |
||
607 | pop ebp |
||
608 | xor eax, eax ; set ZF flag |
||
609 | ret |
||
71 | diamond | 610 | .done: |
766 | Rus | 611 | cmp al, '/' |
612 | jnz @f |
||
613 | cmp byte [esp], 0 |
||
614 | jnz @f |
||
615 | mov [esp+4], esi |
||
71 | diamond | 616 | @@: |
766 | Rus | 617 | pop eax |
618 | pop esi ebp |
||
619 | ret |
||
71 | diamond | 620 | |
75 | diamond | 621 | fat_time_to_bdfe: |
622 | ; in: eax=FAT time |
||
623 | ; out: eax=BDFE time |
||
766 | Rus | 624 | push ecx edx |
625 | mov ecx, eax |
||
626 | mov edx, eax |
||
627 | shr eax, 11 |
||
628 | shl eax, 16 ; hours |
||
629 | and edx, 0x1F |
||
630 | add edx, edx |
||
631 | mov al, dl ; seconds |
||
632 | shr ecx, 5 |
||
633 | and ecx, 0x3F |
||
634 | mov ah, cl ; minutes |
||
635 | pop edx ecx |
||
636 | ret |
||
75 | diamond | 637 | |
638 | fat_date_to_bdfe: |
||
766 | Rus | 639 | push ecx edx |
640 | mov ecx, eax |
||
641 | mov edx, eax |
||
642 | shr eax, 9 |
||
643 | add ax, 1980 |
||
644 | shl eax, 16 ; year |
||
645 | and edx, 0x1F |
||
646 | mov al, dl ; day |
||
647 | shr ecx, 5 |
||
648 | and ecx, 0xF |
||
649 | mov ah, cl ; month |
||
650 | pop edx ecx |
||
651 | ret |
||
75 | diamond | 652 | |
86 | diamond | 653 | bdfe_to_fat_time: |
766 | Rus | 654 | push edx |
655 | mov edx, eax |
||
656 | shr eax, 16 |
||
657 | and dh, 0x3F |
||
658 | shl eax, 6 |
||
659 | or al, dh |
||
660 | shr dl, 1 |
||
661 | and dl, 0x1F |
||
662 | shl eax, 5 |
||
663 | or al, dl |
||
664 | pop edx |
||
665 | ret |
||
86 | diamond | 666 | |
667 | bdfe_to_fat_date: |
||
766 | Rus | 668 | push edx |
669 | mov edx, eax |
||
670 | shr eax, 16 |
||
671 | sub ax, 1980 |
||
672 | and dh, 0xF |
||
673 | shl eax, 4 |
||
674 | or al, dh |
||
675 | and dl, 0x1F |
||
676 | shl eax, 5 |
||
677 | or al, dl |
||
678 | pop edx |
||
679 | ret |
||
86 | diamond | 680 | |
75 | diamond | 681 | fat_entry_to_bdfe: |
682 | ; convert FAT entry at edi to BDFE (block of data of folder entry) at esi, advance esi |
||
683 | ; destroys eax |
||
766 | Rus | 684 | mov eax, [ebp-4] |
685 | mov [esi+4], eax ; ASCII/UNICODE name |
||
86 | diamond | 686 | fat_entry_to_bdfe2: |
766 | Rus | 687 | movzx eax, byte [edi+11] |
688 | mov [esi], eax ; attributes |
||
689 | movzx eax, word [edi+14] |
||
690 | call fat_time_to_bdfe |
||
691 | mov [esi+8], eax ; creation time |
||
692 | movzx eax, word [edi+16] |
||
693 | call fat_date_to_bdfe |
||
694 | mov [esi+12], eax ; creation date |
||
695 | and dword [esi+16], 0 ; last access time is not supported on FAT |
||
696 | movzx eax, word [edi+18] |
||
697 | call fat_date_to_bdfe |
||
698 | mov [esi+20], eax ; last access date |
||
699 | movzx eax, word [edi+22] |
||
700 | call fat_time_to_bdfe |
||
701 | mov [esi+24], eax ; last write time |
||
702 | movzx eax, word [edi+24] |
||
703 | call fat_date_to_bdfe |
||
704 | mov [esi+28], eax ; last write date |
||
705 | mov eax, [edi+28] |
||
706 | mov [esi+32], eax ; file size (low dword) |
||
707 | xor eax, eax |
||
708 | mov [esi+36], eax ; file size (high dword) |
||
709 | test ebp, ebp |
||
710 | jz .ret |
||
711 | push ecx edi |
||
712 | lea edi, [esi+40] |
||
713 | mov esi, ebp |
||
714 | test byte [esi-4], 1 |
||
715 | jz .ansi |
||
716 | mov ecx, 260/2 |
||
717 | rep movsd |
||
718 | mov [edi-2], ax |
||
78 | diamond | 719 | @@: |
766 | Rus | 720 | mov esi, edi |
721 | pop edi ecx |
||
86 | diamond | 722 | .ret: |
766 | Rus | 723 | ret |
78 | diamond | 724 | .ansi: |
766 | Rus | 725 | mov ecx, 264/4 |
726 | rep movsd |
||
727 | mov [edi-1], al |
||
728 | jmp @b |
||
75 | diamond | 729 | |
86 | diamond | 730 | bdfe_to_fat_entry: |
731 | ; convert BDFE at edx to FAT entry at edi |
||
732 | ; destroys eax |
||
733 | ; attributes byte |
||
766 | Rus | 734 | test byte [edi+11], 8 ; volume label? |
735 | jnz @f |
||
736 | mov al, [edx] |
||
737 | and al, 0x27 |
||
738 | and byte [edi+11], 0x10 |
||
739 | or byte [edi+11], al |
||
86 | diamond | 740 | @@: |
766 | Rus | 741 | mov eax, [edx+8] |
742 | call bdfe_to_fat_time |
||
743 | mov [edi+14], ax ; creation time |
||
744 | mov eax, [edx+12] |
||
745 | call bdfe_to_fat_date |
||
746 | mov [edi+16], ax ; creation date |
||
747 | mov eax, [edx+20] |
||
748 | call bdfe_to_fat_date |
||
749 | mov [edi+18], ax ; last access date |
||
750 | mov eax, [edx+24] |
||
751 | call bdfe_to_fat_time |
||
752 | mov [edi+22], ax ; last write time |
||
753 | mov eax, [edx+28] |
||
754 | call bdfe_to_fat_date |
||
755 | mov [edi+24], ax ; last write date |
||
756 | ret |
||
86 | diamond | 757 | |
758 | ramdisk_root_first: |
||
766 | Rus | 759 | mov edi, RAMDISK+512*19 |
760 | clc |
||
761 | ret |
||
86 | diamond | 762 | ramdisk_root_next: |
766 | Rus | 763 | add edi, 0x20 |
764 | cmp edi, RAMDISK+512*33 |
||
765 | cmc |
||
766 | ret |
||
86 | diamond | 767 | |
91 | diamond | 768 | ramdisk_root_extend_dir: |
766 | Rus | 769 | stc |
770 | ret |
||
91 | diamond | 771 | |
171 | diamond | 772 | uglobal |
773 | ; this is for delete support |
||
766 | Rus | 774 | rd_prev_sector dd ? |
775 | rd_prev_prev_sector dd ? |
||
171 | diamond | 776 | endg |
777 | |||
91 | diamond | 778 | ramdisk_notroot_next: |
766 | Rus | 779 | add edi, 0x20 |
780 | test edi, 0x1FF |
||
781 | jz ramdisk_notroot_next_sector |
||
782 | ret ; CF=0 |
||
91 | diamond | 783 | ramdisk_notroot_next_sector: |
766 | Rus | 784 | push ecx |
785 | mov ecx, [eax] |
||
786 | push [rd_prev_sector] |
||
787 | pop [rd_prev_prev_sector] |
||
788 | mov [rd_prev_sector], ecx |
||
789 | mov ecx, [ecx*2+RAMDISK_FAT] |
||
790 | and ecx, 0xFFF |
||
791 | cmp ecx, 2849 |
||
792 | jae ramdisk_notroot_first.err2 |
||
793 | mov [eax], ecx |
||
794 | pop ecx |
||
91 | diamond | 795 | ramdisk_notroot_first: |
766 | Rus | 796 | mov eax, [eax] |
797 | cmp eax, 2 |
||
798 | jb .err |
||
799 | cmp eax, 2849 |
||
800 | jae .err |
||
801 | shl eax, 9 |
||
802 | lea edi, [eax+(31 shl 9)+RAMDISK] |
||
803 | clc |
||
804 | ret |
||
91 | diamond | 805 | .err2: |
766 | Rus | 806 | pop ecx |
91 | diamond | 807 | .err: |
766 | Rus | 808 | stc |
809 | ret |
||
91 | diamond | 810 | ramdisk_notroot_next_write: |
766 | Rus | 811 | test edi, 0x1FF |
812 | jz ramdisk_notroot_next_sector |
||
91 | diamond | 813 | ramdisk_root_next_write: |
766 | Rus | 814 | ret |
91 | diamond | 815 | |
816 | ramdisk_notroot_extend_dir: |
||
766 | Rus | 817 | pusha |
818 | xor eax, eax |
||
819 | mov edi, RAMDISK_FAT |
||
820 | mov ecx, 2849 |
||
821 | repnz scasw |
||
822 | jnz .notfound |
||
823 | mov word [edi-2], 0xFFF |
||
824 | sub edi, RAMDISK_FAT |
||
825 | shr edi, 1 |
||
826 | dec edi |
||
827 | mov eax, [esp+28] |
||
828 | mov ecx, [eax] |
||
829 | mov [RAMDISK_FAT+ecx*2], di |
||
830 | mov [eax], edi |
||
831 | shl edi, 9 |
||
832 | add edi, (31 shl 9)+RAMDISK |
||
833 | mov [esp], edi |
||
834 | xor eax, eax |
||
835 | mov ecx, 128 |
||
836 | rep stosd |
||
837 | popa |
||
838 | clc |
||
839 | ret |
||
91 | diamond | 840 | .notfound: |
766 | Rus | 841 | popa |
842 | stc |
||
843 | ret |
||
91 | diamond | 844 | |
71 | diamond | 845 | rd_find_lfn: |
521 | diamond | 846 | ; in: esi+ebp -> name |
71 | diamond | 847 | ; out: CF=1 - file not found |
848 | ; else CF=0 and edi->direntry |
||
766 | Rus | 849 | push esi edi |
850 | push 0 |
||
851 | push ramdisk_root_first |
||
852 | push ramdisk_root_next |
||
91 | diamond | 853 | .loop: |
766 | Rus | 854 | call fat_find_lfn |
855 | jc .notfound |
||
856 | cmp byte [esi], 0 |
||
857 | jz .found |
||
521 | diamond | 858 | .continue: |
766 | Rus | 859 | test byte [edi+11], 10h |
860 | jz .notfound |
||
861 | movzx eax, word [edi+26] |
||
862 | mov [esp+8], eax |
||
863 | mov dword [esp+4], ramdisk_notroot_first |
||
864 | mov dword [esp], ramdisk_notroot_next |
||
1021 | diamond | 865 | test eax, eax |
866 | jnz .loop |
||
867 | mov dword [esp+4], ramdisk_root_first |
||
868 | mov dword [esp], ramdisk_notroot_next |
||
766 | Rus | 869 | jmp .loop |
91 | diamond | 870 | .notfound: |
766 | Rus | 871 | add esp, 12 |
872 | pop edi esi |
||
873 | stc |
||
874 | ret |
||
91 | diamond | 875 | .found: |
766 | Rus | 876 | test ebp, ebp |
877 | jz @f |
||
878 | mov esi, ebp |
||
879 | xor ebp, ebp |
||
880 | jmp .continue |
||
521 | diamond | 881 | @@: |
766 | Rus | 882 | mov eax, [esp+8] |
883 | add esp, 16 ; CF=0 |
||
884 | pop esi |
||
885 | ret |
||
71 | diamond | 886 | |
887 | ;---------------------------------------------------------------- |
||
888 | ; |
||
889 | ; fs_RamdiskRead - LFN variant for reading sys floppy |
||
890 | ; |
||
891 | ; esi points to filename |
||
892 | ; ebx pointer to 64-bit number = first wanted byte, 0+ |
||
893 | ; may be ebx=0 - start from first byte |
||
894 | ; ecx number of bytes to read, 0+ |
||
895 | ; edx mem location to return data |
||
896 | ; |
||
77 | diamond | 897 | ; ret ebx = bytes read or 0xffffffff file not found |
71 | diamond | 898 | ; eax = 0 ok read or other = errormsg |
899 | ; |
||
900 | ;-------------------------------------------------------------- |
||
901 | fs_RamdiskRead: |
||
766 | Rus | 902 | cmp byte [esi], 0 |
903 | jnz @f |
||
904 | or ebx, -1 |
||
905 | mov eax, 10 ; access denied |
||
906 | ret |
||
71 | diamond | 907 | @@: |
766 | Rus | 908 | push edi |
909 | call rd_find_lfn |
||
910 | jnc .found |
||
911 | pop edi |
||
912 | or ebx, -1 |
||
913 | mov eax, 5 ; file not found |
||
914 | ret |
||
71 | diamond | 915 | .found: |
766 | Rus | 916 | test ebx, ebx |
917 | jz .l1 |
||
918 | cmp dword [ebx+4], 0 |
||
919 | jz @f |
||
920 | xor ebx, ebx |
||
71 | diamond | 921 | .reteof: |
766 | Rus | 922 | mov eax, 6 ; EOF |
923 | pop edi |
||
924 | ret |
||
71 | diamond | 925 | @@: |
766 | Rus | 926 | mov ebx, [ebx] |
71 | diamond | 927 | .l1: |
766 | Rus | 928 | push ecx edx |
929 | push 0 |
||
930 | mov eax, [edi+28] |
||
931 | sub eax, ebx |
||
932 | jb .eof |
||
933 | cmp eax, ecx |
||
934 | jae @f |
||
935 | mov ecx, eax |
||
936 | mov byte [esp], 6 ; EOF |
||
77 | diamond | 937 | @@: |
766 | Rus | 938 | movzx edi, word [edi+26] ; cluster |
71 | diamond | 939 | .new: |
766 | Rus | 940 | jecxz .done |
941 | test edi, edi |
||
942 | jz .eof |
||
943 | cmp edi, 0xFF8 |
||
944 | jae .eof |
||
945 | lea eax, [edi+31] ; bootsector+2*fat+filenames |
||
946 | shl eax, 9 ; *512 |
||
947 | add eax, RAMDISK ; image base |
||
71 | diamond | 948 | ; now eax points to data of cluster |
766 | Rus | 949 | sub ebx, 512 |
950 | jae .skip |
||
951 | lea eax, [eax+ebx+512] |
||
952 | neg ebx |
||
953 | push ecx |
||
954 | cmp ecx, ebx |
||
955 | jbe @f |
||
956 | mov ecx, ebx |
||
71 | diamond | 957 | @@: |
766 | Rus | 958 | mov ebx, edx |
959 | call memmove |
||
960 | add edx, ecx |
||
961 | sub [esp], ecx |
||
962 | pop ecx |
||
963 | xor ebx, ebx |
||
71 | diamond | 964 | .skip: |
766 | Rus | 965 | movzx edi, word [edi*2+RAMDISK_FAT] ; find next cluster from FAT |
966 | jmp .new |
||
71 | diamond | 967 | .eof: |
766 | Rus | 968 | mov ebx, edx |
969 | pop eax edx ecx |
||
970 | sub ebx, edx |
||
971 | jmp .reteof |
||
71 | diamond | 972 | .done: |
766 | Rus | 973 | mov ebx, edx |
974 | pop eax edx ecx edi |
||
975 | sub ebx, edx |
||
976 | ret |
||
71 | diamond | 977 | |
75 | diamond | 978 | ;---------------------------------------------------------------- |
979 | ; |
||
980 | ; fs_RamdiskReadFolder - LFN variant for reading sys floppy folder |
||
981 | ; |
||
982 | ; esi points to filename; only root is folder on ramdisk |
||
78 | diamond | 983 | ; ebx pointer to structure 32-bit number = first wanted block |
984 | ; & flags (bitfields) |
||
985 | ; flags: bit 0: 0=ANSI names, 1=UNICODE names |
||
75 | diamond | 986 | ; ecx number of blocks to read, 0+ |
987 | ; edx mem location to return data |
||
988 | ; |
||
989 | ; ret ebx = size or 0xffffffff file not found |
||
990 | ; eax = 0 ok read or other = errormsg |
||
991 | ; |
||
992 | ;-------------------------------------------------------------- |
||
993 | fs_RamdiskReadFolder: |
||
766 | Rus | 994 | push edi |
995 | cmp byte [esi], 0 |
||
996 | jz .root |
||
997 | call rd_find_lfn |
||
998 | jnc .found |
||
999 | pop edi |
||
1000 | or ebx, -1 |
||
1001 | mov eax, ERROR_FILE_NOT_FOUND |
||
1002 | ret |
||
91 | diamond | 1003 | .found: |
766 | Rus | 1004 | test byte [edi+11], 0x10 |
1005 | jnz .found_dir |
||
1006 | pop edi |
||
1007 | or ebx, -1 |
||
1008 | mov eax, ERROR_ACCESS_DENIED |
||
1009 | ret |
||
91 | diamond | 1010 | .found_dir: |
766 | Rus | 1011 | movzx eax, word [edi+26] |
1012 | add eax, 31 |
||
1013 | push 0 |
||
1014 | jmp .doit |
||
91 | diamond | 1015 | .root: |
766 | Rus | 1016 | mov eax, 19 |
1017 | push 14 |
||
91 | diamond | 1018 | .doit: |
766 | Rus | 1019 | push esi ecx ebp |
1020 | sub esp, 262*2 ; reserve space for LFN |
||
1021 | mov ebp, esp |
||
1022 | push dword [ebx+4] ; for fat_get_name: read ANSI/UNICODE names |
||
1023 | mov ebx, [ebx] |
||
75 | diamond | 1024 | ; init header |
766 | Rus | 1025 | push eax ecx |
1026 | mov edi, edx |
||
1027 | mov ecx, 32/4 |
||
1028 | xor eax, eax |
||
1029 | rep stosd |
||
1030 | mov byte [edx], 1 ; version |
||
1031 | pop ecx eax |
||
1032 | mov esi, edi ; esi points to block of data of folder entry (BDFE) |
||
91 | diamond | 1033 | .main_loop: |
766 | Rus | 1034 | mov edi, eax |
1035 | shl edi, 9 |
||
1036 | add edi, RAMDISK |
||
1037 | push eax |
||
75 | diamond | 1038 | .l1: |
766 | Rus | 1039 | call fat_get_name |
1040 | jc .l2 |
||
1041 | cmp byte [edi+11], 0xF |
||
1042 | jnz .do_bdfe |
||
1043 | add edi, 0x20 |
||
1044 | test edi, 0x1FF |
||
1045 | jnz .do_bdfe |
||
1046 | pop eax |
||
1047 | inc eax |
||
1048 | dec byte [esp+262*2+16] |
||
1049 | jz .done |
||
1050 | jns @f |
||
91 | diamond | 1051 | ; read next sector from FAT |
766 | Rus | 1052 | mov eax, [(eax-31-1)*2+RAMDISK_FAT] |
1053 | and eax, 0xFFF |
||
1054 | cmp eax, 0xFF8 |
||
1055 | jae .done |
||
1056 | add eax, 31 |
||
1057 | mov byte [esp+262*2+16], 0 |
||
75 | diamond | 1058 | @@: |
766 | Rus | 1059 | mov edi, eax |
1060 | shl edi, 9 |
||
1061 | add edi, RAMDISK |
||
1062 | push eax |
||
91 | diamond | 1063 | .do_bdfe: |
766 | Rus | 1064 | inc dword [edx+8] ; new file found |
1065 | dec ebx |
||
1066 | jns .l2 |
||
1067 | dec ecx |
||
1068 | js .l2 |
||
1069 | inc dword [edx+4] ; new file block copied |
||
1070 | call fat_entry_to_bdfe |
||
75 | diamond | 1071 | .l2: |
766 | Rus | 1072 | add edi, 0x20 |
1073 | test edi, 0x1FF |
||
1074 | jnz .l1 |
||
1075 | pop eax |
||
1076 | inc eax |
||
1077 | dec byte [esp+262*2+16] |
||
1078 | jz .done |
||
1079 | jns @f |
||
91 | diamond | 1080 | ; read next sector from FAT |
766 | Rus | 1081 | mov eax, [(eax-31-1)*2+RAMDISK_FAT] |
1082 | and eax, 0xFFF |
||
1083 | cmp eax, 0xFF8 |
||
1084 | jae .done |
||
1085 | add eax, 31 |
||
1086 | mov byte [esp+262*2+16], 0 |
||
91 | diamond | 1087 | @@: |
766 | Rus | 1088 | jmp .main_loop |
91 | diamond | 1089 | .done: |
766 | Rus | 1090 | add esp, 262*2+4 |
1091 | pop ebp |
||
1092 | mov ebx, [edx+4] |
||
1093 | xor eax, eax |
||
1094 | dec ecx |
||
1095 | js @f |
||
1096 | mov al, ERROR_END_OF_FILE |
||
75 | diamond | 1097 | @@: |
766 | Rus | 1098 | pop ecx esi edi edi |
1099 | ret |
||
75 | diamond | 1100 | |
83 | diamond | 1101 | iglobal |
1102 | label fat_legal_chars byte |
||
1103 | ; 0 = not allowed |
||
1104 | ; 1 = allowed only in long names |
||
1105 | ; 3 = allowed |
||
766 | Rus | 1106 | times 32 db 0 |
83 | diamond | 1107 | ; ! " # $ % & ' ( ) * + , - . / |
766 | Rus | 1108 | db 1,3,0,3,3,3,3,3,3,3,0,1,1,3,3,0 |
83 | diamond | 1109 | ; 0 1 2 3 4 5 6 7 8 9 : ; < = > ? |
766 | Rus | 1110 | db 3,3,3,3,3,3,3,3,3,3,0,1,0,1,0,0 |
83 | diamond | 1111 | ; @ A B C D E F G H I J K L M N O |
766 | Rus | 1112 | db 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 |
83 | diamond | 1113 | ; P Q R S T U V W X Y Z [ \ ] ^ _ |
766 | Rus | 1114 | db 3,3,3,3,3,3,3,3,3,3,3,1,0,1,3,3 |
83 | diamond | 1115 | ; ` a b c d e f g h i j k l m n o |
766 | Rus | 1116 | db 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 |
83 | diamond | 1117 | ; p q r s t u v w x y z { | } ~ |
766 | Rus | 1118 | db 3,3,3,3,3,3,3,3,3,3,3,3,0,3,3,0 |
83 | diamond | 1119 | endg |
1120 | |||
1121 | fat_name_is_legal: |
||
1122 | ; in: esi->(long) name |
||
1123 | ; out: CF set <=> legal |
||
1124 | ; destroys eax |
||
766 | Rus | 1125 | push esi |
1126 | xor eax, eax |
||
83 | diamond | 1127 | @@: |
766 | Rus | 1128 | lodsb |
1129 | test al, al |
||
1130 | jz .done |
||
1131 | cmp al, 80h |
||
1132 | jae .big |
||
1133 | test [fat_legal_chars+eax], 1 |
||
1134 | jnz @b |
||
83 | diamond | 1135 | .err: |
766 | Rus | 1136 | pop esi |
1137 | clc |
||
1138 | ret |
||
83 | diamond | 1139 | .big: |
1140 | ; 0x80-0xAF, 0xE0-0xEF |
||
766 | Rus | 1141 | cmp al, 0xB0 |
1142 | jb @b |
||
1143 | cmp al, 0xE0 |
||
1144 | jb .err |
||
1145 | cmp al, 0xF0 |
||
1146 | jb @b |
||
1147 | jmp .err |
||
83 | diamond | 1148 | .done: |
766 | Rus | 1149 | sub esi, [esp] |
1150 | cmp esi, 257 |
||
1151 | pop esi |
||
1152 | ret |
||
83 | diamond | 1153 | |
1154 | fat_next_short_name: |
||
1155 | ; in: edi->8+3 name |
||
1156 | ; out: name corrected |
||
1157 | ; CF=1 <=> error |
||
766 | Rus | 1158 | pushad |
1159 | mov ecx, 8 |
||
1160 | mov al, '~' |
||
1161 | std |
||
1162 | push edi |
||
1163 | add edi, 7 |
||
1164 | repnz scasb |
||
1165 | pop edi |
||
1166 | cld |
||
1167 | jz .tilde |
||
83 | diamond | 1168 | ; tilde is not found, insert "~1" at end |
766 | Rus | 1169 | add edi, 6 |
1170 | cmp word [edi], ' ' |
||
1171 | jnz .insert_tilde |
||
1172 | @@: dec edi |
||
1173 | cmp byte [edi], ' ' |
||
1174 | jz @b |
||
1175 | inc edi |
||
83 | diamond | 1176 | .insert_tilde: |
766 | Rus | 1177 | mov word [edi], '~1' |
1178 | popad |
||
1179 | clc |
||
1180 | ret |
||
83 | diamond | 1181 | .tilde: |
766 | Rus | 1182 | push edi |
1183 | add edi, 7 |
||
1184 | xor ecx, ecx |
||
83 | diamond | 1185 | @@: |
1186 | ; after tilde may be only digits and trailing spaces |
||
766 | Rus | 1187 | cmp byte [edi], '~' |
1188 | jz .break |
||
1189 | cmp byte [edi], ' ' |
||
1190 | jz .space |
||
1191 | cmp byte [edi], '9' |
||
1192 | jnz .found |
||
1193 | dec edi |
||
1194 | jmp @b |
||
83 | diamond | 1195 | .space: |
766 | Rus | 1196 | dec edi |
1197 | inc ecx |
||
1198 | jmp @b |
||
83 | diamond | 1199 | .found: |
766 | Rus | 1200 | inc byte [edi] |
1201 | add dword [esp], 8 |
||
1202 | jmp .zerorest |
||
83 | diamond | 1203 | .break: |
766 | Rus | 1204 | jecxz .noplace |
1205 | inc edi |
||
1206 | mov al, '1' |
||
83 | diamond | 1207 | @@: |
766 | Rus | 1208 | xchg al, [edi] |
1209 | inc edi |
||
1210 | cmp al, ' ' |
||
1211 | mov al, '0' |
||
1212 | jnz @b |
||
466 | diamond | 1213 | .succ: |
766 | Rus | 1214 | pop edi |
1215 | popad |
||
1216 | clc |
||
1217 | ret |
||
83 | diamond | 1218 | .noplace: |
766 | Rus | 1219 | dec edi |
1220 | cmp edi, [esp] |
||
1221 | jz .err |
||
1222 | add dword [esp], 8 |
||
1223 | mov word [edi], '~1' |
||
1224 | inc edi |
||
1225 | inc edi |
||
83 | diamond | 1226 | @@: |
766 | Rus | 1227 | mov byte [edi], '0' |
466 | diamond | 1228 | .zerorest: |
766 | Rus | 1229 | inc edi |
1230 | cmp edi, [esp] |
||
1231 | jb @b |
||
1232 | pop edi |
||
1233 | popad |
||
1234 | ;clc ; automatically |
||
1235 | ret |
||
83 | diamond | 1236 | .err: |
766 | Rus | 1237 | pop edi |
1238 | popad |
||
1239 | stc |
||
1240 | ret |
||
83 | diamond | 1241 | |
1242 | fat_gen_short_name: |
||
1243 | ; in: esi->long name |
||
1244 | ; edi->buffer (8+3=11 chars) |
||
1245 | ; out: buffer filled |
||
766 | Rus | 1246 | pushad |
1247 | mov eax, ' ' |
||
1248 | push edi |
||
1249 | stosd |
||
1250 | stosd |
||
1251 | stosd |
||
1252 | pop edi |
||
1253 | xor eax, eax |
||
1254 | push 8 |
||
1255 | pop ebx |
||
1256 | lea ecx, [edi+8] |
||
83 | diamond | 1257 | .loop: |
766 | Rus | 1258 | lodsb |
1259 | test al, al |
||
1260 | jz .done |
||
1261 | call char_toupper |
||
1262 | cmp al, ' ' |
||
1263 | jz .space |
||
1264 | cmp al, 80h |
||
1265 | ja .big |
||
1266 | test [fat_legal_chars+eax], 2 |
||
1267 | jnz .symbol |
||
83 | diamond | 1268 | .inv_symbol: |
766 | Rus | 1269 | mov al, '_' |
1270 | or bh, 1 |
||
83 | diamond | 1271 | .symbol: |
766 | Rus | 1272 | cmp al, '.' |
1273 | jz .dot |
||
83 | diamond | 1274 | .normal_symbol: |
766 | Rus | 1275 | dec bl |
1276 | jns .store |
||
1277 | mov bl, 0 |
||
83 | diamond | 1278 | .space: |
766 | Rus | 1279 | or bh, 1 |
1280 | jmp .loop |
||
83 | diamond | 1281 | .store: |
766 | Rus | 1282 | stosb |
1283 | jmp .loop |
||
83 | diamond | 1284 | .big: |
766 | Rus | 1285 | cmp al, 0xB0 |
1286 | jb .normal_symbol |
||
1287 | cmp al, 0xE0 |
||
1288 | jb .inv_symbol |
||
1289 | cmp al, 0xF0 |
||
1290 | jb .normal_symbol |
||
1291 | jmp .inv_symbol |
||
83 | diamond | 1292 | .dot: |
766 | Rus | 1293 | test bh, 2 |
1294 | jz .firstdot |
||
1295 | pop ebx |
||
1296 | add ebx, edi |
||
1297 | sub ebx, ecx |
||
1298 | push ebx |
||
1299 | cmp ebx, ecx |
||
1300 | jb @f |
||
1301 | pop ebx |
||
1302 | push ecx |
||
527 | diamond | 1303 | @@: |
766 | Rus | 1304 | cmp edi, ecx |
1305 | jbe .skip |
||
83 | diamond | 1306 | @@: |
766 | Rus | 1307 | dec edi |
1308 | mov al, [edi] |
||
1309 | dec ebx |
||
1310 | mov [ebx], al |
||
1311 | mov byte [edi], ' ' |
||
1312 | cmp edi, ecx |
||
1313 | ja @b |
||
83 | diamond | 1314 | .skip: |
766 | Rus | 1315 | mov bh, 3 |
1316 | jmp @f |
||
83 | diamond | 1317 | .firstdot: |
766 | Rus | 1318 | cmp bl, 8 |
1319 | jz .space |
||
1320 | push edi |
||
1321 | or bh, 2 |
||
83 | diamond | 1322 | @@: |
766 | Rus | 1323 | mov edi, ecx |
1324 | mov bl, 3 |
||
1325 | jmp .loop |
||
83 | diamond | 1326 | .done: |
766 | Rus | 1327 | test bh, 2 |
1328 | jz @f |
||
1329 | pop edi |
||
83 | diamond | 1330 | @@: |
766 | Rus | 1331 | lea edi, [ecx-8] |
1332 | test bh, 1 |
||
1333 | jz @f |
||
1334 | call fat_next_short_name |
||
83 | diamond | 1335 | @@: |
766 | Rus | 1336 | popad |
1337 | ret |
||
83 | diamond | 1338 | |
1339 | ;---------------------------------------------------------------- |
||
1340 | ; |
||
321 | diamond | 1341 | ; fs_RamdiskRewrite - LFN variant for writing ramdisk |
1342 | ; fs_RamdiskCreateFolder - create folder on ramdisk |
||
83 | diamond | 1343 | ; |
321 | diamond | 1344 | ; esi points to file/folder name |
83 | diamond | 1345 | ; ebx ignored (reserved) |
321 | diamond | 1346 | ; ecx number of bytes to write, 0+ (ignored for folders) |
1347 | ; edx mem location to data (ignored for folders) |
||
83 | diamond | 1348 | ; |
1349 | ; ret ebx = number of written bytes |
||
1350 | ; eax = 0 ok read or other = errormsg |
||
1351 | ; |
||
1352 | ;-------------------------------------------------------------- |
||
1353 | @@: |
||
766 | Rus | 1354 | mov eax, ERROR_ACCESS_DENIED |
1355 | xor ebx, ebx |
||
1356 | ret |
||
83 | diamond | 1357 | |
321 | diamond | 1358 | fs_RamdiskCreateFolder: |
766 | Rus | 1359 | mov al, 1 ; create folder |
1360 | jmp fs_RamdiskRewrite.common |
||
321 | diamond | 1361 | |
83 | diamond | 1362 | fs_RamdiskRewrite: |
766 | Rus | 1363 | xor eax, eax ; create file |
321 | diamond | 1364 | .common: |
766 | Rus | 1365 | cmp byte [esi], 0 |
1366 | jz @b |
||
1367 | pushad |
||
1368 | xor edi, edi |
||
1369 | push esi |
||
1370 | test ebp, ebp |
||
1371 | jz @f |
||
1372 | mov esi, ebp |
||
83 | diamond | 1373 | @@: |
766 | Rus | 1374 | lodsb |
1375 | test al, al |
||
1376 | jz @f |
||
1377 | cmp al, '/' |
||
1378 | jnz @b |
||
1379 | lea edi, [esi-1] |
||
1380 | jmp @b |
||
91 | diamond | 1381 | @@: |
766 | Rus | 1382 | pop esi |
1383 | test edi, edi |
||
1384 | jnz .noroot |
||
1385 | test ebp, ebp |
||
1386 | jnz .hasebp |
||
1387 | push ramdisk_root_extend_dir |
||
1388 | push ramdisk_root_next_write |
||
1389 | push edi |
||
1390 | push ramdisk_root_first |
||
1391 | push ramdisk_root_next |
||
1392 | jmp .common1 |
||
521 | diamond | 1393 | .hasebp: |
766 | Rus | 1394 | mov eax, ERROR_ACCESS_DENIED |
1395 | cmp byte [ebp], 0 |
||
1396 | jz .ret1 |
||
1397 | push ebp |
||
1398 | xor ebp, ebp |
||
1399 | call rd_find_lfn |
||
1400 | pop esi |
||
1401 | jc .notfound0 |
||
1402 | jmp .common0 |
||
91 | diamond | 1403 | .noroot: |
766 | Rus | 1404 | mov eax, ERROR_ACCESS_DENIED |
1405 | cmp byte [edi+1], 0 |
||
1406 | jz .ret1 |
||
91 | diamond | 1407 | ; check existence |
766 | Rus | 1408 | mov byte [edi], 0 |
1409 | push edi |
||
1410 | call rd_find_lfn |
||
1411 | pop esi |
||
1412 | mov byte [esi], '/' |
||
1413 | jnc @f |
||
521 | diamond | 1414 | .notfound0: |
766 | Rus | 1415 | mov eax, ERROR_FILE_NOT_FOUND |
91 | diamond | 1416 | .ret1: |
766 | Rus | 1417 | mov [esp+28], eax |
1418 | popad |
||
1419 | xor ebx, ebx |
||
1420 | ret |
||
83 | diamond | 1421 | @@: |
766 | Rus | 1422 | inc esi |
521 | diamond | 1423 | .common0: |
766 | Rus | 1424 | test byte [edi+11], 0x10 ; must be directory |
1425 | mov eax, ERROR_ACCESS_DENIED |
||
1426 | jz .ret1 |
||
1427 | movzx ebp, word [edi+26] ; ebp=cluster |
||
1428 | mov eax, ERROR_FAT_TABLE |
||
1429 | cmp ebp, 2 |
||
1430 | jb .ret1 |
||
1431 | cmp ebp, 2849 |
||
1432 | jae .ret1 |
||
1433 | push ramdisk_notroot_extend_dir |
||
1434 | push ramdisk_notroot_next_write |
||
1435 | push ebp |
||
1436 | push ramdisk_notroot_first |
||
1437 | push ramdisk_notroot_next |
||
91 | diamond | 1438 | .common1: |
766 | Rus | 1439 | call fat_find_lfn |
1440 | jc .notfound |
||
321 | diamond | 1441 | ; found |
766 | Rus | 1442 | test byte [edi+11], 10h |
1443 | jz .exists_file |
||
321 | diamond | 1444 | ; found directory; if we are creating directory, return OK, |
1445 | ; if we are creating file, say "access denied" |
||
766 | Rus | 1446 | add esp, 20 |
1447 | popad |
||
1448 | test al, al |
||
1449 | mov eax, ERROR_ACCESS_DENIED |
||
1450 | jz @f |
||
1451 | mov al, 0 |
||
321 | diamond | 1452 | @@: |
766 | Rus | 1453 | xor ebx, ebx |
1454 | ret |
||
321 | diamond | 1455 | .exists_file: |
1456 | ; found file; if we are creating directory, return "access denied", |
||
1457 | ; if we are creating file, delete existing file and continue |
||
766 | Rus | 1458 | cmp byte [esp+20+28], 0 |
1459 | jz @f |
||
1460 | add esp, 20 |
||
1461 | popad |
||
1462 | mov eax, ERROR_ACCESS_DENIED |
||
1463 | xor ebx, ebx |
||
1464 | ret |
||
91 | diamond | 1465 | @@: |
1466 | ; delete FAT chain |
||
766 | Rus | 1467 | push edi |
1468 | xor eax, eax |
||
1469 | mov dword [edi+28], eax ; zero size |
||
1470 | xchg ax, word [edi+26] ; start cluster |
||
1471 | test eax, eax |
||
1472 | jz .done1 |
||
83 | diamond | 1473 | @@: |
766 | Rus | 1474 | cmp eax, 0xFF8 |
1475 | jae .done1 |
||
1476 | lea edi, [RAMDISK_FAT + eax*2] ; position in FAT |
||
1477 | xor eax, eax |
||
1478 | xchg ax, [edi] |
||
1479 | jmp @b |
||
83 | diamond | 1480 | .done1: |
766 | Rus | 1481 | pop edi |
1482 | call get_time_for_file |
||
1483 | mov [edi+22], ax |
||
1484 | call get_date_for_file |
||
1485 | mov [edi+24], ax |
||
1486 | mov [edi+18], ax |
||
1487 | or byte [edi+11], 20h ; set 'archive' attribute |
||
1488 | jmp .doit |
||
83 | diamond | 1489 | .notfound: |
1490 | ; file is not found; generate short name |
||
766 | Rus | 1491 | call fat_name_is_legal |
1492 | jc @f |
||
1493 | add esp, 20 |
||
1494 | popad |
||
1495 | mov eax, ERROR_FILE_NOT_FOUND |
||
1496 | xor ebx, ebx |
||
1497 | ret |
||
83 | diamond | 1498 | @@: |
766 | Rus | 1499 | sub esp, 12 |
1500 | mov edi, esp |
||
1501 | call fat_gen_short_name |
||
83 | diamond | 1502 | .test_short_name_loop: |
766 | Rus | 1503 | push esi edi ecx |
1504 | mov esi, edi |
||
1505 | lea eax, [esp+12+12+8] |
||
1506 | mov [eax], ebp |
||
1507 | call dword [eax-4] |
||
1508 | jc .found |
||
83 | diamond | 1509 | .test_short_name_entry: |
766 | Rus | 1510 | cmp byte [edi+11], 0xF |
1511 | jz .test_short_name_cont |
||
1512 | mov ecx, 11 |
||
1513 | push esi edi |
||
1514 | repz cmpsb |
||
1515 | pop edi esi |
||
1516 | jz .short_name_found |
||
83 | diamond | 1517 | .test_short_name_cont: |
766 | Rus | 1518 | lea eax, [esp+12+12+8] |
1519 | call dword [eax-8] |
||
1520 | jnc .test_short_name_entry |
||
1521 | jmp .found |
||
83 | diamond | 1522 | .short_name_found: |
766 | Rus | 1523 | pop ecx edi esi |
1524 | call fat_next_short_name |
||
1525 | jnc .test_short_name_loop |
||
83 | diamond | 1526 | .disk_full: |
766 | Rus | 1527 | add esp, 12+20 |
1528 | popad |
||
1529 | mov eax, ERROR_DISK_FULL |
||
1530 | xor ebx, ebx |
||
1531 | ret |
||
83 | diamond | 1532 | .found: |
766 | Rus | 1533 | pop ecx edi esi |
83 | diamond | 1534 | ; now find space in directory |
1535 | ; we need to save LFN <=> LFN is not equal to short name <=> generated name contains '~' |
||
766 | Rus | 1536 | mov al, '~' |
1537 | push ecx edi |
||
1538 | mov ecx, 8 |
||
1539 | repnz scasb |
||
1540 | push 1 |
||
1541 | pop eax ; 1 entry |
||
1542 | jnz .notilde |
||
83 | diamond | 1543 | ; we need ceil(strlen(esi)/13) additional entries = floor((strlen(esi)+12+13)/13) total |
766 | Rus | 1544 | xor eax, eax |
83 | diamond | 1545 | @@: |
766 | Rus | 1546 | cmp byte [esi], 0 |
1547 | jz @f |
||
1548 | inc esi |
||
1549 | inc eax |
||
1550 | jmp @b |
||
83 | diamond | 1551 | @@: |
766 | Rus | 1552 | sub esi, eax |
1553 | add eax, 12+13 |
||
1554 | mov ecx, 13 |
||
1555 | push edx |
||
1556 | cdq |
||
1557 | div ecx |
||
1558 | pop edx |
||
83 | diamond | 1559 | .notilde: |
766 | Rus | 1560 | push -1 |
1561 | push -1 |
||
83 | diamond | 1562 | ; find |
766 | Rus | 1563 | xor ecx, ecx |
1564 | push eax |
||
1565 | lea eax, [esp+12+8+12+8] |
||
1566 | mov [eax], ebp |
||
1567 | call dword [eax-4] |
||
1568 | pop eax |
||
83 | diamond | 1569 | .scan_dir: |
766 | Rus | 1570 | cmp byte [edi], 0 |
1571 | jz .free |
||
1572 | cmp byte [edi], 0xE5 |
||
1573 | jz .free |
||
1574 | xor ecx, ecx |
||
83 | diamond | 1575 | .scan_cont: |
766 | Rus | 1576 | push eax |
1577 | lea eax, [esp+12+8+12+8] |
||
1578 | call dword [eax-8] |
||
1579 | pop eax |
||
1580 | jnc .scan_dir |
||
1581 | push eax |
||
1582 | lea eax, [esp+12+8+12+8] |
||
1583 | call dword [eax+8] ; extend directory |
||
1584 | pop eax |
||
1585 | jnc .scan_dir |
||
1586 | add esp, 8+8+12+20 |
||
1587 | popad |
||
1588 | mov eax, ERROR_DISK_FULL |
||
1589 | xor ebx, ebx |
||
1590 | ret |
||
83 | diamond | 1591 | .free: |
766 | Rus | 1592 | test ecx, ecx |
1593 | jnz @f |
||
1594 | mov [esp], edi |
||
1595 | mov ecx, [esp+8+8+12+8] |
||
1596 | mov [esp+4], ecx |
||
1597 | xor ecx, ecx |
||
91 | diamond | 1598 | @@: |
766 | Rus | 1599 | inc ecx |
1600 | cmp ecx, eax |
||
1601 | jb .scan_cont |
||
83 | diamond | 1602 | ; found! |
1603 | ; calculate name checksum |
||
766 | Rus | 1604 | push esi ecx |
1605 | mov esi, [esp+8+8] |
||
1606 | mov ecx, 11 |
||
1607 | xor eax, eax |
||
83 | diamond | 1608 | @@: |
766 | Rus | 1609 | ror al, 1 |
1610 | add al, [esi] |
||
1611 | inc esi |
||
1612 | loop @b |
||
1613 | pop ecx esi |
||
1614 | pop edi |
||
1615 | pop dword [esp+8+12+8] |
||
83 | diamond | 1616 | ; edi points to last entry in free chunk |
766 | Rus | 1617 | dec ecx |
1618 | jz .nolfn |
||
1619 | push esi |
||
1620 | push eax |
||
1621 | mov al, 40h |
||
83 | diamond | 1622 | .writelfn: |
766 | Rus | 1623 | or al, cl |
1624 | mov esi, [esp+4] |
||
1625 | push ecx |
||
1626 | dec ecx |
||
1627 | imul ecx, 13 |
||
1628 | add esi, ecx |
||
1629 | stosb |
||
1630 | mov cl, 5 |
||
1631 | call .read_symbols |
||
1632 | mov ax, 0xF |
||
1633 | stosw |
||
1634 | mov al, [esp+4] |
||
1635 | stosb |
||
1636 | mov cl, 6 |
||
1637 | call .read_symbols |
||
1638 | xor eax, eax |
||
1639 | stosw |
||
1640 | mov cl, 2 |
||
1641 | call .read_symbols |
||
1642 | pop ecx |
||
1643 | lea eax, [esp+8+8+12+8] |
||
1644 | call dword [eax+4] ; next write |
||
1645 | xor eax, eax |
||
1646 | loop .writelfn |
||
1647 | pop eax |
||
1648 | pop esi |
||
83 | diamond | 1649 | .nolfn: |
766 | Rus | 1650 | xchg esi, [esp] |
1651 | mov ecx, 11 |
||
1652 | rep movsb |
||
1653 | mov word [edi], 20h ; attributes |
||
1654 | sub edi, 11 |
||
1655 | pop esi ecx |
||
1656 | add esp, 12 |
||
1657 | mov byte [edi+13], 0 ; tenths of a second at file creation time |
||
1658 | call get_time_for_file |
||
1659 | mov [edi+14], ax ; creation time |
||
1660 | mov [edi+22], ax ; last write time |
||
1661 | call get_date_for_file |
||
1662 | mov [edi+16], ax ; creation date |
||
1663 | mov [edi+24], ax ; last write date |
||
1664 | mov [edi+18], ax ; last access date |
||
1665 | and word [edi+20], 0 ; high word of cluster |
||
1666 | and word [edi+26], 0 ; low word of cluster - to be filled |
||
1667 | and dword [edi+28], 0 ; file size - to be filled |
||
1668 | cmp byte [esp+20+28], 0 |
||
1669 | jz .doit |
||
321 | diamond | 1670 | ; create directory |
766 | Rus | 1671 | mov byte [edi+11], 10h ; attributes: folder |
1672 | mov ecx, 32*2 |
||
1673 | mov edx, edi |
||
83 | diamond | 1674 | .doit: |
766 | Rus | 1675 | push edx |
1676 | push ecx |
||
1677 | push edi |
||
1678 | add edi, 26 ; edi points to low word of cluster |
||
1679 | push edi |
||
1680 | jecxz .done |
||
1681 | mov ecx, 2849 |
||
1682 | mov edi, RAMDISK_FAT |
||
83 | diamond | 1683 | .write_loop: |
1684 | ; allocate new cluster |
||
766 | Rus | 1685 | xor eax, eax |
1686 | repnz scasw |
||
1687 | jnz .disk_full2 |
||
1688 | dec edi |
||
1689 | dec edi |
||
465 | serge | 1690 | |
1691 | ; lea eax, [edi-(RAMDISK_FAT)] |
||
1692 | |||
766 | Rus | 1693 | mov eax, edi |
1694 | sub eax, RAMDISK_FAT |
||
465 | serge | 1695 | |
766 | Rus | 1696 | shr eax, 1 ; eax = cluster |
1697 | mov word [edi], 0xFFF ; mark as last cluster |
||
1698 | xchg edi, [esp] |
||
1699 | stosw |
||
1700 | pop edi |
||
1701 | push edi |
||
1702 | inc ecx |
||
83 | diamond | 1703 | ; write data |
766 | Rus | 1704 | cmp byte [esp+16+20+28], 0 |
1705 | jnz .writedir |
||
1706 | shl eax, 9 |
||
1707 | add eax, RAMDISK+31*512 |
||
321 | diamond | 1708 | .writefile: |
766 | Rus | 1709 | mov ebx, edx |
1710 | xchg eax, ebx |
||
1711 | push ecx |
||
1712 | mov ecx, 512 |
||
1713 | cmp dword [esp+12], ecx |
||
1714 | jae @f |
||
1715 | mov ecx, [esp+12] |
||
83 | diamond | 1716 | @@: |
766 | Rus | 1717 | call memmove |
1718 | add edx, ecx |
||
1719 | sub [esp+12], ecx |
||
1720 | pop ecx |
||
1721 | jnz .write_loop |
||
83 | diamond | 1722 | .done: |
766 | Rus | 1723 | mov ebx, edx |
1724 | pop edi edi ecx edx |
||
1725 | sub ebx, edx |
||
1726 | mov [edi+28], ebx |
||
1727 | add esp, 20 |
||
1728 | mov [esp+16], ebx |
||
1729 | popad |
||
1730 | xor eax, eax |
||
1731 | ret |
||
83 | diamond | 1732 | .disk_full2: |
766 | Rus | 1733 | mov ebx, edx |
1734 | pop edi edi ecx edx |
||
1735 | sub ebx, edx |
||
1736 | mov [edi+28], ebx |
||
1737 | add esp, 20 |
||
1738 | mov [esp+16], ebx |
||
1739 | popad |
||
1740 | push ERROR_DISK_FULL |
||
1741 | pop eax |
||
1742 | ret |
||
321 | diamond | 1743 | .writedir: |
766 | Rus | 1744 | mov edi, eax |
1745 | shl edi, 9 |
||
1746 | add edi, RAMDISK+31*512 |
||
1747 | mov esi, edx |
||
1748 | mov ecx, 32/4 |
||
1749 | push ecx |
||
1750 | rep movsd |
||
1751 | mov dword [edi-32], '. ' |
||
1752 | mov dword [edi-32+4], ' ' |
||
1753 | mov dword [edi-32+8], ' ' |
||
1754 | mov byte [edi-32+11], 10h |
||
1755 | mov word [edi-32+26], ax |
||
1756 | mov esi, edx |
||
1757 | pop ecx |
||
1758 | rep movsd |
||
1759 | mov dword [edi-32], '.. ' |
||
1760 | mov dword [edi-32+4], ' ' |
||
1761 | mov dword [edi-32+8], ' ' |
||
1762 | mov byte [edi-32+11], 10h |
||
1763 | mov eax, [esp+16+8] |
||
1764 | mov word [edi-32+26], ax |
||
1765 | xor eax, eax |
||
1766 | mov ecx, (512-32*2)/4 |
||
1767 | rep stosd |
||
1768 | pop edi edi ecx edx |
||
1769 | add esp, 20 |
||
1770 | popad |
||
1771 | xor eax, eax |
||
1772 | xor ebx, ebx |
||
1773 | ret |
||
83 | diamond | 1774 | |
1775 | .read_symbol: |
||
766 | Rus | 1776 | or ax, -1 |
1777 | test esi, esi |
||
1778 | jz .retFFFF |
||
1779 | lodsb |
||
1780 | test al, al |
||
1781 | jnz ansi2uni_char |
||
1782 | xor eax, eax |
||
1783 | xor esi, esi |
||
83 | diamond | 1784 | .retFFFF: |
766 | Rus | 1785 | ret |
83 | diamond | 1786 | |
1787 | .read_symbols: |
||
766 | Rus | 1788 | call .read_symbol |
1789 | stosw |
||
1790 | loop .read_symbols |
||
1791 | ret |
||
83 | diamond | 1792 | |
131 | diamond | 1793 | ;---------------------------------------------------------------- |
1794 | ; |
||
1795 | ; fs_RamdiskWrite - LFN variant for writing to sys floppy |
||
1796 | ; |
||
1797 | ; esi points to filename |
||
1798 | ; ebx pointer to 64-bit number = first wanted byte, 0+ |
||
1799 | ; may be ebx=0 - start from first byte |
||
1800 | ; ecx number of bytes to write, 0+ |
||
1801 | ; edx mem location to data |
||
1802 | ; |
||
1803 | ; ret ebx = bytes written (maybe 0) |
||
1804 | ; eax = 0 ok write or other = errormsg |
||
1805 | ; |
||
1806 | ;-------------------------------------------------------------- |
||
1807 | @@: |
||
766 | Rus | 1808 | push ERROR_ACCESS_DENIED |
131 | diamond | 1809 | fs_RamdiskWrite.ret0: |
766 | Rus | 1810 | pop eax |
1811 | xor ebx, ebx |
||
1812 | ret |
||
131 | diamond | 1813 | |
1814 | fs_RamdiskWrite: |
||
766 | Rus | 1815 | cmp byte [esi], 0 |
1816 | jz @b |
||
1817 | pushad |
||
1818 | call rd_find_lfn |
||
1819 | jnc .found |
||
1820 | popad |
||
1821 | push ERROR_FILE_NOT_FOUND |
||
1822 | jmp .ret0 |
||
131 | diamond | 1823 | .found: |
1824 | ; must not be directory |
||
766 | Rus | 1825 | test byte [edi+11], 10h |
1826 | jz @f |
||
1827 | popad |
||
1828 | push ERROR_ACCESS_DENIED |
||
1829 | jmp .ret0 |
||
131 | diamond | 1830 | @@: |
1831 | ; FAT does not support files larger than 4GB |
||
766 | Rus | 1832 | test ebx, ebx |
1833 | jz .l1 |
||
1834 | cmp dword [ebx+4], 0 |
||
1835 | jz @f |
||
131 | diamond | 1836 | .eof: |
766 | Rus | 1837 | popad |
1838 | push ERROR_END_OF_FILE |
||
1839 | jmp .ret0 |
||
131 | diamond | 1840 | @@: |
766 | Rus | 1841 | mov ebx, [ebx] |
131 | diamond | 1842 | .l1: |
1843 | ; now edi points to direntry, ebx=start byte to write, |
||
1844 | ; ecx=number of bytes to write, edx=data pointer |
||
766 | Rus | 1845 | call fat_update_datetime |
131 | diamond | 1846 | |
1847 | ; extend file if needed |
||
766 | Rus | 1848 | add ecx, ebx |
1849 | jc .eof ; FAT does not support files larger than 4GB |
||
1850 | push 0 ; return value=0 |
||
1851 | cmp ecx, [edi+28] |
||
1852 | jbe .length_ok |
||
1853 | cmp ecx, ebx |
||
1854 | jz .length_ok |
||
1855 | call ramdisk_extend_file |
||
1856 | jnc .length_ok |
||
131 | diamond | 1857 | ; ramdisk_extend_file can return two error codes: FAT table error or disk full. |
1858 | ; First case is fatal error, in second case we may write some data |
||
766 | Rus | 1859 | mov [esp], eax |
1860 | cmp al, ERROR_DISK_FULL |
||
1861 | jz .disk_full |
||
1862 | pop eax |
||
1863 | mov [esp+28], eax |
||
1864 | popad |
||
1865 | xor ebx, ebx |
||
1866 | ret |
||
131 | diamond | 1867 | .disk_full: |
1868 | ; correct number of bytes to write |
||
766 | Rus | 1869 | mov ecx, [edi+28] |
1870 | cmp ecx, ebx |
||
1871 | ja .length_ok |
||
131 | diamond | 1872 | .ret: |
766 | Rus | 1873 | pop eax |
1874 | mov [esp+28], eax ; eax=return value |
||
1875 | sub edx, [esp+20] |
||
1876 | mov [esp+16], edx ; ebx=number of written bytes |
||
1877 | popad |
||
1878 | ret |
||
131 | diamond | 1879 | .length_ok: |
1880 | ; now ebx=start pos, ecx=end pos, both lie inside file |
||
766 | Rus | 1881 | sub ecx, ebx |
1882 | jz .ret |
||
1883 | movzx edi, word [edi+26] ; starting cluster |
||
131 | diamond | 1884 | .write_loop: |
766 | Rus | 1885 | sub ebx, 0x200 |
1886 | jae .next_cluster |
||
1887 | push ecx |
||
1888 | neg ebx |
||
1889 | cmp ecx, ebx |
||
1890 | jbe @f |
||
1891 | mov ecx, ebx |
||
131 | diamond | 1892 | @@: |
766 | Rus | 1893 | mov eax, edi |
1894 | shl eax, 9 |
||
1895 | add eax, RAMDISK+31*512+0x200 |
||
1896 | sub eax, ebx |
||
1897 | mov ebx, eax |
||
1898 | mov eax, edx |
||
1899 | call memmove |
||
1900 | xor ebx, ebx |
||
1901 | add edx, ecx |
||
1902 | sub [esp], ecx |
||
1903 | pop ecx |
||
1904 | jz .ret |
||
131 | diamond | 1905 | .next_cluster: |
766 | Rus | 1906 | movzx edi, word [edi*2+RAMDISK_FAT] |
1907 | jmp .write_loop |
||
131 | diamond | 1908 | |
1909 | ramdisk_extend_file.zero_size: |
||
766 | Rus | 1910 | xor eax, eax |
1911 | jmp ramdisk_extend_file.start_extend |
||
131 | diamond | 1912 | |
1913 | ; extends file on ramdisk to given size, new data area is filled by 0 |
||
1914 | ; in: edi->direntry, ecx=new size |
||
133 | diamond | 1915 | ; out: CF=0 => OK, eax=0 |
131 | diamond | 1916 | ; CF=1 => error, eax=code (ERROR_FAT_TABLE or ERROR_DISK_FULL) |
1917 | ramdisk_extend_file: |
||
766 | Rus | 1918 | push ecx |
131 | diamond | 1919 | ; find the last cluster of file |
766 | Rus | 1920 | movzx eax, word [edi+26] ; first cluster |
1921 | mov ecx, [edi+28] |
||
1922 | jecxz .zero_size |
||
131 | diamond | 1923 | @@: |
766 | Rus | 1924 | sub ecx, 0x200 |
1925 | jbe @f |
||
1926 | mov eax, [eax*2+RAMDISK_FAT] |
||
1927 | and eax, 0xFFF |
||
1928 | jz .fat_err |
||
1929 | cmp eax, 0xFF8 |
||
1930 | jb @b |
||
131 | diamond | 1931 | .fat_err: |
766 | Rus | 1932 | pop ecx |
1933 | push ERROR_FAT_TABLE |
||
1934 | pop eax |
||
1935 | stc |
||
1936 | ret |
||
131 | diamond | 1937 | @@: |
766 | Rus | 1938 | push eax |
1939 | mov eax, [eax*2+RAMDISK_FAT] |
||
1940 | and eax, 0xFFF |
||
1941 | cmp eax, 0xFF8 |
||
1942 | pop eax |
||
1943 | jb .fat_err |
||
131 | diamond | 1944 | ; set length to full number of sectors and make sure that last sector is zero-padded |
766 | Rus | 1945 | sub [edi+28], ecx |
1946 | push eax edi |
||
1947 | mov edi, eax |
||
1948 | shl edi, 9 |
||
1949 | lea edi, [edi+RAMDISK+31*512+0x200+ecx] |
||
1950 | neg ecx |
||
1951 | xor eax, eax |
||
1952 | rep stosb |
||
1953 | pop edi eax |
||
131 | diamond | 1954 | .start_extend: |
766 | Rus | 1955 | pop ecx |
131 | diamond | 1956 | ; now do extend |
766 | Rus | 1957 | push edx esi |
1958 | mov esi, RAMDISK_FAT+2*2 ; start scan from cluster 2 |
||
1959 | mov edx, 2847 ; number of clusters to scan |
||
131 | diamond | 1960 | .extend_loop: |
766 | Rus | 1961 | cmp [edi+28], ecx |
1962 | jae .extend_done |
||
131 | diamond | 1963 | ; add new sector |
766 | Rus | 1964 | push ecx |
1965 | mov ecx, edx |
||
1966 | push edi |
||
1967 | mov edi, esi |
||
1968 | jecxz .disk_full |
||
1969 | push eax |
||
1970 | xor eax, eax |
||
1971 | repnz scasw |
||
1972 | pop eax |
||
1973 | jnz .disk_full |
||
1974 | mov word [edi-2], 0xFFF |
||
1975 | mov esi, edi |
||
1976 | mov edx, ecx |
||
1977 | sub edi, RAMDISK_FAT |
||
1978 | shr edi, 1 |
||
1979 | dec edi ; now edi=new cluster |
||
1980 | test eax, eax |
||
1981 | jz .first_cluster |
||
1982 | mov [RAMDISK_FAT+eax*2], di |
||
1983 | jmp @f |
||
131 | diamond | 1984 | .first_cluster: |
766 | Rus | 1985 | pop eax ; eax->direntry |
1986 | push eax |
||
1987 | mov [eax+26], di |
||
131 | diamond | 1988 | @@: |
766 | Rus | 1989 | push edi |
1990 | shl edi, 9 |
||
1991 | add edi, RAMDISK+31*512 |
||
1992 | xor eax, eax |
||
1993 | mov ecx, 512/4 |
||
1994 | rep stosd |
||
1995 | pop eax ; eax=new cluster |
||
1996 | pop edi ; edi->direntry |
||
1997 | pop ecx ; ecx=required size |
||
1998 | add dword [edi+28], 0x200 |
||
1999 | jmp .extend_loop |
||
131 | diamond | 2000 | .extend_done: |
766 | Rus | 2001 | mov [edi+28], ecx |
2002 | pop esi edx |
||
2003 | xor eax, eax ; CF=0 |
||
2004 | ret |
||
131 | diamond | 2005 | .disk_full: |
766 | Rus | 2006 | pop edi ecx |
2007 | pop esi edx |
||
2008 | stc |
||
2009 | push ERROR_DISK_FULL |
||
2010 | pop eax |
||
2011 | ret |
||
131 | diamond | 2012 | |
133 | diamond | 2013 | fat_update_datetime: |
766 | Rus | 2014 | call get_time_for_file |
2015 | mov [edi+22], ax ; last write time |
||
2016 | call get_date_for_file |
||
2017 | mov [edi+24], ax ; last write date |
||
2018 | mov [edi+18], ax ; last access date |
||
2019 | ret |
||
133 | diamond | 2020 | |
2021 | ;---------------------------------------------------------------- |
||
2022 | ; |
||
2023 | ; fs_RamdiskSetFileEnd - set end of file on ramdisk |
||
2024 | ; |
||
2025 | ; esi points to filename |
||
2026 | ; ebx points to 64-bit number = new file size |
||
2027 | ; ecx ignored (reserved) |
||
2028 | ; edx ignored (reserved) |
||
2029 | ; |
||
2030 | ; ret eax = 0 ok or other = errormsg |
||
2031 | ; |
||
2032 | ;-------------------------------------------------------------- |
||
2033 | fs_RamdiskSetFileEnd: |
||
766 | Rus | 2034 | cmp byte [esi], 0 |
2035 | jnz @f |
||
133 | diamond | 2036 | .access_denied: |
766 | Rus | 2037 | push ERROR_ACCESS_DENIED |
2038 | jmp .ret |
||
133 | diamond | 2039 | @@: |
766 | Rus | 2040 | push edi |
2041 | call rd_find_lfn |
||
2042 | jnc @f |
||
2043 | pop edi |
||
2044 | push ERROR_FILE_NOT_FOUND |
||
133 | diamond | 2045 | .ret: |
766 | Rus | 2046 | pop eax |
2047 | ret |
||
133 | diamond | 2048 | @@: |
2049 | ; must not be directory |
||
766 | Rus | 2050 | test byte [edi+11], 10h |
2051 | jz @f |
||
2052 | pop edi |
||
2053 | jmp .access_denied |
||
133 | diamond | 2054 | @@: |
2055 | ; file size must not exceed 4Gb |
||
766 | Rus | 2056 | cmp dword [ebx+4], 0 |
2057 | jz @f |
||
2058 | pop edi |
||
2059 | push ERROR_END_OF_FILE |
||
2060 | jmp .ret |
||
133 | diamond | 2061 | @@: |
2062 | ; set file modification date/time to current |
||
766 | Rus | 2063 | call fat_update_datetime |
2064 | mov eax, [ebx] |
||
2065 | cmp eax, [edi+28] |
||
2066 | jb .truncate |
||
2067 | ja .expand |
||
2068 | pop edi |
||
2069 | xor eax, eax |
||
2070 | ret |
||
133 | diamond | 2071 | .expand: |
766 | Rus | 2072 | push ecx |
2073 | mov ecx, eax |
||
2074 | call ramdisk_extend_file |
||
2075 | pop ecx |
||
2076 | pop edi |
||
2077 | ret |
||
133 | diamond | 2078 | .truncate: |
766 | Rus | 2079 | mov [edi+28], eax |
2080 | push ecx |
||
2081 | movzx ecx, word [edi+26] |
||
2082 | test eax, eax |
||
2083 | jz .zero_size |
||
133 | diamond | 2084 | ; find new last sector |
2085 | @@: |
||
766 | Rus | 2086 | sub eax, 0x200 |
2087 | jbe @f |
||
2088 | movzx ecx, word [RAMDISK_FAT+ecx*2] |
||
2089 | jmp @b |
||
133 | diamond | 2090 | @@: |
2091 | ; zero data at the end of last sector |
||
766 | Rus | 2092 | push ecx |
2093 | mov edi, ecx |
||
2094 | shl edi, 9 |
||
2095 | lea edi, [edi+RAMDISK+31*512+eax+0x200] |
||
2096 | mov ecx, eax |
||
2097 | neg ecx |
||
2098 | xor eax, eax |
||
2099 | rep stosb |
||
2100 | pop ecx |
||
133 | diamond | 2101 | ; terminate FAT chain |
766 | Rus | 2102 | lea ecx, [RAMDISK_FAT+ecx+ecx] |
2103 | push dword [ecx] |
||
2104 | mov word [ecx], 0xFFF |
||
2105 | pop ecx |
||
2106 | and ecx, 0xFFF |
||
2107 | jmp .delete |
||
133 | diamond | 2108 | .zero_size: |
766 | Rus | 2109 | and word [edi+26], 0 |
133 | diamond | 2110 | .delete: |
2111 | ; delete FAT chain starting with ecx |
||
2112 | ; mark all clusters as free |
||
766 | Rus | 2113 | cmp ecx, 0xFF8 |
2114 | jae .deleted |
||
2115 | lea ecx, [RAMDISK_FAT+ecx+ecx] |
||
2116 | push dword [ecx] |
||
2117 | and word [ecx], 0 |
||
2118 | pop ecx |
||
2119 | and ecx, 0xFFF |
||
2120 | jmp .delete |
||
133 | diamond | 2121 | .deleted: |
766 | Rus | 2122 | pop ecx |
2123 | pop edi |
||
2124 | xor eax, eax |
||
2125 | ret |
||
133 | diamond | 2126 | |
86 | diamond | 2127 | fs_RamdiskGetFileInfo: |
766 | Rus | 2128 | cmp byte [esi], 0 |
2129 | jnz @f |
||
2130 | mov eax, 2 ; unsupported |
||
2131 | ret |
||
86 | diamond | 2132 | @@: |
766 | Rus | 2133 | push edi |
2134 | call rd_find_lfn |
||
86 | diamond | 2135 | fs_GetFileInfo_finish: |
766 | Rus | 2136 | jnc @f |
2137 | pop edi |
||
2138 | mov eax, ERROR_FILE_NOT_FOUND |
||
2139 | ret |
||
86 | diamond | 2140 | @@: |
766 | Rus | 2141 | push esi ebp |
2142 | xor ebp, ebp |
||
2143 | mov esi, edx |
||
2144 | and dword [esi+4], 0 |
||
2145 | call fat_entry_to_bdfe2 |
||
2146 | pop ebp esi |
||
2147 | pop edi |
||
2148 | xor eax, eax |
||
2149 | ret |
||
86 | diamond | 2150 | |
2151 | fs_RamdiskSetFileInfo: |
||
766 | Rus | 2152 | cmp byte [esi], 0 |
2153 | jnz @f |
||
2154 | mov eax, 2 ; unsupported |
||
2155 | ret |
||
86 | diamond | 2156 | @@: |
766 | Rus | 2157 | push edi |
2158 | call rd_find_lfn |
||
2159 | jnc @f |
||
2160 | pop edi |
||
2161 | mov eax, ERROR_FILE_NOT_FOUND |
||
2162 | ret |
||
86 | diamond | 2163 | @@: |
766 | Rus | 2164 | call bdfe_to_fat_entry |
2165 | pop edi |
||
2166 | xor eax, eax |
||
2167 | ret |
||
86 | diamond | 2168 | |
91 | diamond | 2169 | ;---------------------------------------------------------------- |
2170 | ; |
||
171 | diamond | 2171 | ; fs_RamdiskDelete - delete file or empty folder from ramdisk |
2172 | ; |
||
2173 | ; esi points to filename |
||
2174 | ; |
||
2175 | ; ret eax = 0 ok or other = errormsg |
||
2176 | ; |
||
2177 | ;-------------------------------------------------------------- |
||
2178 | fs_RamdiskDelete: |
||
766 | Rus | 2179 | cmp byte [esi], 0 |
2180 | jnz @f |
||
171 | diamond | 2181 | ; cannot delete root! |
2182 | .access_denied: |
||
766 | Rus | 2183 | push ERROR_ACCESS_DENIED |
171 | diamond | 2184 | .pop_ret: |
766 | Rus | 2185 | pop eax |
2186 | ret |
||
171 | diamond | 2187 | @@: |
766 | Rus | 2188 | and [rd_prev_sector], 0 |
2189 | and [rd_prev_prev_sector], 0 |
||
2190 | push edi |
||
2191 | call rd_find_lfn |
||
2192 | jnc .found |
||
2193 | pop edi |
||
2194 | push ERROR_FILE_NOT_FOUND |
||
2195 | jmp .pop_ret |
||
171 | diamond | 2196 | .found: |
766 | Rus | 2197 | cmp dword [edi], '. ' |
2198 | jz .access_denied2 |
||
2199 | cmp dword [edi], '.. ' |
||
2200 | jz .access_denied2 |
||
2201 | test byte [edi+11], 10h |
||
2202 | jz .dodel |
||
171 | diamond | 2203 | ; we can delete only empty folders! |
766 | Rus | 2204 | movzx eax, word [edi+26] |
2205 | push ebx |
||
2206 | mov ebx, eax |
||
2207 | shl ebx, 9 |
||
2208 | add ebx, RAMDISK + 31*0x200 + 2*0x20 |
||
171 | diamond | 2209 | .checkempty: |
766 | Rus | 2210 | cmp byte [ebx], 0 |
2211 | jz .empty |
||
2212 | cmp byte [ebx], 0xE5 |
||
2213 | jnz .notempty |
||
2214 | add ebx, 0x20 |
||
2215 | test ebx, 0x1FF |
||
2216 | jnz .checkempty |
||
2217 | movzx eax, word [RAMDISK_FAT + eax*2] |
||
2218 | test eax, eax |
||
2219 | jz .empty |
||
2220 | mov ebx, eax |
||
2221 | shl ebx, 9 |
||
2222 | add ebx, RAMDISK + 31*0x200 |
||
2223 | jmp .checkempty |
||
171 | diamond | 2224 | .notempty: |
766 | Rus | 2225 | pop ebx |
171 | diamond | 2226 | .access_denied2: |
766 | Rus | 2227 | pop edi |
2228 | jmp .access_denied |
||
171 | diamond | 2229 | .empty: |
766 | Rus | 2230 | pop ebx |
171 | diamond | 2231 | .dodel: |
766 | Rus | 2232 | movzx eax, word [edi+26] |
171 | diamond | 2233 | ; delete folder entry |
766 | Rus | 2234 | mov byte [edi], 0xE5 |
171 | diamond | 2235 | ; delete LFN (if present) |
2236 | .lfndel: |
||
766 | Rus | 2237 | test edi, 0x1FF |
2238 | jnz @f |
||
2239 | cmp [rd_prev_sector], 0 |
||
2240 | jz @f |
||
2241 | cmp [rd_prev_sector], -1 |
||
2242 | jz .lfndone |
||
2243 | mov edi, [rd_prev_sector] |
||
2244 | push [rd_prev_prev_sector] |
||
2245 | pop [rd_prev_sector] |
||
2246 | or [rd_prev_prev_sector], -1 |
||
2247 | shl edi, 9 |
||
2248 | add edi, RAMDISK + 31*0x200 + 0x200 |
||
171 | diamond | 2249 | @@: |
766 | Rus | 2250 | sub edi, 0x20 |
2251 | cmp byte [edi], 0xE5 |
||
2252 | jz .lfndone |
||
2253 | cmp byte [edi+11], 0xF |
||
2254 | jnz .lfndone |
||
2255 | mov byte [edi], 0xE5 |
||
2256 | jmp .lfndel |
||
171 | diamond | 2257 | .lfndone: |
2258 | ; delete FAT chain |
||
766 | Rus | 2259 | test eax, eax |
2260 | jz .done |
||
2261 | lea eax, [RAMDISK_FAT + eax*2] |
||
2262 | push dword [eax] |
||
2263 | and word [eax], 0 |
||
2264 | pop eax |
||
2265 | and eax, 0xFFF |
||
2266 | jmp .lfndone |
||
171 | diamond | 2267 | .done: |
766 | Rus | 2268 | pop edi |
2269 | xor eax, eax |
||
2270 | ret |
||
171 | diamond | 2271 | |
78 | diamond | 2272 | ; \end{diamond}=>=>=>=>>->-> |