Rev 75 | Rev 83 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
72 | diamond | 1 | ; System function 70 - files with long names (LFN) |
71 | diamond | 2 | ; diamond, 2006 |
3 | |||
4 | iglobal |
||
5 | ; in this table names must be in lowercase |
||
6 | rootdirs: |
||
75 | diamond | 7 | db 2,'rd' |
8 | dd fs_OnRamdisk |
||
9 | dd fs_NextRamdisk |
||
10 | db 7,'ramdisk' |
||
11 | dd fs_OnRamdisk |
||
12 | dd fs_NextRamdisk |
||
13 | db 2,'fd' |
||
14 | dd fs_OnFloppy |
||
15 | dd fs_NextFloppy |
||
16 | db 10,'floppydisk' |
||
17 | dd fs_OnFloppy |
||
18 | dd fs_NextFloppy |
||
19 | db 3,'hd0' |
||
20 | dd fs_OnHd0 |
||
21 | dd fs_NextHd0 |
||
22 | db 3,'hd1' |
||
23 | dd fs_OnHd1 |
||
24 | dd fs_NextHd1 |
||
25 | db 3,'hd2' |
||
26 | dd fs_OnHd2 |
||
27 | dd fs_NextHd2 |
||
28 | db 3,'hd3' |
||
29 | dd fs_OnHd3 |
||
30 | dd fs_NextHd3 |
||
31 | db 0 |
||
32 | |||
33 | virtual_root_query: |
||
34 | dd fs_HasRamdisk |
||
78 | diamond | 35 | db 'rd',0 |
75 | diamond | 36 | dd fs_HasFloppy |
78 | diamond | 37 | db 'fd',0 |
75 | diamond | 38 | dd fs_HasHd0 |
78 | diamond | 39 | db 'hd0',0 |
75 | diamond | 40 | dd fs_HasHd1 |
78 | diamond | 41 | db 'hd1',0 |
75 | diamond | 42 | dd fs_HasHd2 |
78 | diamond | 43 | db 'hd2',0 |
75 | diamond | 44 | dd fs_HasHd3 |
78 | diamond | 45 | db 'hd3',0 |
75 | diamond | 46 | dd 0 |
71 | diamond | 47 | endg |
48 | |||
49 | file_system_lfn: |
||
50 | ; in: eax->fileinfo block |
||
51 | ; operation codes: |
||
72 | diamond | 52 | ; 0 : read file |
75 | diamond | 53 | ; 1 : read folder |
54 | ; 2 : rewrite file - not implemented yet |
||
72 | diamond | 55 | ; 3 : write/append to file - not implemented yet |
75 | diamond | 56 | ; 4 : start application - not implemented yet |
57 | ; 5 : delete file - not implemented yet |
||
58 | ; 6 : create directory - not implemented yet |
||
59 | ; 7 : rename file/directory - not implemented yet |
||
60 | ; 8 : get file attributes structure - not implemented yet |
||
71 | diamond | 61 | |
75 | diamond | 62 | add eax, std_application_base_address |
71 | diamond | 63 | ; parse file name |
75 | diamond | 64 | xchg ebx, eax |
65 | lea esi, [ebx+20] |
||
66 | lodsb |
||
67 | cmp al, '/' |
||
68 | jz @f |
||
71 | diamond | 69 | .notfound: |
75 | diamond | 70 | mov dword [esp+36], 5 ; file not found |
71 | ret |
||
71 | diamond | 72 | @@: |
75 | diamond | 73 | cmp byte [esi], 0 |
74 | jz .rootdir |
||
75 | mov edi, rootdirs-8 |
||
76 | xor ecx, ecx |
||
77 | push esi |
||
71 | diamond | 78 | .scan1: |
75 | diamond | 79 | pop esi |
80 | add edi, ecx |
||
81 | scasd |
||
82 | scasd |
||
83 | mov cl, byte [edi] |
||
84 | jecxz .notfound |
||
85 | inc edi |
||
86 | push esi |
||
71 | diamond | 87 | @@: |
75 | diamond | 88 | lodsb |
89 | or al, 20h |
||
90 | scasb |
||
91 | loopz @b |
||
92 | jnz .scan1 |
||
93 | lodsb |
||
94 | cmp al, '/' |
||
95 | jz .found1 |
||
96 | test al, al |
||
97 | jnz .scan1 |
||
98 | pop eax |
||
71 | diamond | 99 | ; directory /xxx |
100 | .maindir: |
||
75 | diamond | 101 | cmp dword [ebx], 1 |
102 | jnz .access_denied |
||
103 | xor eax, eax |
||
104 | mov ebp, [ebx+12] |
||
105 | mov edx, [ebx+16] |
||
106 | add edx, std_application_base_address |
||
78 | diamond | 107 | push dword [ebx+4] ; first block |
108 | mov ebx, [ebx+8] ; flags |
||
75 | diamond | 109 | mov esi, [edi+4] |
78 | diamond | 110 | ; ebx=flags, [esp]=first block, ebp=number of blocks, edx=return area, esi='Next' handler |
75 | diamond | 111 | mov edi, edx |
112 | mov ecx, 32/4 |
||
113 | rep stosd |
||
114 | mov byte [edx], 1 ; version |
||
115 | .maindir_loop: |
||
116 | call esi |
||
117 | jc .maindir_done |
||
118 | inc dword [edx+8] |
||
78 | diamond | 119 | dec dword [esp] |
75 | diamond | 120 | jns .maindir_loop |
121 | dec ebp |
||
122 | js .maindir_loop |
||
123 | inc dword [edx+4] |
||
124 | mov dword [edi], 0x10 ; attributes: folder |
||
125 | mov dword [edi+4], 1 ; name type: UNICODE |
||
126 | push eax |
||
127 | xor eax, eax |
||
128 | add edi, 8 |
||
129 | mov ecx, 40/4-2 |
||
130 | rep stosd |
||
131 | pop eax |
||
132 | push eax edx |
||
133 | ; convert number in eax to decimal UNICODE string |
||
134 | push edi |
||
135 | push -'0' |
||
136 | mov cl, 10 |
||
137 | @@: |
||
138 | xor edx, edx |
||
139 | div ecx |
||
140 | push edx |
||
141 | test eax, eax |
||
142 | jnz @b |
||
143 | @@: |
||
144 | pop eax |
||
145 | add al, '0' |
||
78 | diamond | 146 | stosb |
147 | test bl, 1 ; UNICODE name? |
||
148 | jz .ansi2 |
||
149 | mov byte [edi], 0 |
||
150 | inc edi |
||
151 | .ansi2: |
||
152 | test al, al |
||
75 | diamond | 153 | jnz @b |
154 | mov byte [edi-1], 0 |
||
155 | pop edi |
||
78 | diamond | 156 | ; UNICODE name length is 520 bytes, ANSI - 264 |
75 | diamond | 157 | add edi, 520 |
78 | diamond | 158 | test bl, 1 |
159 | jnz @f |
||
160 | sub edi, 520-264 |
||
161 | @@: |
||
75 | diamond | 162 | pop edx eax |
163 | jmp .maindir_loop |
||
164 | .maindir_done: |
||
78 | diamond | 165 | pop eax |
166 | mov ebx, [edx+4] |
||
75 | diamond | 167 | xor eax, eax |
168 | dec ebp |
||
169 | js @f |
||
170 | mov al, ERROR_END_OF_FILE |
||
171 | @@: |
||
172 | mov [esp+36], eax |
||
173 | mov [esp+24], ebx |
||
174 | ret |
||
71 | diamond | 175 | ; directory / |
176 | .rootdir: |
||
75 | diamond | 177 | cmp dword [ebx], 1 ; read folder? |
178 | jz .readroot |
||
179 | .access_denied: |
||
180 | mov dword [esp+36], 10 ; access denied |
||
181 | ret |
||
71 | diamond | 182 | |
75 | diamond | 183 | .readroot: |
184 | ; virtual root folder - special handler |
||
185 | mov esi, virtual_root_query |
||
186 | mov ebp, [ebx+12] |
||
187 | mov edx, [ebx+16] |
||
188 | add edx, std_application_base_address |
||
78 | diamond | 189 | push dword [ebx+4] ; first block |
190 | mov ebx, [ebx+8] ; flags |
||
75 | diamond | 191 | xor eax, eax |
78 | diamond | 192 | ; eax=0, [esp]=first block, ebx=flags, ebp=number of blocks, edx=return area |
75 | diamond | 193 | mov edi, edx |
194 | mov ecx, 32/4 |
||
195 | rep stosd |
||
196 | mov byte [edx], 1 ; version |
||
197 | .readroot_loop: |
||
198 | cmp dword [esi], eax |
||
199 | jz .readroot_done |
||
200 | call dword [esi] |
||
201 | add esi, 4 |
||
202 | test eax, eax |
||
203 | jnz @f |
||
204 | .readroot_next: |
||
205 | or ecx, -1 |
||
206 | xchg esi, edi |
||
78 | diamond | 207 | repnz scasb |
75 | diamond | 208 | xchg esi, edi |
209 | jmp .readroot_loop |
||
210 | @@: |
||
211 | xor eax, eax |
||
212 | inc dword [edx+8] |
||
78 | diamond | 213 | dec dword [esp] |
75 | diamond | 214 | jns .readroot_next |
215 | dec ebp |
||
216 | js .readroot_next |
||
217 | inc dword [edx+4] |
||
218 | mov dword [edi], 0x10 ; attributes: folder |
||
219 | mov dword [edi+4], 1 ; name type: UNICODE |
||
220 | add edi, 8 |
||
221 | mov ecx, 40/4-2 |
||
222 | rep stosd |
||
223 | push edi |
||
224 | @@: |
||
78 | diamond | 225 | lodsb |
226 | stosb |
||
227 | test bl, 1 |
||
228 | jz .ansi |
||
229 | mov byte [edi], 0 |
||
230 | inc edi |
||
231 | .ansi: |
||
75 | diamond | 232 | test eax, eax |
233 | jnz @b |
||
234 | pop edi |
||
235 | add edi, 520 |
||
78 | diamond | 236 | test bl, 1 |
237 | jnz .readroot_loop |
||
238 | sub edi, 520-264 |
||
75 | diamond | 239 | jmp .readroot_loop |
240 | .readroot_done: |
||
78 | diamond | 241 | pop eax |
242 | mov ebx, [edx+4] |
||
75 | diamond | 243 | xor eax, eax |
244 | dec ebp |
||
245 | js @f |
||
246 | mov al, ERROR_END_OF_FILE |
||
247 | @@: |
||
248 | mov [esp+36], eax |
||
249 | mov [esp+24], ebx |
||
250 | ret |
||
251 | |||
71 | diamond | 252 | .found1: |
75 | diamond | 253 | pop eax |
254 | cmp byte [esi], 0 |
||
255 | jz .maindir |
||
71 | diamond | 256 | ; read partition number |
75 | diamond | 257 | xor ecx, ecx |
258 | xor eax, eax |
||
71 | diamond | 259 | @@: |
75 | diamond | 260 | lodsb |
261 | cmp al, '/' |
||
262 | jz .done1 |
||
263 | test al, al |
||
264 | jz .done1 |
||
265 | sub al, '0' |
||
266 | cmp al, 9 |
||
267 | ja .notfound |
||
268 | imul ecx, 10 |
||
269 | add ecx, eax |
||
270 | jmp @b |
||
71 | diamond | 271 | .done1: |
75 | diamond | 272 | test ecx, ecx |
273 | jz .notfound |
||
274 | test al, al |
||
275 | jnz @f |
||
276 | dec esi |
||
71 | diamond | 277 | @@: |
75 | diamond | 278 | ; now [edi] contains handler address, ecx - partition number, |
279 | ; esi points to ASCIIZ string - rest of name |
||
280 | jmp dword [edi] |
||
71 | diamond | 281 | |
282 | ; handlers for devices |
||
75 | diamond | 283 | ; in: ecx = 0 => query virtual directory /xxx |
71 | diamond | 284 | ; in: ecx = partition number |
285 | ; esi -> relative (for device) name |
||
286 | ; ebx -> fileinfo |
||
287 | ; out: [esp+36]=image of eax, [esp+24]=image of ebx |
||
288 | |||
289 | fs_OnRamdisk: |
||
75 | diamond | 290 | cmp ecx, 1 |
291 | jnz file_system_lfn.notfound |
||
292 | mov eax, [ebx] |
||
293 | cmp eax, 1 |
||
294 | ja .not_impl |
||
295 | mov ecx, [ebx+12] |
||
296 | mov edx, [ebx+16] |
||
297 | add edx, std_application_base_address |
||
298 | add ebx, 4 |
||
299 | call dword [fs_RamdiskServices + eax*4] |
||
300 | mov [esp+36], eax |
||
301 | mov [esp+24], ebx |
||
302 | ret |
||
71 | diamond | 303 | .not_impl: |
75 | diamond | 304 | mov dword [esp+36], 2 ; not implemented |
305 | ret |
||
71 | diamond | 306 | |
307 | fs_RamdiskServices: |
||
75 | diamond | 308 | dd fs_RamdiskRead |
309 | dd fs_RamdiskReadFolder |
||
71 | diamond | 310 | |
311 | fs_OnFloppy: |
||
75 | diamond | 312 | cmp ecx, 2 |
313 | ja file_system_lfn.notfound |
||
314 | mov eax, [ebx] |
||
315 | cmp eax, 1 |
||
316 | ja fs_OnRamdisk.not_impl |
||
317 | call reserve_flp |
||
318 | mov [flp_number], cl |
||
319 | mov ecx, [ebx+12] |
||
320 | mov edx, [ebx+16] |
||
321 | add edx, std_application_base_address |
||
322 | add ebx, 4 |
||
323 | call dword [fs_FloppyServices + eax*4] |
||
324 | and [flp_status], 0 |
||
325 | mov [esp+36], eax |
||
326 | mov [esp+24], ebx |
||
327 | ret |
||
71 | diamond | 328 | |
329 | fs_FloppyServices: |
||
75 | diamond | 330 | dd fs_FloppyRead |
331 | dd fs_FloppyReadFolder |
||
71 | diamond | 332 | |
333 | fs_OnHd0: |
||
75 | diamond | 334 | call reserve_hd1 |
335 | mov [hdbase], 0x1F0 |
||
336 | mov [hdid], 0 |
||
337 | push 1 |
||
338 | jmp fs_OnHd |
||
71 | diamond | 339 | fs_OnHd1: |
75 | diamond | 340 | call reserve_hd1 |
341 | mov [hdbase], 0x1F0 |
||
342 | mov [hdid], 0x10 |
||
343 | push 2 |
||
344 | jmp fs_OnHd |
||
71 | diamond | 345 | fs_OnHd2: |
75 | diamond | 346 | call reserve_hd1 |
347 | mov [hdbase], 0x170 |
||
348 | mov [hdid], 0 |
||
349 | push 3 |
||
350 | jmp fs_OnHd |
||
71 | diamond | 351 | fs_OnHd3: |
75 | diamond | 352 | call reserve_hd1 |
353 | mov [hdbase], 0x170 |
||
354 | mov [hdid], 0x10 |
||
355 | push 4 |
||
71 | diamond | 356 | fs_OnHd: |
75 | diamond | 357 | pop eax |
358 | mov [hdpos], eax |
||
359 | cmp ecx, 0x100 |
||
360 | jae .nf |
||
361 | cmp cl, [0x40001+eax] |
||
362 | jbe @f |
||
363 | .nf: |
||
364 | and [hd1_status], 0 |
||
365 | mov dword [esp+36], 5 ; not found |
||
366 | ret |
||
71 | diamond | 367 | @@: |
75 | diamond | 368 | mov [fat32part], ecx |
369 | push ebx esi |
||
370 | call choice_necessity_partition_1 |
||
371 | pop esi ebx |
||
372 | mov ecx, [ebx+12] |
||
373 | mov edx, [ebx+16] |
||
374 | add edx, std_application_base_address |
||
375 | mov eax, [ebx] |
||
376 | cmp eax, 1 |
||
377 | ja .not_impl |
||
378 | add ebx, 4 |
||
379 | call dword [fs_HdServices + eax*4] |
||
380 | and [hd1_status], 0 |
||
381 | mov [esp+36], eax |
||
382 | mov [esp+24], ebx |
||
383 | ret |
||
384 | .not_impl: |
||
385 | and [hd1_status], 0 |
||
386 | mov dword [esp+36], 2 ; not implemented |
||
387 | ret |
||
71 | diamond | 388 | |
389 | fs_HdServices: |
||
75 | diamond | 390 | dd fs_HdRead |
391 | dd fs_HdReadFolder |
||
392 | |||
393 | fs_HasRamdisk: |
||
394 | mov al, 1 ; we always have ramdisk |
||
395 | ret |
||
396 | |||
397 | fs_HasFloppy: |
||
398 | cmp byte [0x40000], 0 |
||
399 | setnz al |
||
400 | ret |
||
401 | |||
402 | fs_HasHd0: |
||
403 | mov al, [0x40001] |
||
404 | and al, 11000000b |
||
405 | cmp al, 01000000b |
||
406 | setz al |
||
407 | ret |
||
408 | fs_HasHd1: |
||
409 | mov al, [0x40001] |
||
410 | and al, 00110000b |
||
411 | cmp al, 00010000b |
||
412 | setz al |
||
413 | ret |
||
414 | fs_HasHd2: |
||
415 | mov al, [0x40001] |
||
416 | and al, 00001100b |
||
417 | cmp al, 00000100b |
||
418 | setz al |
||
419 | ret |
||
420 | fs_HasHd3: |
||
421 | mov al, [0x40001] |
||
422 | and al, 00000011b |
||
423 | cmp al, 00000001b |
||
424 | setz al |
||
425 | ret |
||
426 | |||
427 | ; fs_NextXXX functions: |
||
428 | ; in: eax = partition number, from which start to scan |
||
429 | ; out: CF=1 => no more partitions |
||
430 | ; CF=0 => eax=next partition number |
||
431 | |||
432 | fs_NextRamdisk: |
||
433 | ; we always have /rd/1 |
||
434 | test eax, eax |
||
435 | stc |
||
436 | jnz @f |
||
437 | mov al, 1 |
||
438 | clc |
||
439 | @@: |
||
440 | ret |
||
441 | |||
442 | fs_NextFloppy: |
||
443 | ; we have /fd/1 iff (([0x40000] and 0xF0) != 0) and /fd/2 iff (([0x40000] and 0x0F) != 0) |
||
444 | test byte [0x40000], 0xF0 |
||
445 | jz .no1 |
||
446 | test eax, eax |
||
447 | jnz .no1 |
||
448 | inc eax |
||
449 | ret ; CF cleared |
||
450 | .no1: |
||
451 | test byte [0x40000], 0x0F |
||
452 | jz .no2 |
||
453 | cmp al, 2 |
||
454 | jae .no2 |
||
455 | mov al, 2 |
||
456 | clc |
||
457 | ret |
||
458 | .no2: |
||
459 | stc |
||
460 | ret |
||
461 | |||
462 | ; on hdx, we have partitions from 1 to [0x40002+x] |
||
463 | fs_NextHd0: |
||
464 | push 0 |
||
465 | jmp fs_NextHd |
||
466 | fs_NextHd1: |
||
467 | push 1 |
||
468 | jmp fs_NextHd |
||
469 | fs_NextHd2: |
||
470 | push 2 |
||
471 | jmp fs_NextHd |
||
472 | fs_NextHd3: |
||
473 | push 3 |
||
474 | fs_NextHd: |
||
475 | pop ecx |
||
476 | movzx ecx, byte [0x40002+ecx] |
||
477 | cmp eax, ecx |
||
478 | jae fs_NextFloppy.no2 |
||
479 | inc eax |
||
480 | clc |
||
481 | ret |