Subversion Repositories Kolibri OS

Rev

Rev 2455 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2455 Rev 2643
Line 42... Line 42...
42
;;  20.5.2002  Hd status check - VT                                ;;
42
;;  20.5.2002  Hd status check - VT                                ;;
43
;;  29.6.2002  Improved fat32 verification - VT                    ;;
43
;;  29.6.2002  Improved fat32 verification - VT                    ;;
44
;;                                                                 ;;
44
;;                                                                 ;;
45
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
45
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 46... Line 46...
46
 
46
 
Line 47... Line 47...
47
$Revision: 2455 $
47
$Revision: 2643 $
Line 48... Line 48...
48
 
48
 
Line 68... Line 68...
68
PUSHAD_EBX equ [esp+16]
68
PUSHAD_EBX equ [esp+16]
69
PUSHAD_EBP equ [esp+8]
69
PUSHAD_EBP equ [esp+8]
70
PUSHAD_ESI equ [esp+4]
70
PUSHAD_ESI equ [esp+4]
71
PUSHAD_EDI equ [esp+0]
71
PUSHAD_EDI equ [esp+0]
Line -... Line 72...
-
 
72
 
-
 
73
; Internal data for every FAT partition.
-
 
74
struct FAT
-
 
75
p       PARTITION       ; must be the first item
-
 
76
fs_type              db ?
-
 
77
fat16_root           db 0       ; flag for fat16 rootdir
-
 
78
fat_change           db 0       ; 1=fat has changed
-
 
79
                     db ?       ; alignment
-
 
80
Lock                 MUTEX ?    ; currently operations with one partition
-
 
81
                                 ; can not be executed in parallel since the
-
 
82
                                 ; legacy code is not ready; this mutex guards
-
 
83
                                 ; all operations
-
 
84
SECTORS_PER_FAT      dd 0x1f3a
-
 
85
NUMBER_OF_FATS       dd 0x2
-
 
86
SECTORS_PER_CLUSTER  dd 0x8
-
 
87
BYTES_PER_SECTOR     dd 0x200   ; Note: if BPS <> 512 need lots of changes
-
 
88
ROOT_CLUSTER         dd 2       ; first rootdir cluster
-
 
89
FAT_START            dd 0       ; start of fat table
-
 
90
ROOT_START           dd 0       ; start of rootdir (only fat16)
-
 
91
ROOT_SECTORS         dd 0       ; count of rootdir sectors (only fat16)
-
 
92
DATA_START           dd 0       ; start of data area (=first cluster 2)
-
 
93
LAST_CLUSTER         dd 0       ; last availabe cluster
-
 
94
ADR_FSINFO           dd 0       ; used only by fat32
-
 
95
 
-
 
96
fatRESERVED          dd 0x0FFFFFF6
-
 
97
fatBAD               dd 0x0FFFFFF7
-
 
98
fatEND               dd 0x0FFFFFF8
-
 
99
fatMASK              dd 0x0FFFFFFF
-
 
100
 
-
 
101
fatStartScan         dd 2
-
 
102
 
-
 
103
cluster_tmp          dd 0       ; used by analyze_directory
-
 
104
                                ; and analyze_directory_to_write
-
 
105
 
-
 
106
longname_sec1        dd 0       ; used by analyze_directory to save 2 previous
-
 
107
longname_sec2        dd 0       ; directory sectors for delete long filename
-
 
108
 
-
 
109
fat_in_cache         dd -1
-
 
110
 
-
 
111
fat_cache            rb 512
-
 
112
buffer               rb 512
-
 
113
fsinfo_buffer        rb 512
-
 
114
ends
72
 
115
 
73
uglobal
116
uglobal
74
align 4
117
align 4
75
partition_count      dd 0       ; partitions found by set_FAT32_variables
-
 
76
longname_sec1        dd 0       ; used by analyze_directory to save 2 previous
-
 
Line 77... Line 118...
77
longname_sec2        dd 0       ; directory sectors for delete long filename
118
partition_count      dd 0       ; partitions found by set_FAT32_variables
78
 
119
 
79
hd_error             dd 0       ; set by wait_for_sector_buffer
120
hd_error             dd 0       ; set by wait_for_sector_buffer
Line 80... Line -...
80
hd_setup             dd 0
-
 
81
hd_wait_timeout      dd 0
-
 
82
 
-
 
83
cluster_tmp          dd 0       ; used by analyze_directory
-
 
84
                                ; and analyze_directory_to_write
-
 
85
 
121
hd_setup             dd 0
86
file_size            dd 0       ; used by file_read
122
hd_wait_timeout      dd 0
Line 87... Line -...
87
 
-
 
88
cache_search_start   dd 0       ; used by find_empty_slot
-
 
89
endg
-
 
90
 
-
 
91
iglobal
123
 
92
fat_in_cache         dd -1
124
cache_search_start   dd 0       ; used by find_empty_slot
93
endg
-
 
94
 
-
 
95
uglobal
125
endg
96
align 4
126
 
97
fat_cache:
127
uglobal
98
                     times 512 db 0
-
 
99
 Sector512:                      ; label for dev_hdcd.inc
-
 
100
  buffer:
128
align 4
Line 101... Line 129...
101
                       times 512 db 0
129
 Sector512:                      ; label for dev_hdcd.inc
-
 
130
  buffer:
-
 
131
                times 512 db 0
-
 
132
endg
-
 
133
 
102
  fsinfo_buffer:
134
iglobal
-
 
135
align 4
-
 
136
fat_user_functions:
103
                       times 512 db 0
137
        dd      (fat_user_functions_end - fat_user_functions - 4) / 4
-
 
138
        dd      fat_Read
-
 
139
        dd      fat_ReadFolder
-
 
140
        dd      fat_Rewrite
-
 
141
        dd      fat_Write
-
 
142
        dd      fat_SetFileEnd
-
 
143
        dd      fat_GetFileInfo
104
endg
144
        dd      fat_SetFileInfo
Line -... Line 145...
-
 
145
        dd      0
-
 
146
        dd      fat_Delete
-
 
147
        dd      fat_CreateFolder
-
 
148
fat_user_functions_end:
-
 
149
endg
-
 
150
 
-
 
151
; these labels are located before the main function to make
-
 
152
; most of jumps to these be short
-
 
153
fat_create_partition.free_return0:
-
 
154
        push    ebx
-
 
155
        mov     eax, ebp
105
 
156
        call    free
-
 
157
        pop     ebx
-
 
158
        pop     ebp
-
 
159
fat_create_partition.return0:
-
 
160
        xor     eax, eax
-
 
161
        ret
-
 
162
fat_create_partition:
-
 
163
; bootsector must have been successfully read
-
 
164
        cmp     dword [esp+4], 1
-
 
165
        jnz     .return0
-
 
166
; bootsector signature must be correct
-
 
167
        cmp     word [ebx+0x1fe], 0xaa55
-
 
168
        jnz     .return0
-
 
169
; sectors per cluster must be nonzero
-
 
170
        cmp     byte [ebx+0xd], 0
-
 
171
        jz      .return0
-
 
172
; bytes per sector must be 0x200
-
 
173
        cmp     word [ebx+0xb], 0x200
-
 
174
        jnz     .return0
-
 
175
; number of fats must be nonzero
-
 
176
        cmp     byte [ebx+0x10], 0
-
 
177
        jz      .return0
-
 
178
; The only reason to be invalid partition now is FAT12. Since the test for
-
 
179
; FAT size requires knowledge of some calculated values, which are also used
-
 
180
; in the normal operation, let's hope for the best and allocate data now; if
-
 
181
; it will prove wrong, just deallocate it.
-
 
182
        push    ebx
-
 
183
        push    sizeof.FAT
-
 
184
        pop     eax
-
 
185
        call    malloc
-
 
186
        pop     ebx
-
 
187
        test    eax, eax
-
 
188
        jz      .return0
-
 
189
        mov     ecx, [ebp+8]
-
 
190
        mov     dword [eax+FAT.p.FirstSector], ecx
-
 
191
        mov     ecx, [ebp+12]
-
 
192
        mov     dword [eax+FAT.p.FirstSector+4], ecx
-
 
193
        mov     ecx, [ebp+16]
-
 
194
        mov     dword [eax+FAT.p.Length], ecx
-
 
195
        mov     ecx, [ebp+20]
-
 
196
        mov     dword [eax+FAT.p.Length+4], ecx
-
 
197
        mov     [eax+FAT.p.Disk], esi
-
 
198
        mov     [eax+FAT.p.FSUserFunctions], fat_user_functions
-
 
199
        or      [eax+FAT.fat_in_cache], -1
Line 106... Line -...
106
uglobal
-
 
107
  fat16_root           db 0       ; flag for fat16 rootdir
200
        mov     [eax+FAT.fat_change], 0
108
  fat_change           db 0       ; 1=fat has changed
201
        push    ebp
Line 109... Line -...
109
endg
-
 
110
 
202
        mov     ebp, eax
111
reserve_hd1:
203
 
Line -... Line 204...
-
 
204
        lea     ecx, [ebp+FAT.Lock]
112
 
205
        call    mutex_init
Line 113... Line 206...
113
        cli
206
 
114
        cmp     [hd1_status], 0
207
        movzx   eax, word [ebx+0xe]     ; sectors reserved
115
        je      reserve_ok1
208
        mov     [ebp+FAT.FAT_START], eax
116
 
209
 
117
        sti
210
        movzx   eax, byte [ebx+0xd]     ; sectors per cluster
118
        call    change_task
211
        mov     [ebp+FAT.SECTORS_PER_CLUSTER], eax
119
        jmp     reserve_hd1
-
 
120
 
212
 
121
  reserve_ok1:
213
        movzx   ecx, word [ebx+0xb]     ; bytes per sector
Line -... Line 214...
-
 
214
        mov     [ebp+FAT.BYTES_PER_SECTOR], ecx
122
 
215
 
123
        push    eax
216
        movzx   eax, word [ebx+0x11]    ; count of rootdir entries (=0 fat32)
-
 
217
        shl     eax, 5                  ; mul 32
124
        mov     eax, [CURRENT_TASK]
218
        dec     ecx
-
 
219
        add     eax, ecx                ; round up if not equal count
Line 125... Line -...
125
        shl     eax, 5
-
 
126
        mov     eax, [eax+CURRENT_TASK+TASKDATA.pid]
220
        inc     ecx                     ; bytes per sector
127
        mov     [hd1_status], eax
-
 
128
        pop     eax
221
        xor     edx, edx
129
        sti
-
 
130
        ret
222
        div     ecx
131
;********************************************
-
 
132
 
-
 
133
uglobal
-
 
134
hd_in_cache db ?
223
        mov     [ebp+FAT.ROOT_SECTORS], eax     ; count of rootdir sectors
135
endg
224
 
136
 
-
 
137
reserve_hd_channel:
-
 
138
; BIOS disk accesses are protected with common mutex hd1_status
-
 
139
; This must be modified when hd1_status will not be valid!
-
 
140
        cmp     [hdpos], 0x80
-
 
141
        jae     .ret
225
        movzx   eax, word [ebx+0x16]    ; sectors per fat <65536
142
        cmp     [hdbase], 0x1F0
226
        test    eax, eax
143
        jne     .IDE_Channel_2
227
        jnz     @f
144
.IDE_Channel_1:
-
 
145
        cli
-
 
146
        cmp     [IDE_Channel_1], 0
-
 
147
        je      .reserve_ok_1
228
        mov     eax, [ebx+0x24]         ; sectors per fat
148
        sti
229
@@:
149
        call    change_task
-
 
150
        jmp     .IDE_Channel_1
230
        mov     [ebp+FAT.SECTORS_PER_FAT], eax
151
.IDE_Channel_2:
-
 
152
        cli
231
 
153
        cmp     [IDE_Channel_2], 0
-
 
154
        je      .reserve_ok_2
-
 
155
        sti
232
        movzx   eax, byte [ebx+0x10]    ; number of fats
-
 
233
        mov     [ebp+FAT.NUMBER_OF_FATS], eax
-
 
234
        imul    eax, [ebp+FAT.SECTORS_PER_FAT]
-
 
235
        add     eax, [ebp+FAT.FAT_START]
156
        call    change_task
236
        mov     [ebp+FAT.ROOT_START], eax       ; rootdir = fat_start + fat_size * fat_count
-
 
237
        add     eax, [ebp+FAT.ROOT_SECTORS]     ; rootdir sectors should be 0 on fat32
-
 
238
        mov     [ebp+FAT.DATA_START], eax       ; data area = rootdir + rootdir_size
-
 
239
 
-
 
240
        movzx   eax, word [ebx+0x13]    ; total sector count <65536
-
 
241
        test    eax, eax
-
 
242
        jnz     @f
-
 
243
        mov     eax, [ebx+0x20]         ; total sector count
-
 
244
@@:
-
 
245
        mov     dword [ebp+FAT.p.Length], eax
-
 
246
        and     dword [ebp+FAT.p.Length+4], 0
-
 
247
        sub     eax, [ebp+FAT.DATA_START]       ; eax = count of data sectors
-
 
248
        xor     edx, edx
-
 
249
        div     [ebp+FAT.SECTORS_PER_CLUSTER]
-
 
250
        inc     eax
-
 
251
        mov     [ebp+FAT.LAST_CLUSTER], eax
-
 
252
        dec     eax                     ; cluster count
-
 
253
        mov     [ebp+FAT.fatStartScan], 2
157
        jmp     .IDE_Channel_2
254
 
-
 
255
        ; limits by Microsoft Hardware White Paper v1.03
-
 
256
        cmp     eax, 4085               ; 0xff5
-
 
257
        jb      .free_return0           ; fat12 not supported
158
.reserve_ok_1:
258
        cmp     eax, 65525              ; 0xfff5
-
 
259
        jb      .fat16
159
        mov     [IDE_Channel_1], 1
260
.fat32:
160
        push    eax
261
        mov     eax, [ebx+0x2c]         ; rootdir cluster
161
        mov     al, 1
-
 
162
        jmp     @f
262
        mov     [ebp+FAT.ROOT_CLUSTER], eax
163
.reserve_ok_2:
263
        movzx   eax, word [ebx+0x30]
164
        mov     [IDE_Channel_2], 1
264
        mov     [ebp+FAT.ADR_FSINFO], eax
165
        push    eax
-
 
166
        mov     al, 3
265
        push    ebx
167
@@:
-
 
168
        cmp     [hdid], 1
-
 
169
        sbb     al, -1
266
        add     ebx, 512
170
        cmp     al, [hd_in_cache]
267
        call    fs_read32_sys
171
        jz      @f
268
        test    eax, eax
172
        mov     [hd_in_cache], al
269
        jnz     @f
173
        call    clear_hd_cache
270
        mov     eax, [ebx+0x1ec]
174
@@:
271
        cmp     eax, -1
175
        pop     eax
272
        jz      @f
176
        sti
-
 
177
.ret:
273
        mov     [ebp+FAT.fatStartScan], eax
178
        ret
274
@@:
-
 
275
        pop     ebx
-
 
276
        mov     [ebp+FAT.fatRESERVED], 0x0FFFFFF6
-
 
277
        mov     [ebp+FAT.fatBAD], 0x0FFFFFF7
-
 
278
        mov     [ebp+FAT.fatEND], 0x0FFFFFF8
-
 
279
        mov     [ebp+FAT.fatMASK], 0x0FFFFFFF
-
 
280
        mov     al, 32
179
 
281
        mov     [fs_type], al
-
 
282
        mov     [ebp+FAT.fs_type], al
-
 
283
        mov     eax, ebp
-
 
284
        pop     ebp
180
free_hd_channel:
285
        ret
181
; see comment at reserve_hd_channel
-
 
182
        cmp     [hdpos], 0x80
-
 
183
        jae     .ret
-
 
184
        cmp     [hdbase], 0x1F0
-
 
Line 185... Line 286...
185
        jne     .IDE_Channel_2
286
.fat16:
186
.IDE_Channel_1:
287
        and     [ebp+FAT.ROOT_CLUSTER], 0
187
        mov     [IDE_Channel_1], 0
288
        mov     [ebp+FAT.fatRESERVED], 0x0000FFF6
188
.ret:
289
        mov     [ebp+FAT.fatBAD], 0x0000FFF7
-
 
290
        mov     [ebp+FAT.fatEND], 0x0000FFF8
189
        ret
291
        mov     [ebp+FAT.fatMASK], 0x0000FFFF
190
.IDE_Channel_2:
292
        mov     al, 16
-
 
293
        mov     [fs_type], al
191
        mov     [IDE_Channel_2], 0
294
        mov     [ebp+FAT.fs_type], al
Line 192... Line 295...
192
        ret
295
        mov     eax, ebp
193
;********************************************
296
        pop     ebp
194
problem_partition db 0  ; used for partitions search
297
        ret
195
 
298
 
196
include  'part_set.inc'
299
set_FAT:
197
 
300
;--------------------------------
198
set_FAT:
301
; input  : EAX = cluster
199
;--------------------------------
302
;          EDX = value to save
200
; input  : EAX = cluster
303
;          EBP = pointer to FAT structure
201
;          EDX = value to save
304
; output : EDX = old value
202
; output : EDX = old value
305
;--------------------------------
203
;--------------------------------
306
; out: CF set <=> error
204
        push    eax ebx esi
307
        push    eax ebx esi
205
 
308
 
Line 206... Line 309...
206
        cmp     eax, 2
309
        cmp     eax, 2
207
        jb      sfc_error
310
        jb      sfc_error
Line 208... Line 311...
208
        cmp     eax, [LAST_CLUSTER]
311
        cmp     eax, [ebp+FAT.LAST_CLUSTER]
209
        ja      sfc_error
312
        ja      sfc_error
210
        cmp     [fs_type], 16
313
        cmp     [ebp+FAT.fs_type], 16
211
        je      sfc_1
-
 
212
        add     eax, eax
314
        je      sfc_1
Line 213... Line 315...
213
  sfc_1:
315
        add     eax, eax
214
        add     eax, eax
316
  sfc_1:
215
        mov     esi, 511
317
        add     eax, eax
216
        and     esi, eax        ; esi = position in fat sector
318
        mov     esi, 511
217
        shr     eax, 9          ; eax = fat sector
319
        and     esi, eax        ; esi = position in fat sector
Line 218... Line 320...
218
        add     eax, [FAT_START]
320
        shr     eax, 9          ; eax = fat sector
219
        mov     ebx, fat_cache
321
        add     eax, [ebp+FAT.FAT_START]
220
 
322
        lea     ebx, [ebp+FAT.fat_cache]
Line 221... Line 323...
221
        cmp     eax, [fat_in_cache]; is fat sector already in memory?
323
 
222
        je      sfc_in_cache    ; yes
324
        cmp     eax, [ebp+FAT.fat_in_cache]; is fat sector already in memory?
223
 
325
        je      sfc_in_cache    ; yes
Line 224... Line 326...
224
        cmp     [fat_change], 0 ; is fat changed?
326
 
225
        je      sfc_no_change   ; no
327
        cmp     [ebp+FAT.fat_change], 0; is fat changed?
Line 226... Line 328...
226
        call    write_fat_sector; yes. write it into disk
328
        je      sfc_no_change   ; no
227
        cmp     [hd_error], 0
329
        call    write_fat_sector; yes. write it into disk
228
        jne     sfc_error
330
        jc      sfc_error
229
 
331
 
230
  sfc_no_change:
332
  sfc_no_change:
231
        mov     [fat_in_cache], eax; save fat sector
333
        mov     [ebp+FAT.fat_in_cache], eax; save fat sector
232
        call    hd_read
334
        call    fs_read32_sys
Line 233... Line 335...
233
        cmp     [hd_error], 0
335
        test    eax, eax
234
        jne     sfc_error
336
        jne     sfc_error
Line 235... Line 337...
235
 
337
 
236
 
338
 
Line 237... Line 339...
237
  sfc_in_cache:
339
  sfc_in_cache:
238
        cmp     [fs_type], 16
340
        cmp     [ebp+FAT.fs_type], 16
239
        jne     sfc_test32
341
        jne     sfc_test32
-
 
342
 
-
 
343
  sfc_set16:
-
 
344
        xchg    [ebx+esi], dx   ; save new value and get old value
Line 240... Line 345...
240
 
345
        jmp     sfc_write
241
  sfc_set16:
346
 
242
        xchg    [ebx+esi], dx   ; save new value and get old value
347
  sfc_test32:
-
 
348
        mov     eax, [ebp+FAT.fatMASK]
243
        jmp     sfc_write
349
 
244
 
350
  sfc_set32:
-
 
351
        and     edx, eax
245
  sfc_test32:
352
        xor     eax, -1         ; mask for high bits
Line 246... Line 353...
246
        mov     eax, [fatMASK]
353
        and     eax, [ebx+esi]  ; get high 4 bits
247
 
354
        or      eax, edx
248
  sfc_set32:
355
        mov     edx, [ebx+esi]  ; get old value
249
        and     edx, eax
356
        mov     [ebx+esi], eax  ; save new value
250
        xor     eax, -1         ; mask for high bits
357
 
251
        and     eax, [ebx+esi]  ; get high 4 bits
358
  sfc_write:
252
        or      eax, edx
359
        mov     [ebp+FAT.fat_change], 1; fat has changed
253
        mov     edx, [ebx+esi]  ; get old value
360
 
254
        mov     [ebx+esi], eax  ; save new value
361
  sfc_nonzero:
255
 
362
        and     edx, [ebp+FAT.fatMASK]
Line 256... Line 363...
256
  sfc_write:
363
 
257
        mov     [fat_change], 1 ; fat has changed
364
  sfc_return:
Line 258... Line 365...
258
 
365
        pop     esi ebx eax
259
  sfc_nonzero:
366
        ret
260
        and     edx, [fatMASK]
367
  sfc_error:
261
 
-
 
262
  sfc_error:
368
        stc
Line 263... Line 369...
263
        pop     esi ebx eax
369
        jmp     sfc_return
264
        ret
370
 
265
 
371
 
266
 
372
get_FAT:
267
get_FAT:
373
;--------------------------------
Line 268... Line 374...
268
;--------------------------------
374
; input  : EAX = cluster
269
; input  : EAX = cluster
375
;          EBP = pointer to FAT structure
270
; output : EAX = next cluster
376
; output : EAX = next cluster
271
;--------------------------------
377
;--------------------------------
272
        push    ebx esi
378
; out: CF set <=> error
273
 
379
        push    ebx esi
-
 
380
 
-
 
381
        cmp     [ebp+FAT.fs_type], 16
-
 
382
        je      gfc_1
Line 274... Line 383...
274
        cmp     [fs_type], 16
383
        add     eax, eax
275
        je      gfc_1
384
  gfc_1:
276
        add     eax, eax
385
        add     eax, eax
277
  gfc_1:
386
        mov     esi, 511
278
        add     eax, eax
387
        and     esi, eax        ; esi = position in fat sector
279
        mov     esi, 511
388
        shr     eax, 9          ; eax = fat sector
280
        and     esi, eax        ; esi = position in fat sector
389
        add     eax, [ebp+FAT.FAT_START]
281
        shr     eax, 9          ; eax = fat sector
390
        lea     ebx, [ebp+FAT.fat_cache]
282
        add     eax, [FAT_START]
391
 
283
        mov     ebx, fat_cache
392
        cmp     eax, [ebp+FAT.fat_in_cache]; is fat sector already in memory?
284
 
393
        je      gfc_in_cache
285
        cmp     eax, [fat_in_cache]; is fat sector already in memory?
394
 
Line 286... Line 395...
286
        je      gfc_in_cache
395
        cmp     [ebp+FAT.fat_change], 0; is fat changed?
287
 
396
        je      gfc_no_change   ; no
288
        cmp     [fat_change], 0 ; is fat changed?
397
        call    write_fat_sector; yes. write it into disk
289
        je      gfc_no_change   ; no
398
        jc      hd_error_01
290
        call    write_fat_sector; yes. write it into disk
399
 
Line 291... Line 400...
291
        cmp     [hd_error], 0
400
  gfc_no_change:
292
        jne     hd_error_01
401
        mov     [ebp+FAT.fat_in_cache], eax
293
 
402
        call    fs_read32_sys
294
  gfc_no_change:
-
 
295
        mov     [fat_in_cache], eax
403
        test    eax, eax
Line 296... Line 404...
296
        call    hd_read
404
        jne     hd_error_01
297
        cmp     [hd_error], 0
405
 
298
        jne     hd_error_01
406
  gfc_in_cache:
299
 
407
        mov     eax, [ebx+esi]
300
  gfc_in_cache:
408
        and     eax, [ebp+FAT.fatMASK]
301
        mov     eax, [ebx+esi]
409
  gfc_return:
Line 302... Line -...
302
        and     eax, [fatMASK]
-
 
303
 hd_error_01:
-
 
304
        pop     esi ebx
410
        pop     esi ebx
305
        ret
411
        ret
306
 
412
 hd_error_01:
307
 
413
        stc
Line -... Line 414...
-
 
414
        jmp     gfc_return
-
 
415
 
-
 
416
 
-
 
417
get_free_FAT:
308
get_free_FAT:
418
;-----------------------------------------------------------
309
;-----------------------------------------------------------
419
; output : if CARRY=0 EAX = # first cluster found free
310
; output : if CARRY=0 EAX = # first cluster found free
420
;          if CARRY=1 disk full
311
;          if CARRY=1 disk full
421
; Note   : for more speed need to use fat_cache directly
312
; Note   : for more speed need to use fat_cache directly
422
;-----------------------------------------------------------
313
;-----------------------------------------------------------
423
        push    ecx
Line 356... Line 466...
356
;-----------------------------------------------------------
466
;-----------------------------------------------------------
357
; write changed fat to disk
467
; write changed fat to disk
358
;-----------------------------------------------------------
468
;-----------------------------------------------------------
359
        push    eax ebx ecx
469
        push    eax ebx ecx
Line 360... Line 470...
360
 
470
 
361
        mov     [fat_change], 0
471
        mov     [ebp+FAT.fat_change], 0
362
        mov     eax, [fat_in_cache]
472
        mov     eax, [ebp+FAT.fat_in_cache]
363
        cmp     eax, -1
473
        cmp     eax, -1
364
        jz      write_fat_not_used
474
        jz      write_fat_not_used
365
        mov     ebx, fat_cache
475
        lea     ebx, [ebp+FAT.fat_cache]
Line 366... Line 476...
366
        mov     ecx, [NUMBER_OF_FATS]
476
        mov     ecx, [ebp+FAT.NUMBER_OF_FATS]
-
 
477
 
367
 
478
  write_next_fat:
-
 
479
        push    eax
368
  write_next_fat:
480
        call    fs_write32_sys
369
        call    hd_write
481
        test    eax, eax
Line 370... Line 482...
370
        cmp     [hd_error], 0
482
        pop     eax
371
        jne     write_fat_not_used
483
        jnz     write_fat_not_used
372
 
484
 
Line 373... Line 485...
373
        add     eax, [SECTORS_PER_FAT]
485
        add     eax, [ebp+FAT.SECTORS_PER_FAT]
374
        dec     ecx
486
        dec     ecx
375
        jnz     write_next_fat
487
        jnz     write_next_fat
Line 376... Line -...
376
 
-
 
377
  write_fat_not_used:
-
 
378
        pop     ecx ebx eax
-
 
379
        ret
-
 
380
 
-
 
381
 
-
 
382
analyze_directory:
-
 
383
;-----------------------------------------------------------
-
 
384
; input  : EAX = first cluster of the directory
-
 
385
;          EBX = pointer to filename
-
 
386
; output : IF CARRY=0 EAX = sector where th file is found
-
 
387
;                     EBX = pointer in buffer
-
 
388
;                     [buffer .. buffer+511]
-
 
389
;                     ECX,EDX,ESI,EDI not changed
-
 
390
;          IF CARRY=1 filename not found
-
 
391
; Note   : if cluster=0 it's changed to read rootdir
-
 
392
;          save 2 previous directory sectors in longname_sec
-
 
393
;-----------------------------------------------------------
-
 
394
        push    ecx edx esi edi ebx; ebx = [esp+0]
-
 
395
        mov     [longname_sec1], 0
-
 
396
        mov     [longname_sec2], 0
-
 
397
 
-
 
398
  adr_new_cluster:
-
 
399
        mov     [cluster_tmp], eax
-
 
400
        mov     [fat16_root], 0
-
 
401
        cmp     eax, [LAST_CLUSTER]
-
 
402
        ja      adr_not_found   ; too big cluster number, something is wrong
-
 
403
        cmp     eax, 2
-
 
404
        jnb     adr_data_cluster
-
 
405
 
-
 
406
        mov     eax, [ROOT_CLUSTER]; if cluster < 2 then read rootdir
-
 
407
        cmp     [fs_type], 16
-
 
408
        jne     adr_data_cluster
-
 
409
        mov     eax, [ROOT_START]
-
 
410
        mov     edx, [ROOT_SECTORS]
-
 
411
        mov     [fat16_root], 1 ; flag for fat16 rootdir
-
 
412
        jmp     adr_new_sector
-
 
413
 
-
 
414
  adr_data_cluster:
-
 
415
        sub     eax, 2
-
 
416
        mov     edx, [SECTORS_PER_CLUSTER]
-
 
417
        imul    eax, edx
-
 
418
        add     eax, [DATA_START]
-
 
419
 
-
 
420
  adr_new_sector:
-
 
421
        mov     ebx, buffer
-
 
422
        call    hd_read
-
 
423
        cmp     [hd_error], 0
-
 
424
        jne     adr_not_found
-
 
425
 
-
 
426
        mov     ecx, 512/32     ; count of dir entrys per sector = 16
-
 
427
 
-
 
428
  adr_analyze:
-
 
429
        mov     edi, [ebx+11]   ; file attribute
-
 
430
        and     edi, 0xf
-
 
431
        cmp     edi, 0xf
-
 
432
        je      adr_long_filename
-
 
433
        test    edi, 0x8        ; skip over volume label
-
 
434
        jne     adr_long_filename; Note: label can be same name as file/dir
-
 
435
 
-
 
436
        mov     esi, [esp+0]    ; filename need to be uppercase
-
 
437
        mov     edi, ebx
-
 
438
        push    ecx
-
 
439
        mov     ecx, 11
-
 
440
        cld
-
 
441
        rep cmpsb               ; compare 8+3 filename
-
 
442
        pop     ecx
-
 
443
        je      adr_found
-
 
444
 
-
 
445
  adr_long_filename:
-
 
446
        add     ebx, 32         ; position of next dir entry
-
 
447
        dec     ecx
-
 
448
        jnz     adr_analyze
-
 
449
 
-
 
450
        mov     ecx, [longname_sec1]; save 2 previous directory sectors
-
 
451
        mov     [longname_sec1], eax; for delete long filename
-
 
452
        mov     [longname_sec2], ecx
-
 
453
        inc     eax             ; next sector
-
 
454
        dec     edx
-
 
455
        jne     adr_new_sector
-
 
456
        cmp     [fat16_root], 1 ; end of fat16 rootdir
-
 
457
        je      adr_not_found
-
 
458
 
-
 
459
  adr_next_cluster:
-
 
460
        mov     eax, [cluster_tmp]
-
 
461
        call    get_FAT         ; get next cluster
-
 
462
        cmp     [hd_error], 0
-
 
463
        jne     adr_not_found
-
 
464
 
-
 
465
        cmp     eax, 2          ; incorrect fat chain?
-
 
466
        jb      adr_not_found   ; yes
-
 
467
        cmp     eax, [fatRESERVED]; is it end of directory?
-
 
468
        jb      adr_new_cluster ; no. analyse it
-
 
469
 
-
 
470
  adr_not_found:
-
 
471
        pop     edi edi esi edx ecx; first edi will remove ebx
-
 
472
        stc                     ; file not found
-
 
473
        ret
-
 
474
 
-
 
475
  adr_found:
-
 
476
        pop     edi edi esi edx ecx; first edi will remove ebx
-
 
477
        clc                     ; file found
-
 
478
        ret
-
 
479
 
-
 
480
 
-
 
481
get_data_cluster:
-
 
482
;-----------------------------------------------------------
-
 
483
; input  : EAX = cluster
-
 
484
;          EBX = pointer to buffer
-
 
485
;          EDX = # blocks to read in buffer
-
 
486
;          ESI = # blocks to skip over
-
 
487
; output : if CARRY=0 ok EBX/EDX/ESI updated
-
 
488
;          if CARRY=1 cluster out of range
-
 
489
; Note   : if cluster=0 it's changed to read rootdir
-
 
490
;-----------------------------------------------------------
-
 
491
        push    eax ecx
-
 
492
 
-
 
493
        mov     [fat16_root], 0
-
 
494
        cmp     eax, [LAST_CLUSTER]
-
 
495
        ja      gdc_error       ; too big cluster number, something is wrong
-
 
496
        cmp     eax, 2
-
 
497
        jnb     gdc_cluster
-
 
498
 
-
 
499
        mov     eax, [ROOT_CLUSTER]; if cluster < 2 then read rootdir
-
 
500
        cmp     [fs_type], 16
-
 
501
        jne     gdc_cluster
-
 
502
        mov     eax, [ROOT_START]
-
 
503
        mov     ecx, [ROOT_SECTORS]; Note: not cluster size
-
 
504
        mov     [fat16_root], 1 ; flag for fat16 rootdir
-
 
505
        jmp     gdc_read
-
 
506
 
-
 
507
  gdc_cluster:
-
 
508
        sub     eax, 2
-
 
509
        mov     ecx, [SECTORS_PER_CLUSTER]
-
 
510
        imul    eax, ecx
-
 
511
        add     eax, [DATA_START]
-
 
512
 
-
 
513
  gdc_read:
-
 
514
        test    esi, esi        ; first wanted block
-
 
515
        je      gdcl1           ; yes, skip count is 0
-
 
516
        dec     esi
-
 
517
        jmp     gdcl2
-
 
518
 
-
 
519
  gdcl1:
-
 
520
        call    hd_read
-
 
521
        cmp     [hd_error], 0
-
 
522
        jne     gdc_error
-
 
523
 
-
 
524
        add     ebx, 512        ; update pointer
-
 
525
        dec     edx
-
 
526
 
-
 
527
  gdcl2:
-
 
Line 528... Line -...
528
        test    edx, edx        ; is all read?
-
 
529
        je      out_of_read
-
 
530
 
-
 
531
        inc     eax             ; next sector
-
 
532
        dec     ecx
-
 
533
        jnz     gdc_read
-
 
534
 
-
 
535
  out_of_read:
-
 
536
        pop     ecx eax
-
 
537
        clc
-
 
538
        ret
-
 
539
 
-
 
540
  gdc_error:
-
 
541
        pop     ecx eax
-
 
542
        stc
-
 
543
        ret
-
 
544
 
-
 
545
 
-
 
546
get_cluster_of_a_path:
-
 
547
;---------------------------------------------------------
-
 
548
; input  : EBX = pointer to a path string
-
 
549
;          (example: the path "/files/data/document" become
-
 
550
;                             "files......data.......document...0"
-
 
551
;          '.' = space char
-
 
552
;          '0' = char(0) (ASCII=0) !!! )
-
 
553
; output : if (CARRY=1) -> ERROR in the PATH
-
 
554
;          if (CARRY=0) -> EAX=cluster
-
 
555
;---------------------------------------------------------
-
 
556
        push    ebx edx
-
 
557
 
-
 
558
        mov     eax, [ROOT_CLUSTER]
-
 
559
        mov     edx, ebx
-
 
560
 
-
 
561
search_end_of_path:
-
 
562
        cmp     byte [edx], 0
-
 
563
        je      found_end_of_path
-
 
564
 
-
 
565
        inc     edx; '/'
-
 
566
        mov     ebx, edx
-
 
567
        call    analyze_directory
-
 
568
        jc      directory_not_found
-
 
569
 
-
 
570
        mov     eax, [ebx+20-2] ; read the HIGH 16bit cluster field
-
 
571
        mov     ax, [ebx+26]    ; read the LOW 16bit cluster field
-
 
572
        and     eax, [fatMASK]
-
 
573
        add     edx, 11         ; 8+3 (name+extension)
-
 
574
        jmp     search_end_of_path
-
 
575
 
-
 
576
found_end_of_path:
-
 
577
        pop     edx ebx
-
 
Line 578... Line 488...
578
        clc                     ; no errors
488
 
579
        ret
489
  write_fat_not_used:
580
 
490
        pop     ecx ebx eax
Line 674... Line 584...
674
; Note   : negative = remove clusters from free space
584
; Note   : negative = remove clusters from free space
675
;          positive = add clusters to free space
585
;          positive = add clusters to free space
676
;-----------------------------------------------------
586
;-----------------------------------------------------
677
        test    ecx, ecx        ; no change
587
        test    ecx, ecx        ; no change
678
        je      add_dfs_no
588
        je      add_dfs_no
679
        cmp     [fs_type], 32  ; free disk space only used by fat32
589
        cmp     [ebp+FAT.fs_type], 32  ; free disk space only used by fat32
680
        jne     add_dfs_no
590
        jne     add_dfs_no
Line 681... Line 591...
681
 
591
 
682
        push    eax ebx
592
        push    eax ebx
683
        mov     eax, [ADR_FSINFO]
593
        mov     eax, [ebp+FAT.ADR_FSINFO]
684
        mov     ebx, fsinfo_buffer
594
        lea     ebx, [ebp+FAT.fsinfo_buffer]
685
        call    hd_read
595
        call    fs_read32_sys
686
        cmp     [hd_error], 0
596
        test    eax, eax
Line 687... Line 597...
687
        jne     add_not_fs
597
        jnz     add_not_fs
688
 
598
 
Line 689... Line 599...
689
        cmp     dword [ebx+0x1fc], 0xaa550000; check sector id
599
        cmp     dword [ebx+0x1fc], 0xaa550000; check sector id
690
        jne     add_not_fs
600
        jne     add_not_fs
691
 
601
 
692
        add     [ebx+0x1e8], ecx
602
        add     [ebx+0x1e8], ecx
693
        push    [fatStartScan]
603
        push    [ebp+FAT.fatStartScan]
694
        pop     dword [ebx+0x1ec]
604
        pop     dword [ebx+0x1ec]
Line 695... Line 605...
695
        call    hd_write
605
        mov     eax, [ebp+FAT.ADR_FSINFO]
696
;    cmp   [hd_error],0
606
        call    fs_write32_sys
Line 697... Line 607...
697
;    jne   add_not_fs
607
;    jc    add_not_fs
698
 
608
 
Line 699... Line -...
699
  add_not_fs:
-
 
700
        pop     ebx eax
-
 
701
 
-
 
702
  add_dfs_no:
-
 
703
        ret
-
 
704
 
-
 
705
 
-
 
706
file_read:
-
 
707
;--------------------------------------------------------------------------
-
 
708
;   INPUT :  user-register register-in-this  meaning         symbol-in-this
-
 
709
;
-
 
710
;            EAX           EDI               system call to write   /
-
 
711
;            EBX           EAX   (PAR0)      pointer to file-name   PAR0
-
 
712
;            EDX           ECX   (PAR1)      pointer to buffer      PAR1
-
 
713
;            ECX           EBX   (PAR2)   vt file blocks to read    PAR2
-
 
714
;            ESI           EDX   (PAR3)      pointer to path        PAR3
-
 
715
;            EDI           ESI            vt first 512 block to read
-
 
716
;                          EDI               if 0 - read root
-
 
717
;
-
 
718
; output : eax = 0 - ok
-
 
719
;                3 - unknown FS
-
 
720
;                5 - file not found
-
 
721
;                6 - end of file
-
 
722
;                9 - fat table corrupted
-
 
723
;               10 - access denied
-
 
724
;          ebx = size of file/directory
-
 
725
;--------------------------------------------------------------------------
-
 
726
        cmp     [fs_type], 16
-
 
727
        jz      fat_ok_for_reading
-
 
728
        cmp     [fs_type], 32
-
 
729
        jz      fat_ok_for_reading
-
 
730
        xor     ebx, ebx
-
 
731
        mov     eax, ERROR_UNKNOWN_FS
-
 
732
        mov     [hd1_status], ebx
-
 
733
        ret
-
 
734
 
-
 
735
  fat_ok_for_reading:
-
 
736
;    call  reserve_hd1
-
 
737
 
-
 
738
        pushad
-
 
739
 
-
 
740
        mov     ebx, edx
-
 
741
        call    get_cluster_of_a_path
-
 
742
        jc      file_to_read_not_found
-
 
743
 
-
 
744
        test    edi, edi        ; read rootdir
-
 
745
        jne     no_read_root
-
 
746
 
-
 
747
        xor     eax, eax
-
 
748
        call    get_dir_size    ; return rootdir size
-
 
749
        cmp     [hd_error], 0
-
 
750
        jne     file_access_denied
-
 
751
 
-
 
752
        mov     [file_size], eax
-
 
753
        mov     eax, [ROOT_CLUSTER]
-
 
754
        jmp     file_read_start
-
 
755
 
-
 
756
  no_read_root:
-
 
757
        mov     ebx, PUSHAD_EAX ; file name
-
 
758
        call    analyze_directory
-
 
759
        jc      file_to_read_not_found
-
 
760
 
-
 
761
        mov     eax, [ebx+28]   ; file size
-
 
762
        test    byte [ebx+11], 0x10; is it directory?
-
 
763
        jz      read_set_size   ; no
-
 
764
 
-
 
765
        mov     eax, [ebx+20-2] ; FAT entry
-
 
766
        mov     ax, [ebx+26]
-
 
767
        and     eax, [fatMASK]
-
 
768
        call    get_dir_size
-
 
769
        cmp     [hd_error], 0
-
 
770
        jne     file_access_denied
-
 
771
 
-
 
772
  read_set_size:
-
 
773
        mov     [file_size], eax
-
 
774
 
-
 
775
        mov     eax, [ebx+20-2] ; FAT entry
-
 
776
        mov     ax, [ebx+26]
-
 
777
        and     eax, [fatMASK]
-
 
778
 
-
 
779
  file_read_start:
-
 
780
        mov     ebx, PUSHAD_ECX ; pointer to buffer
-
 
781
        mov     edx, PUSHAD_EBX ; file blocks to read
-
 
782
        mov     esi, PUSHAD_ESI ; first 512 block to read
-
 
783
 
-
 
784
  file_read_new_cluster:
-
 
785
        call    get_data_cluster
-
 
786
        jc      file_read_eof   ; end of file or cluster out of range
-
 
787
 
-
 
788
        test    edx, edx        ; is all read?
-
 
789
        je      file_read_OK    ; yes
-
 
790
 
-
 
791
        call    get_FAT         ; get next cluster
-
 
792
        cmp     [hd_error], 0
-
 
793
        jne     file_access_denied
-
 
794
 
-
 
795
        cmp     eax, [fatRESERVED]; end of file
-
 
796
        jnb     file_read_eof
-
 
797
        cmp     eax, 2          ; incorrect fat chain
-
 
798
        jnb     file_read_new_cluster
-
 
799
 
-
 
800
        popad
-
 
801
        mov     [hd1_status], 0
-
 
802
        mov     ebx, [file_size]
-
 
803
        mov     eax, ERROR_FAT_TABLE
-
 
804
        ret
-
 
805
 
-
 
806
  file_read_eof:
-
 
807
        cmp     [hd_error], 0
-
 
808
        jne     file_access_denied
-
 
809
        popad
-
 
810
        mov     [hd1_status], 0
-
 
811
        mov     ebx, [file_size]
-
 
812
        mov     eax, ERROR_END_OF_FILE
-
 
813
        ret
-
 
814
 
-
 
815
  file_read_OK:
-
 
816
        popad
-
 
817
        mov     [hd1_status], 0
-
 
818
        mov     ebx, [file_size]
-
 
819
        xor     eax, eax
-
 
820
        ret
-
 
821
 
-
 
822
  file_to_read_not_found:
-
 
823
        cmp     [hd_error], 0
-
 
824
        jne     file_access_denied
-
 
825
        popad
-
 
826
        mov     [hd1_status], 0
-
 
827
        xor     ebx, ebx
-
 
828
        mov     eax, ERROR_FILE_NOT_FOUND
-
 
829
        ret
-
 
830
 
-
 
831
  file_access_denied:
-
 
832
        popad
-
 
833
        mov     [hd1_status], 0
-
 
834
        xor     ebx, ebx
-
 
835
        mov     eax, ERROR_ACCESS_DENIED
-
 
836
        ret
-
 
837
 
-
 
838
get_dir_size:
-
 
839
;-----------------------------------------------------
-
 
840
; input  : eax = first cluster (0=rootdir)
-
 
841
; output : eax = directory size in bytes
-
 
842
;-----------------------------------------------------
-
 
843
        push    edx
-
 
844
        xor     edx, edx        ; count of directory clusters
-
 
845
        test    eax, eax
-
 
846
        jnz     dir_size_next
-
 
847
 
-
 
848
        mov     eax, [ROOT_SECTORS]
-
 
849
        shl     eax, 9          ; fat16 rootdir size in bytes
-
 
850
        cmp     [fs_type], 16
-
 
851
        je      dir_size_ret
-
 
852
        mov     eax, [ROOT_CLUSTER]
-
 
853
 
-
 
854
  dir_size_next:
-
 
855
        cmp     eax, 2          ; incorrect fat chain
-
 
856
        jb      dir_size_end
-
 
857
        cmp     eax, [fatRESERVED]; end of directory
-
 
858
        ja      dir_size_end
-
 
859
        call    get_FAT         ; get next cluster
-
 
860
        cmp     [hd_error], 0
-
 
861
        jne     dir_size_ret
-
 
862
 
-
 
863
        inc     edx
-
 
864
        jmp     dir_size_next
-
 
865
 
-
 
866
  dir_size_end:
-
 
Line 867... Line 609...
867
        imul    eax, [SECTORS_PER_CLUSTER], 512; cluster size in bytes
609
  add_not_fs:
868
        imul    eax, edx
610
        pop     ebx eax
869
 
611
 
870
  dir_size_ret:
612
  add_dfs_no:
871
        pop     edx
613
        ret
872
        ret
614
 
Line 873... Line 615...
873
 
615
 
874
 
616
 
875
clear_cluster_chain:
617
clear_cluster_chain:
876
;-----------------------------------------------------
618
;-----------------------------------------------------
877
; input  : eax = first cluster
619
; input  : eax = first cluster
878
;-----------------------------------------------------
620
;-----------------------------------------------------
879
        push    eax ecx edx
621
        push    eax ecx edx
Line 880... Line 622...
880
        xor     ecx, ecx        ; cluster count
622
        xor     ecx, ecx        ; cluster count
881
 
623
 
882
  clean_new_chain:
-
 
883
        cmp     eax, [LAST_CLUSTER]; end of file
624
  clean_new_chain:
Line 884... Line 625...
884
        ja      delete_OK
625
        cmp     eax, [ebp+FAT.LAST_CLUSTER]; end of file
885
        cmp     eax, 2          ; unfinished fat chain or zero length file
626
        ja      delete_OK
886
        jb      delete_OK
627
        cmp     eax, 2          ; unfinished fat chain or zero length file
Line 887... Line 628...
887
        cmp     eax, [ROOT_CLUSTER]; don't remove root cluster
628
        jb      delete_OK
888
        jz      delete_OK
629
        cmp     eax, [ebp+FAT.ROOT_CLUSTER]; don't remove root cluster
-
 
630
        jz      delete_OK
889
 
631
 
890
        xor     edx, edx
632
        xor     edx, edx
891
        call    set_FAT         ; clear fat entry
633
        call    set_FAT         ; clear fat entry
Line -... Line 634...
-
 
634
        jc      access_denied_01
892
        cmp     [hd_error], 0
635
 
893
        jne     access_denied_01
636
        inc     ecx             ; update cluster count
894
 
637
        mov     eax, edx        ; old cluster
895
        inc     ecx             ; update cluster count
638
        jmp     clean_new_chain
896
        mov     eax, edx        ; old cluster
639
 
897
        jmp     clean_new_chain
640
  delete_OK:
898
 
641
        call    add_disk_free_space; add clusters to free disk space
899
  delete_OK:
642
        clc
900
        call    add_disk_free_space; add clusters to free disk space
643
  access_denied_01:
901
  access_denied_01:
644
        pop     edx ecx eax
902
        pop     edx ecx eax
645
        ret
903
        ret
646
 
904
 
647
 
905
 
648
if 0
906
get_hd_info:
649
get_hd_info:
907
;-----------------------------------------------------------
650
;-----------------------------------------------------------
908
; output : eax = 0 - ok
651
; output : eax = 0 - ok
Line 925... Line 668...
925
  info_fat_ok:
668
  info_fat_ok:
926
;    call  reserve_hd1
669
;    call  reserve_hd1
Line 927... Line 670...
927
 
670
 
928
        xor     ecx, ecx        ; count of free clusters
671
        xor     ecx, ecx        ; count of free clusters
929
        mov     eax, 2
672
        mov     eax, 2
Line 930... Line 673...
930
        mov     ebx, [LAST_CLUSTER]
673
        mov     ebx, [ebp+FAT.LAST_CLUSTER]
931
 
674
 
932
  info_cluster:
675
  info_cluster:
933
        push    eax
-
 
934
        call    get_FAT         ; get cluster info
676
        push    eax
Line 935... Line 677...
935
        cmp     [hd_error], 0
677
        call    get_FAT         ; get cluster info
936
        jne     info_access_denied
678
        jc      info_access_denied
937
 
679
 
Line 944... Line 686...
944
        inc     eax
686
        inc     eax
945
        cmp     eax, ebx        ; is above last cluster?
687
        cmp     eax, ebx        ; is above last cluster?
946
        jbe     info_cluster    ; no. test next cluster
688
        jbe     info_cluster    ; no. test next cluster
Line 947... Line 689...
947
 
689
 
948
        dec     ebx             ; cluster count
690
        dec     ebx             ; cluster count
949
        imul    edx, [SECTORS_PER_CLUSTER], 512; cluster size in bytes
-
 
950
        mov     [hd1_status], 0
691
        imul    edx, [ebp+FAT.SECTORS_PER_CLUSTER], 512; cluster size in bytes
951
        xor     eax, eax
692
        xor     eax, eax
Line 952... Line 693...
952
        ret
693
        ret
953
 
694
 
954
  info_access_denied:
695
  info_access_denied:
955
        add     esp, 4
696
        add     esp, 4
956
        xor     edx, edx
697
        xor     edx, edx
957
        xor     ebx, ebx
698
        xor     ebx, ebx
958
        xor     ecx, ecx
699
        xor     ecx, ecx
-
 
700
        mov     eax, ERROR_ACCESS_DENIED
Line 959... Line 701...
959
        mov     eax, ERROR_ACCESS_DENIED
701
        ret
960
        ret
702
end if
961
 
703
 
962
update_disk:
704
update_disk:
963
;-----------------------------------------------------------
705
;-----------------------------------------------------------
964
; write changed fat and cache to disk
706
; write changed fat and cache to disk
Line 965... Line 707...
965
;-----------------------------------------------------------
707
;-----------------------------------------------------------
966
        cmp     [fat_change], 0 ; is fat changed?
-
 
967
        je      upd_no_change
708
        cmp     [ebp+FAT.fat_change], 0 ; is fat changed?
Line 968... Line 709...
968
 
709
        je      upd_no_change
Line -... Line 710...
-
 
710
 
-
 
711
        call    write_fat_sector
969
        call    write_fat_sector
712
        jc      update_disk_acces_denied
-
 
713
 
970
        cmp     [hd_error], 0
714
  upd_no_change:
971
        jne     update_disk_acces_denied
715
 
Line -... Line 716...
-
 
716
        push    esi
-
 
717
        mov     esi, [ebp+PARTITION.Disk]
-
 
718
        call    disk_sync
-
 
719
        pop     esi
-
 
720
  update_disk_acces_denied:
-
 
721
        ret
Line 972... Line 722...
972
 
722
 
973
  upd_no_change:
723
fat_lock:
-
 
724
        lea     ecx, [ebp+FAT.Lock]
974
 
725
        jmp     mutex_lock
975
        call    write_cache
726
fat_unlock:
976
  update_disk_acces_denied:
727
        lea     ecx, [ebp+FAT.Lock]
977
        ret
728
        jmp     mutex_unlock
978
 
729
 
979
 
730
; \begin{diamond}
980
; \begin{diamond}
731
hd_find_lfn:
981
hd_find_lfn:
732
; in: ebp -> FAT structure
982
; in: esi+ebp -> name
733
; in: esi+[esp+4] -> name
983
; out: CF=1 - file not found
734
; out: CF=1 - file not found, eax=error code
984
;      else CF=0 and edi->direntry, eax=sector
735
;      else CF=0 and edi->direntry, eax=sector
985
; destroys eax
736
; destroys eax
986
        push    esi edi
737
        push    esi edi
987
        push    0
738
        push    0
988
        push    0
739
        push    0
989
        push    fat16_root_first
740
        push    fat16_root_first
Line 1009... Line 760...
1009
        jmp     .loop
760
        jmp     .loop
1010
.notfound:
761
.notfound:
1011
        add     esp, 16
762
        add     esp, 16
1012
        pop     edi esi
763
        pop     edi esi
1013
        stc
764
        stc
1014
        ret
765
        ret     4
1015
.found:
766
.found:
1016
        test    ebp, ebp
767
        lea     eax, [esp+4+24]
-
 
768
        cmp     dword [eax], 0
1017
        jz      @f
769
        jz      @f
1018
        mov     esi, ebp
770
        mov     esi, [eax]
1019
        xor     ebp, ebp
771
        and     dword [eax], 0
1020
        jmp     .continue
772
        jmp     .continue
1021
@@:
773
@@:
1022
        lea     eax, [esp+8]
774
        lea     eax, [esp+8]
1023
        cmp     dword [eax], 0
775
        cmp     dword [eax], 0
1024
        jz      .root
776
        jz      .root
1025
        call    fat_get_sector
777
        call    fat_get_sector
1026
        jmp     .cmn
778
        jmp     .cmn
1027
.root:
779
.root:
1028
        mov     eax, [eax+4]
780
        mov     eax, [eax+4]
1029
        add     eax, [ROOT_START]
781
        add     eax, [ebp+FAT.ROOT_START]
1030
.cmn:
782
.cmn:
1031
        add     esp, 20         ; CF=0
783
        add     esp, 20         ; CF=0
1032
        pop     esi
784
        pop     esi
1033
        ret
785
        ret     4
Line 1034... Line 786...
1034
 
786
 
1035
;----------------------------------------------------------------
787
;----------------------------------------------------------------
1036
;
788
;
1037
;  fs_HdRead - LFN variant for reading hard disk
789
;  fs_HdRead - LFN variant for reading hard disk
-
 
790
;
-
 
791
;  Obsolete, will be replaced with filesystem-specific functions.
1038
;
792
;
1039
;  esi  points to filename
793
;  esi  points to filename
1040
;  ebx  pointer to 64-bit number = first wanted byte, 0+
794
;  ebx  pointer to 64-bit number = first wanted byte, 0+
1041
;       may be ebx=0 - start from first byte
795
;       may be ebx=0 - start from first byte
1042
;  ecx  number of bytes to read, 0+
796
;  ecx  number of bytes to read, 0+
Line 1057... Line 811...
1057
        jz      ext2_HdRead
811
        jz      ext2_HdRead
1058
        or      ebx, -1
812
        or      ebx, -1
1059
        mov     eax, ERROR_UNKNOWN_FS
813
        mov     eax, ERROR_UNKNOWN_FS
1060
        ret
814
        ret
1061
@@:
815
@@:
-
 
816
        sub     ebx, 4
-
 
817
        push    ebp
-
 
818
        mov     ebp, [fs_dependent_data_start.partition]
-
 
819
        call    fat_Read
-
 
820
        pop     ebp
-
 
821
        ret
-
 
822
 
-
 
823
;----------------------------------------------------------------
-
 
824
; fat_Read - FAT16/32 implementation of reading a file
-
 
825
; in:  ebp = pointer to FAT structure
-
 
826
; in:  esi+[esp+4] = name
-
 
827
; in:  ebx = pointer to parameters from sysfunc 70
-
 
828
; out: eax, ebx = return values for sysfunc 70
-
 
829
;----------------------------------------------------------------
-
 
830
fat_Read:
-
 
831
        call    fat_lock
1062
        push    edi
832
        push    edi
1063
        cmp     byte [esi], 0
833
        cmp     byte [esi], 0
1064
        jnz     @f
834
        jnz     @f
1065
.noaccess:
835
.noaccess:
1066
        pop     edi
836
        pop     edi
1067
.noaccess_2:
837
.noaccess_2:
-
 
838
        call    fat_unlock
1068
        or      ebx, -1
839
        or      ebx, -1
1069
        mov     eax, ERROR_ACCESS_DENIED
840
        mov     eax, ERROR_ACCESS_DENIED
1070
        ret
841
        ret
Line 1071... Line 842...
1071
 
842
 
1072
@@:
843
@@:
1073
        call    hd_find_lfn
844
        stdcall hd_find_lfn, [esp+4+4]
1074
        jnc     .found
845
        jnc     .found
-
 
846
        pop     edi
1075
        pop     edi
847
        push    eax
1076
        cmp     [hd_error], 0
848
        call    fat_unlock
1077
        jne     .noaccess_2
849
        pop     eax
1078
        or      ebx, -1
-
 
1079
        mov     eax, ERROR_FILE_NOT_FOUND
850
        or      ebx, -1
Line 1080... Line 851...
1080
        ret
851
        ret
1081
 
852
 
1082
.found:
853
.found:
1083
        test    byte [edi+11], 0x10; do not allow read directories
-
 
1084
        jnz     .noaccess
-
 
1085
        test    ebx, ebx
854
        test    byte [edi+11], 0x10; do not allow read directories
1086
        jz      .l1
855
        jnz     .noaccess
1087
        cmp     dword [ebx+4], 0
856
        cmp     dword [ebx+8], 0
1088
        jz      @f
857
        jz      @f
1089
        xor     ebx, ebx
858
        xor     ebx, ebx
-
 
859
.reteof:
1090
.reteof:
860
        call    fat_unlock
1091
        mov     eax, 6
861
        mov     eax, ERROR_END_OF_FILE
1092
        pop     edi
862
        pop     edi
1093
        ret
863
        ret
1094
@@:
-
 
-
 
864
@@:
-
 
865
        mov     ecx, [ebx+12]   ; size
1095
        mov     ebx, [ebx]
866
        mov     edx, [ebx+16]   ; pointer
1096
.l1:
867
        mov     ebx, [ebx+4]    ; file offset
1097
        push    ecx edx
868
        push    edx
1098
        push    0
869
        push    0
1099
        mov     eax, [edi+28]
870
        mov     eax, [edi+28]
1100
        sub     eax, ebx
871
        sub     eax, ebx
Line 1107... Line 878...
1107
        mov     eax, [edi+20-2]
878
        mov     eax, [edi+20-2]
1108
        mov     ax, [edi+26]
879
        mov     ax, [edi+26]
1109
; now eax=cluster, ebx=position, ecx=count, edx=buffer for data
880
; now eax=cluster, ebx=position, ecx=count, edx=buffer for data
1110
.new_cluster:
881
.new_cluster:
1111
        jecxz   .new_sector
882
        jecxz   .new_sector
1112
        test    eax, eax
883
        cmp     eax, 2
1113
        jz      .eof
884
        jb      .eof
1114
        cmp     eax, [fatRESERVED]
885
        cmp     eax, [ebp+FAT.fatRESERVED]
1115
        jae     .eof
886
        jae     .eof
1116
        mov     [cluster_tmp], eax
887
        mov     [ebp+FAT.cluster_tmp], eax
1117
        dec     eax
888
        dec     eax
1118
        dec     eax
889
        dec     eax
1119
        mov     edi, [SECTORS_PER_CLUSTER]
890
        mov     edi, [ebp+FAT.SECTORS_PER_CLUSTER]
1120
        imul    eax, edi
891
        imul    eax, edi
1121
        add     eax, [DATA_START]
892
        add     eax, [ebp+FAT.DATA_START]
1122
.new_sector:
893
.new_sector:
1123
        test    ecx, ecx
894
        test    ecx, ecx
1124
        jz      .done
895
        jz      .done
1125
        sub     ebx, 512
896
        sub     ebx, 512
1126
        jae     .skip
897
        jae     .skip
1127
        add     ebx, 512
898
        add     ebx, 512
1128
        jnz     .force_buf
899
        jnz     .force_buf
1129
        cmp     ecx, 512
900
        cmp     ecx, 512
1130
        jb      .force_buf
901
        jb      .force_buf
1131
; we may read directly to given buffer
902
; we may read directly to given buffer
1132
        push    ebx
903
        push    eax ebx
1133
        mov     ebx, edx
904
        mov     ebx, edx
1134
        call    hd_read
905
        call    fs_read32_app
1135
        pop     ebx
906
        test    eax, eax
1136
        cmp     [hd_error], 0
907
        pop     ebx eax
1137
        jne     .noaccess_1
908
        jne     .noaccess_1
1138
        add     edx, 512
909
        add     edx, 512
1139
        sub     ecx, 512
910
        sub     ecx, 512
1140
        jmp     .skip
911
        jmp     .skip
1141
.force_buf:
912
.force_buf:
1142
; we must read sector to temporary buffer and then copy it to destination
913
; we must read sector to temporary buffer and then copy it to destination
1143
        push    eax ebx
914
        push    eax ebx
1144
        mov     ebx, buffer
915
        lea     ebx, [ebp+FAT.buffer]
1145
        call    hd_read
916
        call    fs_read32_app
-
 
917
        test    eax, eax
1146
        mov     eax, ebx
918
        mov     eax, ebx
1147
        pop     ebx
919
        pop     ebx
1148
        cmp     [hd_error], 0
-
 
1149
        jne     .noaccess_3
920
        jne     .noaccess_3
1150
        add     eax, ebx
921
        add     eax, ebx
1151
        push    ecx
922
        push    ecx
1152
        add     ecx, ebx
923
        add     ecx, ebx
1153
        cmp     ecx, 512
924
        cmp     ecx, 512
Line 1164... Line 935...
1164
        xor     ebx, ebx
935
        xor     ebx, ebx
1165
.skip:
936
.skip:
1166
        inc     eax
937
        inc     eax
1167
        dec     edi
938
        dec     edi
1168
        jnz     .new_sector
939
        jnz     .new_sector
1169
        mov     eax, [cluster_tmp]
940
        mov     eax, [ebp+FAT.cluster_tmp]
1170
        call    get_FAT
941
        call    get_FAT
1171
        cmp     [hd_error], 0
-
 
1172
        jne     .noaccess_1
942
        jc      .noaccess_1
Line 1173... Line 943...
1173
 
943
 
1174
        jmp     .new_cluster
944
        jmp     .new_cluster
1175
.noaccess_3:
945
.noaccess_3:
1176
        pop     eax
946
        pop     eax
1177
.noaccess_1:
947
.noaccess_1:
1178
        pop     eax
948
        pop     eax
1179
        push    11
949
        push    ERROR_DEVICE
1180
.done:
950
.done:
-
 
951
        mov     ebx, edx
1181
        mov     ebx, edx
952
        call    fat_unlock
1182
        pop     eax edx ecx edi
953
        pop     eax edx edi
1183
        sub     ebx, edx
954
        sub     ebx, edx
1184
        ret
955
        ret
1185
.eof:
956
.eof:
1186
        mov     ebx, edx
957
        mov     ebx, edx
1187
        pop     eax edx ecx
958
        pop     eax edx
1188
        sub     ebx, edx
959
        sub     ebx, edx
Line 1189... Line 960...
1189
        jmp     .reteof
960
        jmp     .reteof
1190
 
961
 
1191
;----------------------------------------------------------------
962
;----------------------------------------------------------------
1192
;
963
;
-
 
964
;  fs_HdReadFolder - LFN variant for reading hard disk folder
-
 
965
;
1193
;  fs_HdReadFolder - LFN variant for reading hard disk folder
966
;  Obsolete, will be replaced with filesystem-specific functions.
1194
;
967
;
1195
;  esi  points to filename
968
;  esi  points to filename
1196
;  ebx  pointer to structure 32-bit number = first wanted block, 0+
969
;  ebx  pointer to structure 32-bit number = first wanted block, 0+
1197
;                          & flags (bitfields)
970
;                          & flags (bitfields)
Line 1202... Line 975...
1202
;  ret ebx = blocks read or 0xffffffff folder not found
975
;  ret ebx = blocks read or 0xffffffff folder not found
1203
;      eax = 0 ok read or other = errormsg
976
;      eax = 0 ok read or other = errormsg
1204
;
977
;
1205
;--------------------------------------------------------------
978
;--------------------------------------------------------------
1206
fs_HdReadFolder:
979
fs_HdReadFolder:
1207
        cmp     [fs_type], 1
-
 
1208
        jz      ntfs_HdReadFolder
-
 
1209
        cmp     [fs_type], 2
-
 
1210
        jz      ext2_HdReadFolder
-
 
1211
        cmp     [fs_type], 16
980
        cmp     [fs_type], 16
1212
        jz      @f
981
        jz      @f
1213
        cmp     [fs_type], 32
982
        cmp     [fs_type], 32
1214
        jz      @f
983
        jz      @f
-
 
984
        cmp     [fs_type], 1
-
 
985
        jz      ntfs_HdReadFolder
-
 
986
        cmp     [fs_type], 2
-
 
987
        jz      ext2_HdReadFolder
1215
        push    ERROR_UNSUPPORTED_FS
988
        push    ERROR_UNSUPPORTED_FS
1216
        pop     eax
989
        pop     eax
1217
        or      ebx, -1
990
        or      ebx, -1
1218
        ret
991
        ret
1219
@@:
992
@@:
-
 
993
        sub     ebx, 4
-
 
994
        push    ebp
-
 
995
        mov     ebp, [fs_dependent_data_start.partition]
-
 
996
        call    fat_ReadFolder
-
 
997
        pop     ebp
-
 
998
        ret
-
 
999
 
-
 
1000
;----------------------------------------------------------------
-
 
1001
; fat_ReadFolder - FAT16/32 implementation of reading a folder
-
 
1002
; in:  ebp = pointer to FAT structure
-
 
1003
; in:  esi+[esp+4] = name
-
 
1004
; in:  ebx = pointer to parameters from sysfunc 70
-
 
1005
; out: eax, ebx = return values for sysfunc 70
-
 
1006
;----------------------------------------------------------------
-
 
1007
fat_ReadFolder:
-
 
1008
        call    fat_lock
1220
        mov     eax, [ROOT_CLUSTER]
1009
        mov     eax, [ebp+FAT.ROOT_CLUSTER]
1221
        push    edi
1010
        push    edi
1222
        cmp     byte [esi], 0
1011
        cmp     byte [esi], 0
1223
        jz      .doit
1012
        jz      .doit
1224
        call    hd_find_lfn
1013
        stdcall hd_find_lfn, [esp+4+4]
1225
        jnc     .found
1014
        jnc     .found
1226
        pop     edi
1015
        pop     edi
-
 
1016
        push    eax
-
 
1017
        call    fat_unlock
-
 
1018
        pop     eax
1227
        or      ebx, -1
1019
        or      ebx, -1
1228
        mov     eax, ERROR_FILE_NOT_FOUND
-
 
1229
        ret
1020
        ret
1230
.found:
1021
.found:
1231
        test    byte [edi+11], 0x10     ; do not allow read files
1022
        test    byte [edi+11], 0x10     ; do not allow read files
1232
        jnz     .found_dir
1023
        jnz     .found_dir
1233
        pop     edi
1024
        pop     edi
-
 
1025
        call    fat_unlock
1234
        or      ebx, -1
1026
        or      ebx, -1
1235
        mov     eax, ERROR_ACCESS_DENIED
1027
        mov     eax, ERROR_ACCESS_DENIED
1236
        ret
1028
        ret
1237
.found_dir:
1029
.found_dir:
1238
        mov     eax, [edi+20-2]
1030
        mov     eax, [edi+20-2]
1239
        mov     ax, [edi+26]    ; eax=cluster
1031
        mov     ax, [edi+26]    ; eax=cluster
1240
.doit:
1032
.doit:
1241
        push    esi ecx
-
 
1242
        push    ebp
1033
        push    esi
1243
        sub     esp, 262*2      ; reserve space for LFN
1034
        sub     esp, 262*2      ; reserve space for LFN
1244
        mov     ebp, esp
-
 
1245
        push    dword [ebx+4]   ; for fat_get_name: read ANSI/UNICODE name
1035
        push    dword [ebx+8]   ; for fat_get_name: read ANSI/UNICODE name
1246
        mov     ebx, [ebx]
1036
        mov     edx, [ebx+16]   ; pointer to buffer
1247
; init header
1037
; init header
1248
        push    eax ecx
1038
        push    eax
1249
        mov     edi, edx
1039
        mov     edi, edx
1250
        mov     ecx, 32/4
1040
        mov     ecx, 32/4
1251
        xor     eax, eax
1041
        xor     eax, eax
1252
        rep stosd
1042
        rep stosd
1253
        pop     ecx eax
1043
        pop     eax
1254
        mov     byte [edx], 1   ; version
1044
        mov     byte [edx], 1   ; version
1255
        mov     esi, edi        ; esi points to BDFE
1045
        mov     esi, edi        ; esi points to BDFE
-
 
1046
        mov     ecx, [ebx+12]   ; number of blocks to read
-
 
1047
        mov     ebx, [ebx+4]    ; index of the first block
1256
.new_cluster:
1048
.new_cluster:
1257
        mov     [cluster_tmp], eax
1049
        mov     [ebp+FAT.cluster_tmp], eax
1258
        test    eax, eax
1050
        test    eax, eax
1259
        jnz     @f
1051
        jnz     @f
1260
        cmp     [fs_type], 32
1052
        cmp     [ebp+FAT.fs_type], 32
1261
        jz      .notfound
1053
        jz      .notfound
1262
        mov     eax, [ROOT_START]
1054
        mov     eax, [ebp+FAT.ROOT_START]
1263
        push    [ROOT_SECTORS]
1055
        push    [ebp+FAT.ROOT_SECTORS]
1264
        push    ebx
1056
        push    ebx
1265
        jmp     .new_sector
1057
        jmp     .new_sector
1266
@@:
1058
@@:
1267
        dec     eax
1059
        dec     eax
1268
        dec     eax
1060
        dec     eax
1269
        imul    eax, [SECTORS_PER_CLUSTER]
1061
        imul    eax, [ebp+FAT.SECTORS_PER_CLUSTER]
1270
        push    [SECTORS_PER_CLUSTER]
1062
        push    [ebp+FAT.SECTORS_PER_CLUSTER]
1271
        add     eax, [DATA_START]
1063
        add     eax, [ebp+FAT.DATA_START]
1272
        push    ebx
1064
        push    ebx
1273
.new_sector:
1065
.new_sector:
1274
        mov     ebx, buffer
1066
        lea     ebx, [ebp+FAT.buffer]
1275
        mov     edi, ebx
1067
        mov     edi, ebx
-
 
1068
        push    eax
1276
        call    hd_read
1069
        call    fs_read32_sys
-
 
1070
        test    eax, eax
1277
        cmp     [hd_error], 0
1071
        pop     eax
1278
        jnz     .notfound2
1072
        jnz     .notfound2
1279
        add     ebx, 512
1073
        add     ebx, 512
1280
        push    eax
1074
        push    eax
1281
.l1:
1075
.l1:
-
 
1076
        push    ebp
-
 
1077
        lea     ebp, [esp+20]
1282
        call    fat_get_name
1078
        call    fat_get_name
-
 
1079
        pop     ebp
1283
        jc      .l2
1080
        jc      .l2
1284
        cmp     byte [edi+11], 0xF
1081
        cmp     byte [edi+11], 0xF
1285
        jnz     .do_bdfe
1082
        jnz     .do_bdfe
1286
        add     edi, 0x20
1083
        add     edi, 0x20
1287
        cmp     edi, ebx
1084
        cmp     edi, ebx
1288
        jb      .do_bdfe
1085
        jb      .do_bdfe
1289
        pop     eax
1086
        pop     eax
1290
        inc     eax
1087
        inc     eax
1291
        dec     dword [esp+4]
1088
        dec     dword [esp+4]
1292
        jnz     @f
1089
        jnz     @f
1293
        mov     eax, [cluster_tmp]
1090
        mov     eax, [ebp+FAT.cluster_tmp]
1294
        test    eax, eax
1091
        test    eax, eax
1295
        jz      .done
1092
        jz      .done
1296
        call    get_FAT
1093
        call    get_FAT
1297
        cmp     [hd_error], 0
-
 
1298
        jnz     .notfound2
1094
        jc      .notfound2
1299
        cmp     eax, 2
1095
        cmp     eax, 2
1300
        jb      .done
1096
        jb      .done
1301
        cmp     eax, [fatRESERVED]
1097
        cmp     eax, [ebp+FAT.fatRESERVED]
1302
        jae     .done
1098
        jae     .done
1303
        push    eax
1099
        push    eax
1304
        mov     eax, [SECTORS_PER_CLUSTER]
1100
        mov     eax, [ebp+FAT.SECTORS_PER_CLUSTER]
1305
        mov     [esp+8], eax
1101
        mov     [esp+8], eax
1306
        pop     eax
1102
        pop     eax
1307
        mov     [cluster_tmp], eax
1103
        mov     [ebp+FAT.cluster_tmp], eax
1308
        dec     eax
1104
        dec     eax
1309
        dec     eax
1105
        dec     eax
1310
        imul    eax, [SECTORS_PER_CLUSTER]
1106
        imul    eax, [ebp+FAT.SECTORS_PER_CLUSTER]
1311
        add     eax, [DATA_START]
1107
        add     eax, [ebp+FAT.DATA_START]
1312
@@:
1108
@@:
1313
        mov     ebx, buffer
1109
        lea     ebx, [ebp+FAT.buffer]
1314
        mov     edi, ebx
1110
        mov     edi, ebx
-
 
1111
        push    eax
1315
        call    hd_read
1112
        call    fs_read32_sys
-
 
1113
        test    eax, eax
1316
        cmp     [hd_error], 0
1114
        pop     eax
1317
        jnz     .notfound2
1115
        jnz     .notfound2
1318
        add     ebx, 512
1116
        add     ebx, 512
1319
        push    eax
1117
        push    eax
1320
.do_bdfe:
1118
.do_bdfe:
1321
        inc     dword [edx+8]   ; new file found
1119
        inc     dword [edx+8]   ; new file found
1322
        dec     dword [esp+4]
1120
        dec     dword [esp+4]
1323
        jns     .l2
1121
        jns     .l2
1324
        dec     ecx
1122
        dec     ecx
1325
        js      .l2
1123
        js      .l2
1326
        inc     dword [edx+4]   ; new file block copied
1124
        inc     dword [edx+4]   ; new file block copied
-
 
1125
        push    ebp
-
 
1126
        lea     ebp, [esp+20]
1327
        call    fat_entry_to_bdfe
1127
        call    fat_entry_to_bdfe
-
 
1128
        pop     ebp
1328
.l2:
1129
.l2:
1329
        add     edi, 0x20
1130
        add     edi, 0x20
1330
        cmp     edi, ebx
1131
        cmp     edi, ebx
1331
        jb      .l1
1132
        jb      .l1
1332
        pop     eax
1133
        pop     eax
1333
        inc     eax
1134
        inc     eax
1334
        dec     dword [esp+4]
1135
        dec     dword [esp+4]
1335
        jnz     .new_sector
1136
        jnz     .new_sector
1336
        mov     eax, [cluster_tmp]
1137
        mov     eax, [ebp+FAT.cluster_tmp]
1337
        test    eax, eax
1138
        test    eax, eax
1338
        jz      .done
1139
        jz      .done
1339
        call    get_FAT
1140
        call    get_FAT
1340
        cmp     [hd_error], 0
-
 
1341
        jnz     .notfound2
1141
        jc      .notfound2
1342
        cmp     eax, 2
1142
        cmp     eax, 2
1343
        jb      .done
1143
        jb      .done
1344
        cmp     eax, [fatRESERVED]
1144
        cmp     eax, [ebp+FAT.fatRESERVED]
1345
        jae     .done
1145
        jae     .done
1346
        push    eax
1146
        push    eax
1347
        mov     eax, [SECTORS_PER_CLUSTER]
1147
        mov     eax, [ebp+FAT.SECTORS_PER_CLUSTER]
1348
        mov     [esp+8], eax
1148
        mov     [esp+8], eax
1349
        pop     eax
1149
        pop     eax
1350
        pop     ebx
1150
        pop     ebx
1351
        add     esp, 4
1151
        add     esp, 4
1352
        jmp     .new_cluster
1152
        jmp     .new_cluster
1353
.notfound2:
1153
.notfound2:
1354
        add     esp, 8
1154
        add     esp, 8
1355
.notfound:
1155
.notfound:
1356
        add     esp, 262*2+4
1156
        add     esp, 262*2+4
1357
        pop     ebp ecx esi edi
1157
        pop     esi edi
1358
        mov     eax, ERROR_FILE_NOT_FOUND
1158
        mov     ebx, [edx+4]
1359
        or      ebx, -1
1159
        call    fat_unlock
-
 
1160
        mov     eax, ERROR_DEVICE
1360
        ret
1161
        ret
1361
.done:
1162
.done:
1362
        add     esp, 262*2+4+8
1163
        add     esp, 262*2+4+8
1363
        pop     ebp
-
 
1364
        mov     ebx, [edx+4]
1164
        mov     ebx, [edx+4]
1365
        xor     eax, eax
1165
        xor     eax, eax
1366
        dec     ecx
1166
        dec     ecx
1367
        js      @f
1167
        js      @f
1368
        mov     al, ERROR_END_OF_FILE
1168
        mov     al, ERROR_END_OF_FILE
1369
@@:
1169
@@:
-
 
1170
        push    eax
-
 
1171
        call    fat_unlock
-
 
1172
        pop     eax
1370
        pop     ecx esi edi
1173
        pop     esi edi
1371
        ret
1174
        ret
Line 1372... Line 1175...
1372
 
1175
 
-
 
1176
fat16_root_next:
1373
fat16_root_next:
1177
        push    ecx
-
 
1178
        lea     ecx, [ebp+FAT.buffer+0x200-0x20]
1374
        cmp     edi, buffer+0x200-0x20
1179
        cmp     edi, ecx
-
 
1180
        jae     fat16_root_next_sector
1375
        jae     fat16_root_next_sector
1181
        pop     ecx
1376
        add     edi, 0x20
1182
        add     edi, 0x20
1377
        ret     ; CF=0
1183
        ret     ; CF=0
1378
fat16_root_next_sector:
1184
fat16_root_next_sector:
1379
; read next sector
1185
; read next sector
1380
        push    [longname_sec2]
1186
        push    [ebp+FAT.longname_sec2]
1381
        pop     [longname_sec1]
-
 
1382
        push    ecx
1187
        pop     [ebp+FAT.longname_sec1]
1383
        mov     ecx, [eax+4]
1188
        mov     ecx, [eax+4]
1384
        push    ecx
1189
        push    ecx
1385
        add     ecx, [ROOT_START]
1190
        add     ecx, [ebp+FAT.ROOT_START]
1386
        mov     [longname_sec2], ecx
1191
        mov     [ebp+FAT.longname_sec2], ecx
1387
        pop     ecx
1192
        pop     ecx
1388
        inc     ecx
1193
        inc     ecx
1389
        mov     [eax+4], ecx
1194
        mov     [eax+4], ecx
1390
        cmp     ecx, [ROOT_SECTORS]
1195
        cmp     ecx, [ebp+FAT.ROOT_SECTORS]
1391
        pop     ecx
1196
        pop     ecx
-
 
1197
        jb      fat16_root_first
-
 
1198
        mov     eax, ERROR_FILE_NOT_FOUND
-
 
1199
        stc
1392
        jae     fat16_root_first.readerr
1200
        ret
1393
fat16_root_first:
1201
fat16_root_first:
1394
        mov     eax, [eax+4]
1202
        mov     eax, [eax+4]
1395
        add     eax, [ROOT_START]
1203
        add     eax, [ebp+FAT.ROOT_START]
1396
        push    ebx
1204
        push    ebx
1397
        mov     edi, buffer
1205
        lea     edi, [ebp+FAT.buffer]
1398
        mov     ebx, edi
1206
        mov     ebx, edi
1399
        call    hd_read
1207
        call    fs_read32_sys
1400
        pop     ebx
1208
        pop     ebx
1401
        cmp     [hd_error], 0
1209
        test    eax, eax
1402
        jnz     .readerr
1210
        jnz     .readerr
1403
        ret     ; CF=0
1211
        ret     ; CF=0
-
 
1212
.readerr:
-
 
1213
        mov     eax, ERROR_DEVICE
-
 
1214
        stc
-
 
1215
        ret
-
 
1216
.notfound:
1404
.readerr:
1217
        mov     eax, ERROR_FILE_NOT_FOUND
1405
        stc
1218
        stc
1406
        ret
1219
        ret
1407
fat16_root_begin_write:
1220
fat16_root_begin_write:
1408
        push    edi eax
1221
        push    edi eax
1409
        call    fat16_root_first
1222
        call    fat16_root_first
1410
        pop     eax edi
1223
        pop     eax edi
1411
        ret
1224
        ret
1412
fat16_root_end_write:
1225
fat16_root_end_write:
1413
        pusha
1226
        pusha
1414
        mov     eax, [eax+4]
1227
        mov     eax, [eax+4]
1415
        add     eax, [ROOT_START]
1228
        add     eax, [ebp+FAT.ROOT_START]
1416
        mov     ebx, buffer
1229
        lea     ebx, [ebp+FAT.buffer]
1417
        call    hd_write
1230
        call    fs_write32_sys
1418
        popa
1231
        popa
1419
        ret
1232
        ret
-
 
1233
fat16_root_next_write:
-
 
1234
        push    ecx
1420
fat16_root_next_write:
1235
        lea     ecx, [ebp+FAT.buffer+0x200]
1421
        cmp     edi, buffer+0x200
1236
        cmp     edi, ecx
-
 
1237
        jae     @f
1422
        jae     @f
1238
        pop     ecx
1423
        ret
1239
        ret
1424
@@:
1240
@@:
1425
        call    fat16_root_end_write
1241
        call    fat16_root_end_write
1426
        jmp     fat16_root_next_sector
1242
        jmp     fat16_root_next_sector
1427
fat16_root_extend_dir:
1243
fat16_root_extend_dir:
1428
        stc
1244
        stc
Line 1429... Line 1245...
1429
        ret
1245
        ret
-
 
1246
 
1430
 
1247
fat_notroot_next:
-
 
1248
        push    ecx
1431
fat_notroot_next:
1249
        lea     ecx, [ebp+FAT.buffer+0x200-0x20]
-
 
1250
        cmp     edi, ecx
1432
        cmp     edi, buffer+0x200-0x20
1251
        jae     fat_notroot_next_sector
1433
        jae     fat_notroot_next_sector
1252
        pop     ecx
1434
        add     edi, 0x20
1253
        add     edi, 0x20
1435
        ret     ; CF=0
1254
        ret     ; CF=0
1436
fat_notroot_next_sector:
1255
fat_notroot_next_sector:
1437
        push    [longname_sec2]
1256
        push    [ebp+FAT.longname_sec2]
1438
        pop     [longname_sec1]
1257
        pop     [ebp+FAT.longname_sec1]
1439
        push    eax
1258
        push    eax
1440
        call    fat_get_sector
1259
        call    fat_get_sector
1441
        mov     [longname_sec2], eax
-
 
1442
        pop     eax
1260
        mov     [ebp+FAT.longname_sec2], eax
1443
        push    ecx
1261
        pop     eax
1444
        mov     ecx, [eax+4]
1262
        mov     ecx, [eax+4]
1445
        inc     ecx
1263
        inc     ecx
1446
        cmp     ecx, [SECTORS_PER_CLUSTER]
1264
        cmp     ecx, [ebp+FAT.SECTORS_PER_CLUSTER]
1447
        jae     fat_notroot_next_cluster
1265
        jae     fat_notroot_next_cluster
1448
        mov     [eax+4], ecx
1266
        mov     [eax+4], ecx
1449
        jmp     @f
1267
        jmp     @f
1450
fat_notroot_next_cluster:
1268
fat_notroot_next_cluster:
1451
        push    eax
1269
        push    eax
1452
        mov     eax, [eax]
1270
        mov     eax, [eax]
1453
        call    get_FAT
1271
        call    get_FAT
-
 
1272
        mov     ecx, eax
1454
        mov     ecx, eax
1273
        pop     eax
1455
        pop     eax
1274
        jc      fat_notroot_first.deverr
1456
        cmp     [hd_error], 0
1275
        cmp     ecx, 2
1457
        jnz     fat_notroot_next_err
1276
        jb      fat_notroot_next_err
1458
        cmp     ecx, [fatRESERVED]
1277
        cmp     ecx, [ebp+FAT.fatRESERVED]
1459
        jae     fat_notroot_next_err
1278
        jae     fat_notroot_next_err
1460
        mov     [eax], ecx
1279
        mov     [eax], ecx
1461
        and     dword [eax+4], 0
1280
        and     dword [eax+4], 0
1462
@@:
1281
@@:
1463
        pop     ecx
1282
        pop     ecx
1464
fat_notroot_first:
1283
fat_notroot_first:
1465
        call    fat_get_sector
1284
        call    fat_get_sector
1466
        push    ebx
1285
        push    ebx
1467
        mov     edi, buffer
1286
        lea     edi, [ebp+FAT.buffer]
1468
        mov     ebx, edi
1287
        mov     ebx, edi
-
 
1288
        call    fs_read32_sys
1469
        call    hd_read
1289
        pop     ebx
1470
        pop     ebx
1290
        test    eax, eax
-
 
1291
        jz      .ret ; CF=0
1471
        cmp     [hd_error], 0
1292
        push    ecx
-
 
1293
.deverr:
-
 
1294
        pop     ecx
-
 
1295
        mov     eax, ERROR_DEVICE
-
 
1296
        stc
1472
        jnz     @f
1297
.ret:
1473
        ret     ; CF=0
1298
        ret
1474
fat_notroot_next_err:
-
 
-
 
1299
fat_notroot_next_err:
1475
        pop     ecx
1300
        pop     ecx
1476
@@:
1301
        mov     eax, ERROR_FILE_NOT_FOUND
1477
        stc
1302
        stc
1478
        ret
1303
        ret
1479
fat_notroot_begin_write:
1304
fat_notroot_begin_write:
1480
        push    eax edi
1305
        push    eax edi
1481
        call    fat_notroot_first
1306
        call    fat_notroot_first
1482
        pop     edi eax
1307
        pop     edi eax
1483
        ret
1308
        ret
1484
fat_notroot_end_write:
1309
fat_notroot_end_write:
1485
        call    fat_get_sector
1310
        call    fat_get_sector
1486
        push    ebx
1311
        push    ebx
1487
        mov     ebx, buffer
1312
        lea     ebx, [ebp+FAT.buffer]
1488
        call    hd_write
1313
        call    fs_write32_sys
1489
        pop     ebx
1314
        pop     ebx
-
 
1315
        ret
-
 
1316
fat_notroot_next_write:
1490
        ret
1317
        push    ecx
1491
fat_notroot_next_write:
1318
        lea     ecx, [ebp+FAT.buffer+0x200]
-
 
1319
        cmp     edi, ecx
1492
        cmp     edi, buffer+0x200
1320
        jae     @f
1493
        jae     @f
1321
        pop     ecx
1494
        ret
1322
        ret
1495
@@:
1323
@@:
1496
        push    eax
1324
        push    eax
Line 1503... Line 1331...
1503
        jnc     .found
1331
        jnc     .found
1504
        pop     eax
1332
        pop     eax
1505
        ret     ; CF=1
1333
        ret     ; CF=1
1506
.found:
1334
.found:
1507
        push    edx
1335
        push    edx
1508
        mov     edx, [fatEND]
1336
        mov     edx, [ebp+FAT.fatEND]
1509
        call    set_FAT
1337
        call    set_FAT
-
 
1338
        jc      .writeerr
1510
        mov     edx, eax
1339
        mov     edx, eax
1511
        mov     eax, [esp+4]
1340
        mov     eax, [esp+4]
1512
        mov     eax, [eax]
1341
        mov     eax, [eax]
1513
        push    edx
1342
        push    edx
1514
        call    set_FAT
1343
        call    set_FAT
1515
        pop     edx
1344
        pop     edx
1516
        cmp     [hd_error], 0
-
 
1517
        jz      @f
1345
        jnc     @f
-
 
1346
.writeerr:
1518
        pop     edx
1347
        pop     edx
1519
        pop     eax
1348
        pop     eax
1520
        stc
1349
        stc
1521
        ret
1350
        ret
1522
@@:
1351
@@:
1523
        push    ecx
1352
        push    ecx
1524
        or      ecx, -1
1353
        or      ecx, -1
1525
        call    add_disk_free_space
1354
        call    add_disk_free_space
1526
; zero new cluster
1355
; zero new cluster
1527
        mov     ecx, 512/4
1356
        mov     ecx, 512/4
1528
        mov     edi, buffer
1357
        lea     edi, [ebp+FAT.buffer]
1529
        push    edi
1358
        push    edi
1530
        xor     eax, eax
1359
        xor     eax, eax
1531
        rep stosd
1360
        rep stosd
1532
        pop     edi
1361
        pop     edi
1533
        pop     ecx
1362
        pop     ecx
Line 1537... Line 1366...
1537
        pop     edx
1366
        pop     edx
1538
        mov     eax, [eax]
1367
        mov     eax, [eax]
1539
        dec     eax
1368
        dec     eax
1540
        dec     eax
1369
        dec     eax
1541
        push    ebx ecx
1370
        push    ebx ecx
1542
        mov     ecx, [SECTORS_PER_CLUSTER]
1371
        mov     ecx, [ebp+FAT.SECTORS_PER_CLUSTER]
1543
        imul    eax, ecx
1372
        imul    eax, ecx
1544
        add     eax, [DATA_START]
1373
        add     eax, [ebp+FAT.DATA_START]
1545
        mov     ebx, edi
1374
        mov     ebx, edi
1546
@@:
1375
@@:
-
 
1376
        push    eax
1547
        call    hd_write
1377
        call    fs_write32_sys
-
 
1378
        pop     eax
1548
        inc     eax
1379
        inc     eax
1549
        loop    @b
1380
        loop    @b
1550
        pop     ecx ebx eax
1381
        pop     ecx ebx eax
1551
        clc
1382
        clc
1552
        ret
1383
        ret
Line 1554... Line 1385...
1554
fat_get_sector:
1385
fat_get_sector:
1555
        push    ecx
1386
        push    ecx
1556
        mov     ecx, [eax]
1387
        mov     ecx, [eax]
1557
        dec     ecx
1388
        dec     ecx
1558
        dec     ecx
1389
        dec     ecx
1559
        imul    ecx, [SECTORS_PER_CLUSTER]
1390
        imul    ecx, [ebp+FAT.SECTORS_PER_CLUSTER]
1560
        add     ecx, [DATA_START]
1391
        add     ecx, [ebp+FAT.DATA_START]
1561
        add     ecx, [eax+4]
1392
        add     ecx, [eax+4]
1562
        mov     eax, ecx
1393
        mov     eax, ecx
1563
        pop     ecx
1394
        pop     ecx
1564
        ret
1395
        ret
Line 1565... Line 1396...
1565
 
1396
 
1566
;----------------------------------------------------------------
1397
;----------------------------------------------------------------
1567
;
1398
;
1568
;  fs_HdRewrite - LFN variant for writing hard disk
1399
;  fs_HdRewrite - LFN variant for writing hard disk
-
 
1400
;
-
 
1401
;  Obsolete, will be replaced with filesystem-specific functions.
1569
;
1402
;
1570
;  esi  points to filename
1403
;  esi  points to filename
1571
;  ebx  ignored (reserved)
1404
;  ebx  ignored (reserved)
1572
;  ecx  number of bytes to write, 0+
1405
;  ecx  number of bytes to write, 0+
1573
;  edx  mem location to data
1406
;  edx  mem location to data
1574
;
1407
;
1575
;  ret ebx = number of written bytes
1408
;  ret ebx = number of written bytes
1576
;      eax = 0 ok read or other = errormsg
1409
;      eax = 0 ok read or other = errormsg
1577
;
1410
;
1578
;--------------------------------------------------------------
-
 
1579
fshrad:
-
 
1580
        mov     eax, ERROR_ACCESS_DENIED
-
 
1581
        xor     ebx, ebx
-
 
1582
        ret
-
 
1583
fshrfs:
-
 
1584
        mov     eax, ERROR_UNKNOWN_FS
-
 
1585
        xor     ebx, ebx
-
 
1586
        ret
-
 
1587
 
1411
;--------------------------------------------------------------
1588
fs_HdCreateFolder:
1412
fs_HdCreateFolder:
1589
        mov     al, 1
1413
        mov     al, 1
Line 1590... Line 1414...
1590
        jmp     fs_HdRewrite.common
1414
        jmp     fs_HdRewrite.common
1591
 
1415
 
1592
fs_HdRewrite:
1416
fs_HdRewrite:
-
 
1417
        xor     eax, eax
-
 
1418
.common:
-
 
1419
        cmp     [fs_type], 16
-
 
1420
        jz      @f
1593
        xor     eax, eax
1421
        cmp     [fs_type], 32
1594
.common:
1422
        jz      @f
1595
        cmp     [fs_type], 1
1423
        cmp     [fs_type], 1
1596
        jz      ntfs_HdRewrite
1424
        jz      ntfs_HdRewrite
1597
        cmp     [fs_type], 2
1425
        cmp     [fs_type], 2
1598
        jz      ext2_HdRewrite
1426
        jz      ext2_HdRewrite
1599
        cmp     [fs_type], 16
-
 
1600
        jz      @f
1427
        mov     eax, ERROR_UNKNOWN_FS
1601
        cmp     [fs_type], 32
1428
        xor     ebx, ebx
-
 
1429
        ret
-
 
1430
@@:
-
 
1431
        sub     ebx, 4
-
 
1432
        push    ebp
-
 
1433
        mov     ebp, [fs_dependent_data_start.partition]
-
 
1434
        test    eax, eax
-
 
1435
        mov     eax, fat_CreateFolder
-
 
1436
        jnz     @f
-
 
1437
        mov     eax, fat_Rewrite
-
 
1438
@@:
-
 
1439
        call    eax
-
 
1440
        pop     ebp
-
 
1441
        ret
-
 
1442
 
-
 
1443
fshrad:
-
 
1444
        call    fat_unlock
-
 
1445
        mov     eax, ERROR_ACCESS_DENIED
-
 
1446
        xor     ebx, ebx
-
 
1447
        ret
-
 
1448
 
-
 
1449
;----------------------------------------------------------------
-
 
1450
; fat_CreateFolder - FAT16/32 implementation of creating a folder
-
 
1451
; in:  ebp = pointer to FAT structure
-
 
1452
; in:  esi+[esp+4] = name
-
 
1453
; in:  ebx = pointer to parameters from sysfunc 70
-
 
1454
; out: eax, ebx = return values for sysfunc 70
-
 
1455
;----------------------------------------------------------------
-
 
1456
fat_CreateFolder:
-
 
1457
        push    1
-
 
1458
        jmp     fat_Rewrite.common
-
 
1459
 
-
 
1460
;----------------------------------------------------------------
-
 
1461
; fat_HdRewrite - FAT16/32 implementation of creating a new file
-
 
1462
; in:  ebp = pointer to FAT structure
-
 
1463
; in:  esi+[esp+4] = name
-
 
1464
; in:  ebx = pointer to parameters from sysfunc 70
-
 
1465
; out: eax, ebx = return values for sysfunc 70
-
 
1466
;----------------------------------------------------------------
-
 
1467
fat_Rewrite:
-
 
1468
        push    0
-
 
1469
.common:
1602
        jnz     fshrfs
1470
        call    fat_lock
1603
@@:
1471
        pop     eax
-
 
1472
        cmp     byte [esi], 0
-
 
1473
        jz      fshrad
1604
        cmp     byte [esi], 0
1474
        mov     ecx, [ebx+12]
1605
        jz      fshrad
1475
        mov     edx, [ebx+16]
-
 
1476
        pushad
1606
        pushad
1477
        xor     edi, edi
1607
        xor     edi, edi
1478
        mov     edx, [esp+4+20h]
1608
        push    esi
1479
        push    esi
1609
        test    ebp, ebp
1480
        test    edx, edx
1610
        jz      @f
1481
        jz      @f
1611
        mov     esi, ebp
1482
        mov     esi, edx
1612
@@:
1483
@@:
1613
        lodsb
1484
        lodsb
1614
        test    al, al
1485
        test    al, al
Line 1619... Line 1490...
1619
        jmp     @b
1490
        jmp     @b
1620
@@:
1491
@@:
1621
        pop     esi
1492
        pop     esi
1622
        test    edi, edi
1493
        test    edi, edi
1623
        jnz     .noroot
1494
        jnz     .noroot
1624
        test    ebp, ebp
1495
        test    edx, edx
1625
        jnz     .hasebp
1496
        jnz     .hasebp
1626
        mov     ebp, [ROOT_CLUSTER]
1497
        mov     edx, [ebp+FAT.ROOT_CLUSTER]
1627
        cmp     [fs_type], 32
1498
        cmp     [ebp+FAT.fs_type], 32
1628
        jz      .pushnotroot
1499
        jz      .pushnotroot
-
 
1500
        xor     edx, edx
-
 
1501
        push    edx
1629
        push    fat16_root_extend_dir
1502
        push    fat16_root_extend_dir
1630
        push    fat16_root_end_write
1503
        push    fat16_root_end_write
1631
        push    fat16_root_next_write
1504
        push    fat16_root_next_write
1632
        push    fat16_root_begin_write
1505
        push    fat16_root_begin_write
1633
        xor     ebp, ebp
-
 
1634
        push    ebp
1506
        push    edx
1635
        push    ebp
1507
        push    edx
1636
        push    fat16_root_first
1508
        push    fat16_root_first
1637
        push    fat16_root_next
1509
        push    fat16_root_next
1638
        jmp     .common1
1510
        jmp     .common1
1639
.hasebp:
1511
.hasebp:
1640
        mov     eax, ERROR_ACCESS_DENIED
1512
        mov     eax, ERROR_ACCESS_DENIED
1641
        cmp     byte [ebp], 0
1513
        cmp     byte [edx], 0
1642
        jz      .ret1
1514
        jz      .ret1
1643
        push    ebp
-
 
1644
        xor     ebp, ebp
-
 
1645
        call    hd_find_lfn
1515
        stdcall hd_find_lfn, 0
1646
        pop     esi
1516
        mov     esi, [esp+4+20h]
1647
        jc      .notfound0
1517
        jc      .ret1
1648
        jmp     .common0
1518
        jmp     .common0
1649
.noroot:
1519
.noroot:
1650
        mov     eax, ERROR_ACCESS_DENIED
1520
        mov     eax, ERROR_ACCESS_DENIED
1651
        cmp     byte [edi+1], 0
1521
        cmp     byte [edi+1], 0
1652
        jz      .ret1
1522
        jz      .ret1
1653
; check existence
1523
; check existence
1654
        mov     byte [edi], 0
1524
        mov     byte [edi], 0
1655
        push    edi
1525
        push    edi
1656
        call    hd_find_lfn
1526
        stdcall hd_find_lfn, [esp+4+24h]
1657
        pop     esi
1527
        pop     esi
1658
        mov     byte [esi], '/'
1528
        mov     byte [esi], '/'
1659
        jnc     @f
1529
        jnc     @f
1660
.notfound0:
1530
.notfound0:
1661
        mov     eax, ERROR_FILE_NOT_FOUND
1531
        mov     eax, ERROR_FILE_NOT_FOUND
1662
.ret1:
1532
.ret1:
1663
        mov     [esp+28], eax
1533
        mov     [esp+28], eax
-
 
1534
        call    fat_unlock
1664
        popad
1535
        popad
1665
        xor     ebx, ebx
1536
        xor     ebx, ebx
1666
        ret
1537
        ret
1667
@@:
1538
@@:
1668
        inc     esi
1539
        inc     esi
1669
.common0:
1540
.common0:
1670
        test    byte [edi+11], 0x10     ; must be directory
1541
        test    byte [edi+11], 0x10     ; must be directory
1671
        mov     eax, ERROR_ACCESS_DENIED
1542
        mov     eax, ERROR_ACCESS_DENIED
1672
        jz      .ret1
1543
        jz      .ret1
1673
        mov     ebp, [edi+20-2]
1544
        mov     edx, [edi+20-2]
1674
        mov     bp, [edi+26]            ; ebp=cluster
1545
        mov     dx, [edi+26]            ; ebp=cluster
1675
        mov     eax, ERROR_FAT_TABLE
1546
        mov     eax, ERROR_FAT_TABLE
1676
        cmp     ebp, 2
1547
        cmp     edx, 2
1677
        jb      .ret1
1548
        jb      .ret1
1678
.pushnotroot:
1549
.pushnotroot:
-
 
1550
        push    edx
1679
        push    fat_notroot_extend_dir
1551
        push    fat_notroot_extend_dir
1680
        push    fat_notroot_end_write
1552
        push    fat_notroot_end_write
1681
        push    fat_notroot_next_write
1553
        push    fat_notroot_next_write
1682
        push    fat_notroot_begin_write
1554
        push    fat_notroot_begin_write
1683
        push    0
1555
        push    0
1684
        push    ebp
1556
        push    edx
1685
        push    fat_notroot_first
1557
        push    fat_notroot_first
1686
        push    fat_notroot_next
1558
        push    fat_notroot_next
1687
.common1:
1559
.common1:
1688
        call    fat_find_lfn
1560
        call    fat_find_lfn
1689
        jc      .notfound
1561
        jc      .notfound
1690
; found
1562
; found
1691
        test    byte [edi+11], 10h
1563
        test    byte [edi+11], 10h
1692
        jz      .exists_file
1564
        jz      .exists_file
1693
; found directory; if we are creating directory, return OK,
1565
; found directory; if we are creating directory, return OK,
1694
;                  if we are creating file, say "access denied"
1566
;                  if we are creating file, say "access denied"
1695
        add     esp, 32
1567
        add     esp, 36
-
 
1568
        call    fat_unlock
1696
        popad
1569
        popad
1697
        test    al, al
1570
        test    al, al
1698
        mov     eax, ERROR_ACCESS_DENIED
1571
        mov     eax, ERROR_ACCESS_DENIED
1699
        jz      @f
1572
        jz      @f
1700
        mov     al, 0
1573
        mov     al, 0
Line 1702... Line 1575...
1702
        xor     ebx, ebx
1575
        xor     ebx, ebx
1703
        ret
1576
        ret
1704
.exists_file:
1577
.exists_file:
1705
; found file; if we are creating directory, return "access denied",
1578
; found file; if we are creating directory, return "access denied",
1706
;             if we are creating file, delete existing file and continue
1579
;             if we are creating file, delete existing file and continue
1707
        cmp     byte [esp+32+28], 0
1580
        cmp     byte [esp+36+28], 0
1708
        jz      @f
1581
        jz      @f
1709
        add     esp, 32
1582
        add     esp, 36
-
 
1583
        call    fat_unlock
1710
        popad
1584
        popad
1711
        mov     eax, ERROR_ACCESS_DENIED
1585
        mov     eax, ERROR_ACCESS_DENIED
1712
        xor     ebx, ebx
1586
        xor     ebx, ebx
1713
        ret
1587
        ret
1714
@@:
1588
@@:
Line 1722... Line 1596...
1722
        mov     word [edi+20], cx
1596
        mov     word [edi+20], cx
1723
        mov     word [edi+26], cx
1597
        mov     word [edi+26], cx
1724
        test    eax, eax
1598
        test    eax, eax
1725
        jz      .done1
1599
        jz      .done1
1726
@@:
1600
@@:
1727
        cmp     eax, [fatRESERVED]
1601
        cmp     eax, [ebp+FAT.fatRESERVED]
1728
        jae     .done1
1602
        jae     .done1
1729
        push    edx
1603
        push    edx
1730
        xor     edx, edx
1604
        xor     edx, edx
1731
        call    set_FAT
1605
        call    set_FAT
1732
        mov     eax, edx
1606
        mov     eax, edx
1733
        pop     edx
1607
        pop     edx
-
 
1608
        jc      .done1
1734
        inc     ecx
1609
        inc     ecx
1735
        jmp     @b
1610
        jmp     @b
1736
.done1:
1611
.done1:
1737
        pop     edi
1612
        pop     edi
1738
        call    get_time_for_file
1613
        call    get_time_for_file
Line 1744... Line 1619...
1744
        jmp     .doit
1619
        jmp     .doit
1745
.notfound:
1620
.notfound:
1746
; file is not found; generate short name
1621
; file is not found; generate short name
1747
        call    fat_name_is_legal
1622
        call    fat_name_is_legal
1748
        jc      @f
1623
        jc      @f
1749
        add     esp, 32
1624
        add     esp, 36
-
 
1625
        call    fat_unlock
1750
        popad
1626
        popad
1751
        mov     eax, ERROR_FILE_NOT_FOUND
1627
        mov     eax, ERROR_FILE_NOT_FOUND
1752
        xor     ebx, ebx
1628
        xor     ebx, ebx
1753
        ret
1629
        ret
1754
@@:
1630
@@:
Line 1757... Line 1633...
1757
        call    fat_gen_short_name
1633
        call    fat_gen_short_name
1758
.test_short_name_loop:
1634
.test_short_name_loop:
1759
        push    esi edi ecx
1635
        push    esi edi ecx
1760
        mov     esi, edi
1636
        mov     esi, edi
1761
        lea     eax, [esp+12+12+8]
1637
        lea     eax, [esp+12+12+8]
-
 
1638
        mov     edx, [eax+24]
1762
        mov     [eax], ebp
1639
        mov     [eax], edx
1763
        and     dword [eax+4], 0
1640
        and     dword [eax+4], 0
1764
        call    dword [eax-4]
1641
        call    dword [eax-4]
1765
        jc      .found
1642
        jc      .found
1766
.test_short_name_entry:
1643
.test_short_name_entry:
1767
        cmp     byte [edi+11], 0xF
1644
        cmp     byte [edi+11], 0xF
Line 1779... Line 1656...
1779
.short_name_found:
1656
.short_name_found:
1780
        pop     ecx edi esi
1657
        pop     ecx edi esi
1781
        call    fat_next_short_name
1658
        call    fat_next_short_name
1782
        jnc     .test_short_name_loop
1659
        jnc     .test_short_name_loop
1783
.disk_full:
1660
.disk_full:
1784
        add     esp, 12+32
1661
        add     esp, 12+36
-
 
1662
        call    fat_unlock
1785
        popa
1663
        popa
1786
        mov     eax, ERROR_DISK_FULL
1664
        mov     eax, ERROR_DISK_FULL
1787
        xor     ebx, ebx
1665
        xor     ebx, ebx
1788
        ret
1666
        ret
1789
.found:
1667
.found:
Line 1819... Line 1697...
1819
        push    -1
1697
        push    -1
1820
; find  successive entries in directory
1698
; find  successive entries in directory
1821
        xor     ecx, ecx
1699
        xor     ecx, ecx
1822
        push    eax
1700
        push    eax
1823
        lea     eax, [esp+16+8+12+8]
1701
        lea     eax, [esp+16+8+12+8]
-
 
1702
        mov     edx, [eax+24]
1824
        mov     [eax], ebp
1703
        mov     [eax], edx
1825
        and     dword [eax+4], 0
1704
        and     dword [eax+4], 0
1826
        call    dword [eax-4]
1705
        call    dword [eax-4]
1827
        pop     eax
1706
        pop     eax
1828
        jnc     .scan_dir
1707
        jnc     .scan_dir
1829
.fsfrfe3:
1708
.fsfrfe3:
1830
        add     esp, 12+8+12+32
1709
        add     esp, 12+8+12+36
-
 
1710
        call    fat_unlock
1831
        popad
1711
        popad
1832
        mov     eax, 11
1712
        mov     eax, ERROR_DEVICE
1833
        xor     ebx, ebx
1713
        xor     ebx, ebx
1834
        ret
1714
        ret
1835
.scan_dir:
1715
.scan_dir:
1836
        cmp     byte [edi], 0
1716
        cmp     byte [edi], 0
1837
        jz      .free
1717
        jz      .free
Line 1840... Line 1720...
1840
        xor     ecx, ecx
1720
        xor     ecx, ecx
1841
.scan_cont:
1721
.scan_cont:
1842
        push    eax
1722
        push    eax
1843
        lea     eax, [esp+16+8+12+8]
1723
        lea     eax, [esp+16+8+12+8]
1844
        call    dword [eax-8]
1724
        call    dword [eax-8]
-
 
1725
        mov     edx, eax
1845
        pop     eax
1726
        pop     eax
1846
        jnc     .scan_dir
1727
        jnc     .scan_dir
1847
        cmp     [hd_error], 0
1728
        cmp     edx, ERROR_DEVICE
1848
        jnz     .fsfrfe3
1729
        jz      .fsfrfe3
1849
        push    eax
1730
        push    eax
1850
        lea     eax, [esp+16+8+12+8]
1731
        lea     eax, [esp+16+8+12+8]
1851
        call    dword [eax+20]          ; extend directory
1732
        call    dword [eax+20]          ; extend directory
1852
        pop     eax
1733
        pop     eax
1853
        jnc     .scan_dir
1734
        jnc     .scan_dir
1854
        add     esp, 12+8+12+32
1735
        add     esp, 12+8+12+36
-
 
1736
        call    fat_unlock
1855
        popad
1737
        popad
1856
        mov     eax, ERROR_DISK_FULL
1738
        mov     eax, ERROR_DISK_FULL
1857
        xor     ebx, ebx
1739
        xor     ebx, ebx
1858
        ret
1740
        ret
1859
.free:
1741
.free:
Line 1868... Line 1750...
1868
@@:
1750
@@:
1869
        inc     ecx
1751
        inc     ecx
1870
        cmp     ecx, eax
1752
        cmp     ecx, eax
1871
        jb      .scan_cont
1753
        jb      .scan_cont
1872
; found!
1754
; found!
1873
; calculate name checksum
-
 
1874
        push    esi ecx
1755
        push    esi ecx
-
 
1756
; If creating a directory, allocate one data cluster now and fail immediately
-
 
1757
; if this is impossible. This prevents from creating an invalid directory entry
-
 
1758
; on a full disk.
-
 
1759
; yup, the argument is quite non-intuitive... but what should I do if
-
 
1760
; the entire function uses such arguments? BTW, it refers to al from pushad,
-
 
1761
; which in turn is filled with 0 in fat_Rewrite and 1 in fat_CreateFolder.
-
 
1762
        cmp     byte [esp+8+12+8+12+36+28], 0
-
 
1763
        jz      .no.preallocate.folder.data
-
 
1764
        call    get_free_FAT
-
 
1765
        jnc     @f
-
 
1766
        add     esp, 8+12+8
-
 
1767
        jmp     .disk_full
-
 
1768
@@:
-
 
1769
        mov     [esp+8+12+8+12+36+20], eax ; store the cluster somewhere
-
 
1770
.no.preallocate.folder.data:
-
 
1771
; calculate name checksum
1875
        mov     esi, [esp+8+12]
1772
        mov     esi, [esp+8+12]
1876
        mov     ecx, 11
1773
        mov     ecx, 11
1877
        xor     eax, eax
1774
        xor     eax, eax
1878
@@:
1775
@@:
1879
        ror     al, 1
1776
        ror     al, 1
Line 1939... Line 1836...
1939
        mov     [edi+18], ax            ; last access date
1836
        mov     [edi+18], ax            ; last access date
1940
        xor     ecx, ecx
1837
        xor     ecx, ecx
1941
        mov     word [edi+20], cx       ; high word of cluster
1838
        mov     word [edi+20], cx       ; high word of cluster
1942
        mov     word [edi+26], cx       ; low word of cluster - to be filled
1839
        mov     word [edi+26], cx       ; low word of cluster - to be filled
1943
        mov     dword [edi+28], ecx     ; file size - to be filled
1840
        mov     dword [edi+28], ecx     ; file size - to be filled
1944
        cmp     byte [esp+32+28], cl
1841
        cmp     byte [esp+36+28], cl
1945
        jz      .doit
1842
        jz      .doit
1946
; create directory
1843
; create directory
1947
        mov     byte [edi+11], 10h      ; attributes: folder
1844
        mov     byte [edi+11], 10h      ; attributes: folder
1948
        mov     edx, edi
1845
        mov     esi, edi
1949
        lea     eax, [esp+8]
1846
        lea     eax, [esp+8]
1950
        call    dword [eax+16]  ; flush directory
1847
        call    dword [eax+16]  ; flush directory
-
 
1848
        mov     eax, [esp+36+20] ; extract saved cluster
-
 
1849
        mov     [esp+36+20], edi ; this is needed for calculating arg of add_disk_free_space!
1951
        push    ecx
1850
        push    ecx
1952
        mov     ecx, [SECTORS_PER_CLUSTER]
1851
        mov     ecx, [ebp+FAT.SECTORS_PER_CLUSTER]
1953
        shl     ecx, 9
1852
        shl     ecx, 9
-
 
1853
        push    ecx
-
 
1854
        push    edi
1954
        jmp     .doit2
1855
        jmp     .doit2
1955
.doit:
1856
.doit:
-
 
1857
        mov     esi, [esp+36+20]
1956
        lea     eax, [esp+8]
1858
        lea     eax, [esp+8]
1957
        call    dword [eax+16]  ; flush directory
1859
        call    dword [eax+16]  ; flush directory
1958
        push    ecx
1860
        push    ecx
1959
        mov     ecx, [esp+4+32+24]
1861
        mov     ecx, [esp+4+36+24]
1960
.doit2:
-
 
1961
        push    ecx
1862
        push    ecx
1962
        push    edi
1863
        push    edi
1963
        mov     esi, edx
-
 
1964
        test    ecx, ecx
1864
        test    ecx, ecx
1965
        jz      .done
1865
        jz      .done
1966
        call    get_free_FAT
1866
        call    get_free_FAT
1967
        jc      .diskfull
1867
        jc      .diskfull
-
 
1868
.doit2:
1968
        push    eax
1869
        push    eax
1969
        mov     [edi+26], ax
1870
        mov     [edi+26], ax
1970
        shr     eax, 16
1871
        shr     eax, 16
1971
        mov     [edi+20], ax
1872
        mov     [edi+20], ax
1972
        lea     eax, [esp+16+8]
1873
        lea     eax, [esp+16+8]
1973
        call    dword [eax+16]  ; flush directory
1874
        call    dword [eax+16]  ; flush directory
1974
        pop     eax
1875
        pop     eax
1975
        push    edx
1876
        push    edx
1976
        mov     edx, [fatEND]
1877
        mov     edx, [ebp+FAT.fatEND]
1977
        call    set_FAT
1878
        call    set_FAT
1978
        pop     edx
1879
        pop     edx
1979
.write_cluster:
1880
.write_cluster:
1980
        push    eax
1881
        push    eax
1981
        dec     eax
1882
        dec     eax
1982
        dec     eax
1883
        dec     eax
1983
        mov     ebp, [SECTORS_PER_CLUSTER]
1884
        imul    eax, [ebp+FAT.SECTORS_PER_CLUSTER]
1984
        imul    eax, ebp
1885
        add     eax, [ebp+FAT.DATA_START]
1985
        add     eax, [DATA_START]
1886
        push    [ebp+FAT.SECTORS_PER_CLUSTER]
1986
; write data
1887
; write data
1987
.write_sector:
1888
.write_sector:
1988
        cmp     byte [esp+16+32+28], 0
1889
        cmp     byte [esp+20+36+28], 0
1989
        jnz     .writedir
1890
        jnz     .writedir
1990
        mov     ecx, 512
1891
        mov     ecx, 512
1991
        cmp     dword [esp+8], ecx
1892
        cmp     dword [esp+12], ecx
1992
        jb      .writeshort
1893
        jb      .writeshort
1993
; we can write directly from given buffer
1894
; we can write directly from given buffer
1994
        mov     ebx, esi
1895
        mov     ebx, esi
1995
        add     esi, ecx
1896
        add     esi, ecx
1996
        jmp     .writecommon
1897
        jmp     .writecommon
1997
.writeshort:
1898
.writeshort:
1998
        mov     ecx, [esp+8]
1899
        mov     ecx, [esp+12]
1999
        push    ecx
1900
        push    ecx
2000
        mov     edi, buffer
1901
        lea     edi, [ebp+FAT.buffer]
2001
        mov     ebx, edi
1902
        mov     ebx, edi
2002
        rep movsb
1903
        rep movsb
2003
.writedircont:
1904
.writedircont:
2004
        mov     ecx, buffer+0x200
1905
        lea     ecx, [ebp+FAT.buffer+0x200]
2005
        sub     ecx, edi
1906
        sub     ecx, edi
2006
        push    eax
1907
        push    eax
2007
        xor     eax, eax
1908
        xor     eax, eax
2008
        rep stosb
1909
        rep stosb
2009
        pop     eax
1910
        pop     eax
2010
        pop     ecx
1911
        pop     ecx
2011
.writecommon:
1912
.writecommon:
-
 
1913
        push    eax
2012
        call    hd_write
1914
        call    fs_write32_app
-
 
1915
        test    eax, eax
2013
        cmp     [hd_error], 0
1916
        pop     eax
2014
        jnz     .writeerr
1917
        jnz     .writeerr
2015
        inc     eax
1918
        inc     eax
2016
        sub     dword [esp+8], ecx
1919
        sub     dword [esp+12], ecx
2017
        jz      .writedone
1920
        jz      .writedone
2018
        dec     ebp
1921
        dec     dword [esp]
2019
        jnz     .write_sector
1922
        jnz     .write_sector
-
 
1923
        pop     eax
2020
; allocate new cluster
1924
; allocate new cluster
2021
        pop     eax
1925
        pop     eax
2022
        mov     ecx, eax
1926
        mov     ecx, eax
2023
        call    get_free_FAT
1927
        call    get_free_FAT
2024
        jc      .diskfull
1928
        jc      .diskfull
2025
        push    edx
1929
        push    edx
2026
        mov     edx, [fatEND]
1930
        mov     edx, [ebp+FAT.fatEND]
2027
        call    set_FAT
1931
        call    set_FAT
2028
        xchg    eax, ecx
1932
        xchg    eax, ecx
2029
        mov     edx, ecx
1933
        mov     edx, ecx
2030
        call    set_FAT
1934
        call    set_FAT
2031
        pop     edx
1935
        pop     edx
Line 2033... Line 1937...
2033
        jmp     .write_cluster
1937
        jmp     .write_cluster
2034
.diskfull:
1938
.diskfull:
2035
        mov     eax, ERROR_DISK_FULL
1939
        mov     eax, ERROR_DISK_FULL
2036
        jmp     .ret
1940
        jmp     .ret
2037
.writeerr:
1941
.writeerr:
2038
        pop     eax
1942
        pop     eax eax
2039
        sub     esi, ecx
1943
        sub     esi, ecx
2040
        mov     eax, 11
1944
        mov     eax, ERROR_DEVICE
2041
        jmp     .ret
1945
        jmp     .ret
2042
.writedone:
1946
.writedone:
2043
        pop     eax
1947
        pop     eax eax
2044
.done:
1948
.done:
2045
        xor     eax, eax
1949
        xor     eax, eax
2046
.ret:
1950
.ret:
2047
        pop     edi ecx
1951
        pop     edi ecx
2048
        mov     ebx, esi
1952
        sub     esi, [esp+4+36+20]
2049
        sub     ebx, edx
1953
        mov     [esp+4+36+28], eax
2050
        pop     ebp
-
 
2051
        mov     [esp+32+28], eax
1954
        mov     [esp+4+36+16], esi
2052
        lea     eax, [esp+8]
1955
        lea     eax, [esp+12]
2053
        call    dword [eax+8]
1956
        call    dword [eax+8]
2054
        mov     [edi+28], ebx
1957
        mov     [edi+28], esi
2055
        call    dword [eax+16]
1958
        call    dword [eax+16]
2056
        mov     [esp+32+16], ebx
1959
        mov     [esp+36+16], ebx
2057
        lea     eax, [ebx+511]
1960
        lea     eax, [esi+511]
2058
        shr     eax, 9
1961
        shr     eax, 9
2059
        mov     ecx, [SECTORS_PER_CLUSTER]
1962
        mov     ecx, [ebp+FAT.SECTORS_PER_CLUSTER]
2060
        lea     eax, [eax+ecx-1]
1963
        lea     eax, [eax+ecx-1]
2061
        xor     edx, edx
1964
        xor     edx, edx
2062
        div     ecx
1965
        div     ecx
2063
        mov     ecx, ebp
1966
        pop     ecx
2064
        sub     ecx, eax
1967
        sub     ecx, eax
2065
        call    add_disk_free_space
1968
        call    add_disk_free_space
2066
        add     esp, 32
1969
        add     esp, 36
2067
        call    update_disk
1970
        call    update_disk
-
 
1971
        call    fat_unlock
2068
        popad
1972
        popad
2069
        ret
1973
        ret
2070
.writedir:
1974
.writedir:
2071
        push    512
1975
        push    512
2072
        mov     edi, buffer
1976
        lea     edi, [ebp+FAT.buffer]
2073
        mov     ebx, edi
1977
        mov     ebx, edi
2074
        mov     ecx, [SECTORS_PER_CLUSTER]
1978
        mov     ecx, [ebp+FAT.SECTORS_PER_CLUSTER]
2075
        shl     ecx, 9
1979
        shl     ecx, 9
2076
        cmp     ecx, [esp+12]
1980
        cmp     ecx, [esp+16]
2077
        jnz     .writedircont
1981
        jnz     .writedircont
2078
        dec     dword [esp+16]
1982
        dec     dword [esp+20]
2079
        push    esi
1983
        push    esi
2080
        mov     ecx, 32/4
1984
        mov     ecx, 32/4
2081
        rep movsd
1985
        rep movsd
2082
        pop     esi
1986
        pop     esi
2083
        mov     dword [edi-32], '.   '
1987
        mov     dword [edi-32], '.   '
Line 2090... Line 1994...
2090
        pop     esi
1994
        pop     esi
2091
        mov     dword [edi-32], '..  '
1995
        mov     dword [edi-32], '..  '
2092
        mov     dword [edi-32+4], '    '
1996
        mov     dword [edi-32+4], '    '
2093
        mov     dword [edi-32+8], '    '
1997
        mov     dword [edi-32+8], '    '
2094
        mov     byte [edi-32+11], 10h
1998
        mov     byte [edi-32+11], 10h
2095
        mov     ecx, [esp+20+8]
1999
        mov     ecx, [esp+20+36]
2096
        cmp     ecx, [ROOT_CLUSTER]
2000
        cmp     ecx, [ebp+FAT.ROOT_CLUSTER]
2097
        jnz     @f
2001
        jnz     @f
2098
        xor     ecx, ecx
2002
        xor     ecx, ecx
2099
@@:
2003
@@:
2100
        mov     word [edi-32+26], cx
2004
        mov     word [edi-32+26], cx
2101
        shr     ecx, 16
2005
        shr     ecx, 16
Line 2104... Line 2008...
2104
 
2008
 
2105
;----------------------------------------------------------------
2009
;----------------------------------------------------------------
2106
;
2010
;
2107
;  fs_HdWrite - LFN variant for writing to hard disk
2011
;  fs_HdWrite - LFN variant for writing to hard disk
-
 
2012
;
-
 
2013
;  Obsolete, will be replaced with filesystem-specific functions.
2108
;
2014
;
2109
;  esi  points to filename
2015
;  esi  points to filename
2110
;  ebx  pointer to 64-bit number = first wanted byte, 0+
2016
;  ebx  pointer to 64-bit number = first wanted byte, 0+
2111
;       may be ebx=0 - start from first byte
2017
;       may be ebx=0 - start from first byte
2112
;  ecx  number of bytes to write, 0+
2018
;  ecx  number of bytes to write, 0+
2113
;  edx  mem location to data
2019
;  edx  mem location to data
2114
;
2020
;
2115
;  ret ebx = bytes written (maybe 0)
2021
;  ret ebx = bytes written (maybe 0)
2116
;      eax = 0 ok write or other = errormsg
2022
;      eax = 0 ok write or other = errormsg
2117
;
2023
;
2118
;--------------------------------------------------------------
2024
;--------------------------------------------------------------
2119
fs_HdWrite.access_denied:
2025
fat_Write.access_denied:
2120
        push    ERROR_ACCESS_DENIED
2026
        push    ERROR_ACCESS_DENIED
2121
fs_HdWrite.ret0:
2027
fs_HdWrite.ret0:
2122
        pop     eax
2028
        pop     eax
2123
        xor     ebx, ebx
2029
        xor     ebx, ebx
Line 2124... Line 2030...
2124
        ret
2030
        ret
2125
 
2031
 
2126
fs_HdWrite.ret11:
2032
fs_HdWrite.ret11:
Line 2127... Line 2033...
2127
        push    11
2033
        push    ERROR_DEVICE
2128
        jmp     fs_HdWrite.ret0
-
 
2129
 
-
 
2130
fs_HdWrite:
-
 
2131
        cmp     [fs_type], 1
-
 
2132
        jz      ntfs_HdWrite
2034
        jmp     fs_HdWrite.ret0
2133
        cmp     [fs_type], 2
2035
 
2134
        jz      ext2_HdWrite
2036
fs_HdWrite:
2135
        cmp     [fs_type], 16
2037
        cmp     [fs_type], 16
-
 
2038
        jz      @f
-
 
2039
        cmp     [fs_type], 32
-
 
2040
        jz      @f
-
 
2041
        cmp     [fs_type], 1
2136
        jz      @f
2042
        jz      ntfs_HdWrite
2137
        cmp     [fs_type], 32
2043
        cmp     [fs_type], 2
2138
        jz      @f
2044
        jz      ext2_HdWrite
-
 
2045
        push    ERROR_UNKNOWN_FS
-
 
2046
        jmp     .ret0
-
 
2047
@@:
-
 
2048
        sub     ebx, 4
-
 
2049
        push    ebp
-
 
2050
        mov     ebp, [fs_dependent_data_start.partition]
-
 
2051
        call    fat_Write
-
 
2052
        pop     ebp
-
 
2053
        ret
-
 
2054
 
-
 
2055
;----------------------------------------------------------------
-
 
2056
; fat_Write - FAT16/32 implementation of writing to file
-
 
2057
; in:  ebp = pointer to FAT structure
-
 
2058
; in:  esi+[esp+4] = name
-
 
2059
; in:  ebx = pointer to parameters from sysfunc 70
2139
        push    ERROR_UNKNOWN_FS
2060
; out: eax, ebx = return values for sysfunc 70
2140
        jmp     .ret0
2061
;----------------------------------------------------------------
2141
@@:
-
 
2142
        cmp     byte [esi], 0
2062
fat_Write:
2143
        jz      .access_denied
2063
        cmp     byte [esi], 0
2144
        pushad
2064
        jz      .access_denied
2145
        call    hd_find_lfn
-
 
2146
        pushfd
-
 
2147
        cmp     [hd_error], 0
-
 
2148
        jz      @f
-
 
2149
        popfd
-
 
2150
        popad
-
 
2151
        push    11
-
 
2152
        jmp     .ret0
2065
        call    fat_lock
2153
@@:
2066
        push    edi
2154
        popfd
2067
        stdcall hd_find_lfn, [esp+4+4]
-
 
2068
        jnc     .found
2155
        jnc     .found
2069
        pop     edi
2156
        popad
2070
        push    eax
2157
        push    ERROR_FILE_NOT_FOUND
2071
        call    fat_unlock
2158
        jmp     .ret0
-
 
2159
.found:
-
 
2160
; FAT does not support files larger than 4GB
2072
        jmp     fs_HdWrite.ret0
2161
        test    ebx, ebx
2073
.found:
2162
        jz      .l1
2074
; FAT does not support files larger than 4GB
2163
        cmp     dword [ebx+4], 0
2075
        cmp     dword [ebx+8], 0
2164
        jz      @f
2076
        jz      @f
-
 
2077
.eof:
2165
.eof:
2078
        pop     edi
2166
        popad
2079
        push    ERROR_END_OF_FILE
2167
        push    ERROR_END_OF_FILE
2080
        call    fat_unlock
2168
        jmp     .ret0
2081
        jmp     fs_HdWrite.ret0
-
 
2082
@@:
2169
@@:
2083
        mov     ecx, [ebx+12]
2170
        mov     ebx, [ebx]
2084
        mov     edx, [ebx+16]
Line 2171... Line 2085...
2171
.l1:
2085
        mov     ebx, [ebx+4]
2172
; now edi points to direntry, ebx=start byte to write,
2086
; now edi points to direntry, ebx=start byte to write,
2173
; ecx=number of bytes to write, edx=data pointer
2087
; ecx=number of bytes to write, edx=data pointer
-
 
2088
 
2174
 
2089
; extend file if needed
2175
; extend file if needed
2090
        add     ecx, ebx
Line 2176... Line 2091...
2176
        add     ecx, ebx
2091
        jc      .eof    ; FAT does not support files larger than 4GB
2177
        jc      .eof    ; FAT does not support files larger than 4GB
2092
        push    edx
Line 2194... Line 2109...
2194
        mov     [esp+4], eax
2109
        mov     [esp+4], eax
2195
; hd_extend_file can return three error codes: FAT table error, device error or disk full.
2110
; hd_extend_file can return three error codes: FAT table error, device error or disk full.
2196
; First two cases are fatal errors, in third case we may write some data
2111
; First two cases are fatal errors, in third case we may write some data
2197
        cmp     al, ERROR_DISK_FULL
2112
        cmp     al, ERROR_DISK_FULL
2198
        jz      .disk_full
2113
        jz      .disk_full
-
 
2114
        call    fat_unlock
2199
        pop     eax
2115
        pop     eax
2200
        pop     eax
2116
        pop     eax
2201
        mov     [esp+4+28], eax
2117
        pop     ecx
2202
        pop     eax
2118
        pop     edx
2203
        popad
2119
        pop     edi
2204
        xor     ebx, ebx
2120
        xor     ebx, ebx
2205
        ret
2121
        ret
2206
.disk_full:
2122
.disk_full:
2207
; correct number of bytes to write
2123
; correct number of bytes to write
2208
        mov     ecx, [edi+28]
2124
        mov     ecx, [edi+28]
2209
        cmp     ecx, ebx
2125
        cmp     ecx, ebx
2210
        ja      .length_ok
2126
        ja      .length_ok
-
 
2127
        push    0
2211
.ret:
2128
.ret:
-
 
2129
        pop     eax
-
 
2130
        sub     edx, [esp+12]
-
 
2131
        mov     ebx, edx        ; ebx=number of written bytes
2212
        call    update_disk
2132
        call    update_disk
2213
        cmp     [hd_error], 0
2133
        test    eax, eax
2214
        jz      @f
2134
        jz      @f
2215
        mov     byte [esp+4], 11
2135
        mov     byte [esp+4], ERROR_DEVICE
2216
@@:
2136
@@:
-
 
2137
        call    fat_unlock
2217
        pop     eax
2138
        pop     eax
2218
        pop     eax
2139
        pop     eax
2219
        mov     [esp+4+28], eax ; eax=return value
-
 
2220
        pop     eax
2140
        pop     ecx
2221
        sub     edx, [esp+20]
2141
        pop     edx
2222
        mov     [esp+16], edx   ; ebx=number of written bytes
-
 
2223
        popad
2142
        pop     edi
2224
        ret
2143
        ret
2225
.length_ok:
2144
.length_ok:
2226
        mov     esi, [edi+28]
2145
        mov     esi, [edi+28]
2227
        mov     eax, [edi+20-2]
2146
        mov     eax, [edi+20-2]
2228
        mov     ax, [edi+26]
2147
        mov     ax, [edi+26]
2229
        mov     edi, eax        ; edi=current cluster
2148
        mov     edi, eax        ; edi=current cluster
2230
        xor     ebp, ebp        ; ebp=current sector in cluster
2149
        push    0               ; current sector in cluster
2231
; save directory
2150
; save directory
2232
        mov     eax, [esp+8]
2151
        mov     eax, [esp+12]
2233
        push    ebx
2152
        push    ebx
2234
        mov     ebx, buffer
2153
        lea     ebx, [ebp+FAT.buffer]
2235
        call    hd_write
2154
        call    fs_write32_sys
2236
        pop     ebx
2155
        pop     ebx
2237
        cmp     [hd_error], 0
2156
        test    eax, eax
2238
        jz      @f
2157
        jz      @f
2239
.device_err:
2158
.device_err:
2240
        mov     byte [esp+4], 11
2159
        mov     byte [esp+8], ERROR_DEVICE
-
 
2160
        jmp     .ret
-
 
2161
.fat_err:
-
 
2162
        mov     byte [esp+8], ERROR_FAT_TABLE
2241
        jmp     .ret
2163
        jmp     .ret
2242
@@:
2164
@@:
Line 2243... Line 2165...
2243
 
2165
 
2244
; now ebx=start pos, ecx=end pos, both lie inside file
2166
; now ebx=start pos, ecx=end pos, both lie inside file
2245
        sub     ecx, ebx
2167
        sub     ecx, ebx
2246
        jz      .ret
2168
        jz      .ret
2247
.write_loop:
2169
.write_loop:
2248
; skip unmodified sectors
2170
; skip unmodified sectors
2249
        cmp     dword [esp], 0x200
2171
        cmp     dword [esp+4], 0x200
2250
        jb      .modify
2172
        jb      .modify
2251
        sub     ebx, 0x200
2173
        sub     ebx, 0x200
2252
        jae     .skip
2174
        jae     .skip
2253
        add     ebx, 0x200
2175
        add     ebx, 0x200
Line 2267... Line 2189...
2267
@@:
2189
@@:
2268
; get current sector number
2190
; get current sector number
2269
        mov     eax, edi
2191
        mov     eax, edi
2270
        dec     eax
2192
        dec     eax
2271
        dec     eax
2193
        dec     eax
2272
        imul    eax, [SECTORS_PER_CLUSTER]
2194
        imul    eax, [ebp+FAT.SECTORS_PER_CLUSTER]
2273
        add     eax, [DATA_START]
2195
        add     eax, [ebp+FAT.DATA_START]
2274
        add     eax, ebp
2196
        add     eax, [esp+4]
2275
; load sector if needed
2197
; load sector if needed
2276
        cmp     dword [esp+4], 0        ; we don't need to read uninitialized data
2198
        cmp     dword [esp+8], 0        ; we don't need to read uninitialized data
2277
        jz      .noread
2199
        jz      .noread
2278
        cmp     ecx, 0x200      ; we don't need to read sector if it is fully rewritten
2200
        cmp     ecx, 0x200      ; we don't need to read sector if it is fully rewritten
2279
        jz      .noread
2201
        jz      .noread
2280
        cmp     ecx, esi        ; (same for the last sector)
2202
        cmp     ecx, esi        ; (same for the last sector)
2281
        jz      .noread
2203
        jz      .noread
2282
        push    ebx
2204
        push    eax ebx
2283
        mov     ebx, buffer
2205
        lea     ebx, [ebp+FAT.buffer]
2284
        call    hd_read
2206
        call    fs_read32_app
2285
        pop     ebx
2207
        test    eax, eax
2286
        cmp     [hd_error], 0
2208
        pop     ebx eax
2287
        jz      @f
2209
        jz      @f
2288
.device_err2:
2210
.device_err2:
2289
        pop     ecx
2211
        pop     ecx
2290
        jmp     .device_err
2212
        jmp     .device_err
2291
@@:
2213
@@:
2292
.noread:
2214
.noread:
2293
; zero uninitialized data if file was extended (because hd_extend_file does not this)
2215
; zero uninitialized data if file was extended (because hd_extend_file does not this)
2294
        push    eax ecx edi
2216
        push    eax ecx edi
2295
        xor     eax, eax
2217
        xor     eax, eax
2296
        mov     ecx, 0x200
2218
        mov     ecx, 0x200
2297
        sub     ecx, [esp+4+12]
2219
        sub     ecx, [esp+8+12]
2298
        jbe     @f
2220
        jbe     @f
2299
        mov     edi, buffer
2221
        lea     edi, [ebp+FAT.buffer]
2300
        add     edi, [esp+4+12]
2222
        add     edi, [esp+8+12]
2301
        rep stosb
2223
        rep stosb
2302
@@:
2224
@@:
2303
; zero uninitialized data in the last sector
2225
; zero uninitialized data in the last sector
2304
        mov     ecx, 0x200
2226
        mov     ecx, 0x200
2305
        sub     ecx, esi
2227
        sub     ecx, esi
2306
        jbe     @f
2228
        jbe     @f
2307
        mov     edi, buffer
2229
        lea     edi, [ebp+FAT.buffer+esi]
2308
        add     edi, esi
-
 
2309
        rep stosb
2230
        rep stosb
2310
@@:
2231
@@:
2311
        pop     edi ecx
2232
        pop     edi ecx
2312
; copy new data
2233
; copy new data
2313
        mov     eax, edx
2234
        mov     eax, edx
2314
        neg     ebx
2235
        neg     ebx
2315
        jecxz   @f
2236
        jecxz   @f
2316
        add     ebx, buffer+0x200
2237
        lea     ebx, [ebp+FAT.buffer+0x200+ebx]
2317
        call    memmove
2238
        call    memmove
2318
        xor     ebx, ebx
2239
        xor     ebx, ebx
2319
@@:
2240
@@:
2320
        pop     eax
2241
        pop     eax
2321
; save sector
2242
; save sector
2322
        push    ebx
2243
        push    ebx
2323
        mov     ebx, buffer
2244
        lea     ebx, [ebp+FAT.buffer]
2324
        call    hd_write
2245
        call    fs_write32_app
2325
        pop     ebx
2246
        pop     ebx
2326
        cmp     [hd_error], 0
2247
        test    eax, eax
2327
        jnz     .device_err2
2248
        jnz     .device_err2
2328
        add     edx, ecx
2249
        add     edx, ecx
2329
        sub     [esp], ecx
2250
        sub     [esp], ecx
2330
        pop     ecx
2251
        pop     ecx
2331
        jz      .ret
2252
        jz      .ret
2332
.skip:
2253
.skip:
2333
; next sector
2254
; next sector
-
 
2255
        pop     eax
2334
        inc     ebp
2256
        inc     eax
-
 
2257
        push    eax
2335
        cmp     ebp, [SECTORS_PER_CLUSTER]
2258
        cmp     eax, [ebp+FAT.SECTORS_PER_CLUSTER]
2336
        jb      @f
2259
        jb      @f
2337
        xor     ebp, ebp
2260
        and     dword [esp], 0
2338
        mov     eax, edi
2261
        mov     eax, edi
2339
        call    get_FAT
2262
        call    get_FAT
2340
        mov     edi, eax
2263
        mov     edi, eax
-
 
2264
        jc      .device_err
2341
        cmp     [hd_error], 0
2265
        cmp     edi, 2
-
 
2266
        jb      .fat_err
-
 
2267
        cmp     edi, [ebp+FAT.fatRESERVED]
2342
        jnz     .device_err
2268
        jae     .fat_err
2343
@@:
2269
@@:
2344
        sub     esi, 0x200
2270
        sub     esi, 0x200
2345
        jae     @f
2271
        jae     @f
2346
        xor     esi, esi
2272
        xor     esi, esi
2347
@@:
2273
@@:
2348
        sub     dword [esp], 0x200
2274
        sub     dword [esp+4], 0x200
2349
        jae     @f
2275
        jae     @f
2350
        and     dword [esp], 0
2276
        and     dword [esp+4], 0
2351
@@:
2277
@@:
2352
        jmp     .write_loop
2278
        jmp     .write_loop
Line 2353... Line 2279...
2353
 
2279
 
2354
hd_extend_file.zero_size:
2280
hd_extend_file.zero_size:
2355
        xor     eax, eax
2281
        xor     eax, eax
Line 2356... Line 2282...
2356
        jmp     hd_extend_file.start_extend
2282
        jmp     hd_extend_file.start_extend
2357
 
2283
 
2358
; extends file on hd to given size (new data area is undefined)
2284
; extends file on hd to given size (new data area is undefined)
2359
; in: edi->direntry, ecx=new size
2285
; in: edi->direntry, ecx=new size
2360
; out: CF=0 => OK, eax=0
2286
; out: CF=0 => OK, eax=0
2361
;      CF=1 => error, eax=code (ERROR_FAT_TABLE or ERROR_DISK_FULL or 11)
2287
;      CF=1 => error, eax=code (ERROR_FAT_TABLE or ERROR_DISK_FULL or ERROR_DEVICE)
2362
hd_extend_file:
2288
hd_extend_file:
2363
        push    ebp
2289
        push    esi
2364
        mov     ebp, [SECTORS_PER_CLUSTER]
2290
        mov     esi, [ebp+FAT.SECTORS_PER_CLUSTER]
2365
        imul    ebp, [BYTES_PER_SECTOR]
2291
        imul    esi, [ebp+FAT.BYTES_PER_SECTOR]
2366
        push    ecx
2292
        push    ecx
2367
; find the last cluster of file
2293
; find the last cluster of file
2368
        mov     eax, [edi+20-2]
2294
        mov     eax, [edi+20-2]
2369
        mov     ax, [edi+26]
2295
        mov     ax, [edi+26]
2370
        mov     ecx, [edi+28]
2296
        mov     ecx, [edi+28]
2371
        jecxz   .zero_size
2297
        jecxz   .zero_size
2372
.last_loop:
2298
.last_loop:
2373
        sub     ecx, ebp
2299
        sub     ecx, esi
2374
        jbe     .last_found
-
 
2375
        call    get_FAT
2300
        jbe     .last_found
2376
        cmp     [hd_error], 0
2301
        call    get_FAT
2377
        jz      @f
2302
        jnc     @f
2378
.device_err:
2303
.device_err:
2379
        pop     ecx
2304
        pop     ecx
2380
.device_err2:
2305
.device_err2:
2381
        pop     ebp
2306
        pop     esi
2382
        push    11
2307
        push    ERROR_DEVICE
2383
.ret_err:
2308
.ret_err:
2384
        pop     eax
2309
        pop     eax
2385
        stc
2310
        stc
2386
        ret
2311
        ret
2387
@@:
2312
@@:
2388
        cmp     eax, 2
2313
        cmp     eax, 2
2389
        jb      .fat_err
2314
        jb      .fat_err
2390
        cmp     eax, [fatRESERVED]
2315
        cmp     eax, [ebp+FAT.fatRESERVED]
2391
        jb      .last_loop
2316
        jb      .last_loop
2392
.fat_err:
2317
.fat_err:
2393
        pop     ecx ebp
2318
        pop     ecx esi
2394
        push    ERROR_FAT_TABLE
2319
        push    ERROR_FAT_TABLE
2395
        jmp     .ret_err
2320
        jmp     .ret_err
2396
.last_found:
2321
.last_found:
2397
        push    eax
-
 
2398
        call    get_FAT
2322
        push    eax
2399
        cmp     [hd_error], 0
2323
        call    get_FAT
2400
        jz      @f
2324
        jnc     @f
2401
        pop     eax
2325
        pop     eax
2402
        jmp     .device_err
2326
        jmp     .device_err
2403
@@:
2327
@@:
2404
        cmp     eax, [fatRESERVED]
2328
        cmp     eax, [ebp+FAT.fatRESERVED]
2405
        pop     eax
2329
        pop     eax
2406
        jb      .fat_err
2330
        jb      .fat_err
2407
; set length to full number of clusters
2331
; set length to full number of clusters
Line 2416... Line 2340...
2416
        jae     .extend_done
2340
        jae     .extend_done
2417
; add new cluster
2341
; add new cluster
2418
        push    eax
2342
        push    eax
2419
        call    get_free_FAT
2343
        call    get_free_FAT
2420
        jc      .disk_full
2344
        jc      .disk_full
2421
        mov     edx, [fatEND]
2345
        mov     edx, [ebp+FAT.fatEND]
2422
        call    set_FAT
2346
        call    set_FAT
2423
        mov     edx, eax
2347
        mov     edx, eax
2424
        pop     eax
2348
        pop     eax
2425
        test    eax, eax
2349
        test    eax, eax
2426
        jz      .first_cluster
2350
        jz      .first_cluster
Line 2437... Line 2361...
2437
        push    ecx
2361
        push    ecx
2438
        mov     ecx, -1
2362
        mov     ecx, -1
2439
        call    add_disk_free_space
2363
        call    add_disk_free_space
2440
        pop     ecx
2364
        pop     ecx
2441
        mov     eax, edx
2365
        mov     eax, edx
2442
        cmp     [hd_error], 0
-
 
2443
        jnz     .device_err3
-
 
2444
        add     [edi+28], ebp
2366
        add     [edi+28], esi
2445
        jmp     .extend_loop
2367
        jmp     .extend_loop
2446
.extend_done:
2368
.extend_done:
2447
        mov     [edi+28], ecx
2369
        mov     [edi+28], ecx
2448
        pop     edx ebp
2370
        pop     edx esi
2449
        xor     eax, eax        ; CF=0
2371
        xor     eax, eax        ; CF=0
2450
        ret
2372
        ret
2451
.device_err3:
2373
.device_err3:
2452
        pop     edx
2374
        pop     edx
2453
        jmp     .device_err2
2375
        jmp     .device_err2
2454
.disk_full:
2376
.disk_full:
2455
        pop     eax edx ebp
2377
        pop     eax edx esi
2456
        push    ERROR_DISK_FULL
2378
        push    ERROR_DISK_FULL
2457
        pop     eax
2379
        pop     eax
2458
        cmp     [hd_error], 0
-
 
2459
        jz      @f
-
 
2460
        mov     al, 11
-
 
2461
@@:
-
 
2462
        stc
2380
        stc
2463
        ret
2381
        ret
Line 2464... Line 2382...
2464
 
2382
 
2465
;----------------------------------------------------------------
2383
;----------------------------------------------------------------
2466
;
2384
;
2467
;  fs_HdSetFileEnd - set end of file on hard disk
2385
;  fs_HdSetFileEnd - set end of file on hard disk
-
 
2386
;
-
 
2387
;  Obsolete, will be replaced with filesystem-specific functions.
2468
;
2388
;
2469
;  esi  points to filename
2389
;  esi  points to filename
2470
;  ebx  points to 64-bit number = new file size
2390
;  ebx  points to 64-bit number = new file size
2471
;  ecx  ignored (reserved)
2391
;  ecx  ignored (reserved)
2472
;  edx  ignored (reserved)
2392
;  edx  ignored (reserved)
2473
;
2393
;
2474
;  ret eax = 0 ok or other = errormsg
2394
;  ret eax = 0 ok or other = errormsg
2475
;
2395
;
2476
;--------------------------------------------------------------
2396
;--------------------------------------------------------------
2477
fs_HdSetFileEnd:
-
 
2478
        cmp     [fs_type], 1
-
 
2479
        jz      ntfs_HdSetFileEnd
-
 
2480
        cmp     [fs_type], 2
-
 
2481
        jz      ext2_HdSetFileEnd
2397
fs_HdSetFileEnd:
2482
        cmp     [fs_type], 16
2398
        cmp     [fs_type], 16
2483
        jz      @f
2399
        jz      @f
2484
        cmp     [fs_type], 32
2400
        cmp     [fs_type], 32
-
 
2401
        jz      @f
-
 
2402
        cmp     [fs_type], 1
-
 
2403
        jz      ntfs_HdSetFileEnd
-
 
2404
        cmp     [fs_type], 2
2485
        jz      @f
2405
        jz      ext2_HdSetFileEnd
2486
        push    ERROR_UNKNOWN_FS
-
 
2487
.ret:
2406
        push    ERROR_UNKNOWN_FS
2488
        pop     eax
2407
        pop     eax
2489
        ret
2408
        ret
-
 
2409
@@:
-
 
2410
        sub     ebx, 4
-
 
2411
        push    ebp
-
 
2412
        mov     ebp, [fs_dependent_data_start.partition]
-
 
2413
        call    fat_SetFileEnd
-
 
2414
        pop     ebp
-
 
2415
        ret
-
 
2416
 
-
 
2417
;----------------------------------------------------------------
-
 
2418
; fat_SetFileEnd - FAT16/32 implementation of setting end-of-file
-
 
2419
; in:  ebp = pointer to FAT structure
-
 
2420
; in:  esi+[esp+4] = name
-
 
2421
; in:  ebx = pointer to parameters from sysfunc 70
-
 
2422
; out: eax, ebx = return values for sysfunc 70
-
 
2423
;----------------------------------------------------------------
-
 
2424
fat_SetFileEnd:
-
 
2425
        call    fat_lock
2490
@@:
2426
        push    edi
2491
        cmp     byte [esi], 0
2427
        cmp     byte [esi], 0
2492
        jnz     @f
2428
        jnz     @f
2493
.access_denied:
2429
.access_denied:
2494
        push    ERROR_ACCESS_DENIED
-
 
2495
        jmp     .ret
2430
        push    ERROR_ACCESS_DENIED
2496
@@:
-
 
2497
        push    edi
2431
.ret:
2498
        call    hd_find_lfn
-
 
2499
        pushfd
-
 
2500
        cmp     [hd_error], 0
2432
        call    fat_unlock
2501
        jz      @f
-
 
2502
        popfd
2433
        pop     eax
2503
        push    11
2434
        pop     edi
2504
        jmp     .ret
2435
        ret
2505
@@:
2436
@@:
2506
        popfd
2437
        stdcall hd_find_lfn, [esp+4+4]
-
 
2438
        jnc     @f
2507
        jnc     @f
2439
.reteax:
2508
        pop     edi
-
 
2509
        push    ERROR_FILE_NOT_FOUND
2440
        push    eax
2510
        jmp     .ret
2441
        jmp     .ret
2511
@@:
2442
@@:
2512
; must not be directory
2443
; must not be directory
2513
        test    byte [edi+11], 10h
-
 
2514
        jz      @f
-
 
2515
        pop     edi
2444
        test    byte [edi+11], 10h
2516
        jmp     .access_denied
-
 
2517
@@:
2445
        jnz     .access_denied
2518
; file size must not exceed 4 Gb
2446
; file size must not exceed 4 Gb
2519
        cmp     dword [ebx+4], 0
2447
        cmp     dword [ebx+8], 0
2520
        jz      @f
-
 
2521
        pop     edi
2448
        jz      @f
2522
        push    ERROR_END_OF_FILE
2449
        push    ERROR_END_OF_FILE
2523
        jmp     .ret
2450
        jmp     .ret
2524
@@:
2451
@@:
2525
        push    eax     ; save directory sector
2452
        push    eax     ; save directory sector
2526
; set file modification date/time to current
2453
; set file modification date/time to current
2527
        call    fat_update_datetime
2454
        call    fat_update_datetime
2528
        mov     eax, [ebx]
2455
        mov     eax, [ebx+4]
2529
        cmp     eax, [edi+28]
2456
        cmp     eax, [edi+28]
2530
        jb      .truncate
2457
        jb      .truncate
2531
        ja      .expand
2458
        ja      .expand
2532
        pop     eax
2459
        pop     eax
2533
        mov     ebx, buffer
2460
        lea     ebx, [ebp+FAT.buffer]
2534
        call    hd_write
2461
        call    fs_write32_sys
2535
        pop     edi
2462
        pop     edi
2536
        xor     eax, eax
-
 
2537
        cmp     [hd_error], 0
2463
        test    eax, eax
-
 
2464
        jz      @f
2538
        jz      @f
2465
        push    ERROR_DEVICE
2539
        mov     al, 11
2466
        jmp     .ret
-
 
2467
@@:
2540
@@:
2468
        push    0
2541
        ret
2469
        jmp     .ret
2542
.expand:
2470
.expand:
2543
        push    ebx ebp ecx
2471
        push    ebx ebp ecx
2544
        push    dword [edi+28]  ; save old size
2472
        push    dword [edi+28]  ; save old size
2545
        mov     ecx, eax
2473
        mov     ecx, eax
Line 2548... Line 2476...
2548
        jnc     .expand_ok
2476
        jnc     .expand_ok
2549
        cmp     al, ERROR_DISK_FULL
2477
        cmp     al, ERROR_DISK_FULL
2550
        jz      .disk_full
2478
        jz      .disk_full
2551
.pop_ret:
2479
.pop_ret:
2552
        call    update_disk
2480
        call    update_disk
2553
        pop     eax ecx ebp ebx ecx edi edi
2481
        pop     eax ecx ecx ebp ebx ecx
2554
        ret
2482
        jmp     .reteax
2555
.expand_ok:
2483
.expand_ok:
2556
.disk_full:
2484
.disk_full:
2557
; save directory
2485
; save directory
2558
        mov     eax, [edi+28]
2486
        mov     eax, [edi+28]
2559
        xchg    eax, [esp+20]
2487
        xchg    eax, [esp+20]
2560
        mov     ebx, buffer
2488
        lea     ebx, [ebp+FAT.buffer]
2561
        call    hd_write
2489
        call    fs_write32_sys
-
 
2490
        test    eax, eax
2562
        mov     eax, [edi+20-2]
2491
        mov     eax, [edi+20-2]
2563
        mov     ax, [edi+26]
2492
        mov     ax, [edi+26]
2564
        mov     edi, eax
2493
        mov     edi, eax
2565
        cmp     [hd_error], 0
-
 
2566
        jz      @f
2494
        jz      @f
2567
.pop_ret11:
2495
.pop_ret11:
2568
        mov     byte [esp], 11
2496
        mov     byte [esp], ERROR_DEVICE
2569
        jmp     .pop_ret
2497
        jmp     .pop_ret
2570
@@:
2498
@@:
-
 
2499
        test    edi, edi
-
 
2500
        jz      .pop_ret
2571
; now zero new data
2501
; now zero new data
2572
        xor     ebp, ebp
2502
        push    0
2573
; edi=current cluster, ebp=sector in cluster
2503
; edi=current cluster, [esp]=sector in cluster
2574
; [esp+20]=new size, [esp+4]=old size, [esp]=return code
2504
; [esp+24]=new size, [esp+8]=old size, [esp+4]=return code
2575
.zero_loop:
2505
.zero_loop:
-
 
2506
        cmp     edi, 2
-
 
2507
        jb      .error_fat
-
 
2508
        cmp     edi, [ebp+FAT.fatRESERVED]
-
 
2509
        jae     .error_fat
2576
        sub     dword [esp+4], 0x200
2510
        sub     dword [esp+8], 0x200
2577
        jae     .next_cluster
2511
        jae     .next_cluster
2578
        lea     eax, [edi-2]
2512
        lea     eax, [edi-2]
2579
        imul    eax, [SECTORS_PER_CLUSTER]
2513
        imul    eax, [ebp+FAT.SECTORS_PER_CLUSTER]
2580
        add     eax, [DATA_START]
2514
        add     eax, [ebp+FAT.DATA_START]
2581
        add     eax, ebp
2515
        add     eax, [esp]
2582
        cmp     dword [esp+4], -0x200
2516
        cmp     dword [esp+8], -0x200
2583
        jz      .noread
2517
        jz      .noread
-
 
2518
        push    eax
2584
        mov     ebx, buffer
2519
        lea     ebx, [ebp+FAT.buffer]
2585
        call    hd_read
2520
        call    fs_read32_app
-
 
2521
        test    eax, eax
2586
        cmp     [hd_error], 0
2522
        pop     eax
2587
        jnz     .err_next
2523
        jnz     .err_next
2588
.noread:
2524
.noread:
2589
        mov     ecx, [esp+4]
2525
        mov     ecx, [esp+8]
2590
        neg     ecx
2526
        neg     ecx
2591
        push    edi
2527
        push    edi
2592
        mov     edi, buffer+0x200
2528
        lea     edi, [ebp+FAT.buffer+0x200]
2593
        add     edi, [esp+8]
2529
        add     edi, [esp+12]
2594
        push    eax
2530
        push    eax
2595
        xor     eax, eax
2531
        xor     eax, eax
2596
        mov     [esp+12], eax
2532
        mov     [esp+16], eax
2597
        rep stosb
2533
        rep stosb
2598
        pop     eax
2534
        pop     eax
2599
        pop     edi
2535
        pop     edi
2600
        call    hd_write
2536
        call    fs_write32_app
2601
        cmp     [hd_error], 0
2537
        test    eax, eax
2602
        jz      .next_cluster
2538
        jz      .next_cluster
2603
.err_next:
2539
.err_next:
2604
        mov     byte [esp], 11
2540
        mov     byte [esp+4], ERROR_DEVICE
2605
.next_cluster:
2541
.next_cluster:
-
 
2542
        pop     eax
2606
        sub     dword [esp+20], 0x200
2543
        sub     dword [esp+20], 0x200
2607
        jbe     .pop_ret
2544
        jbe     .pop_ret
2608
        inc     ebp
2545
        inc     eax
-
 
2546
        push    eax
2609
        cmp     ebp, [SECTORS_PER_CLUSTER]
2547
        cmp     eax, [ebp+FAT.SECTORS_PER_CLUSTER]
2610
        jb      .zero_loop
2548
        jb      .zero_loop
2611
        xor     ebp, ebp
2549
        and     dword [esp], 0
2612
        mov     eax, edi
2550
        mov     eax, edi
2613
        call    get_FAT
2551
        call    get_FAT
2614
        mov     edi, eax
2552
        mov     edi, eax
2615
        cmp     [hd_error], 0
2553
        jnc     .zero_loop
2616
        jnz     .pop_ret11
2554
        pop     eax
2617
        jmp     .zero_loop
2555
        jmp     .pop_ret11
2618
.truncate:
2556
.truncate:
2619
        mov     [edi+28], eax
2557
        mov     [edi+28], eax
2620
        push    ecx
2558
        push    ecx
2621
        mov     ecx, [edi+20-2]
2559
        mov     ecx, [edi+20-2]
2622
        mov     cx, [edi+26]
2560
        mov     cx, [edi+26]
2623
        push    eax
2561
        push    eax
2624
        test    eax, eax
2562
        test    eax, eax
2625
        jz      .zero_size
2563
        jz      .zero_size
2626
; find new last cluster
2564
; find new last cluster
2627
@@:
2565
@@:
-
 
2566
        cmp     ecx, 2
-
 
2567
        jb      .error_fat2
-
 
2568
        cmp     ecx, [ebp+FAT.fatRESERVED]
-
 
2569
        jae     .error_fat2
2628
        mov     eax, [SECTORS_PER_CLUSTER]
2570
        mov     eax, [ebp+FAT.SECTORS_PER_CLUSTER]
2629
        shl     eax, 9
2571
        shl     eax, 9
2630
        sub     [esp], eax
2572
        sub     [esp], eax
2631
        jbe     @f
2573
        jbe     @f
2632
        mov     eax, ecx
2574
        mov     eax, ecx
2633
        call    get_FAT
2575
        call    get_FAT
2634
        mov     ecx, eax
2576
        mov     ecx, eax
2635
        cmp     [hd_error], 0
-
 
2636
        jz      @b
2577
        jnc     @b
2637
.device_err3:
2578
.device_err3:
2638
        pop     eax ecx eax edi
2579
        pop     eax ecx eax edi
-
 
2580
        call    update_disk
-
 
2581
        call    fat_unlock
2639
        push    11
2582
        push    ERROR_DEVICE
2640
        pop     eax
2583
        pop     eax
2641
        ret
2584
        ret
2642
@@:
2585
@@:
2643
; we will zero data at the end of last sector - remember it
2586
; we will zero data at the end of last sector - remember it
2644
        push    ecx
2587
        push    ecx
2645
; terminate FAT chain
2588
; terminate FAT chain
2646
        push    edx
2589
        push    edx
2647
        mov     eax, ecx
2590
        mov     eax, ecx
2648
        mov     edx, [fatEND]
2591
        mov     edx, [ebp+FAT.fatEND]
2649
        call    set_FAT
2592
        call    set_FAT
2650
        mov     eax, edx
2593
        mov     eax, edx
2651
        pop     edx
2594
        pop     edx
2652
        cmp     [hd_error], 0
-
 
2653
        jz      @f
2595
        jnc     @f
2654
.device_err4:
2596
.device_err4:
2655
        pop     ecx
2597
        pop     ecx
2656
        jmp     .device_err3
2598
        jmp     .device_err3
2657
.zero_size:
2599
.zero_size:
2658
        and     word [edi+20], 0
2600
        and     word [edi+20], 0
Line 2660... Line 2602...
2660
        push    0
2602
        push    0
2661
        mov     eax, ecx
2603
        mov     eax, ecx
2662
@@:
2604
@@:
2663
; delete FAT chain
2605
; delete FAT chain
2664
        call    clear_cluster_chain
2606
        call    clear_cluster_chain
2665
        cmp     [hd_error], 0
-
 
2666
        jnz     .device_err4
2607
        jc      .device_err4
2667
; save directory
2608
; save directory
2668
        mov     eax, [esp+12]
2609
        mov     eax, [esp+12]
2669
        push    ebx
2610
        push    ebx
2670
        mov     ebx, buffer
2611
        lea     ebx, [ebp+FAT.buffer]
2671
        call    hd_write
2612
        call    fs_write32_sys
2672
        pop     ebx
2613
        pop     ebx
2673
        cmp     [hd_error], 0
2614
        test    eax, eax
2674
        jnz     .device_err4
2615
        jnz     .device_err4
2675
; zero last sector, ignore errors
2616
; zero last sector, ignore errors
2676
        pop     ecx
2617
        pop     ecx
2677
        pop     eax
2618
        pop     eax
2678
        dec     ecx
2619
        dec     ecx
2679
        imul    ecx, [SECTORS_PER_CLUSTER]
2620
        imul    ecx, [ebp+FAT.SECTORS_PER_CLUSTER]
2680
        add     ecx, [DATA_START]
2621
        add     ecx, [ebp+FAT.DATA_START]
2681
        push    eax
2622
        push    eax
2682
        sar     eax, 9
2623
        sar     eax, 9
2683
        add     ecx, eax
2624
        add     ecx, eax
2684
        pop     eax
2625
        pop     eax
2685
        and     eax, 0x1FF
2626
        and     eax, 0x1FF
2686
        jz      .truncate_done
2627
        jz      .truncate_done
2687
        push    ebx eax
2628
        push    ebx eax
2688
        mov     eax, ecx
2629
        mov     eax, ecx
2689
        mov     ebx, buffer
2630
        lea     ebx, [ebp+FAT.buffer]
2690
        call    hd_read
2631
        call    fs_read32_app
2691
        pop     eax
2632
        pop     eax
2692
        lea     edi, [buffer+eax]
2633
        lea     edi, [ebp+FAT.buffer+eax]
2693
        push    ecx
2634
        push    ecx
2694
        mov     ecx, 0x200
2635
        mov     ecx, 0x200
2695
        sub     ecx, eax
2636
        sub     ecx, eax
2696
        xor     eax, eax
2637
        xor     eax, eax
2697
        rep stosb
2638
        rep stosb
2698
        pop     eax
2639
        pop     eax
2699
        call    hd_write
2640
        call    fs_write32_app
2700
        pop     ebx
2641
        pop     ebx
2701
.truncate_done:
2642
.truncate_done:
2702
        pop     ecx eax edi
2643
        pop     ecx eax edi
2703
        call    update_disk
2644
        call    update_disk
-
 
2645
        call    fat_unlock
2704
        xor     eax, eax
2646
        xor     eax, eax
2705
        cmp     [hd_error], 0
2647
        ret
-
 
2648
.error_fat:
2706
        jz      @f
2649
        pop     eax
-
 
2650
        mov     byte [esp], ERROR_FAT_TABLE
2707
        mov     al, 11
2651
        jmp     .pop_ret
2708
@@:
2652
.error_fat2:
-
 
2653
        pop     eax ecx eax edi
-
 
2654
        call    update_disk
-
 
2655
        call    fat_unlock
-
 
2656
        push    ERROR_FAT_TABLE
-
 
2657
        pop     eax
2709
        ret
2658
        ret
Line 2710... Line 2659...
2710
 
2659
 
2711
fs_HdGetFileInfo:
-
 
2712
        cmp     [fs_type], 1
-
 
2713
        jz      ntfs_HdGetFileInfo
-
 
2714
        cmp     [fs_type], 2
-
 
2715
        jz      ext2_HdGetFileInfo
2660
fs_HdGetFileInfo:
2716
        cmp     [fs_type], 16
2661
        cmp     [fs_type], 16
2717
        jz      @f
2662
        jz      @f
2718
        cmp     [fs_type], 32
2663
        cmp     [fs_type], 32
-
 
2664
        jz      @f
-
 
2665
        cmp     [fs_type], 1
-
 
2666
        jz      ntfs_HdGetFileInfo
-
 
2667
        cmp     [fs_type], 2
2719
        jz      @f
2668
        jz      ext2_HdGetFileInfo
2720
        mov     eax, ERROR_UNKNOWN_FS
2669
        mov     eax, ERROR_UNKNOWN_FS
2721
        ret
2670
        ret
-
 
2671
@@:
-
 
2672
        sub     ebx, 4
-
 
2673
        push    ebp
-
 
2674
        mov     ebp, [fs_dependent_data_start.partition]
-
 
2675
        call    fat_GetFileInfo
-
 
2676
        pop     ebp
-
 
2677
        ret
-
 
2678
 
-
 
2679
;----------------------------------------------------------------
-
 
2680
; fat_GetFileInfo - FAT16/32 implementation of getting file info
-
 
2681
; in:  ebp = pointer to FAT structure
-
 
2682
; in:  esi+[esp+4] = name
-
 
2683
; in:  ebx = pointer to parameters from sysfunc 70
-
 
2684
; out: eax, ebx = return values for sysfunc 70
-
 
2685
;----------------------------------------------------------------
2722
@@:
2686
fat_GetFileInfo:
2723
        cmp     byte [esi], 0
2687
        cmp     byte [esi], 0
2724
        jnz     @f
2688
        jnz     @f
2725
        mov     eax, 2
2689
        mov     eax, 2
2726
        ret
2690
        ret
2727
@@:
2691
@@:
2728
        push    edi
2692
        push    edi
-
 
2693
        call    fat_lock
-
 
2694
        stdcall hd_find_lfn, [esp+4+4]
2729
        call    hd_find_lfn
2695
        jc      .error
-
 
2696
        push    ebp
-
 
2697
        xor     ebp, ebp
-
 
2698
        mov     esi, [ebx+16]
-
 
2699
        mov     dword [esi+4], ebp
-
 
2700
        call    fat_entry_to_bdfe2
2730
        pushfd
2701
        pop     ebp
-
 
2702
        call    fat_unlock
2731
        cmp     [hd_error], 0
2703
        xor     eax, eax
2732
        jz      @f
2704
        pop     edi
-
 
2705
        ret
-
 
2706
.error:
-
 
2707
        push    eax
-
 
2708
        call    fat_unlock
2733
        popfd
2709
        pop     eax
2734
        pop     edi
-
 
2735
        mov     eax, 11
2710
        pop     edi
2736
        ret
-
 
2737
@@:
-
 
2738
        popfd
-
 
Line 2739... Line 2711...
2739
        jmp     fs_GetFileInfo_finish
2711
        ret
2740
 
-
 
2741
fs_HdSetFileInfo:
-
 
2742
        cmp     [fs_type], 1
-
 
2743
        jz      ntfs_HdSetFileInfo
-
 
2744
        cmp     [fs_type], 2
2712
 
2745
        jz      ext2_HdSetFileInfo
2713
fs_HdSetFileInfo:
2746
        cmp     [fs_type], 16
2714
        cmp     [fs_type], 16
2747
        jz      @f
2715
        jz      @f
-
 
2716
        cmp     [fs_type], 32
-
 
2717
        jz      @f
-
 
2718
        cmp     [fs_type], 1
-
 
2719
        jz      ntfs_HdSetFileInfo
2748
        cmp     [fs_type], 32
2720
        cmp     [fs_type], 2
2749
        jz      @f
2721
        jz      ext2_HdSetFileInfo
2750
        mov     eax, ERROR_UNKNOWN_FS
2722
        mov     eax, ERROR_UNKNOWN_FS
-
 
2723
        ret
-
 
2724
@@:
-
 
2725
        sub     ebx, 4
-
 
2726
        push    ebp
-
 
2727
        mov     ebp, [fs_dependent_data_start.partition]
-
 
2728
        call    fat_SetFileInfo
-
 
2729
        pop     ebp
-
 
2730
        ret
-
 
2731
 
-
 
2732
;----------------------------------------------------------------
-
 
2733
; fat_SetFileInfo - FAT16/32 implementation of setting file info
-
 
2734
; in:  ebp = pointer to FAT structure
-
 
2735
; in:  esi+[esp+4] = name
-
 
2736
; in:  ebx = pointer to parameters from sysfunc 70
-
 
2737
; out: eax, ebx = return values for sysfunc 70
2751
        ret
2738
;----------------------------------------------------------------
2752
@@:
2739
fat_SetFileInfo:
2753
        cmp     byte [esi], 0
2740
        cmp     byte [esi], 0
2754
        jnz     @f
2741
        jnz     @f
2755
        mov     eax, 2
2742
        mov     eax, 2
2756
        ret
2743
        ret
2757
@@:
2744
@@:
2758
        push    edi
-
 
2759
        call    hd_find_lfn
2745
        push    edi
2760
        pushfd
2746
        call    fat_lock
2761
        cmp     [hd_error], 0
-
 
2762
        jz      @f
-
 
2763
        popfd
-
 
2764
        pop     edi
-
 
2765
        mov     eax, 11
-
 
2766
        ret
-
 
2767
@@:
-
 
2768
        popfd
-
 
2769
        jnc     @f
-
 
2770
        pop     edi
-
 
2771
        mov     eax, ERROR_FILE_NOT_FOUND
-
 
2772
        ret
2747
        stdcall hd_find_lfn, [esp+4+4]
-
 
2748
        jc      .error
2773
@@:
2749
        push    eax
2774
        push    eax
2750
        mov     edx, [ebx+16]
2775
        call    bdfe_to_fat_entry
2751
        call    bdfe_to_fat_entry
2776
        pop     eax
2752
        pop     eax
2777
        mov     ebx, buffer
2753
        lea     ebx, [ebp+FAT.buffer]
-
 
2754
        call    fs_write32_sys
2778
        call    hd_write
2755
        call    update_disk
2779
        call    update_disk
2756
        call    fat_unlock
2780
        pop     edi
2757
        pop     edi
-
 
2758
        xor     eax, eax
-
 
2759
        ret
-
 
2760
.error:
-
 
2761
        push    eax
-
 
2762
        call    fat_unlock
-
 
2763
        pop     eax
Line 2781... Line 2764...
2781
        xor     eax, eax
2764
        pop     edi
2782
        ret
2765
        ret
2783
 
2766
 
2784
;----------------------------------------------------------------
2767
;----------------------------------------------------------------
-
 
2768
;
-
 
2769
;  fs_HdDelete - delete file or empty folder from hard disk
2785
;
2770
;
2786
;  fs_HdDelete - delete file or empty folder from hard disk
2771
;  Obsolete, will be replaced with filesystem-specific functions.
2787
;
2772
;
2788
;  esi  points to filename
2773
;  esi  points to filename
2789
;
2774
;
2790
;  ret  eax = 0 ok or other = errormsg
2775
;  ret  eax = 0 ok or other = errormsg
2791
;
-
 
2792
;--------------------------------------------------------------
-
 
2793
fs_HdDelete:
-
 
2794
        cmp     [fs_type], 1
-
 
2795
        jz      ntfs_HdDelete
2776
;
2796
        cmp     [fs_type], 2
2777
;--------------------------------------------------------------
2797
        jz      ext2_HdDelete
2778
fs_HdDelete:
2798
        cmp     [fs_type], 16
2779
        cmp     [fs_type], 16
-
 
2780
        jz      @f
-
 
2781
        cmp     [fs_type], 32
-
 
2782
        jz      @f
-
 
2783
        cmp     [fs_type], 1
2799
        jz      @f
2784
        jz      ntfs_HdDelete
2800
        cmp     [fs_type], 32
-
 
2801
        jz      @f
2785
        cmp     [fs_type], 2
2802
        push    ERROR_UNKNOWN_FS
2786
        jz      ext2_HdDelete
2803
.pop_ret:
2787
        push    ERROR_UNKNOWN_FS
-
 
2788
        pop     eax
-
 
2789
        ret
-
 
2790
@@:
-
 
2791
        sub     ebx, 4
-
 
2792
        push    ebp
-
 
2793
        mov     ebp, [fs_dependent_data_start.partition]
-
 
2794
        call    fat_Delete
-
 
2795
        pop     ebp
-
 
2796
        ret
-
 
2797
 
-
 
2798
;----------------------------------------------------------------
-
 
2799
; fat_Delete - FAT16/32 implementation of deleting a file/folder
-
 
2800
; in:  ebp = pointer to FAT structure
-
 
2801
; in:  esi+[esp+4] = name
-
 
2802
; in:  ebx = pointer to parameters from sysfunc 70
-
 
2803
; out: eax, ebx = return values for sysfunc 70
2804
        pop     eax
2804
;----------------------------------------------------------------
2805
        ret
2805
fat_Delete:
2806
@@:
2806
        call    fat_lock
2807
        cmp     byte [esi], 0
2807
        cmp     byte [esi], 0
2808
        jnz     @f
2808
        jnz     @f
-
 
2809
; cannot delete root!
-
 
2810
.access_denied:
-
 
2811
        push    ERROR_ACCESS_DENIED
2809
; cannot delete root!
2812
.pop_ret:
-
 
2813
        call    fat_unlock
2810
.access_denied:
2814
        pop     eax
2811
        push    ERROR_ACCESS_DENIED
2815
        xor     ebx, ebx
2812
        jmp     .pop_ret
2816
        ret
2813
@@:
2817
@@:
2814
        and     [longname_sec1], 0
2818
        and     [ebp+FAT.longname_sec1], 0
2815
        and     [longname_sec2], 0
2819
        and     [ebp+FAT.longname_sec2], 0
2816
        push    edi
2820
        push    edi
2817
        call    hd_find_lfn
2821
        stdcall hd_find_lfn, [esp+4+4]
2818
        jnc     .found
2822
        jnc     .found
2819
        pop     edi
2823
        pop     edi
Line 2826... Line 2830...
2826
        jz      .access_denied2
2830
        jz      .access_denied2
2827
        test    byte [edi+11], 10h
2831
        test    byte [edi+11], 10h
2828
        jz      .dodel
2832
        jz      .dodel
2829
; we can delete only empty folders!
2833
; we can delete only empty folders!
2830
        pushad
2834
        pushad
2831
        mov     ebp, [edi+20-2]
2835
        mov     esi, [edi+20-2]
2832
        mov     bp, [edi+26]
2836
        mov     si, [edi+26]
2833
        xor     ecx, ecx
2837
        xor     ecx, ecx
2834
        lea     eax, [ebp-2]
2838
        lea     eax, [esi-2]
2835
        imul    eax, [SECTORS_PER_CLUSTER]
2839
        imul    eax, [ebp+FAT.SECTORS_PER_CLUSTER]
2836
        add     eax, [DATA_START]
2840
        add     eax, [ebp+FAT.DATA_START]
2837
        mov     ebx, buffer
2841
        lea     ebx, [ebp+FAT.buffer]
2838
        call    hd_read
2842
        call    fs_read32_sys
2839
        cmp     [hd_error], 0
2843
        test    eax, eax
2840
        jnz     .err1
2844
        jnz     .err1
-
 
2845
        lea     eax, [ebx+0x200]
2841
        add     ebx, 2*0x20
2846
        add     ebx, 2*0x20
2842
.checkempty:
2847
.checkempty:
2843
        cmp     byte [ebx], 0
2848
        cmp     byte [ebx], 0
2844
        jz      .empty
2849
        jz      .empty
2845
        cmp     byte [ebx], 0xE5
2850
        cmp     byte [ebx], 0xE5
2846
        jnz     .notempty
2851
        jnz     .notempty
2847
        add     ebx, 0x20
2852
        add     ebx, 0x20
2848
        cmp     ebx, buffer+0x200
2853
        cmp     ebx, eax
2849
        jb      .checkempty
2854
        jb      .checkempty
2850
        inc     ecx
2855
        inc     ecx
2851
        cmp     ecx, [SECTORS_PER_CLUSTER]
2856
        cmp     ecx, [ebp+FAT.SECTORS_PER_CLUSTER]
2852
        jb      @f
2857
        jb      @f
2853
        mov     eax, ebp
2858
        mov     eax, esi
2854
        call    get_FAT
2859
        call    get_FAT
2855
        cmp     [hd_error], 0
-
 
2856
        jnz     .err1
2860
        jc      .err1
2857
        mov     ebp, eax
2861
        mov     esi, eax
2858
        xor     ecx, ecx
2862
        xor     ecx, ecx
2859
@@:
2863
@@:
2860
        lea     eax, [ebp-2]
2864
        lea     eax, [esi-2]
2861
        imul    eax, [SECTORS_PER_CLUSTER]
2865
        imul    eax, [ebp+FAT.SECTORS_PER_CLUSTER]
2862
        add     eax, [DATA_START]
2866
        add     eax, [ebp+FAT.DATA_START]
2863
        add     eax, ecx
2867
        add     eax, ecx
2864
        mov     ebx, buffer
2868
        lea     ebx, [ebp+FAT.buffer]
2865
        call    hd_read
2869
        call    fs_read32_sys
-
 
2870
        test    eax, eax
2866
        cmp     [hd_error], 0
2871
        lea     eax, [ebx+0x200]
2867
        jz      .checkempty
2872
        jz      .checkempty
2868
.err1:
2873
.err1:
2869
        popad
2874
        popad
2870
.err2:
2875
.err2:
2871
        pop     edi
2876
        pop     edi
-
 
2877
        call    fat_unlock
2872
        push    11
2878
        push    ERROR_DEVICE
2873
        pop     eax
2879
        pop     eax
2874
        ret
2880
        ret
2875
.notempty:
2881
.notempty:
2876
        popad
2882
        popad
2877
.access_denied2:
2883
.access_denied2:
2878
        pop     edi
2884
        pop     edi
-
 
2885
        call    fat_unlock
2879
        push    ERROR_ACCESS_DENIED
2886
        push    ERROR_ACCESS_DENIED
2880
        pop     eax
2887
        pop     eax
2881
        ret
2888
        ret
2882
.empty:
2889
.empty:
2883
        popad
2890
        popad
2884
        push    ebx
2891
        push    eax ebx
2885
        mov     ebx, buffer
2892
        lea     ebx, [ebp+FAT.buffer]
2886
        call    hd_read
2893
        call    fs_read32_sys
2887
        pop     ebx
2894
        test    eax, eax
2888
        cmp     [hd_error], 0
2895
        pop     ebx eax
2889
        jnz     .err2
2896
        jnz     .err2
2890
.dodel:
2897
.dodel:
2891
        push    eax
2898
        push    eax
2892
        mov     eax, [edi+20-2]
2899
        mov     eax, [edi+20-2]
2893
        mov     ax, [edi+26]
2900
        mov     ax, [edi+26]
2894
        xchg    eax, [esp]
2901
        xchg    eax, [esp]
2895
; delete folder entry
2902
; delete folder entry
2896
        mov     byte [edi], 0xE5
2903
        mov     byte [edi], 0xE5
2897
; delete LFN (if present)
2904
; delete LFN (if present)
2898
.lfndel:
2905
.lfndel:
-
 
2906
        lea     edx, [ebp+FAT.buffer]
2899
        cmp     edi, buffer
2907
        cmp     edi, edx
2900
        ja      @f
2908
        ja      @f
2901
        cmp     [longname_sec2], 0
2909
        cmp     [ebp+FAT.longname_sec2], 0
2902
        jz      .lfndone
2910
        jz      .lfndone
2903
        push    [longname_sec2]
2911
        push    [ebp+FAT.longname_sec2]
2904
        push    [longname_sec1]
2912
        push    [ebp+FAT.longname_sec1]
2905
        pop     [longname_sec2]
2913
        pop     [ebp+FAT.longname_sec2]
2906
        and     [longname_sec1], 0
2914
        and     [ebp+FAT.longname_sec1], 0
2907
        push    ebx
2915
        push    ebx
2908
        mov     ebx, buffer
2916
        mov     ebx, edx
2909
        call    hd_write
2917
        call    fs_write32_sys
2910
        mov     eax, [esp+4]
2918
        mov     eax, [esp+4]
2911
        call    hd_read
2919
        call    fs_read32_sys
2912
        pop     ebx
2920
        pop     ebx
2913
        pop     eax
2921
        pop     eax
2914
        mov     edi, buffer+0x200
2922
        lea     edi, [ebp+FAT.buffer+0x200]
2915
@@:
2923
@@:
2916
        sub     edi, 0x20
2924
        sub     edi, 0x20
2917
        cmp     byte [edi], 0xE5
2925
        cmp     byte [edi], 0xE5
2918
        jz      .lfndone
2926
        jz      .lfndone
2919
        cmp     byte [edi+11], 0xF
2927
        cmp     byte [edi+11], 0xF
2920
        jnz     .lfndone
2928
        jnz     .lfndone
2921
        mov     byte [edi], 0xE5
2929
        mov     byte [edi], 0xE5
2922
        jmp     .lfndel
2930
        jmp     .lfndel
2923
.lfndone:
2931
.lfndone:
2924
        push    ebx
2932
        push    ebx
2925
        mov     ebx, buffer
2933
        lea     ebx, [ebp+FAT.buffer]
2926
        call    hd_write
2934
        call    fs_write32_sys
2927
        pop     ebx
2935
        pop     ebx
2928
; delete FAT chain
2936
; delete FAT chain
2929
        pop     eax
2937
        pop     eax
2930
        call    clear_cluster_chain
2938
        call    clear_cluster_chain
2931
        call    update_disk
2939
        call    update_disk
-
 
2940
        call    fat_unlock
2932
        pop     edi
2941
        pop     edi
2933
        xor     eax, eax
2942
        xor     eax, eax
2934
        cmp     [hd_error], 0
-
 
2935
        jz      @f
-
 
2936
        mov     al, 11
-
 
2937
@@:
-
 
2938
        ret
2943
        ret
Line 2939... Line 2944...
2939
 
2944