Subversion Repositories Kolibri OS

Rev

Rev 9692 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9692 Rev 9828
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;;
4
;;  Distributed under terms of the GNU General Public License.  ;;
4
;;  Distributed under terms of the GNU General Public License.  ;;
5
;;                                                              ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
7
 
8
$Revision: 9692 $
8
$Revision: 9828 $
9
 
9
 
10
; CD external functions
10
; CD external functions
11
;   in:
11
;   in:
12
; esi -> path string in UTF-8
12
; esi -> path string in UTF-8
13
; ebx -> parameter structure +4
13
; ebx -> parameter structure +4
14
; ecx = bytes to read
14
; ecx = bytes to read
15
; edx -> buffer
15
; edx -> buffer
16
;   out:
16
;   out:
17
; eax, ebx = return values for sysfunc 70
17
; eax, ebx = return values for sysfunc 70
18
iglobal
18
iglobal
19
align 4
19
align 4
20
fs_CdServices:
20
fs_CdServices:
21
        dd      fs_CdRead
21
        dd      fs_CdRead
22
        dd      fs_CdReadFolder
22
        dd      fs_CdReadFolder
23
        dd      fs_NotImplemented
23
        dd      fs_NotImplemented
24
        dd      fs_NotImplemented
24
        dd      fs_NotImplemented
25
        dd      fs_NotImplemented
25
        dd      fs_NotImplemented
26
        dd      fs_CdGetFileInfo
26
        dd      fs_CdGetFileInfo
27
        dd      fs_NotImplemented
27
        dd      fs_NotImplemented
28
        dd      0
28
        dd      0
29
        dd      fs_NotImplemented
29
        dd      fs_NotImplemented
30
        dd      fs_NotImplemented
30
        dd      fs_NotImplemented
31
fs_NumCdServices = ($ - fs_CdServices)/4
31
fs_NumCdServices = ($ - fs_CdServices)/4
32
endg
32
endg
33
 
33
 
34
uglobal
34
uglobal
35
align 4
35
align 4
36
cd_current_pointer_of_input     dd  0
36
cd_current_pointer_of_input     dd  0
37
cd_current_pointer_of_input_2   dd  0
37
cd_current_pointer_of_input_2   dd  0
38
cd_mem_location                 dd  0
38
cd_mem_location                 dd  0
39
cd_counter_block                dd  0
39
cd_counter_block                dd  0
40
cd_status                       dd  0
40
cd_status                       dd  0
41
endg
41
endg
42
 
42
 
43
;-----------------------------------------------------------------------------
43
;-----------------------------------------------------------------------------
44
fs_NotImplemented:
44
fs_NotImplemented:
45
        movi    eax, ERROR_UNSUPPORTED_FS
45
        movi    eax, ERROR_UNSUPPORTED_FS
46
        ret
46
        ret
47
;-----------------------------------------------------------------------------
47
;-----------------------------------------------------------------------------
48
reserve_cd:
48
reserve_cd:
49
        cli
49
        cli
50
        cmp     [cd_status], 0
50
        cmp     [cd_status], 0
51
        je      reserve_ok2
51
        je      reserve_ok2
52
 
52
 
53
        sti
53
        sti
54
        call    change_task
54
        call    change_task
55
        jmp     reserve_cd
55
        jmp     reserve_cd
56
;-----------------------------------------------------------------------------
56
;-----------------------------------------------------------------------------
57
reserve_ok2:
57
reserve_ok2:
58
        push    eax
58
        push    eax
59
        mov     eax, [current_slot_idx]
59
        mov     eax, [current_slot]
60
        shl     eax, BSF sizeof.APPDATA
-
 
61
        mov     eax, [eax + SLOT_BASE + APPDATA.tid]
60
        mov     eax, [eax + APPDATA.tid]
62
        mov     [cd_status], eax
61
        mov     [cd_status], eax
63
        pop     eax
62
        pop     eax
64
        sti
63
        sti
65
        ret
64
        ret
66
;-----------------------------------------------------------------------------
65
;-----------------------------------------------------------------------------
67
reserve_cd_channel:
66
reserve_cd_channel:
68
        pushad
67
        pushad
69
        mov     eax, [cdpos]
68
        mov     eax, [cdpos]
70
        dec     eax
69
        dec     eax
71
        shr     eax, 2
70
        shr     eax, 2
72
 
71
 
73
        test    eax, eax
72
        test    eax, eax
74
        jnz     .1
73
        jnz     .1
75
 
74
 
76
        cmp     [ChannelNumber], 1
75
        cmp     [ChannelNumber], 1
77
        jne     @f
76
        jne     @f
78
 
77
 
79
        mov     ecx, ide_channel1_mutex
78
        mov     ecx, ide_channel1_mutex
80
        jmp     .mutex_lock
79
        jmp     .mutex_lock
81
;--------------------------------------
80
;--------------------------------------
82
@@:
81
@@:
83
        mov     ecx, ide_channel2_mutex
82
        mov     ecx, ide_channel2_mutex
84
        jmp     .mutex_lock
83
        jmp     .mutex_lock
85
;--------------------------------------
84
;--------------------------------------
86
.1:
85
.1:
87
        dec     eax
86
        dec     eax
88
        jnz     .2
87
        jnz     .2
89
 
88
 
90
        cmp     [ChannelNumber], 1
89
        cmp     [ChannelNumber], 1
91
        jne     @f
90
        jne     @f
92
 
91
 
93
        mov     ecx, ide_channel3_mutex
92
        mov     ecx, ide_channel3_mutex
94
        jmp     .mutex_lock
93
        jmp     .mutex_lock
95
;--------------------------------------
94
;--------------------------------------
96
@@:
95
@@:
97
        mov     ecx, ide_channel4_mutex
96
        mov     ecx, ide_channel4_mutex
98
        jmp     .mutex_lock
97
        jmp     .mutex_lock
99
;--------------------------------------
98
;--------------------------------------
100
.2:
99
.2:
101
        cmp     [ChannelNumber], 1
100
        cmp     [ChannelNumber], 1
102
        jne     @f
101
        jne     @f
103
 
102
 
104
        mov     ecx, ide_channel5_mutex
103
        mov     ecx, ide_channel5_mutex
105
        jmp     .mutex_lock
104
        jmp     .mutex_lock
106
;--------------------------------------
105
;--------------------------------------
107
@@:
106
@@:
108
        mov     ecx, ide_channel6_mutex
107
        mov     ecx, ide_channel6_mutex
109
.mutex_lock:
108
.mutex_lock:
110
        call    mutex_lock
109
        call    mutex_lock
111
        popad
110
        popad
112
        ret
111
        ret
113
;-----------------------------------------------------------------------------
112
;-----------------------------------------------------------------------------
114
free_cd_channel:
113
free_cd_channel:
115
        pushad
114
        pushad
116
        mov     eax, [cdpos]
115
        mov     eax, [cdpos]
117
        dec     eax
116
        dec     eax
118
        shr     eax, 2
117
        shr     eax, 2
119
 
118
 
120
        test    eax, eax
119
        test    eax, eax
121
        jnz     .1
120
        jnz     .1
122
 
121
 
123
        cmp     [ChannelNumber], 1
122
        cmp     [ChannelNumber], 1
124
        jne     @f
123
        jne     @f
125
 
124
 
126
        mov     ecx, ide_channel1_mutex
125
        mov     ecx, ide_channel1_mutex
127
        jmp     .mutex_unlock
126
        jmp     .mutex_unlock
128
;--------------------------------------
127
;--------------------------------------
129
@@:
128
@@:
130
        mov     ecx, ide_channel2_mutex
129
        mov     ecx, ide_channel2_mutex
131
        jmp     .mutex_unlock
130
        jmp     .mutex_unlock
132
;--------------------------------------
131
;--------------------------------------
133
.1:
132
.1:
134
        dec     eax
133
        dec     eax
135
        jnz     .2
134
        jnz     .2
136
 
135
 
137
        cmp     [ChannelNumber], 1
136
        cmp     [ChannelNumber], 1
138
        jne     @f
137
        jne     @f
139
 
138
 
140
        mov     ecx, ide_channel3_mutex
139
        mov     ecx, ide_channel3_mutex
141
        jmp     .mutex_unlock
140
        jmp     .mutex_unlock
142
;--------------------------------------
141
;--------------------------------------
143
@@:
142
@@:
144
        mov     ecx, ide_channel4_mutex
143
        mov     ecx, ide_channel4_mutex
145
        jmp     .mutex_unlock
144
        jmp     .mutex_unlock
146
;--------------------------------------
145
;--------------------------------------
147
.2:
146
.2:
148
        cmp     [ChannelNumber], 1
147
        cmp     [ChannelNumber], 1
149
        jne     @f
148
        jne     @f
150
 
149
 
151
        mov     ecx, ide_channel5_mutex
150
        mov     ecx, ide_channel5_mutex
152
        jmp     .mutex_unlock
151
        jmp     .mutex_unlock
153
;--------------------------------------
152
;--------------------------------------
154
@@:
153
@@:
155
        mov     ecx, ide_channel6_mutex
154
        mov     ecx, ide_channel6_mutex
156
.mutex_unlock:
155
.mutex_unlock:
157
        call    mutex_unlock
156
        call    mutex_unlock
158
        popad
157
        popad
159
        ret
158
        ret
160
 
159
 
161
;-----------------------------------------------------------------------------
160
;-----------------------------------------------------------------------------
162
fs_CdRead:
161
fs_CdRead:
163
        call    cd_find_lfn
162
        call    cd_find_lfn
164
        jc      .notFound
163
        jc      .notFound
165
        mov     edi, [cd_current_pointer_of_input]
164
        mov     edi, [cd_current_pointer_of_input]
166
        test    byte [edi+25], 10b  ; do not allow read directories
165
        test    byte [edi+25], 10b  ; do not allow read directories
167
        jnz     .noaccess
166
        jnz     .noaccess
168
        test    ebx, ebx
167
        test    ebx, ebx
169
        jz      .l1
168
        jz      .l1
170
        cmp     dword [ebx+4], 0
169
        cmp     dword [ebx+4], 0
171
        jz      @f
170
        jz      @f
172
        xor     ebx, ebx
171
        xor     ebx, ebx
173
        movi    eax, ERROR_END_OF_FILE
172
        movi    eax, ERROR_END_OF_FILE
174
        ret
173
        ret
175
 
174
 
176
.notFound:
175
.notFound:
177
        cmp     [DevErrorCode], 0
176
        cmp     [DevErrorCode], 0
178
        jne     .noaccess
177
        jne     .noaccess
179
        xor     ebx, ebx
178
        xor     ebx, ebx
180
        movi    eax, ERROR_FILE_NOT_FOUND
179
        movi    eax, ERROR_FILE_NOT_FOUND
181
        ret
180
        ret
182
 
181
 
183
.noaccess_3:
182
.noaccess_3:
184
        pop     eax edx ecx
183
        pop     eax edx ecx
185
.noaccess:
184
.noaccess:
186
        xor     ebx, ebx
185
        xor     ebx, ebx
187
        movi    eax, ERROR_ACCESS_DENIED
186
        movi    eax, ERROR_ACCESS_DENIED
188
        ret
187
        ret
189
 
188
 
190
@@:
189
@@:
191
        mov     ebx, [ebx]
190
        mov     ebx, [ebx]
192
.l1:
191
.l1:
193
        push    ecx edx 0
192
        push    ecx edx 0
194
        mov     eax, [edi+10]   ; real size of the file section
193
        mov     eax, [edi+10]   ; real size of the file section
195
        sub     eax, ebx
194
        sub     eax, ebx
196
        jb      .eof
195
        jb      .eof
197
        cmp     eax, ecx
196
        cmp     eax, ecx
198
        jae     @f
197
        jae     @f
199
        mov     ecx, eax
198
        mov     ecx, eax
200
        pop     eax
199
        pop     eax
201
        push    ERROR_END_OF_FILE
200
        push    ERROR_END_OF_FILE
202
@@:
201
@@:
203
        mov     eax, [edi+2]
202
        mov     eax, [edi+2]
204
        mov     [CDSectorAddress], eax
203
        mov     [CDSectorAddress], eax
205
; now eax=cluster, ebx=position, ecx=count, edx=buffer for data
204
; now eax=cluster, ebx=position, ecx=count, edx=buffer for data
206
.new_sector:
205
.new_sector:
207
        test    ecx, ecx
206
        test    ecx, ecx
208
        jz      .done
207
        jz      .done
209
        sub     ebx, 2048
208
        sub     ebx, 2048
210
        jae     .next
209
        jae     .next
211
        add     ebx, 2048
210
        add     ebx, 2048
212
        jnz     .incomplete_sector
211
        jnz     .incomplete_sector
213
        cmp     ecx, 2048
212
        cmp     ecx, 2048
214
        jb      .incomplete_sector
213
        jb      .incomplete_sector
215
; we may read and memmove complete sector
214
; we may read and memmove complete sector
216
        mov     [CDDataBuf_pointer], edx
215
        mov     [CDDataBuf_pointer], edx
217
        call    ReadCDWRetr
216
        call    ReadCDWRetr
218
        cmp     [DevErrorCode], 0
217
        cmp     [DevErrorCode], 0
219
        jne     .noaccess_3
218
        jne     .noaccess_3
220
        add     edx, 2048
219
        add     edx, 2048
221
        sub     ecx, 2048
220
        sub     ecx, 2048
222
.next:
221
.next:
223
        inc     dword [CDSectorAddress]
222
        inc     dword [CDSectorAddress]
224
        jmp     .new_sector
223
        jmp     .new_sector
225
 
224
 
226
.eof:
225
.eof:
227
        pop     eax
226
        pop     eax
228
        push    ERROR_END_OF_FILE
227
        push    ERROR_END_OF_FILE
229
.done:
228
.done:
230
        mov     ebx, edx
229
        mov     ebx, edx
231
        pop     eax edx ecx
230
        pop     eax edx ecx
232
        sub     ebx, edx
231
        sub     ebx, edx
233
        ret
232
        ret
234
 
233
 
235
.incomplete_sector: ; we must read and memmove incomplete sector
234
.incomplete_sector: ; we must read and memmove incomplete sector
236
        mov     [CDDataBuf_pointer], CDDataBuf
235
        mov     [CDDataBuf_pointer], CDDataBuf
237
        call    ReadCDWRetr
236
        call    ReadCDWRetr
238
        cmp     [DevErrorCode], 0
237
        cmp     [DevErrorCode], 0
239
        jne     .noaccess_3
238
        jne     .noaccess_3
240
        push    ecx
239
        push    ecx
241
        add     ecx, ebx
240
        add     ecx, ebx
242
        cmp     ecx, 2048
241
        cmp     ecx, 2048
243
        jbe     @f
242
        jbe     @f
244
        mov     ecx, 2048
243
        mov     ecx, 2048
245
@@:
244
@@:
246
        sub     ecx, ebx
245
        sub     ecx, ebx
247
        push    edi esi ecx
246
        push    edi esi ecx
248
        mov     edi, edx
247
        mov     edi, edx
249
        lea     esi, [CDDataBuf + ebx]
248
        lea     esi, [CDDataBuf + ebx]
250
        cld
249
        cld
251
        rep movsb
250
        rep movsb
252
        pop     ecx esi edi
251
        pop     ecx esi edi
253
        add     edx, ecx
252
        add     edx, ecx
254
        sub     [esp], ecx
253
        sub     [esp], ecx
255
        pop     ecx
254
        pop     ecx
256
        xor     ebx, ebx
255
        xor     ebx, ebx
257
        jmp     .next
256
        jmp     .next
258
 
257
 
259
;-----------------------------------------------------------------------------
258
;-----------------------------------------------------------------------------
260
fs_CdReadFolder:
259
fs_CdReadFolder:
261
        push    edi
260
        push    edi
262
        call    cd_find_lfn
261
        call    cd_find_lfn
263
        jnc     .found
262
        jnc     .found
264
        pop     edi
263
        pop     edi
265
        cmp     [DevErrorCode], 0
264
        cmp     [DevErrorCode], 0
266
        jne     .noaccess_1
265
        jne     .noaccess_1
267
        xor     ebx, ebx
266
        xor     ebx, ebx
268
        mov     eax, ERROR_FILE_NOT_FOUND
267
        mov     eax, ERROR_FILE_NOT_FOUND
269
        ret
268
        ret
270
 
269
 
271
.found:
270
.found:
272
        mov     edi, [cd_current_pointer_of_input]
271
        mov     edi, [cd_current_pointer_of_input]
273
        test    byte [edi+25], 10b    ; do not allow read directories
272
        test    byte [edi+25], 10b    ; do not allow read directories
274
        jnz     .found_dir
273
        jnz     .found_dir
275
        pop     edi
274
        pop     edi
276
.noaccess_1:
275
.noaccess_1:
277
        xor     ebx, ebx
276
        xor     ebx, ebx
278
        mov     eax, ERROR_ACCESS_DENIED
277
        mov     eax, ERROR_ACCESS_DENIED
279
        ret
278
        ret
280
 
279
 
281
.end_buffer:
280
.end_buffer:
282
        pop     edx eax
281
        pop     edx eax
283
        sub     eax, 2048   ; directory is over?
282
        sub     eax, 2048   ; directory is over?
284
        ja      .read_to_buffer
283
        ja      .read_to_buffer
285
        mov     eax, [cd_counter_block]
284
        mov     eax, [cd_counter_block]
286
        mov     [edx+8], eax
285
        mov     [edx+8], eax
287
        mov     eax, [ebx]
286
        mov     eax, [ebx]
288
        sub     [edx+4], eax
287
        sub     [edx+4], eax
289
        xor     eax, eax
288
        xor     eax, eax
290
        dec     ecx
289
        dec     ecx
291
        js      @f
290
        js      @f
292
        mov     al, ERROR_END_OF_FILE
291
        mov     al, ERROR_END_OF_FILE
293
@@:
292
@@:
294
        pop     ecx edi
293
        pop     ecx edi
295
        mov     ebx, [edx+4]
294
        mov     ebx, [edx+4]
296
        ret
295
        ret
297
 
296
 
298
.found_dir:
297
.found_dir:
299
        mov     eax, [edi+2]    ; eax=cluster
298
        mov     eax, [edi+2]    ; eax=cluster
300
        mov     [CDSectorAddress], eax
299
        mov     [CDSectorAddress], eax
301
        mov     eax, [edi+10]   ; directory size
300
        mov     eax, [edi+10]   ; directory size
302
        push    eax ecx
301
        push    eax ecx
303
        mov     edi, edx
302
        mov     edi, edx
304
        mov     ecx, 32/4
303
        mov     ecx, 32/4
305
        xor     eax, eax
304
        xor     eax, eax
306
        rep stosd
305
        rep stosd
307
        pop     ecx eax
306
        pop     ecx eax
308
        mov     byte [edx], 1   ; version
307
        mov     byte [edx], 1   ; version
309
        mov     [cd_mem_location], edx
308
        mov     [cd_mem_location], edx
310
        add     [cd_mem_location], 32
309
        add     [cd_mem_location], 32
311
        mov     [cd_counter_block], dword 0
310
        mov     [cd_counter_block], dword 0
312
        dec     dword [CDSectorAddress]
311
        dec     dword [CDSectorAddress]
313
        push    ecx
312
        push    ecx
314
.read_to_buffer:
313
.read_to_buffer:
315
        inc     dword [CDSectorAddress]
314
        inc     dword [CDSectorAddress]
316
        mov     [CDDataBuf_pointer], CDDataBuf
315
        mov     [CDDataBuf_pointer], CDDataBuf
317
        call    ReadCDWRetr     ; read sector of directory
316
        call    ReadCDWRetr     ; read sector of directory
318
        cmp     [DevErrorCode], 0
317
        cmp     [DevErrorCode], 0
319
        jne     .noaccess_1
318
        jne     .noaccess_1
320
        mov     [cd_current_pointer_of_input_2], CDDataBuf
319
        mov     [cd_current_pointer_of_input_2], CDDataBuf
321
        push    eax edx
320
        push    eax edx
322
.get_names_from_buffer:
321
.get_names_from_buffer:
323
        call    cd_get_name
322
        call    cd_get_name
324
        jc      .end_buffer
323
        jc      .end_buffer
325
        inc     dword [cd_counter_block]
324
        inc     dword [cd_counter_block]
326
        mov     eax, [cd_counter_block]
325
        mov     eax, [cd_counter_block]
327
        cmp     [ebx], eax
326
        cmp     [ebx], eax
328
        jae     .get_names_from_buffer
327
        jae     .get_names_from_buffer
329
        test    ecx, ecx
328
        test    ecx, ecx
330
        jz      .get_names_from_buffer
329
        jz      .get_names_from_buffer
331
        mov     edi, [cd_counter_block]
330
        mov     edi, [cd_counter_block]
332
        mov     [edx+4], edi
331
        mov     [edx+4], edi
333
        dec     ecx
332
        dec     ecx
334
        mov     esi, ebp
333
        mov     esi, ebp
335
        call    cd_get_parameters_of_file
334
        call    cd_get_parameters_of_file
336
        add     edi, 40
335
        add     edi, 40
337
        mov     ax, '.'
336
        mov     ax, '.'
338
        cmp     dword[ebx+4], 2
337
        cmp     dword[ebx+4], 2
339
        jz      .utf16
338
        jz      .utf16
340
        cmp     dword[ebx+4], 3
339
        cmp     dword[ebx+4], 3
341
        jz      .utf8
340
        jz      .utf8
342
        cmp     [cd_counter_block], 2
341
        cmp     [cd_counter_block], 2
343
        jbe     .parentDirectory
342
        jbe     .parentDirectory
344
@@:
343
@@:
345
        lodsw
344
        lodsw
346
        xchg    ah, al
345
        xchg    ah, al
347
        call    uni2ansi_char
346
        call    uni2ansi_char
348
        stosb
347
        stosb
349
        call    .checkForEnd
348
        call    .checkForEnd
350
        jc      @b
349
        jc      @b
351
@@:
350
@@:
352
        mov     [edi], byte 0
351
        mov     [edi], byte 0
353
        add     [cd_mem_location], 304
352
        add     [cd_mem_location], 304
354
        jmp     .get_names_from_buffer
353
        jmp     .get_names_from_buffer
355
 
354
 
356
.parentDirectory:
355
.parentDirectory:
357
        stosb
356
        stosb
358
        cmp     [cd_counter_block], 2
357
        cmp     [cd_counter_block], 2
359
        jnz     @b
358
        jnz     @b
360
        stosb
359
        stosb
361
        jmp     @b
360
        jmp     @b
362
 
361
 
363
.utf8:
362
.utf8:
364
        add     [cd_mem_location], 256
363
        add     [cd_mem_location], 256
365
        cmp     [cd_counter_block], 2
364
        cmp     [cd_counter_block], 2
366
        jbe     .parentDirectory
365
        jbe     .parentDirectory
367
        push    ecx
366
        push    ecx
368
        mov     ecx, 519
367
        mov     ecx, 519
369
@@:
368
@@:
370
        lodsw
369
        lodsw
371
        xchg    ah, al
370
        xchg    ah, al
372
        call    UTF16to8
371
        call    UTF16to8
373
        js      @f
372
        js      @f
374
        call    .checkForEnd
373
        call    .checkForEnd
375
        jc      @b
374
        jc      @b
376
@@:
375
@@:
377
        pop     ecx
376
        pop     ecx
378
        mov     [edi], byte 0
377
        mov     [edi], byte 0
379
        add     [cd_mem_location], 304
378
        add     [cd_mem_location], 304
380
        jmp     .get_names_from_buffer
379
        jmp     .get_names_from_buffer
381
 
380
 
382
.checkForEnd:
381
.checkForEnd:
383
        mov     ax, [esi]
382
        mov     ax, [esi]
384
        cmp     ax, 3B00h   ; ';'
383
        cmp     ax, 3B00h   ; ';'
385
        jz      @f
384
        jz      @f
386
; check for files not ending with separator
385
; check for files not ending with separator
387
        movzx   eax, byte [ebp-33]
386
        movzx   eax, byte [ebp-33]
388
        add     eax, ebp
387
        add     eax, ebp
389
        sub     eax, 34
388
        sub     eax, 34
390
        cmp     esi, eax
389
        cmp     esi, eax
391
        jz      @f
390
        jz      @f
392
; check the end of the directory
391
; check the end of the directory
393
        movzx   eax, byte [ebp-1]
392
        movzx   eax, byte [ebp-1]
394
        add     eax, ebp
393
        add     eax, ebp
395
        cmp     esi, eax
394
        cmp     esi, eax
396
@@:
395
@@:
397
        ret
396
        ret
398
 
397
 
399
.utf16:
398
.utf16:
400
        cmp     [cd_counter_block], 2
399
        cmp     [cd_counter_block], 2
401
        jbe     .utf16ParentDirectory
400
        jbe     .utf16ParentDirectory
402
@@:
401
@@:
403
        lodsw
402
        lodsw
404
        xchg    ah, al
403
        xchg    ah, al
405
        stosw
404
        stosw
406
        call    .checkForEnd
405
        call    .checkForEnd
407
        jc      @b
406
        jc      @b
408
@@:
407
@@:
409
        mov     [edi], word 0
408
        mov     [edi], word 0
410
        add     [cd_mem_location], 560
409
        add     [cd_mem_location], 560
411
        jmp     .get_names_from_buffer
410
        jmp     .get_names_from_buffer
412
 
411
 
413
.utf16ParentDirectory:
412
.utf16ParentDirectory:
414
        stosw
413
        stosw
415
        cmp     [cd_counter_block], 2
414
        cmp     [cd_counter_block], 2
416
        jnz     @b
415
        jnz     @b
417
        stosw
416
        stosw
418
        jmp     @b
417
        jmp     @b
419
 
418
 
420
cd_get_parameters_of_file:
419
cd_get_parameters_of_file:
421
        mov     edi, [cd_mem_location]
420
        mov     edi, [cd_mem_location]
422
cd_get_parameters_of_file_1:
421
cd_get_parameters_of_file_1:
423
; get file attributes
422
; get file attributes
424
        xor     eax, eax
423
        xor     eax, eax
425
; file is not archived
424
; file is not archived
426
        inc     eax
425
        inc     eax
427
        shl     eax, 1
426
        shl     eax, 1
428
; is a directory?
427
; is a directory?
429
        test    [ebp-8], byte 2
428
        test    [ebp-8], byte 2
430
        jz      .file
429
        jz      .file
431
        inc     eax
430
        inc     eax
432
.file:
431
.file:
433
; not as a volume label in the FAT, in this form not available
432
; not as a volume label in the FAT, in this form not available
434
; file is not a system
433
; file is not a system
435
        shl     eax, 3
434
        shl     eax, 3
436
; file is hidden? (attribute of existence)
435
; file is hidden? (attribute of existence)
437
        test    [ebp-8], byte 1
436
        test    [ebp-8], byte 1
438
        jz      .hidden
437
        jz      .hidden
439
        inc     eax
438
        inc     eax
440
.hidden:
439
.hidden:
441
        shl     eax, 1
440
        shl     eax, 1
442
; file is always read-only, as this CD
441
; file is always read-only, as this CD
443
        inc     eax
442
        inc     eax
444
        mov     [edi], eax
443
        mov     [edi], eax
445
        mov     eax, [ebx+4]
444
        mov     eax, [ebx+4]
446
        mov     [edi+4], eax
445
        mov     [edi+4], eax
447
; get the time to file
446
; get the time to file
448
; hour
447
; hour
449
        movzx   eax, byte [ebp-12]
448
        movzx   eax, byte [ebp-12]
450
        shl     eax, 8
449
        shl     eax, 8
451
; minute
450
; minute
452
        mov     al, [ebp-11]
451
        mov     al, [ebp-11]
453
        shl     eax, 8
452
        shl     eax, 8
454
; second
453
; second
455
        mov     al, [ebp-10]
454
        mov     al, [ebp-10]
456
; file creation time
455
; file creation time
457
        mov     [edi+8], eax
456
        mov     [edi+8], eax
458
; last access time
457
; last access time
459
        mov     [edi+16], eax
458
        mov     [edi+16], eax
460
; last write time
459
; last write time
461
        mov     [edi+24], eax
460
        mov     [edi+24], eax
462
; get date for file
461
; get date for file
463
; year
462
; year
464
        movzx   eax, byte [ebp-15]
463
        movzx   eax, byte [ebp-15]
465
        add     eax, 1900
464
        add     eax, 1900
466
        shl     eax, 8
465
        shl     eax, 8
467
; month
466
; month
468
        mov     al, [ebp-14]
467
        mov     al, [ebp-14]
469
        shl     eax, 8
468
        shl     eax, 8
470
; day
469
; day
471
        mov     al, [ebp-13]
470
        mov     al, [ebp-13]
472
; file creation date
471
; file creation date
473
        mov     [edi+12], eax
472
        mov     [edi+12], eax
474
; last access date
473
; last access date
475
        mov     [edi+20], eax
474
        mov     [edi+20], eax
476
; last write date
475
; last write date
477
        mov     [edi+28], eax
476
        mov     [edi+28], eax
478
; get the file size in bytes
477
; get the file size in bytes
479
        xor     eax, eax
478
        xor     eax, eax
480
        mov     [edi+32+4], eax
479
        mov     [edi+32+4], eax
481
        mov     eax, [ebp-23]
480
        mov     eax, [ebp-23]
482
        mov     [edi+32], eax
481
        mov     [edi+32], eax
483
        ret
482
        ret
484
 
483
 
485
;-----------------------------------------------------------------------------
484
;-----------------------------------------------------------------------------
486
fs_CdGetFileInfo:
485
fs_CdGetFileInfo:
487
        call    cd_find_lfn
486
        call    cd_find_lfn
488
        movi    eax, ERROR_FILE_NOT_FOUND
487
        movi    eax, ERROR_FILE_NOT_FOUND
489
        jc      @f
488
        jc      @f
490
        mov     edi, edx
489
        mov     edi, edx
491
        mov     eax, [ebx+4]
490
        mov     eax, [ebx+4]
492
        mov     [edx+4], eax
491
        mov     [edx+4], eax
493
        cmp     byte [esi], 0
492
        cmp     byte [esi], 0
494
        jz      .volume
493
        jz      .volume
495
        mov     ebp, [cd_current_pointer_of_input]
494
        mov     ebp, [cd_current_pointer_of_input]
496
        add     ebp, 33
495
        add     ebp, 33
497
        call    cd_get_parameters_of_file_1
496
        call    cd_get_parameters_of_file_1
498
        xor     eax, eax
497
        xor     eax, eax
499
@@:
498
@@:
500
        ret
499
        ret
501
 
500
 
502
.volume:
501
.volume:
503
        test    eax, eax
502
        test    eax, eax
504
        jz      .size
503
        jz      .size
505
        mov     ecx, 16
504
        mov     ecx, 16
506
        mov     esi, CDDataBuf+40
505
        mov     esi, CDDataBuf+40
507
        add     edi, 40
506
        add     edi, 40
508
        cmp     eax, 2
507
        cmp     eax, 2
509
        jz      .utf16
508
        jz      .utf16
510
        cmp     eax, 3
509
        cmp     eax, 3
511
        jz      .utf8
510
        jz      .utf8
512
@@:
511
@@:
513
        lodsw
512
        lodsw
514
        xchg    al, ah
513
        xchg    al, ah
515
        call    uni2ansi_char
514
        call    uni2ansi_char
516
        stosb
515
        stosb
517
        loop    @b
516
        loop    @b
518
        jmp     .size
517
        jmp     .size
519
 
518
 
520
.utf16:
519
.utf16:
521
        lodsw
520
        lodsw
522
        xchg    al, ah
521
        xchg    al, ah
523
        stosw
522
        stosw
524
        loop    .utf16
523
        loop    .utf16
525
        jmp     .size
524
        jmp     .size
526
 
525
 
527
.utf8:
526
.utf8:
528
        mov     ebx, ecx
527
        mov     ebx, ecx
529
        shl     ecx, 1
528
        shl     ecx, 1
530
@@:
529
@@:
531
        lodsw
530
        lodsw
532
        xchg    ah, al
531
        xchg    ah, al
533
        call    UTF16to8
532
        call    UTF16to8
534
        dec     ebx
533
        dec     ebx
535
        jnz     @b
534
        jnz     @b
536
.size:
535
.size:
537
        mov     eax, [CDDataBuf+80]
536
        mov     eax, [CDDataBuf+80]
538
        shl     eax, 11
537
        shl     eax, 11
539
        mov     [edx+32], eax
538
        mov     [edx+32], eax
540
        xor     eax, eax
539
        xor     eax, eax
541
        mov     [edx+36], eax
540
        mov     [edx+36], eax
542
        stosw
541
        stosw
543
        mov     byte [edx], 8
542
        mov     byte [edx], 8
544
        ret
543
        ret
545
 
544
 
546
;-----------------------------------------------------------------------------
545
;-----------------------------------------------------------------------------
547
cd_find_lfn:
546
cd_find_lfn:
548
        mov     [cd_appl_data], 0
547
        mov     [cd_appl_data], 0
549
; in: esi -> path string in UTF-8
548
; in: esi -> path string in UTF-8
550
; out: [cd_current_pointer_of_input] -> direntry, CF=1 -> file not found
549
; out: [cd_current_pointer_of_input] -> direntry, CF=1 -> file not found
551
        push    eax esi
550
        push    eax esi
552
; Sector 16 - start set of volume descriptors
551
; Sector 16 - start set of volume descriptors
553
        call    WaitUnitReady
552
        call    WaitUnitReady
554
        cmp     [DevErrorCode], 0
553
        cmp     [DevErrorCode], 0
555
        jne     .access_denied
554
        jne     .access_denied
556
 
555
 
557
        call    prevent_medium_removal
556
        call    prevent_medium_removal
558
; testing of reading
557
; testing of reading
559
        mov     [CDSectorAddress], dword 16
558
        mov     [CDSectorAddress], dword 16
560
        mov     [CDDataBuf_pointer], CDDataBuf
559
        mov     [CDDataBuf_pointer], CDDataBuf
561
        call    ReadCDWRetr;_1
560
        call    ReadCDWRetr;_1
562
        cmp     [DevErrorCode], 0
561
        cmp     [DevErrorCode], 0
563
        jne     .access_denied
562
        jne     .access_denied
564
 
563
 
565
; calculation of the last session
564
; calculation of the last session
566
        call    WaitUnitReady
565
        call    WaitUnitReady
567
        cmp     [DevErrorCode], 0
566
        cmp     [DevErrorCode], 0
568
        jne     .access_denied
567
        jne     .access_denied
569
 
568
 
570
        call    Read_TOC
569
        call    Read_TOC
571
        mov     ah, [CDDataBuf+4+4]
570
        mov     ah, [CDDataBuf+4+4]
572
        mov     al, [CDDataBuf+4+5]
571
        mov     al, [CDDataBuf+4+5]
573
        shl     eax, 16
572
        shl     eax, 16
574
        mov     ah, [CDDataBuf+4+6]
573
        mov     ah, [CDDataBuf+4+6]
575
        mov     al, [CDDataBuf+4+7]
574
        mov     al, [CDDataBuf+4+7]
576
        add     eax, 15
575
        add     eax, 15
577
        mov     [CDSectorAddress], eax
576
        mov     [CDSectorAddress], eax
578
;  mov  [CDSectorAddress],dword 15
577
;  mov  [CDSectorAddress],dword 15
579
        mov     [CDDataBuf_pointer], CDDataBuf
578
        mov     [CDDataBuf_pointer], CDDataBuf
580
;--------------------------------------
579
;--------------------------------------
581
.start:
580
.start:
582
        inc     dword [CDSectorAddress]
581
        inc     dword [CDSectorAddress]
583
        call    ReadCDWRetr;_1
582
        call    ReadCDWRetr;_1
584
        cmp     [DevErrorCode], 0
583
        cmp     [DevErrorCode], 0
585
        jne     .access_denied
584
        jne     .access_denied
586
 
585
 
587
.start_check:
586
.start_check:
588
; checking for "lice"
587
; checking for "lice"
589
        cmp     [CDDataBuf+1], dword 'CD00'
588
        cmp     [CDDataBuf+1], dword 'CD00'
590
        jne     .access_denied
589
        jne     .access_denied
591
 
590
 
592
        cmp     [CDDataBuf+5], byte '1'
591
        cmp     [CDDataBuf+5], byte '1'
593
        jne     .access_denied
592
        jne     .access_denied
594
; sector is the terminator of set of descriptors volumes?
593
; sector is the terminator of set of descriptors volumes?
595
        cmp     [CDDataBuf], byte 0xff
594
        cmp     [CDDataBuf], byte 0xff
596
        je      .access_denied
595
        je      .access_denied
597
; sector is an additional and improved descriptor of volume?
596
; sector is an additional and improved descriptor of volume?
598
        cmp     [CDDataBuf], byte 0x2
597
        cmp     [CDDataBuf], byte 0x2
599
        jne     .start
598
        jne     .start
600
; sector is an additional descriptor of volume?
599
; sector is an additional descriptor of volume?
601
        cmp     [CDDataBuf+6], byte 0x1
600
        cmp     [CDDataBuf+6], byte 0x1
602
        jne     .start
601
        jne     .start
603
 
602
 
604
; parameters of root directory
603
; parameters of root directory
605
        mov     eax, [CDDataBuf+0x9c+2]; start of root directory
604
        mov     eax, [CDDataBuf+0x9c+2]; start of root directory
606
        mov     [CDSectorAddress], eax
605
        mov     [CDSectorAddress], eax
607
        mov     eax, [CDDataBuf+0x9c+10]; size of root directory
606
        mov     eax, [CDDataBuf+0x9c+10]; size of root directory
608
        cmp     byte [esi], 0
607
        cmp     byte [esi], 0
609
        jnz     @f
608
        jnz     @f
610
 
609
 
611
        mov     [cd_current_pointer_of_input], CDDataBuf+0x9c
610
        mov     [cd_current_pointer_of_input], CDDataBuf+0x9c
612
        jmp     .done
611
        jmp     .done
613
;--------------------------------------
612
;--------------------------------------
614
@@:
613
@@:
615
; start the search
614
; start the search
616
.mainloop:
615
.mainloop:
617
        dec     dword [CDSectorAddress]
616
        dec     dword [CDSectorAddress]
618
;--------------------------------------
617
;--------------------------------------
619
.read_to_buffer:
618
.read_to_buffer:
620
        inc     dword [CDSectorAddress]
619
        inc     dword [CDSectorAddress]
621
        mov     [CDDataBuf_pointer], CDDataBuf
620
        mov     [CDDataBuf_pointer], CDDataBuf
622
        call    ReadCDWRetr      ; read sector of directory
621
        call    ReadCDWRetr      ; read sector of directory
623
        cmp     [DevErrorCode], 0
622
        cmp     [DevErrorCode], 0
624
        jne     .access_denied
623
        jne     .access_denied
625
        call    cd_find_name_in_buffer
624
        call    cd_find_name_in_buffer
626
        jnc     .found
625
        jnc     .found
627
        sub     eax, 2048
626
        sub     eax, 2048
628
; directory is over?
627
; directory is over?
629
        cmp     eax, 0
628
        cmp     eax, 0
630
        ja      .read_to_buffer
629
        ja      .read_to_buffer
631
; desired element of chain is not found
630
; desired element of chain is not found
632
.access_denied:
631
.access_denied:
633
        pop     esi eax
632
        pop     esi eax
634
        mov     [cd_appl_data], 1
633
        mov     [cd_appl_data], 1
635
        stc
634
        stc
636
        ret
635
        ret
637
;--------------------------------------
636
;--------------------------------------
638
; desired element of chain found
637
; desired element of chain found
639
.found:
638
.found:
640
; the end of the file path
639
; the end of the file path
641
        cmp     byte [esi-1], 0
640
        cmp     byte [esi-1], 0
642
        jz      .done
641
        jz      .done
643
        mov     eax, [cd_current_pointer_of_input]
642
        mov     eax, [cd_current_pointer_of_input]
644
        push    dword [eax+2]
643
        push    dword [eax+2]
645
        pop     dword [CDSectorAddress] ; beginning of the directory
644
        pop     dword [CDSectorAddress] ; beginning of the directory
646
        mov     eax, [eax+2+8] ; size of directory
645
        mov     eax, [eax+2+8] ; size of directory
647
        jmp     .mainloop
646
        jmp     .mainloop
648
;--------------------------------------
647
;--------------------------------------
649
; file pointer found
648
; file pointer found
650
.done:
649
.done:
651
        pop     esi eax
650
        pop     esi eax
652
        mov     [cd_appl_data], 1
651
        mov     [cd_appl_data], 1
653
        clc
652
        clc
654
        ret
653
        ret
655
;-----------------------------------------------------------------------------
654
;-----------------------------------------------------------------------------
656
cd_find_name_in_buffer:
655
cd_find_name_in_buffer:
657
        mov     [cd_current_pointer_of_input_2], CDDataBuf
656
        mov     [cd_current_pointer_of_input_2], CDDataBuf
658
;--------------------------------------
657
;--------------------------------------
659
.start:
658
.start:
660
        call    cd_get_name
659
        call    cd_get_name
661
        jc      .not_found
660
        jc      .not_found
662
 
661
 
663
        call    cd_compare_name
662
        call    cd_compare_name
664
        jc      .start
663
        jc      .start
665
;--------------------------------------
664
;--------------------------------------
666
.found:
665
.found:
667
        clc
666
        clc
668
        ret
667
        ret
669
;--------------------------------------
668
;--------------------------------------
670
.not_found:
669
.not_found:
671
        stc
670
        stc
672
        ret
671
        ret
673
;-----------------------------------------------------------------------------
672
;-----------------------------------------------------------------------------
674
cd_get_name:
673
cd_get_name:
675
        push    eax
674
        push    eax
676
        mov     ebp, [cd_current_pointer_of_input_2]
675
        mov     ebp, [cd_current_pointer_of_input_2]
677
        mov     [cd_current_pointer_of_input], ebp
676
        mov     [cd_current_pointer_of_input], ebp
678
        mov     eax, [ebp]
677
        mov     eax, [ebp]
679
        test    eax, eax ; entry's is over?
678
        test    eax, eax ; entry's is over?
680
        jz      .next_sector
679
        jz      .next_sector
681
 
680
 
682
        cmp     ebp, CDDataBuf+2048  ; buffer is over?
681
        cmp     ebp, CDDataBuf+2048  ; buffer is over?
683
        jae     .next_sector
682
        jae     .next_sector
684
 
683
 
685
        movzx   eax, byte [ebp]
684
        movzx   eax, byte [ebp]
686
        add     [cd_current_pointer_of_input_2], eax ; next entry of directory
685
        add     [cd_current_pointer_of_input_2], eax ; next entry of directory
687
        add     ebp, 33; pointer is set to the beginning of the name
686
        add     ebp, 33; pointer is set to the beginning of the name
688
        pop     eax
687
        pop     eax
689
        clc
688
        clc
690
        ret
689
        ret
691
;--------------------------------------
690
;--------------------------------------
692
.next_sector:
691
.next_sector:
693
        pop     eax
692
        pop     eax
694
        stc
693
        stc
695
        ret
694
        ret
696
;-----------------------------------------------------------------------------
695
;-----------------------------------------------------------------------------
697
cd_compare_name:
696
cd_compare_name:
698
; in: esi -> UTF-8 name, ebp -> UTF-16BE name
697
; in: esi -> UTF-8 name, ebp -> UTF-16BE name
699
; out: CF=0 -> names match, esi -> next component of name
698
; out: CF=0 -> names match, esi -> next component of name
700
;      CF=1 -> esi is not changed
699
;      CF=1 -> esi is not changed
701
        push    edx edi eax esi
700
        push    edx edi eax esi
702
        mov     edi, ebp
701
        mov     edi, ebp
703
.loop:
702
.loop:
704
        call    utf8to16
703
        call    utf8to16
705
        call    utf16toUpper
704
        call    utf16toUpper
706
        mov     edx, eax
705
        mov     edx, eax
707
        mov     ax, [edi]
706
        mov     ax, [edi]
708
        xchg    al, ah
707
        xchg    al, ah
709
        call    utf16toUpper
708
        call    utf16toUpper
710
        cmp     ax, dx
709
        cmp     ax, dx
711
        jne     .name_not_coincide
710
        jne     .name_not_coincide
712
        add     edi, 2
711
        add     edi, 2
713
        cmp     [esi], byte '/' ; path separator is end of current element
712
        cmp     [esi], byte '/' ; path separator is end of current element
714
        je      .done
713
        je      .done
715
        cmp     [esi], byte 0 ; path separator end of name
714
        cmp     [esi], byte 0 ; path separator end of name
716
        jne     .loop
715
        jne     .loop
717
.done:
716
.done:
718
; check end of file
717
; check end of file
719
        cmp     [edi], word 3B00h; separator end of file ';'
718
        cmp     [edi], word 3B00h; separator end of file ';'
720
        je      .done_1
719
        je      .done_1
721
; check for files not ending with separator
720
; check for files not ending with separator
722
        movzx   eax, byte [ebp-33]
721
        movzx   eax, byte [ebp-33]
723
        add     eax, ebp
722
        add     eax, ebp
724
        sub     eax, 34
723
        sub     eax, 34
725
        cmp     edi, eax
724
        cmp     edi, eax
726
        je      .done_1
725
        je      .done_1
727
; check the end of directory
726
; check the end of directory
728
        movzx   eax, byte [ebp-1]
727
        movzx   eax, byte [ebp-1]
729
        add     eax, ebp
728
        add     eax, ebp
730
        cmp     edi, eax
729
        cmp     edi, eax
731
        jne     .name_not_coincide
730
        jne     .name_not_coincide
732
.done_1:
731
.done_1:
733
        pop     eax eax edi edx
732
        pop     eax eax edi edx
734
        inc     esi
733
        inc     esi
735
        ret
734
        ret
736
 
735
 
737
.name_not_coincide:
736
.name_not_coincide:
738
        pop     esi eax edi edx
737
        pop     esi eax edi edx
739
        stc
738
        stc
740
        ret
739
        ret