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