Subversion Repositories Kolibri OS

Rev

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

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