Subversion Repositories Kolibri OS

Rev

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

Rev 6471 Rev 6502
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: 6471 $
8
$Revision: 6502 $
9
 
9
 
10
ERROR_SUCCESS        = 0
10
ERROR_SUCCESS        = 0
11
ERROR_DISK_BASE      = 1
11
ERROR_DISK_BASE      = 1
12
ERROR_UNSUPPORTED_FS = 2
12
ERROR_UNSUPPORTED_FS = 2
13
ERROR_UNKNOWN_FS     = 3
13
ERROR_UNKNOWN_FS     = 3
14
ERROR_PARTITION      = 4
14
ERROR_PARTITION      = 4
15
ERROR_FILE_NOT_FOUND = 5
15
ERROR_FILE_NOT_FOUND = 5
16
ERROR_END_OF_FILE    = 6
16
ERROR_END_OF_FILE    = 6
17
ERROR_MEMORY_POINTER = 7
17
ERROR_MEMORY_POINTER = 7
18
ERROR_DISK_FULL      = 8
18
ERROR_DISK_FULL      = 8
19
ERROR_FS_FAIL        = 9
19
ERROR_FS_FAIL        = 9
20
ERROR_ACCESS_DENIED  = 10
20
ERROR_ACCESS_DENIED  = 10
21
ERROR_DEVICE         = 11
21
ERROR_DEVICE         = 11
22
ERROR_OUT_OF_MEMORY  = 12
22
ERROR_OUT_OF_MEMORY  = 12
23
 
23
 
24
maxPathLength = 1000h
24
maxPathLength = 1000h
25
 
25
 
26
image_of_eax EQU esp+32
26
image_of_eax EQU esp+32
27
image_of_ebx EQU esp+20
27
image_of_ebx EQU esp+20
28
 
28
 
29
; System function 70
29
; System function 70
30
 
30
 
31
file_system_lfn_protected:
31
file_system_lfn_protected:
32
        pushad
32
        pushad
33
        call    protect_from_terminate
33
        call    protect_from_terminate
34
        call    file_system_lfn
34
        call    file_system_lfn
35
        call    unprotect_from_terminate
35
        call    unprotect_from_terminate
36
        popad
36
        popad
37
        mov     [image_of_eax], eax
37
        mov     [image_of_eax], eax
38
        mov     [image_of_ebx], ebx
38
        mov     [image_of_ebx], ebx
39
        ret
39
        ret
40
 
40
 
41
file_system_lfn:
41
file_system_lfn:
42
; in: ebx -> parameter structure
42
; in: ebx -> parameter structure
43
;   operation codes:
43
;   operation codes:
44
; 0 = read file
44
; 0 = read file
45
; 1 = read folder
45
; 1 = read folder
46
; 2 = create/rewrite file
46
; 2 = create/rewrite file
47
; 3 = write/append to file
47
; 3 = write/append to file
48
; 4 = set file end
48
; 4 = set file end
49
; 5 = get file info
49
; 5 = get file info
50
; 6 = set file info
50
; 6 = set file info
51
; start application
51
; start application
52
; 8 = delete file/folder
52
; 8 = delete file/folder
53
; 9 = create folder
53
; 9 = create folder
54
        lea     ebp, [ebx+20]
54
        lea     ebp, [ebx+20]
55
        cmp     byte [ebp], 0
55
        cmp     byte [ebp], 0
56
        jnz     @f
56
        jnz     @f
57
        mov     ebp, [ebx+21]
57
        mov     ebp, [ebx+21]
58
@@:
58
@@:
-
 
59
        cmp     word [ebp], '/'
-
 
60
        jz      .rootdir
-
 
61
        cmp     byte [ebp], 4
-
 
62
        jnc     @f
-
 
63
        cmp     byte [ebp], 0
-
 
64
        jz      @f
-
 
65
        cmp     word [ebp+1], '/'
-
 
66
        jnz     @f
-
 
67
        cmp     byte [ebp], 2
-
 
68
        jnz     .rootdir
-
 
69
        cmp     word [ebp+3], 0
-
 
70
        jz      .rootdir
-
 
71
@@:
59
        cmp     dword[ebx], 7   ; start application
72
        cmp     dword[ebx], 7   ; start application
60
        jne     @f
73
        jnz     @f
61
        mov     edx, [ebx+4]
74
        mov     edx, [ebx+4]
62
        mov     ebx, [ebx+8]
75
        mov     ebx, [ebx+8]
63
        call    fs_execute      ; ebp, ebx, edx
76
        call    fs_execute      ; ebp, ebx, edx
64
        mov     [image_of_eax], eax
77
        mov     [image_of_eax], eax
65
        ret
78
        ret
66
 
79
 
67
@@:
80
@@:
68
        cmp     word [ebp], '/'
-
 
69
        jz      .rootdir
-
 
70
        cmp     byte [ebp], 2
-
 
71
        jnz     @f
-
 
72
        cmp     dword[ebp+1], '/'
-
 
73
        jz      .rootdir
-
 
74
@@:
-
 
75
        stdcall kernel_alloc, maxPathLength
81
        stdcall kernel_alloc, maxPathLength
76
        push    ebx
82
        push    ebx
77
        mov     ebx, ebp
83
        mov     ebx, ebp
78
        mov     ebp, eax
84
        mov     ebp, eax
79
        push    maxPathLength
-
 
80
        push    eax
-
 
81
        call    get_full_file_name
85
        stdcall get_full_file_name, eax, maxPathLength
82
        pop     ebx
86
        pop     ebx
83
        test    eax, eax
87
        test    eax, eax
84
        jz      .notfound
88
        jz      .notfound
85
        mov     esi, ebp
89
        lea     esi, [ebp+2]
86
        mov     ax, [ebp]
90
        mov     ax, [esi]
87
        or      ax, 2020h
91
        or      ax, 2020h
88
        cmp     ax, 'cd'
92
        cmp     ax, 'cd'
89
        jz      .CD
93
        jz      .CD
90
        call    dyndisk_handler ; not returns if success
94
        call    dyndisk_handler ; not returns if success
91
.notfound:
95
.notfound:
92
        stdcall kernel_free, ebp
96
        stdcall kernel_free, ebp
93
        mov     dword[image_of_eax], ERROR_FILE_NOT_FOUND
97
        mov     dword[image_of_eax], ERROR_FILE_NOT_FOUND
94
        ret
98
        ret
95
 
99
 
96
.CD:
100
.CD:
97
        add     esi, 2
101
        add     esi, 2
98
        xor     eax, eax
102
        xor     eax, eax
99
        lodsb       ; disk number
103
        lodsb       ; disk number
100
        sub     eax, '0'
104
        sub     eax, '0'
101
        cmp     eax, 10
105
        cmp     eax, 10
102
        jnc     .notfound
106
        jnc     .notfound
103
        mov     edi, eax
107
        mov     edi, eax
104
        lodsb
108
        lodsb
105
        test    eax, eax
109
        test    eax, eax
106
        jz      .maindir
110
        jz      .maindir
107
        cmp     al, '/'
111
        cmp     al, '/'
108
        jnz     .notfound
112
        jnz     .notfound
109
        lodsb       ; partition number
113
        lodsb       ; partition number
110
        test    eax, eax
114
        test    eax, eax
111
        jz      .maindir
115
        jz      .maindir
112
        cmp     al, '1'
116
        cmp     al, '1'
113
        jnz     .notfound
117
        jnz     .notfound
114
        cmp     byte [esi], '/'
118
        cmp     byte [esi], '/'
115
        jnz     @f
119
        jnz     @f
116
        inc     esi
120
        inc     esi
117
@@:
121
@@:
118
        call    reserve_cd
122
        call    reserve_cd
119
        mov     eax, edi
123
        mov     eax, edi
120
        bt      eax, 0
124
        bt      eax, 0
121
        setc    [DiskNumber]
125
        setc    [DiskNumber]
122
        bt      eax, 1
126
        bt      eax, 1
123
        setc    [ChannelNumber]
127
        setc    [ChannelNumber]
124
        inc     [ChannelNumber]
128
        inc     [ChannelNumber]
125
        inc     eax
129
        inc     eax
126
        mov     [cdpos], eax
130
        mov     [cdpos], eax
127
        call    reserve_cd_channel
131
        call    reserve_cd_channel
128
        mov     eax, edi
132
        mov     eax, edi
129
        not     eax
133
        not     eax
130
        and     eax, 3
134
        and     eax, 3
131
        shl     eax, 1
135
        shl     eax, 1
132
        inc     eax
136
        inc     eax
133
        shr     edi, 2
137
        shr     edi, 2
134
        mov     dword[image_of_eax], ERROR_FILE_NOT_FOUND
138
        mov     dword[image_of_eax], ERROR_FILE_NOT_FOUND
135
        bt      [edi*5+DRIVE_DATA+1], ax
139
        bt      [edi*5+DRIVE_DATA+1], ax
136
        jnc     @f
140
        jnc     @f
137
        mov     ecx, [ebx+12]
141
        mov     ecx, [ebx+12]
138
        mov     edx, [ebx+16]
142
        mov     edx, [ebx+16]
139
        mov     eax, [ebx]
143
        mov     eax, [ebx]
140
        mov     dword[image_of_eax], ERROR_UNSUPPORTED_FS
144
        mov     dword[image_of_eax], ERROR_UNSUPPORTED_FS
141
        cmp     eax, fs_NumCdServices
145
        cmp     eax, fs_NumCdServices
142
        jae     @f
146
        jae     @f
143
        add     ebx, 4
147
        add     ebx, 4
144
        call    dword[fs_CdServices + eax*4]
148
        call    dword[fs_CdServices + eax*4]
145
        mov     [image_of_eax], eax
149
        mov     [image_of_eax], eax
146
        mov     [image_of_ebx], ebx
150
        mov     [image_of_ebx], ebx
147
@@:
151
@@:
148
        call    free_cd_channel
152
        call    free_cd_channel
149
        and     [cd_status], 0
153
        and     [cd_status], 0
150
        stdcall kernel_free, ebp
154
        stdcall kernel_free, ebp
151
        ret
155
        ret
152
 
156
 
153
.nextCD:
157
.nextCD:
154
        test    eax, eax    ; partition number
158
        test    eax, eax    ; partition number
155
        stc
159
        stc
156
        jnz     @f      ; no more partitions
160
        jnz     @f      ; no more partitions
157
        mov     al, 1   ; /cdX/1
161
        mov     al, 1   ; /cdX/1
158
        clc
162
        clc
159
@@:
163
@@:
160
        ret
164
        ret
161
 
165
 
162
.maindir:   ; list partitions
166
.maindir:   ; list partitions
163
        mov     esi, .nextCD
167
        mov     esi, .nextCD
164
.maindir_noesi:     ; backjump from dyndisk_handler
168
.maindir_noesi:     ; backjump from dyndisk_handler
165
        push    ebp
169
        push    ebp
166
        mov     ebp, ecx
170
        mov     ebp, ecx
167
        call    kernel_free
171
        call    kernel_free
168
        cmp     dword[ebx], 1
172
        cmp     dword[ebx], 1
169
        jnz     .access_denied  ; read folder?
173
        jnz     .access_denied  ; read folder?
170
        push    ebp
174
        push    ebp
171
        pushd   [ebx+4]         ; first block
175
        pushd   [ebx+4]         ; first block
172
        mov     ebp, [ebx+12]   ; the number of blocks to read
176
        mov     ebp, [ebx+12]   ; the number of blocks to read
173
        mov     edx, [ebx+16]   ; buffer
177
        mov     edx, [ebx+16]   ; buffer
174
        mov     ebx, [ebx+8]    ; flags
178
        mov     ebx, [ebx+8]    ; flags
175
        mov     ecx, 32/4
179
        mov     ecx, 32/4
176
        mov     edi, edx
180
        mov     edi, edx
177
        xor     eax, eax
181
        xor     eax, eax
178
        rep stosd
182
        rep stosd
179
        mov     byte [edx], 1   ; version
183
        mov     byte [edx], 1   ; version
180
.maindir_loop:
184
.maindir_loop:
181
        call    esi
185
        call    esi
182
        jc      .maindir_done
186
        jc      .maindir_done
183
        inc     dword[edx+8]
187
        inc     dword[edx+8]
184
        dec     dword[esp]
188
        dec     dword[esp]
185
        jns     .maindir_loop
189
        jns     .maindir_loop
186
        dec     ebp
190
        dec     ebp
187
        js      .maindir_loop
191
        js      .maindir_loop
188
        inc     dword[edx+4]
192
        inc     dword[edx+4]
189
        mov     dword[edi], 16      ; attributes: folder
193
        mov     dword[edi], 16      ; attributes: folder
190
        mov     dword[edi+4], ebx   ; name encoding
194
        mov     dword[edi+4], ebx   ; name encoding
191
        push    eax
195
        push    eax
192
        mov     ecx, 32/4
196
        mov     ecx, 32/4
193
        add     edi, 8
197
        add     edi, 8
194
        xor     eax, eax
198
        xor     eax, eax
195
        rep stosd
199
        rep stosd
196
        pop     eax
200
        pop     eax
197
        push    eax edx edi
201
        push    eax edx edi
198
; convert number in eax to decimal string
202
; convert number in eax to decimal string
199
        push    -'0'
203
        push    -'0'
200
        mov     ecx, 10
204
        mov     ecx, 10
201
@@:
205
@@:
202
        xor     edx, edx
206
        xor     edx, edx
203
        div     ecx
207
        div     ecx
204
        push    edx
208
        push    edx
205
        test    eax, eax
209
        test    eax, eax
206
        jnz     @b
210
        jnz     @b
207
        cmp     ebx, 1
211
        cmp     ebx, 1
208
        jz      .uni
212
        jz      .uni
209
@@:
213
@@:
210
        pop     eax
214
        pop     eax
211
        add     eax, '0'
215
        add     eax, '0'
212
        stosb
216
        stosb
213
        test    eax, eax
217
        test    eax, eax
214
        jnz     @b
218
        jnz     @b
215
        pop     edi edx eax
219
        pop     edi edx eax
216
        add     edi, 264
220
        add     edi, 264
217
        jmp     .maindir_loop
221
        jmp     .maindir_loop
218
 
222
 
219
.uni:
223
.uni:
220
        pop     eax
224
        pop     eax
221
        add     eax, '0'
225
        add     eax, '0'
222
        stosw
226
        stosw
223
        test    eax, eax
227
        test    eax, eax
224
        jnz     .uni
228
        jnz     .uni
225
        pop     edi edx eax
229
        pop     edi edx eax
226
        add     edi, 520
230
        add     edi, 520
227
        jmp     .maindir_loop
231
        jmp     .maindir_loop
228
 
232
 
229
.maindir_done:
233
.maindir_done:
230
        pop     eax eax
234
        pop     eax eax
231
        mov     ebx, [edx+4]
235
        mov     ebx, [edx+4]
232
        xor     eax, eax
236
        xor     eax, eax
233
        dec     ebp
237
        dec     ebp
234
        js      @f
238
        js      @f
235
        mov     al, ERROR_END_OF_FILE
239
        mov     al, ERROR_END_OF_FILE
236
@@:
240
@@:
237
        mov     [image_of_eax], eax
241
        mov     [image_of_eax], eax
238
        mov     [image_of_ebx], ebx
242
        mov     [image_of_ebx], ebx
239
        ret
243
        ret
240
 
244
 
241
.access_denied:
245
.access_denied:
242
        mov     dword[image_of_eax], ERROR_ACCESS_DENIED
246
        mov     dword[image_of_eax], ERROR_ACCESS_DENIED
243
        ret
247
        ret
244
 
248
 
245
.rootdir:   ; / - virtual root folder
249
.rootdir:   ; / - virtual root folder
246
        cmp     dword[ebx], 1   ; read folder?
250
        cmp     dword[ebx], 1   ; read folder?
247
        jnz     .access_denied
251
        jnz     .access_denied
248
        mov     ebp, [ebx+12]   ; number of blocks
252
        mov     ebp, [ebx+12]   ; number of blocks
249
        mov     edx, [ebx+16]   ; return area
253
        mov     edx, [ebx+16]   ; return area
250
        push    dword[ebx+4]    ; first block
254
        push    dword[ebx+4]    ; first block
251
        mov     ebx, [ebx+8]    ; flags
255
        mov     ebx, [ebx+8]    ; flags
252
        mov     ecx, 32/4
256
        mov     ecx, 32/4
253
        mov     edi, edx
257
        mov     edi, edx
254
        xor     eax, eax
258
        xor     eax, eax
255
        rep stosd
259
        rep stosd
256
        mov     byte [edx], 1   ; version
260
        mov     byte [edx], 1   ; version
257
        sub     esp, 16
261
        sub     esp, 16
258
.rootdir_loop:
262
.rootdir_loop:
259
        push    edi
263
        push    edi
260
        lea     edi, [esp+4]
264
        lea     edi, [esp+4]
261
        call    dyndisk_enum_root
265
        call    dyndisk_enum_root
262
        pop     edi
266
        pop     edi
263
        test    eax, eax
267
        test    eax, eax
264
        jz      .rootdirCD
268
        jz      .rootdirCD
265
        inc     dword[edx+8]
269
        inc     dword[edx+8]
266
        dec     dword[esp+16]
270
        dec     dword[esp+16]
267
        jns     .rootdir_loop
271
        jns     .rootdir_loop
268
        dec     ebp
272
        dec     ebp
269
        js      .rootdir_loop
273
        js      .rootdir_loop
270
        inc     dword[edx+4]
274
        inc     dword[edx+4]
271
        mov     dword[edi], 16      ; attributes: folder
275
        mov     dword[edi], 16      ; attributes: folder
272
        mov     dword[edi+4], ebx   ; name encoding
276
        mov     dword[edi+4], ebx   ; name encoding
273
        push    eax
277
        push    eax
274
        mov     ecx, 32/4
278
        mov     ecx, 32/4
275
        add     edi, 8
279
        add     edi, 8
276
        xor     eax, eax
280
        xor     eax, eax
277
        rep stosd
281
        rep stosd
278
        push    edi
282
        push    edi
279
        lea     esi, [esp+8]
283
        lea     esi, [esp+8]
280
        cmp     ebx, 1
284
        cmp     ebx, 1
281
        jz      .uni2
285
        jz      .uni2
282
@@:
286
@@:
283
        lodsb
287
        lodsb
284
        stosb
288
        stosb
285
        test    eax, eax
289
        test    eax, eax
286
        jnz     @b
290
        jnz     @b
287
        pop     edi eax
291
        pop     edi eax
288
        add     edi, 264
292
        add     edi, 264
289
        jmp     .rootdir_loop
293
        jmp     .rootdir_loop
290
 
294
 
291
.uni2:
295
.uni2:
292
        lodsb
296
        lodsb
293
        stosw
297
        stosw
294
        test    eax, eax
298
        test    eax, eax
295
        jnz     .uni2
299
        jnz     .uni2
296
        pop     edi eax
300
        pop     edi eax
297
        add     edi, 520
301
        add     edi, 520
298
        jmp     .rootdir_loop
302
        jmp     .rootdir_loop
299
 
303
 
300
.rootdirCD:
304
.rootdirCD:
301
        add     esp, 16
305
        add     esp, 16
302
        or      esi, -1
306
        or      esi, -1
303
.rootdirCD_loop:
307
.rootdirCD_loop:
304
        inc     esi
308
        inc     esi
305
        cmp     esi, 10
309
        cmp     esi, 10
306
        jnc     .rootdir_done
310
        jnc     .rootdir_done
307
        mov     eax, esi
311
        mov     eax, esi
308
        not     eax
312
        not     eax
309
        and     eax, 3
313
        and     eax, 3
310
        shl     eax, 1
314
        shl     eax, 1
311
        inc     eax
315
        inc     eax
312
        mov     ecx, esi
316
        mov     ecx, esi
313
        shr     ecx, 2
317
        shr     ecx, 2
314
        bt      [ecx*5+DRIVE_DATA+1], ax
318
        bt      [ecx*5+DRIVE_DATA+1], ax
315
        jnc     .rootdirCD_loop
319
        jnc     .rootdirCD_loop
316
        inc     dword[edx+8]
320
        inc     dword[edx+8]
317
        dec     dword[esp]
321
        dec     dword[esp]
318
        jns     .rootdirCD_loop
322
        jns     .rootdirCD_loop
319
        dec     ebp
323
        dec     ebp
320
        js      .rootdirCD_loop
324
        js      .rootdirCD_loop
321
        inc     dword[edx+4]
325
        inc     dword[edx+4]
322
        mov     dword[edi], 16      ; attributes: folder
326
        mov     dword[edi], 16      ; attributes: folder
323
        mov     dword[edi+4], ebx   ; name encoding
327
        mov     dword[edi+4], ebx   ; name encoding
324
        mov     ecx, 32/4
328
        mov     ecx, 32/4
325
        add     edi, 8
329
        add     edi, 8
326
        xor     eax, eax
330
        xor     eax, eax
327
        rep stosd
331
        rep stosd
328
        mov     eax, esi
332
        mov     eax, esi
329
        add     eax, '0'
333
        add     eax, '0'
330
        cmp     ebx, 1
334
        cmp     ebx, 1
331
        jz      @f
335
        jz      @f
332
        mov     word [edi], 'cd'
336
        mov     word [edi], 'cd'
333
        mov     [edi+2], ax
337
        mov     [edi+2], ax
334
        add     edi, 264
338
        add     edi, 264
335
        jmp     .rootdirCD_loop
339
        jmp     .rootdirCD_loop
336
 
340
 
337
@@:
341
@@:
338
        mov     dword[edi], 640063h
342
        mov     dword[edi], 640063h
339
        mov     [edi+4], eax
343
        mov     [edi+4], eax
340
        add     edi, 520
344
        add     edi, 520
341
        jmp     .rootdirCD_loop
345
        jmp     .rootdirCD_loop
342
 
346
 
343
.rootdir_done:
347
.rootdir_done:
344
        pop     eax
348
        pop     eax
345
        mov     ebx, [edx+4]
349
        mov     ebx, [edx+4]
346
        xor     eax, eax
350
        xor     eax, eax
347
        dec     ebp
351
        dec     ebp
348
        js      @f
352
        js      @f
349
        mov     al, ERROR_END_OF_FILE
353
        mov     al, ERROR_END_OF_FILE
350
@@:
354
@@:
351
        mov     [image_of_eax], eax
355
        mov     [image_of_eax], eax
352
        mov     [image_of_ebx], ebx
356
        mov     [image_of_ebx], ebx
353
        ret
357
        ret
354
 
358
 
355
;-----------------------------------------------------------------------------
359
;-----------------------------------------------------------------------------
356
process_replace_file_name:
360
process_replace_file_name:
357
; in: [esi] = virtual path
361
; in: [esi] = virtual path
358
; out: [esi]+[ebp] = physical path
362
; out: [esi]+[ebp] = physical path
359
        xor     edi, edi
363
        xor     edi, edi
360
        xor     ebp, ebp
364
        xor     ebp, ebp
361
.loop:
365
.loop:
362
        cmp     edi, [full_file_name_table.size]
366
        cmp     edi, [full_file_name_table.size]
363
        jae     .notfound
367
        jae     .notfound
364
        push    esi edi
368
        push    esi edi
365
        shl     edi, 7
369
        shl     edi, 7
366
        add     edi, [full_file_name_table]
370
        add     edi, [full_file_name_table]
367
@@:
371
@@:
368
        cmp     byte [edi], 0
372
        cmp     byte [edi], 0
369
        jz      .dest_done
373
        jz      .dest_done
370
        lodsb
374
        lodsb
371
        test    al, al
375
        test    al, al
372
        jz      .cont
376
        jz      .cont
373
        or      al, 20h
377
        or      al, 20h
374
        scasb
378
        scasb
375
        jz      @b
379
        jz      @b
376
.cont:
380
.cont:
377
        pop     edi esi
381
        pop     edi esi
378
        inc     edi
382
        inc     edi
379
        jmp     .loop
383
        jmp     .loop
380
 
384
 
381
.dest_done:
385
.dest_done:
382
        cmp     byte [esi], 0
386
        cmp     byte [esi], 0
383
        jz      .found
387
        jz      .found
384
        cmp     byte [esi], '/'
388
        cmp     byte [esi], '/'
385
        jnz     .cont
389
        jnz     .cont
386
.found:
390
.found:
387
        pop     edi eax
391
        pop     edi eax
388
        shl     edi, 7
392
        shl     edi, 7
389
        add     edi, [full_file_name_table]
393
        add     edi, [full_file_name_table]
390
        mov     ebp, esi
394
        mov     ebp, esi
391
        lea     esi, [edi+64]
395
        lea     esi, [edi+64]
392
.notfound:
396
.notfound:
393
        ret
397
        ret
394
 
398
 
395
;-----------------------------------------------------------------------------
399
;-----------------------------------------------------------------------------
396
uglobal
400
uglobal
397
addDirSeal db  ?
401
addDirSeal db  ?
398
endg
402
endg
399
 
403
 
400
sys_current_directory:  ; sysfunction 30
404
sys_current_directory:  ; sysfunction 30
401
        mov     eax, [current_slot]
405
        mov     eax, [current_slot]
402
        mov     edi, [eax+APPDATA.cur_dir]
406
        mov     edi, [eax+APPDATA.cur_dir]
403
        dec     ebx
407
        dec     ebx
404
        jz      .set
408
        jz      .set
405
        dec     ebx
409
        dec     ebx
406
        jz      .get
410
        jz      .get
407
        dec     ebx
411
        dec     ebx
408
        jz      .mount_additional_directory
412
        jz      .mount_additional_directory
409
        dec     ebx
413
        dec     ebx
410
        jz      .get16
414
        jz      .get16
411
@@:
415
@@:
412
        ret
416
        ret
413
 
417
 
414
.mount_additional_directory:
418
.mount_additional_directory:
415
; in: ecx -> dir name+dir path (128)
419
; in: ecx -> dir name+dir path (128)
416
        mov     al, 1
420
        mov     al, 1
417
        xchg    [addDirSeal], al
421
        xchg    [addDirSeal], al
418
        test    al, al
422
        test    al, al
419
        jnz     @b
423
        jnz     @b
420
        mov     esi, ecx
424
        mov     esi, ecx
421
        mov     edi, sysdir_name1
425
        mov     edi, sysdir_name1
422
        mov     ecx, 63
426
        mov     ecx, 63
423
        rep movsb   ; copying fake directory name
427
        rep movsb   ; copying fake directory name
424
        inc     esi
428
        inc     esi
425
        xor     eax, eax
429
        xor     eax, eax
426
        stosb       ; terminator of name, in case if we get the inlet trash
430
        stosb       ; terminator of name, in case if we get the inlet trash
427
        mov     cl, 63
431
        mov     cl, 63
428
        cmp     word [esi], 2
432
        cmp     word [esi], 2
429
        jz      .utf16
433
        jz      .utf16
430
        call    cp866toUTF8_string
434
        call    cp866toUTF8_string
431
@@:
435
@@:
432
        mov     byte [edi], 0
436
        mov     byte [edi], 0
433
        mov     [full_file_name_table.size], 2
437
        mov     [full_file_name_table.size], 2
434
        ret
438
        ret
435
 
439
 
436
.utf16:
440
.utf16:
437
        add     esi, 2
441
        add     esi, 2
438
        call    UTF16to8_string
442
        call    UTF16to8_string
439
        jmp     @b
443
        jmp     @b
440
 
444
 
441
.get:       ; in: ecx -> buffer, edx = length
445
.get:       ; in: ecx -> buffer, edx = length
442
        mov     esi, edi
446
        mov     esi, edi
443
        mov     edi, ecx
447
        mov     edi, ecx
444
        cmp     edx, maxPathLength
448
        cmp     edx, maxPathLength
445
        jc      @f
449
        jc      @f
446
        mov     edx, maxPathLength
450
        mov     edx, maxPathLength
447
@@:
451
@@:
448
        mov     al, '/'
452
        mov     al, '/'
449
        stosb
453
        stosb
450
        mov     ecx, edx
454
        mov     ecx, edx
451
        dec     ecx
455
        dec     ecx
452
@@:
456
@@:
453
        dec     ecx
457
        dec     ecx
454
        js      @f
458
        js      @f
455
        call    utf8to16
459
        call    utf8to16
456
        call    uni2ansi_char
460
        call    uni2ansi_char
457
        stosb
461
        stosb
458
        test    al, al
462
        test    al, al
459
        jnz     @b
463
        jnz     @b
460
        sub     edx, ecx
464
        sub     edx, ecx
461
        mov     ecx, edx
465
        mov     ecx, edx
462
@@:
466
@@:
463
        mov     [esp+32], ecx
467
        mov     [esp+32], ecx
464
        ret
468
        ret
465
 
469
 
466
.get16:
470
.get16:
467
        mov     esi, edi
471
        mov     esi, edi
468
        mov     edi, ecx
472
        mov     edi, ecx
469
        cmp     edx, maxPathLength
473
        cmp     edx, maxPathLength
470
        jc      @f
474
        jc      @f
471
        mov     edx, maxPathLength
475
        mov     edx, maxPathLength
472
@@:
476
@@:
473
        shr     edx, 1
477
        shr     edx, 1
474
        mov     ax, '/'
478
        mov     ax, '/'
475
        stosw
479
        stosw
476
        mov     ecx, edx
480
        mov     ecx, edx
477
        dec     ecx
481
        dec     ecx
478
@@:
482
@@:
479
        dec     ecx
483
        dec     ecx
480
        js      @f
484
        js      @f
481
        call    utf8to16
485
        call    utf8to16
482
        stosw
486
        stosw
483
        test    ax, ax
487
        test    ax, ax
484
        jnz     @b
488
        jnz     @b
485
        sub     edx, ecx
489
        sub     edx, ecx
486
        mov     ecx, edx
490
        mov     ecx, edx
487
@@:
491
@@:
488
        mov     [esp+32], ecx
492
        mov     [esp+32], ecx
489
        ret
493
        ret
490
 
494
 
491
.set:
495
.set:
492
        pop     eax
496
        pop     eax
493
        push    maxPathLength
497
        push    maxPathLength
494
        push    edi
498
        push    edi
495
        push    eax
499
        push    eax
496
        mov     ebx, ecx
500
        mov     ebx, ecx
497
get_full_file_name:
501
get_full_file_name:
498
; in: ebx -> file name, [esp+4] -> destination, [esp+8] = max length
502
; in: ebx -> file name, [esp+4] -> destination, [esp+8] = max length
499
; out: eax=0 -> out of length
503
; out: UTF-8 string, eax=0 -> out of length
500
        push    ebp ebx
504
        push    ebp ebx
-
 
505
        cmp     byte [ebx], 0
-
 
506
        jz      .set_relative
501
        mov     esi, ebx
507
        mov     esi, ebx
502
        cmp     byte [ebx], 2
508
        cmp     byte [ebx], 4
503
        jnz     @f
509
        jnc     @f
504
        inc     esi
510
        inc     esi
505
@@:
511
@@:
506
        cmp     byte [esi], '/'
512
        cmp     byte [esi], '/'
507
        jnz     .set_relative
513
        jnz     .set_relative
508
        inc     esi
514
        inc     esi
509
        cmp     byte [ebx], 2
515
        cmp     byte [ebx], 2
510
        jnz     @f
516
        jnz     @f
511
        inc     esi
517
        inc     esi
512
@@:
518
@@:
513
        call    process_replace_file_name
519
        call    process_replace_file_name
514
        mov     edi, [esp+12]
520
        mov     edi, [esp+12]
515
        mov     ecx, [esp+16]
521
        mov     ecx, [esp+16]
-
 
522
        mov     al, 3
-
 
523
        mov     ah, '/'
-
 
524
        stosw
-
 
525
        sub     ecx, 2
516
        test    ebp, ebp
526
        test    ebp, ebp
517
        jz      .absolute
527
        jz      .absolute
518
@@:
528
@@:
519
        lodsb
529
        lodsb
520
        stosb
530
        stosb
521
        dec     ecx
531
        dec     ecx
522
        test    al, al
532
        test    al, al
523
        jnz     @b
533
        jnz     @b
524
        mov     esi, ebp
534
        mov     esi, ebp
525
        dec     edi
535
        dec     edi
526
.absolute:
536
.absolute:
527
        cmp     byte [ebx], 2
537
        cmp     byte [ebx], 2
-
 
538
        jz      .utf16
-
 
539
        cmp     byte [ebx], 3
528
        jz      @f
540
        jz      .utf8
529
        call    cp866toUTF8_string
541
        call    cp866toUTF8_string
530
        jns     .ret
542
        jns     .ret
531
        jmp     .fail
543
        jmp     .fail
532
 
544
 
-
 
545
.utf8:
-
 
546
        dec     ecx
-
 
547
        js      .fail
-
 
548
        lodsb
-
 
549
        stosb
-
 
550
        test    al, al
-
 
551
        jz      .ret
-
 
552
        jmp     .utf8
-
 
553
 
533
@@:
554
.utf16:
534
        call    UTF16to8_string
555
        call    UTF16to8_string
535
        jns     .ret
556
        jns     .ret
536
.fail:
557
.fail:
537
        mov     byte [edi], 0
558
        mov     byte [edi], 0
538
        xor     eax, eax
559
        xor     eax, eax
539
        pop     ebx ebp
560
        pop     ebx ebp
540
        ret     8
561
        ret     8
541
 
562
 
542
.set_relative:
563
.set_relative:
543
        mov     edi, [current_slot]
564
        mov     edi, [current_slot]
544
        mov     edi, [edi+APPDATA.cur_dir]
565
        mov     edi, [edi+APPDATA.cur_dir]
545
        mov     edx, edi
566
        mov     edx, edi
546
        mov     ecx, [esp+16]
567
        mov     ecx, [esp+16]
547
        xor     eax, eax
568
        xor     eax, eax
548
        repnz scasb
569
        repnz scasb
549
        mov     esi, edi
570
        mov     esi, edi
550
        dec     esi
571
        dec     esi
551
        mov     edi, [esp+12]
572
        mov     edi, [esp+12]
552
        jecxz   .fail
573
        jecxz   .fail
553
        cmp     byte [ebx], 2
574
        cmp     byte [ebx], 0
-
 
575
        jz      .set_ok
-
 
576
        cmp     byte [ebx], 4
-
 
577
        jnc     .relative
-
 
578
        inc     ebx
-
 
579
        cmp     byte [ebx-1], 2
554
        jz      .relative16
580
        jz      .relative16
555
.relative:
581
.relative:
556
        cmp     byte [ebx], 0
582
        cmp     byte [ebx], 0
557
        jz      .set_ok
583
        jz      .set_ok
558
        cmp     word [ebx], '.'
584
        cmp     word [ebx], '.'
559
        jz      .set_ok
585
        jz      .set_ok
560
        cmp     word [ebx], './'
586
        cmp     word [ebx], './'
561
        jz      .next
587
        jz      .next
562
        cmp     word [ebx], '..'
588
        cmp     word [ebx], '..'
563
        jnz     .doset_relative
589
        jnz     .doset_relative
564
        cmp     byte [ebx+2], 0
590
        cmp     byte [ebx+2], 0
565
        jz      @f
591
        jz      @f
566
        cmp     byte [ebx+2], '/'
592
        cmp     byte [ebx+2], '/'
567
        jnz     .doset_relative
593
        jnz     .doset_relative
568
        inc     ebx
594
        inc     ebx
569
@@:
595
@@:
570
        dec     esi
596
        dec     esi
571
        cmp     byte [esi], '/'
597
        cmp     byte [esi], '/'
572
        jnz     @b
598
        jnz     @b
573
.next:
599
.next:
574
        add     ebx, 2
600
        add     ebx, 2
575
        jmp     .relative
601
        jmp     .relative
576
 
602
 
577
.set_ok:
603
.set_ok:
578
        cmp     edx, edi    ; is destination equal to cur_dir?
604
        cmp     edx, edi    ; is destination equal to cur_dir?
579
        jz      @f
605
        jz      @f
580
        mov     ecx, esi
606
        mov     ecx, esi
581
        sub     ecx, edx
607
        sub     ecx, edx
582
        mov     esi, edx
608
        mov     esi, edx
583
        rep movsb
609
        rep movsb
584
        mov     byte [edi], 0
610
        mov     byte [edi], 0
585
.ret:
611
.ret:
586
        mov     al, 1
612
        mov     al, 1
587
        pop     ebx ebp
613
        pop     ebx ebp
588
        ret     8
614
        ret     8
589
 
615
 
590
@@:
616
@@:
591
        mov     byte [esi], 0
617
        mov     byte [esi], 0
592
        jmp     .ret
618
        jmp     .ret
593
 
619
 
594
.doset_relative:
620
.doset_relative:
595
        cmp     edx, edi    ; is destination equal to cur_dir?
621
        cmp     edx, edi    ; is destination equal to cur_dir?
596
        mov     edi, esi
622
        mov     edi, esi
597
        jz      @f
623
        jz      @f
598
        mov     edi, [esp+12]
624
        mov     edi, [esp+12]
599
        mov     ecx, esi
625
        mov     ecx, esi
600
        sub     ecx, edx
626
        sub     ecx, edx
601
        mov     esi, edx
627
        mov     esi, edx
602
        mov     edx, edi
628
        mov     edx, edi
603
        rep movsb
629
        rep movsb
604
@@:
630
@@:
605
        mov     byte [edi], '/'
631
        mov     byte [edi], '/'
606
        inc     edi
632
        inc     edi
607
        mov     esi, ebx
633
        mov     esi, ebx
608
        mov     ecx, edx
634
        mov     ecx, edx
609
        add     ecx, [esp+16]
635
        add     ecx, [esp+16]
610
        sub     ecx, edi
636
        sub     ecx, edi
611
        mov     ebx, [esp]
637
        mov     ebx, [esp]
612
        jmp     .absolute
638
        jmp     .absolute
613
 
639
 
614
.relative16:
640
.relative16:
615
        cmp     word [ebx], 0
641
        cmp     word [ebx], 0
616
        jz      .set_ok
642
        jz      .set_ok
617
        cmp     word [ebx], '.'
643
        cmp     word [ebx], '.'
618
        jnz     .doset_relative
644
        jnz     .doset_relative
619
        cmp     word [ebx+2], 0
645
        cmp     word [ebx+2], 0
620
        jz      .set_ok
646
        jz      .set_ok
621
        cmp     word [ebx+2], '/'
647
        cmp     word [ebx+2], '/'
622
        jz      .next16
648
        jz      .next16
623
        cmp     word [ebx+2], '.'
649
        cmp     word [ebx+2], '.'
624
        jnz     .doset_relative
650
        jnz     .doset_relative
625
        cmp     word [ebx+4], 0
651
        cmp     word [ebx+4], 0
626
        jz      @f
652
        jz      @f
627
        cmp     word [ebx+4], '/'
653
        cmp     word [ebx+4], '/'
628
        jnz     .doset_relative
654
        jnz     .doset_relative
629
        add     ebx, 2
655
        add     ebx, 2
630
@@:
656
@@:
631
        dec     esi
657
        dec     esi
632
        cmp     byte [esi], '/'
658
        cmp     byte [esi], '/'
633
        jnz     @b
659
        jnz     @b
634
.next16:
660
.next16:
635
        add     ebx, 4
661
        add     ebx, 4
636
        jmp     .relative16
662
        jmp     .relative16
637
 
663
 
638
include "parse_fn.inc"
664
include "parse_fn.inc"
639
include "fs_common.inc"
665
include "fs_common.inc"
640
include "iso9660.inc"   ; read for CD filesystem
666
include "iso9660.inc"   ; read for CD filesystem
641
include "fat.inc"
667
include "fat.inc"
642
include "ntfs.inc"
668
include "ntfs.inc"
643
include "ext.inc"
669
include "ext.inc"
644
include "xfs.asm"
670
include "xfs.asm"