Subversion Repositories Kolibri OS

Rev

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

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