Subversion Repositories Kolibri OS

Rev

Rev 6876 | Rev 9692 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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