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