Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2783 | clevermous | 1 | fat32_parse_dir: |
2 | ; in: eax=directory cluster |
||
3 | ; out: eax=entry cluster |
||
4 | mov bx, 900h |
||
5 | mov di, bx |
||
6 | push eax |
||
7 | call read_cluster |
||
8 | mov cx, word [cluster_size] |
||
9 | shr cx, 5 ; div 20h |
||
10 | .scan_cluster: |
||
11 | pop eax |
||
12 | cmp byte [di], 0 |
||
13 | jz file_not_found |
||
14 | mov si, [esp+2] |
||
15 | push eax |
||
16 | call fat_compare_name |
||
17 | jz .file_found |
||
18 | and di, not 1Fh |
||
19 | add di, 20h |
||
20 | loop .scan_cluster |
||
21 | pop eax |
||
22 | call next_cluster |
||
23 | jnc file_not_found |
||
24 | jc fat32_parse_dir |
||
25 | .file_found: |
||
26 | pop eax |
||
27 | mov si, [esp+2] |
||
28 | mov [cur_obj], si |
||
29 | and di, not 1Fh |
||
30 | mov si, directory_string |
||
31 | mov ax, [di+14h] |
||
32 | shl eax, 10h |
||
33 | mov ax, [di+1Ah] |
||
34 | test eax, eax |
||
35 | mov si, nodata_string |
||
36 | jz find_error_si |
||
37 | ret 2 |
||
38 | |||
39 | fat_compare_name: |
||
40 | push cx |
||
41 | mov cx, 9 |
||
42 | .scan: |
||
43 | lodsb |
||
44 | cmp al, '.' |
||
45 | jz .ext |
||
46 | cmp al, 0 |
||
47 | jz .nameend |
||
48 | cmp al, 'a' |
||
49 | jb .notletter |
||
50 | cmp al, 'z' |
||
51 | ja .notletter |
||
52 | or byte [di], 20h |
||
53 | .notletter: |
||
54 | scasb |
||
55 | loopz .scan |
||
56 | .notfound: |
||
57 | inc cx ; to clear ZF flag |
||
58 | pop cx |
||
59 | ret |
||
60 | .ext: |
||
61 | mov al, ' ' |
||
62 | dec cx |
||
63 | repz scasb |
||
64 | jnz .notfound |
||
65 | test di, 1 |
||
66 | jnz .notfound |
||
67 | mov cx, 4 |
||
68 | jmp .scan |
||
69 | .nameend: |
||
70 | mov al, ' ' |
||
71 | dec cx |
||
72 | repz scasb |
||
73 | jnz .notfound |
||
74 | test di, 1 |
||
75 | jnz .file_found |
||
76 | mov cx, 3 |
||
77 | repz scasb |
||
78 | jnz .notfound |
||
79 | .file_found: |
||
80 | xor cx, cx ; to set ZF flag |
||
81 | pop cx |
||
82 | ret |
||
83 | |||
84 | read_cluster: |
||
85 | ; in: eax=cluster,bx->buffer |
||
86 | and eax, 0FFFFFFFh |
||
87 | movzx ecx, byte [50Dh] ; sects_per_clust |
||
88 | mul ecx |
||
89 | add eax, [data_start] |
||
90 | ; call read |
||
91 | ; ret |
||
92 | jmp relative_read |
||
93 | next_cluster: |
||
94 | mov bx, 700h |
||
95 | ; sector is 200h bytes long, one entry in FAT occupies 4 bytes => 80h entries in sector |
||
96 | push eax |
||
97 | shr eax, 7 ; div 80h |
||
98 | cmp eax, [fat_cur_sector] |
||
99 | jz @f |
||
100 | mov [fat_cur_sector], eax |
||
101 | add eax, [fat_start] |
||
102 | mov cx, 1 |
||
103 | call relative_read |
||
104 | @@: |
||
105 | pop eax |
||
106 | and eax, 7Fh |
||
107 | mov eax, [700h+eax*4] |
||
108 | and eax, 0FFFFFFFh |
||
109 | cmp eax, 0FFFFFF7h |
||
110 | mov si, bad_cluster_string |
||
111 | jz find_error_si |
||
112 | ret |