Subversion Repositories Kolibri OS

Rev

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

Rev 3742 Rev 4273
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2011. 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: 3742 $
8
$Revision: 4273 $
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_FAT_TABLE      = 9 ;deprecated
19
ERROR_FAT_TABLE      = 9 ;deprecated
20
ERROR_FS_FAIL        = 9
20
ERROR_FS_FAIL        = 9
21
ERROR_ACCESS_DENIED  = 10
21
ERROR_ACCESS_DENIED  = 10
22
ERROR_DEVICE         = 11
22
ERROR_DEVICE         = 11
23
 
23
 
24
image_of_eax EQU esp+32
24
image_of_eax EQU esp+32
25
image_of_ebx EQU esp+20
25
image_of_ebx EQU esp+20
26
 
26
 
27
; System function 70 - files with long names (LFN)
27
; System function 70 - files with long names (LFN)
28
; diamond, 2006
28
; diamond, 2006
29
 
29
 
30
iglobal
30
iglobal
31
; in this table names must be in lowercase
31
; in this table names must be in lowercase
32
rootdirs:
32
rootdirs:
33
        db      2,'rd'
-
 
34
        dd      fs_OnRamdisk
-
 
35
        dd      fs_NextRamdisk
-
 
36
        db      7,'ramdisk'
-
 
37
        dd      fs_OnRamdisk
-
 
38
        dd      fs_NextRamdisk
-
 
39
        db      2,'fd'
-
 
40
        dd      fs_OnFloppy
-
 
41
        dd      fs_NextFloppy
-
 
42
        db      10,'floppydisk'
-
 
43
        dd      fs_OnFloppy
-
 
44
        dd      fs_NextFloppy
-
 
45
;**********************************************
33
;**********************************************
46
        db      3,'cd0'
34
        db      3,'cd0'
47
        dd      fs_OnCd0
35
        dd      fs_OnCd0
48
        dd      fs_NextCd
36
        dd      fs_NextCd
49
        db      3,'cd1'
37
        db      3,'cd1'
50
        dd      fs_OnCd1
38
        dd      fs_OnCd1
51
        dd      fs_NextCd
39
        dd      fs_NextCd
52
        db      3,'cd2'
40
        db      3,'cd2'
53
        dd      fs_OnCd2
41
        dd      fs_OnCd2
54
        dd      fs_NextCd
42
        dd      fs_NextCd
55
        db      3,'cd3'
43
        db      3,'cd3'
56
        dd      fs_OnCd3
44
        dd      fs_OnCd3
57
        dd      fs_NextCd
45
        dd      fs_NextCd
58
;***********************************************
46
;***********************************************
59
        db      0
47
        db      0
60
 
48
 
61
 
49
 
62
virtual_root_query:
50
virtual_root_query:
63
        dd      fs_HasRamdisk
-
 
64
        db      'rd',0
-
 
65
        dd      fs_HasFloppy
-
 
66
        db      'fd',0
-
 
67
;**********************************************
51
;**********************************************
68
        dd      fs_HasCd0
52
        dd      fs_HasCd0
69
        db      'cd0',0
53
        db      'cd0',0
70
        dd      fs_HasCd1
54
        dd      fs_HasCd1
71
        db      'cd1',0
55
        db      'cd1',0
72
        dd      fs_HasCd2
56
        dd      fs_HasCd2
73
        db      'cd2',0
57
        db      'cd2',0
74
        dd      fs_HasCd3
58
        dd      fs_HasCd3
75
        db      'cd3',0
59
        db      'cd3',0
76
;**********************************************
60
;**********************************************
77
        dd      0
61
        dd      0
78
 
62
 
79
fs_additional_handlers:
63
fs_additional_handlers:
80
        dd      dyndisk_handler, dyndisk_enum_root
64
        dd      dyndisk_handler, dyndisk_enum_root
81
; add new handlers here
65
; add new handlers here
82
        dd      0
66
        dd      0
83
 
67
 
84
endg
68
endg
85
 
69
 
86
file_system_lfn_protected:
70
file_system_lfn_protected:
87
        pushad
71
        pushad
88
        call    protect_from_terminate
72
        call    protect_from_terminate
89
        call    file_system_lfn
73
        call    file_system_lfn
90
        call    unprotect_from_terminate
74
        call    unprotect_from_terminate
91
        popad
75
        popad
92
        mov     [image_of_eax], eax
76
        mov     [image_of_eax], eax
93
        mov     [image_of_ebx], ebx
77
        mov     [image_of_ebx], ebx
94
        ret
78
        ret
95
 
79
 
96
file_system_lfn:
80
file_system_lfn:
97
; in: ebx->fileinfo block
81
; in: ebx->fileinfo block
98
; operation codes:
82
; operation codes:
99
; 0 : read file
83
; 0 : read file
100
; 1 : read folder
84
; 1 : read folder
101
; 2 : create/rewrite file
85
; 2 : create/rewrite file
102
; 3 : write/append to file
86
; 3 : write/append to file
103
; 4 : set end of file
87
; 4 : set end of file
104
; 5 : get file/directory attributes structure
88
; 5 : get file/directory attributes structure
105
; 6 : set file/directory attributes structure
89
; 6 : set file/directory attributes structure
106
; 7 : start application
90
; 7 : start application
107
; 8 : delete file
91
; 8 : delete file
108
; 9 : create directory
92
; 9 : create directory
109
 
93
 
110
; parse file name
94
; parse file name
111
        lea     esi, [ebx+20]
95
        lea     esi, [ebx+20]
112
        lodsb
96
        lodsb
113
        test    al, al
97
        test    al, al
114
        jnz     @f
98
        jnz     @f
115
        mov     esi, [esi]
99
        mov     esi, [esi]
116
        lodsb
100
        lodsb
117
@@:
101
@@:
118
        cmp     al, '/'
102
        cmp     al, '/'
119
        jz      .notcurdir
103
        jz      .notcurdir
120
        dec     esi
104
        dec     esi
121
        mov     ebp, esi
105
        mov     ebp, esi
122
        test    al, al
106
        test    al, al
123
        jnz     @f
107
        jnz     @f
124
        xor     ebp, ebp
108
        xor     ebp, ebp
125
@@:
109
@@:
126
        mov     esi, [current_slot]
110
        mov     esi, [current_slot]
127
        mov     esi, [esi+APPDATA.cur_dir]
111
        mov     esi, [esi+APPDATA.cur_dir]
128
        jmp     .parse_normal
112
        jmp     .parse_normal
129
.notcurdir:
113
.notcurdir:
130
        cmp     byte [esi], 0
114
        cmp     byte [esi], 0
131
        jz      .rootdir
115
        jz      .rootdir
132
        call    process_replace_file_name
116
        call    process_replace_file_name
133
.parse_normal:
117
.parse_normal:
134
        cmp     dword [ebx], 7
118
        cmp     dword [ebx], 7
135
        jne     @F
119
        jne     @F
136
        mov     edx, [ebx+4]
120
        mov     edx, [ebx+4]
137
        mov     ebx, [ebx+8]
121
        mov     ebx, [ebx+8]
138
        call    fs_execute; esi+ebp, ebx, edx
122
        call    fs_execute; esi+ebp, ebx, edx
139
        mov     [image_of_eax], eax
123
        mov     [image_of_eax], eax
140
        ret
124
        ret
141
@@:
125
@@:
142
        mov     edi, rootdirs-8
126
        mov     edi, rootdirs-8
143
        xor     ecx, ecx
127
        xor     ecx, ecx
144
        push    esi
128
        push    esi
145
.scan1:
129
.scan1:
146
        pop     esi
130
        pop     esi
147
        add     edi, ecx
131
        add     edi, ecx
148
        scasd
132
        scasd
149
        scasd
133
        scasd
150
        mov     cl, byte [edi]
134
        mov     cl, byte [edi]
151
        test    cl, cl
135
        test    cl, cl
152
        jz      .notfound_try
136
        jz      .notfound_try
153
        inc     edi
137
        inc     edi
154
        push    esi
138
        push    esi
155
@@:
139
@@:
156
        lodsb
140
        lodsb
157
        or      al, 20h
141
        or      al, 20h
158
        scasb
142
        scasb
159
        loopz   @b
143
        loopz   @b
160
        jnz     .scan1
144
        jnz     .scan1
161
        lodsb
145
        lodsb
162
        cmp     al, '/'
146
        cmp     al, '/'
163
        jz      .found1
147
        jz      .found1
164
        test    al, al
148
        test    al, al
165
        jnz     .scan1
149
        jnz     .scan1
166
        pop     eax
150
        pop     eax
167
; directory /xxx
151
; directory /xxx
168
.maindir:
152
.maindir:
169
        mov     esi, [edi+4]
153
        mov     esi, [edi+4]
170
.maindir_noesi:
154
.maindir_noesi:
171
        cmp     dword [ebx], 1
155
        cmp     dword [ebx], 1
172
        jnz     .access_denied
156
        jnz     .access_denied
173
        xor     eax, eax
157
        xor     eax, eax
174
        mov     ebp, [ebx+12]                   ;количество блоков для считывания
158
        mov     ebp, [ebx+12]                   ;количество блоков для считывания
175
        mov     edx, [ebx+16]                   ;куда записывать рузельтат
159
        mov     edx, [ebx+16]                   ;куда записывать рузельтат
176
    ;    add     edx, std_application_base_address
160
    ;    add     edx, std_application_base_address
177
        push    dword [ebx+4]   ; first block
161
        push    dword [ebx+4]   ; first block
178
        mov     ebx, [ebx+8]    ; flags
162
        mov     ebx, [ebx+8]    ; flags
179
; ebx=flags, [esp]=first block, ebp=number of blocks, edx=return area, esi='Next' handler
163
; ebx=flags, [esp]=first block, ebp=number of blocks, edx=return area, esi='Next' handler
180
        mov     edi, edx
164
        mov     edi, edx
181
        push    ecx
165
        push    ecx
182
        mov     ecx, 32/4
166
        mov     ecx, 32/4
183
        rep stosd
167
        rep stosd
184
        pop     ecx
168
        pop     ecx
185
        mov     byte [edx], 1   ; version
169
        mov     byte [edx], 1   ; version
186
.maindir_loop:
170
.maindir_loop:
187
        call    esi
171
        call    esi
188
        jc      .maindir_done
172
        jc      .maindir_done
189
        inc     dword [edx+8]
173
        inc     dword [edx+8]
190
        dec     dword [esp]
174
        dec     dword [esp]
191
        jns     .maindir_loop
175
        jns     .maindir_loop
192
        dec     ebp
176
        dec     ebp
193
        js      .maindir_loop
177
        js      .maindir_loop
194
        inc     dword [edx+4]
178
        inc     dword [edx+4]
195
        mov     dword [edi], 0x10       ; attributes: folder
179
        mov     dword [edi], 0x10       ; attributes: folder
196
        mov     dword [edi+4], 1        ; name type: UNICODE
180
        mov     dword [edi+4], 1        ; name type: UNICODE
197
        push    eax
181
        push    eax
198
        xor     eax, eax
182
        xor     eax, eax
199
        add     edi, 8
183
        add     edi, 8
200
        push    ecx
184
        push    ecx
201
        mov     ecx, 40/4-2
185
        mov     ecx, 40/4-2
202
        rep stosd
186
        rep stosd
203
        pop     ecx
187
        pop     ecx
204
        pop     eax
188
        pop     eax
205
        push    eax edx
189
        push    eax edx
206
; convert number in eax to decimal UNICODE string
190
; convert number in eax to decimal UNICODE string
207
        push    edi
191
        push    edi
208
        push    ecx
192
        push    ecx
209
        push    -'0'
193
        push    -'0'
210
        mov     ecx, 10
194
        mov     ecx, 10
211
@@:
195
@@:
212
        xor     edx, edx
196
        xor     edx, edx
213
        div     ecx
197
        div     ecx
214
        push    edx
198
        push    edx
215
        test    eax, eax
199
        test    eax, eax
216
        jnz     @b
200
        jnz     @b
217
@@:
201
@@:
218
        pop     eax
202
        pop     eax
219
        add     al, '0'
203
        add     al, '0'
220
        stosb
204
        stosb
221
        test    bl, 1           ; UNICODE name?
205
        test    bl, 1           ; UNICODE name?
222
        jz      .ansi2
206
        jz      .ansi2
223
        mov     byte [edi], 0
207
        mov     byte [edi], 0
224
        inc     edi
208
        inc     edi
225
.ansi2:
209
.ansi2:
226
        test    al, al
210
        test    al, al
227
        jnz     @b
211
        jnz     @b
228
        mov     byte [edi-1], 0
212
        mov     byte [edi-1], 0
229
        pop     ecx
213
        pop     ecx
230
        pop     edi
214
        pop     edi
231
; UNICODE name length is 520 bytes, ANSI - 264
215
; UNICODE name length is 520 bytes, ANSI - 264
232
        add     edi, 520
216
        add     edi, 520
233
        test    bl, 1
217
        test    bl, 1
234
        jnz     @f
218
        jnz     @f
235
        sub     edi, 520-264
219
        sub     edi, 520-264
236
@@:
220
@@:
237
        pop     edx eax
221
        pop     edx eax
238
        jmp     .maindir_loop
222
        jmp     .maindir_loop
239
.maindir_done:
223
.maindir_done:
240
        pop     eax
224
        pop     eax
241
        mov     ebx, [edx+4]
225
        mov     ebx, [edx+4]
242
        xor     eax, eax
226
        xor     eax, eax
243
        dec     ebp
227
        dec     ebp
244
        js      @f
228
        js      @f
245
        mov     al, ERROR_END_OF_FILE
229
        mov     al, ERROR_END_OF_FILE
246
@@:
230
@@:
247
        mov     [image_of_eax], eax
231
        mov     [image_of_eax], eax
248
        mov     [image_of_ebx], ebx
232
        mov     [image_of_ebx], ebx
249
        ret
233
        ret
250
; directory /
234
; directory /
251
.rootdir:
235
.rootdir:
252
        cmp     dword [ebx], 1  ; read folder?
236
        cmp     dword [ebx], 1  ; read folder?
253
        jz      .readroot
237
        jz      .readroot
254
.access_denied:
238
.access_denied:
255
        mov     dword [image_of_eax], 10      ; access denied
239
        mov     dword [image_of_eax], 10      ; access denied
256
        ret
240
        ret
257
 
241
 
258
.readroot:
242
.readroot:
259
; virtual root folder - special handler
243
; virtual root folder - special handler
260
        mov     esi, virtual_root_query
244
        mov     esi, virtual_root_query
261
        mov     ebp, [ebx+12]
245
        mov     ebp, [ebx+12]
262
        mov     edx, [ebx+16]
246
        mov     edx, [ebx+16]
263
    ;    add     edx, std_application_base_address
247
    ;    add     edx, std_application_base_address
264
        push    dword [ebx+4]   ; first block
248
        push    dword [ebx+4]   ; first block
265
        mov     ebx, [ebx+8]    ; flags
249
        mov     ebx, [ebx+8]    ; flags
266
        xor     eax, eax
250
        xor     eax, eax
267
; eax=0, [esp]=first block, ebx=flags, ebp=number of blocks, edx=return area
251
; eax=0, [esp]=first block, ebx=flags, ebp=number of blocks, edx=return area
268
        mov     edi, edx
252
        mov     edi, edx
269
        mov     ecx, 32/4
253
        mov     ecx, 32/4
270
        rep stosd
254
        rep stosd
271
        mov     byte [edx], 1   ; version
255
        mov     byte [edx], 1   ; version
272
.readroot_loop:
256
.readroot_loop:
273
        cmp     dword [esi], eax
257
        cmp     dword [esi], eax
274
        jz      .readroot_done_static
258
        jz      .readroot_done_static
275
        call    dword [esi]
259
        call    dword [esi]
276
        add     esi, 4
260
        add     esi, 4
277
        test    eax, eax
261
        test    eax, eax
278
        jnz     @f
262
        jnz     @f
279
.readroot_next:
263
.readroot_next:
280
        or      ecx, -1
264
        or      ecx, -1
281
        xchg    esi, edi
265
        xchg    esi, edi
282
        repnz scasb
266
        repnz scasb
283
        xchg    esi, edi
267
        xchg    esi, edi
284
        jmp     .readroot_loop
268
        jmp     .readroot_loop
285
@@:
269
@@:
286
        xor     eax, eax
270
        xor     eax, eax
287
        inc     dword [edx+8]
271
        inc     dword [edx+8]
288
        dec     dword [esp]
272
        dec     dword [esp]
289
        jns     .readroot_next
273
        jns     .readroot_next
290
        dec     ebp
274
        dec     ebp
291
        js      .readroot_next
275
        js      .readroot_next
292
        inc     dword [edx+4]
276
        inc     dword [edx+4]
293
        mov     dword [edi], 0x10       ; attributes: folder
277
        mov     dword [edi], 0x10       ; attributes: folder
294
        mov     dword [edi+4], ebx      ; name type: UNICODE
278
        mov     dword [edi+4], ebx      ; name type: UNICODE
295
        add     edi, 8
279
        add     edi, 8
296
        mov     ecx, 40/4-2
280
        mov     ecx, 40/4-2
297
        rep stosd
281
        rep stosd
298
        push    edi
282
        push    edi
299
@@:
283
@@:
300
        lodsb
284
        lodsb
301
        stosb
285
        stosb
302
        test    bl, 1
286
        test    bl, 1
303
        jz      .ansi
287
        jz      .ansi
304
        mov     byte [edi], 0
288
        mov     byte [edi], 0
305
        inc     edi
289
        inc     edi
306
.ansi:
290
.ansi:
307
        test    eax, eax
291
        test    eax, eax
308
        jnz     @b
292
        jnz     @b
309
        pop     edi
293
        pop     edi
310
        add     edi, 520
294
        add     edi, 520
311
        test    bl, 1
295
        test    bl, 1
312
        jnz     .readroot_loop
296
        jnz     .readroot_loop
313
        sub     edi, 520-264
297
        sub     edi, 520-264
314
        jmp     .readroot_loop
298
        jmp     .readroot_loop
315
.readroot_done_static:
299
.readroot_done_static:
316
        mov     esi, fs_additional_handlers-8
300
        mov     esi, fs_additional_handlers-8
317
        sub     esp, 16
301
        sub     esp, 16
318
.readroot_ah_loop:
302
.readroot_ah_loop:
319
        add     esi, 8
303
        add     esi, 8
320
        cmp     dword [esi], 0
304
        cmp     dword [esi], 0
321
        jz      .readroot_done
305
        jz      .readroot_done
322
        xor     eax, eax
306
        xor     eax, eax
323
.readroot_ah_loop2:
307
.readroot_ah_loop2:
324
        push    edi
308
        push    edi
325
        lea     edi, [esp+4]
309
        lea     edi, [esp+4]
326
        call    dword [esi+4]
310
        call    dword [esi+4]
327
        pop     edi
311
        pop     edi
328
        test    eax, eax
312
        test    eax, eax
329
        jz      .readroot_ah_loop
313
        jz      .readroot_ah_loop
330
        inc     dword [edx+8]
314
        inc     dword [edx+8]
331
        dec     dword [esp+16]
315
        dec     dword [esp+16]
332
        jns     .readroot_ah_loop2
316
        jns     .readroot_ah_loop2
333
        dec     ebp
317
        dec     ebp
334
        js      .readroot_ah_loop2
318
        js      .readroot_ah_loop2
335
        push    eax
319
        push    eax
336
        xor     eax, eax
320
        xor     eax, eax
337
        inc     dword [edx+4]
321
        inc     dword [edx+4]
338
        mov     dword [edi], 0x10       ; attributes: folder
322
        mov     dword [edi], 0x10       ; attributes: folder
339
        mov     dword [edi+4], ebx
323
        mov     dword [edi+4], ebx
340
        add     edi, 8
324
        add     edi, 8
341
        mov     ecx, 40/4-2
325
        mov     ecx, 40/4-2
342
        rep stosd
326
        rep stosd
343
        push    esi edi
327
        push    esi edi
344
        lea     esi, [esp+12]
328
        lea     esi, [esp+12]
345
@@:
329
@@:
346
        lodsb
330
        lodsb
347
        stosb
331
        stosb
348
        test    bl, 1
332
        test    bl, 1
349
        jz      .ansi3
333
        jz      .ansi3
350
        mov     byte [edi], 0
334
        mov     byte [edi], 0
351
        inc     edi
335
        inc     edi
352
.ansi3:
336
.ansi3:
353
        test    al, al
337
        test    al, al
354
        jnz     @b
338
        jnz     @b
355
        pop     edi esi eax
339
        pop     edi esi eax
356
        add     edi, 520
340
        add     edi, 520
357
        test    bl, 1
341
        test    bl, 1
358
        jnz     .readroot_ah_loop2
342
        jnz     .readroot_ah_loop2
359
        sub     edi, 520-264
343
        sub     edi, 520-264
360
        jmp     .readroot_ah_loop2
344
        jmp     .readroot_ah_loop2
361
.readroot_done:
345
.readroot_done:
362
        add     esp, 16
346
        add     esp, 16
363
        pop     eax
347
        pop     eax
364
        mov     ebx, [edx+4]
348
        mov     ebx, [edx+4]
365
        xor     eax, eax
349
        xor     eax, eax
366
        dec     ebp
350
        dec     ebp
367
        js      @f
351
        js      @f
368
        mov     al, ERROR_END_OF_FILE
352
        mov     al, ERROR_END_OF_FILE
369
@@:
353
@@:
370
        mov     [image_of_eax], eax
354
        mov     [image_of_eax], eax
371
        mov     [image_of_ebx], ebx
355
        mov     [image_of_ebx], ebx
372
        ret
356
        ret
373
.notfound_try:
357
.notfound_try:
374
        mov     edi, fs_additional_handlers
358
        mov     edi, fs_additional_handlers
375
@@:
359
@@:
376
        cmp     dword [edi], 0
360
        cmp     dword [edi], 0
377
        jz      .notfound
361
        jz      .notfound
378
        call    dword [edi]
362
        call    dword [edi]
379
        scasd
363
        scasd
380
        scasd
364
        scasd
381
        jmp     @b
365
        jmp     @b
382
.notfound:
366
.notfound:
383
        mov     dword [image_of_eax], ERROR_FILE_NOT_FOUND
367
        mov     dword [image_of_eax], ERROR_FILE_NOT_FOUND
384
        and     dword [image_of_ebx], 0
368
        and     dword [image_of_ebx], 0
385
        ret
369
        ret
386
 
370
 
387
.notfounda:
371
.notfounda:
388
        cmp     edi, esp
372
        cmp     edi, esp
389
        jnz     .notfound
373
        jnz     .notfound
390
        call    dword [edi+4]
374
        call    dword [edi+4]
391
        add     esp, 16
375
        add     esp, 16
392
        jmp     .notfound
376
        jmp     .notfound
393
 
377
 
394
.found1:
378
.found1:
395
        pop     eax
379
        pop     eax
396
        cmp     byte [esi], 0
380
        cmp     byte [esi], 0
397
        jz      .maindir
381
        jz      .maindir
398
.found2:
382
.found2:
399
; read partition number
383
; read partition number
400
        xor     ecx, ecx
384
        xor     ecx, ecx
401
        xor     eax, eax
385
        xor     eax, eax
402
@@:
386
@@:
403
        lodsb
387
        lodsb
404
        cmp     al, '/'
388
        cmp     al, '/'
405
        jz      .done1
389
        jz      .done1
406
        test    al, al
390
        test    al, al
407
        jz      .done1
391
        jz      .done1
408
        sub     al, '0'
392
        sub     al, '0'
409
        cmp     al, 9
393
        cmp     al, 9
410
        ja      .notfounda
394
        ja      .notfounda
411
        lea     ecx, [ecx*5]
395
        lea     ecx, [ecx*5]
412
        lea     ecx, [ecx*2+eax]
396
        lea     ecx, [ecx*2+eax]
413
        jmp     @b
397
        jmp     @b
414
.done1:
398
.done1:
415
        jecxz   .notfounda
399
        jecxz   .notfounda
416
        test    al, al
400
        test    al, al
417
        jnz     @f
401
        jnz     @f
418
        dec     esi
402
        dec     esi
419
@@:
403
@@:
420
        cmp     byte [esi], 0
404
        cmp     byte [esi], 0
421
        jnz     @f
405
        jnz     @f
422
        test    ebp, ebp
406
        test    ebp, ebp
423
        jz      @f
407
        jz      @f
424
        mov     esi, ebp
408
        mov     esi, ebp
425
        xor     ebp, ebp
409
        xor     ebp, ebp
426
@@:
410
@@:
427
; now [edi] contains handler address, ecx - partition number,
411
; now [edi] contains handler address, ecx - partition number,
428
; esi points to ASCIIZ string - rest of name
412
; esi points to ASCIIZ string - rest of name
429
        jmp     dword [edi]
413
        jmp     dword [edi]
430
 
414
 
431
; handlers for devices
415
; handlers for devices
432
; in: ecx = 0 => query virtual directory /xxx
416
; in: ecx = 0 => query virtual directory /xxx
433
; in: ecx = partition number
417
; in: ecx = partition number
434
;     esi -> relative (for device) name
418
;     esi -> relative (for device) name
435
;     ebx -> fileinfo
419
;     ebx -> fileinfo
436
;     ebp = 0 or pointer to rest of name from folder addressed by esi
420
;     ebp = 0 or pointer to rest of name from folder addressed by esi
437
; out: [image_of_eax]=image of eax, [image_of_ebx]=image of ebx
421
; out: [image_of_eax]=image of eax, [image_of_ebx]=image of ebx
438
 
-
 
439
fs_OnRamdisk:
-
 
440
        cmp     ecx, 1
-
 
441
        jnz     file_system_lfn.notfound
-
 
442
        mov     eax, [ebx]
-
 
443
        cmp     eax, fs_NumRamdiskServices
-
 
444
        jae     .not_impl
-
 
445
        mov     ecx, [ebx+12]
-
 
446
        mov     edx, [ebx+16]
-
 
447
   ;     add     edx, std_application_base_address
-
 
448
        add     ebx, 4
-
 
449
        call    dword [fs_RamdiskServices + eax*4]
-
 
450
        mov     [image_of_eax], eax
-
 
451
        mov     [image_of_ebx], ebx
-
 
452
        ret
-
 
453
.not_impl:
-
 
454
        mov     dword [image_of_eax], 2       ; not implemented
-
 
455
        ret
-
 
456
 
422
 
457
fs_NotImplemented:
423
fs_NotImplemented:
458
        mov     eax, 2
424
        mov     eax, 2
459
        ret
425
        ret
460
 
-
 
461
fs_RamdiskServices:
-
 
462
        dd      fs_RamdiskRead
-
 
463
        dd      fs_RamdiskReadFolder
-
 
464
        dd      fs_RamdiskRewrite
-
 
465
        dd      fs_RamdiskWrite
-
 
466
        dd      fs_RamdiskSetFileEnd
-
 
467
        dd      fs_RamdiskGetFileInfo
-
 
468
        dd      fs_RamdiskSetFileInfo
-
 
469
        dd      0
-
 
470
        dd      fs_RamdiskDelete
-
 
471
        dd      fs_RamdiskCreateFolder
-
 
472
fs_NumRamdiskServices = ($ - fs_RamdiskServices)/4
-
 
473
 
-
 
474
fs_OnFloppy:
-
 
475
        cmp     ecx, 2
-
 
476
        ja      file_system_lfn.notfound
-
 
477
        mov     eax, [ebx]
-
 
478
        cmp     eax, fs_NumFloppyServices
-
 
479
        jae     fs_OnRamdisk.not_impl
-
 
480
        call    reserve_flp
-
 
481
        mov     [flp_number], cl
-
 
482
        mov     ecx, [ebx+12]
-
 
483
        mov     edx, [ebx+16]
-
 
484
   ;     add     edx, std_application_base_address
-
 
485
        add     ebx, 4
-
 
486
        call    dword [fs_FloppyServices + eax*4]
-
 
487
        and     [flp_status], 0
-
 
488
        mov     [image_of_eax], eax
-
 
489
        mov     [image_of_ebx], ebx
-
 
490
        ret
-
 
491
 
-
 
492
fs_FloppyServices:
-
 
493
        dd      fs_FloppyRead
-
 
494
        dd      fs_FloppyReadFolder
-
 
495
        dd      fs_FloppyRewrite
-
 
496
        dd      fs_FloppyWrite
-
 
497
        dd      fs_FloppySetFileEnd
-
 
498
        dd      fs_FloppyGetFileInfo
-
 
499
        dd      fs_FloppySetFileInfo
-
 
500
        dd      0
-
 
501
        dd      fs_FloppyDelete
-
 
502
        dd      fs_FloppyCreateFolder
-
 
503
fs_NumFloppyServices = ($ - fs_FloppyServices)/4
-
 
504
 
426
 
505
;*******************************************************
427
;*******************************************************
506
fs_OnCd0:
428
fs_OnCd0:
507
        call    reserve_cd
429
        call    reserve_cd
508
        mov     [ChannelNumber], 1
430
        mov     [ChannelNumber], 1
509
        mov     [DiskNumber], 0
431
        mov     [DiskNumber], 0
510
        push    6
432
        push    6
511
        push    1
433
        push    1
512
        jmp     fs_OnCd
434
        jmp     fs_OnCd
513
fs_OnCd1:
435
fs_OnCd1:
514
        call    reserve_cd
436
        call    reserve_cd
515
        mov     [ChannelNumber], 1
437
        mov     [ChannelNumber], 1
516
        mov     [DiskNumber], 1
438
        mov     [DiskNumber], 1
517
        push    4
439
        push    4
518
        push    2
440
        push    2
519
        jmp     fs_OnCd
441
        jmp     fs_OnCd
520
fs_OnCd2:
442
fs_OnCd2:
521
        call    reserve_cd
443
        call    reserve_cd
522
        mov     [ChannelNumber], 2
444
        mov     [ChannelNumber], 2
523
        mov     [DiskNumber], 0
445
        mov     [DiskNumber], 0
524
        push    2
446
        push    2
525
        push    3
447
        push    3
526
        jmp     fs_OnCd
448
        jmp     fs_OnCd
527
fs_OnCd3:
449
fs_OnCd3:
528
        call    reserve_cd
450
        call    reserve_cd
529
        mov     [ChannelNumber], 2
451
        mov     [ChannelNumber], 2
530
        mov     [DiskNumber], 1
452
        mov     [DiskNumber], 1
531
        push    0
453
        push    0
532
        push    4
454
        push    4
533
fs_OnCd:
455
fs_OnCd:
534
        call    reserve_cd_channel
456
        call    reserve_cd_channel
535
        pop     eax
457
        pop     eax
536
        mov     [cdpos], eax
458
        mov     [cdpos], eax
537
        pop     eax
459
        pop     eax
538
        cmp     ecx, 0x100
460
        cmp     ecx, 0x100
539
        jae     .nf
461
        jae     .nf
540
        push    ecx ebx
462
        push    ecx ebx
541
        mov     cl, al
463
        mov     cl, al
542
        mov     bl, [DRIVE_DATA+1]
464
        mov     bl, [DRIVE_DATA+1]
543
        shr     bl, cl
465
        shr     bl, cl
544
        test    bl, 2
466
        test    bl, 2
545
        pop     ebx ecx
467
        pop     ebx ecx
546
 
468
 
547
        jnz     @f
469
        jnz     @f
548
.nf:
470
.nf:
549
        call    free_cd_channel
471
        call    free_cd_channel
550
        and     [cd_status], 0
472
        and     [cd_status], 0
551
        mov     dword [image_of_eax], 5       ; not found
473
        mov     dword [image_of_eax], 5       ; not found
552
        ret
474
        ret
553
@@:
475
@@:
554
        mov     ecx, [ebx+12]
476
        mov     ecx, [ebx+12]
555
        mov     edx, [ebx+16]
477
        mov     edx, [ebx+16]
556
    ;    add     edx, std_application_base_address
478
    ;    add     edx, std_application_base_address
557
        mov     eax, [ebx]
479
        mov     eax, [ebx]
558
        cmp     eax, fs_NumCdServices
480
        cmp     eax, fs_NumCdServices
559
        jae     .not_impl
481
        jae     .not_impl
560
        add     ebx, 4
482
        add     ebx, 4
561
        call    dword [fs_CdServices + eax*4]
483
        call    dword [fs_CdServices + eax*4]
562
        call    free_cd_channel
484
        call    free_cd_channel
563
        and     [cd_status], 0
485
        and     [cd_status], 0
564
        mov     [image_of_eax], eax
486
        mov     [image_of_eax], eax
565
        mov     [image_of_ebx], ebx
487
        mov     [image_of_ebx], ebx
566
        ret
488
        ret
567
.not_impl:
489
.not_impl:
568
        call    free_cd_channel
490
        call    free_cd_channel
569
        and     [cd_status], 0
491
        and     [cd_status], 0
570
        mov     dword [image_of_eax], 2       ; not implemented
492
        mov     dword [image_of_eax], 2       ; not implemented
571
        ret
493
        ret
572
 
494
 
573
fs_CdServices:
495
fs_CdServices:
574
        dd      fs_CdRead
496
        dd      fs_CdRead
575
        dd      fs_CdReadFolder
497
        dd      fs_CdReadFolder
576
        dd      fs_NotImplemented
498
        dd      fs_NotImplemented
577
        dd      fs_NotImplemented
499
        dd      fs_NotImplemented
578
        dd      fs_NotImplemented
500
        dd      fs_NotImplemented
579
        dd      fs_CdGetFileInfo
501
        dd      fs_CdGetFileInfo
580
        dd      fs_NotImplemented
502
        dd      fs_NotImplemented
581
        dd      0
503
        dd      0
582
        dd      fs_NotImplemented
504
        dd      fs_NotImplemented
583
        dd      fs_NotImplemented
505
        dd      fs_NotImplemented
584
fs_NumCdServices = ($ - fs_CdServices)/4
506
fs_NumCdServices = ($ - fs_CdServices)/4
585
 
507
 
586
;*******************************************************
508
;*******************************************************
587
 
-
 
588
fs_HasRamdisk:
-
 
589
        mov     al, 1   ; we always have ramdisk
-
 
590
        ret
-
 
591
fs_HasFloppy:
-
 
592
        cmp     byte [DRIVE_DATA], 0
-
 
593
        setnz   al
-
 
594
        ret
-
 
595
 
-
 
596
;*******************************************************
-
 
597
fs_HasCd0:
509
fs_HasCd0:
598
        test    byte [DRIVE_DATA+1], 10000000b
510
        test    byte [DRIVE_DATA+1], 10000000b
599
        setnz   al
511
        setnz   al
600
        ret
512
        ret
601
fs_HasCd1:
513
fs_HasCd1:
602
        test    byte [DRIVE_DATA+1], 00100000b
514
        test    byte [DRIVE_DATA+1], 00100000b
603
        setnz   al
515
        setnz   al
604
        ret
516
        ret
605
fs_HasCd2:
517
fs_HasCd2:
606
        test    byte [DRIVE_DATA+1], 00001000b
518
        test    byte [DRIVE_DATA+1], 00001000b
607
        setnz   al
519
        setnz   al
608
        ret
520
        ret
609
fs_HasCd3:
521
fs_HasCd3:
610
        test    byte [DRIVE_DATA+1], 00000010b
522
        test    byte [DRIVE_DATA+1], 00000010b
611
        setnz   al
523
        setnz   al
612
        ret
524
        ret
613
;*******************************************************
525
;*******************************************************
614
 
526
 
615
; fs_NextXXX functions:
527
; fs_NextXXX functions:
616
; in: eax = partition number, from which start to scan
528
; in: eax = partition number, from which start to scan
617
; out: CF=1 => no more partitions
529
; out: CF=1 => no more partitions
618
;      CF=0 => eax=next partition number
530
;      CF=0 => eax=next partition number
619
 
-
 
620
fs_NextRamdisk:
-
 
621
; we always have /rd/1
-
 
622
        test    eax, eax
-
 
623
        stc
-
 
624
        jnz     @f
-
 
625
        mov     al, 1
-
 
626
        clc
-
 
627
@@:
-
 
628
        ret
-
 
629
 
-
 
630
fs_NextFloppy:
-
 
631
; we have /fd/1 iff (([DRIVE_DATA] and 0xF0) != 0) and /fd/2 iff (([DRIVE_DATA] and 0x0F) != 0)
-
 
632
        test    byte [DRIVE_DATA], 0xF0
-
 
633
        jz      .no1
-
 
634
        test    eax, eax
-
 
635
        jnz     .no1
-
 
636
        inc     eax
-
 
637
        ret     ; CF cleared
-
 
638
.no1:
-
 
639
        test    byte [DRIVE_DATA], 0x0F
-
 
640
        jz      .no2
-
 
641
        cmp     al, 2
-
 
642
        jae     .no2
-
 
643
        mov     al, 2
-
 
644
        clc
-
 
645
        ret
-
 
646
.no2:
-
 
647
        stc
-
 
648
        ret
-
 
649
 
531
 
650
;*******************************************************
532
;*******************************************************
651
fs_NextCd:
533
fs_NextCd:
652
; we always have /cdX/1
534
; we always have /cdX/1
653
        test    eax, eax
535
        test    eax, eax
654
        stc
536
        stc
655
        jnz     @f
537
        jnz     @f
656
        mov     al, 1
538
        mov     al, 1
657
        clc
539
        clc
658
@@:
540
@@:
659
        ret
541
        ret
660
;*******************************************************
542
;*******************************************************
661
 
543
 
662
;-----------------------------------------------------------------------------
544
;-----------------------------------------------------------------------------
663
process_replace_file_name:
545
process_replace_file_name:
664
; in
546
; in
665
; esi - path with filename(f.70)
547
; esi - path with filename(f.70)
666
;
548
;
667
; out
549
; out
668
; ebp - full filename
550
; ebp - full filename
669
        pushfd
551
        pushfd
670
        cli
552
        cli
671
        mov     ebp, [full_file_name_table]
553
        mov     ebp, [full_file_name_table]
672
        xor     edi, edi
554
        xor     edi, edi
673
.loop:
555
.loop:
674
        cmp     edi, [full_file_name_table.size]
556
        cmp     edi, [full_file_name_table.size]
675
        jae     .notfound
557
        jae     .notfound
676
        push    esi edi
558
        push    esi edi
677
        shl     edi, 7 ; edi*128
559
        shl     edi, 7 ; edi*128
678
        add     edi, ebp
560
        add     edi, ebp
679
@@:
561
@@:
680
        cmp     byte [edi], 0 ; end of dir_name
562
        cmp     byte [edi], 0 ; end of dir_name
681
        jz      .dest_done
563
        jz      .dest_done
682
        lodsb
564
        lodsb
683
        test    al, al
565
        test    al, al
684
        jz      .cont
566
        jz      .cont
685
        or      al, 20h ; 32 - space char
567
        or      al, 20h ; 32 - space char
686
        scasb
568
        scasb
687
        jz      @b
569
        jz      @b
688
        jmp     .cont
570
        jmp     .cont
689
.dest_done:
571
.dest_done:
690
        cmp     byte [esi], 0
572
        cmp     byte [esi], 0
691
        jz      .found
573
        jz      .found
692
        cmp     byte [esi], '/'
574
        cmp     byte [esi], '/'
693
        jnz     .cont
575
        jnz     .cont
694
        inc     esi
576
        inc     esi
695
        jmp     .found
577
        jmp     .found
696
.cont:
578
.cont:
697
        pop     edi esi
579
        pop     edi esi
698
        inc     edi
580
        inc     edi
699
        jmp     .loop
581
        jmp     .loop
700
.found:
582
.found:
701
        pop     edi eax
583
        pop     edi eax
702
        shl     edi, 7 ; edi*128
584
        shl     edi, 7 ; edi*128
703
        add     edi, ebp
585
        add     edi, ebp
704
        mov     ebp, esi
586
        mov     ebp, esi
705
        cmp     byte [esi], 0
587
        cmp     byte [esi], 0
706
        lea     esi, [edi+64]
588
        lea     esi, [edi+64]
707
        jnz     .ret
589
        jnz     .ret
708
.notfound:
590
.notfound:
709
        xor     ebp, ebp
591
        xor     ebp, ebp
710
.ret:
592
.ret:
711
        popfd
593
        popfd
712
        ret
594
        ret
713
;-----------------------------------------------------------------------------
595
;-----------------------------------------------------------------------------
714
uglobal
596
uglobal
715
lock_flag_for_f30_3 rb 1
597
lock_flag_for_f30_3 rb 1
716
endg
598
endg
717
        
599
        
718
sys_current_directory:
600
sys_current_directory:
719
;       mov     esi, [current_slot]
601
;       mov     esi, [current_slot]
720
;       mov     esi, [esi+APPDATA.cur_dir]
602
;       mov     esi, [esi+APPDATA.cur_dir]
721
;       mov     edx, esi
603
;       mov     edx, esi
722
 
604
 
723
;get length string of appdata.cur_dir
605
;get length string of appdata.cur_dir
724
        mov     eax, [current_slot]
606
        mov     eax, [current_slot]
725
        mov     edi, [eax+APPDATA.cur_dir]
607
        mov     edi, [eax+APPDATA.cur_dir]
726
 
608
 
727
        dec     ebx
609
        dec     ebx
728
        jz      .set
610
        jz      .set
729
        dec     ebx
611
        dec     ebx
730
        jz      .get
612
        jz      .get
731
        dec     ebx
613
        dec     ebx
732
        jz      .mount_additional_directory
614
        jz      .mount_additional_directory
733
        ret
615
        ret
734
 
616
 
735
.mount_additional_directory:
617
.mount_additional_directory:
736
; sysfunction 30.2: [for app] eax=30,ebx=3,ecx->dir name+dir path (128)
618
; sysfunction 30.2: [for app] eax=30,ebx=3,ecx->dir name+dir path (128)
737
; for our code: nothing
619
; for our code: nothing
738
 
620
 
739
; check lock of the function
621
; check lock of the function
740
        cmp     [lock_flag_for_f30_3], 1
622
        cmp     [lock_flag_for_f30_3], 1
741
        je      @f
623
        je      @f
742
        
624
        
743
        mov     esi, ecx
625
        mov     esi, ecx
744
        mov     edi, sysdir_name1
626
        mov     edi, sysdir_name1
745
; copying fake directory name
627
; copying fake directory name
746
        mov     ecx, 63
628
        mov     ecx, 63
747
        pushfd
629
        pushfd
748
        cli
630
        cli
749
        cld
631
        cld
750
        rep movsb
632
        rep movsb
751
; terminator of name, in case if we get the inlet trash
633
; terminator of name, in case if we get the inlet trash
752
        inc     esi
634
        inc     esi
753
        xor     eax, eax
635
        xor     eax, eax
754
        stosb
636
        stosb
755
; copying real directory path for mounting
637
; copying real directory path for mounting
756
        mov     ecx, 63
638
        mov     ecx, 63
757
        rep movsb
639
        rep movsb
758
; terminator of name, in case if we get the inlet trash
640
; terminator of name, in case if we get the inlet trash
759
        xor     eax, eax
641
        xor     eax, eax
760
        stosb
642
        stosb
761
; increase the pointer of inputs for procedure "process_replace_file_name"        
643
; increase the pointer of inputs for procedure "process_replace_file_name"        
762
        mov     [full_file_name_table.size], 2
644
        mov     [full_file_name_table.size], 2
763
; block the ability to call f.30.3 because for one session is necessary
645
; block the ability to call f.30.3 because for one session is necessary
764
; for us only once
646
; for us only once
765
        mov     [lock_flag_for_f30_3], 1
647
        mov     [lock_flag_for_f30_3], 1
766
        popfd
648
        popfd
767
@@:
649
@@:
768
        ret
650
        ret
769
        
651
        
770
.get:
652
.get:
771
; sysfunction 30.2: [for app] eax=30,ebx=2,ecx->buffer,edx=len
653
; sysfunction 30.2: [for app] eax=30,ebx=2,ecx->buffer,edx=len
772
; for our code: ebx->buffer,ecx=len
654
; for our code: ebx->buffer,ecx=len
773
max_cur_dir     equ     0x1000
655
max_cur_dir     equ     0x1000
774
 
656
 
775
        mov     ebx, edi
657
        mov     ebx, edi
776
 
658
 
777
        push    ecx
659
        push    ecx
778
        push    edi
660
        push    edi
779
 
661
 
780
        xor     eax, eax
662
        xor     eax, eax
781
        mov     ecx, max_cur_dir
663
        mov     ecx, max_cur_dir
782
 
664
 
783
        repne scasb             ;find zerro at and string
665
        repne scasb             ;find zerro at and string
784
        jnz     .error          ; no zero in cur_dir: internal error, should not happen
666
        jnz     .error          ; no zero in cur_dir: internal error, should not happen
785
 
667
 
786
        sub     edi, ebx        ;lenght for copy
668
        sub     edi, ebx        ;lenght for copy
787
        inc     edi
669
        inc     edi
788
        mov     [esp+32+8], edi ;return in eax
670
        mov     [esp+32+8], edi ;return in eax
789
 
671
 
790
        cmp     edx, edi
672
        cmp     edx, edi
791
        jbe     @f
673
        jbe     @f
792
        mov     edx, edi
674
        mov     edx, edi
793
@@:
675
@@:
794
;source string
676
;source string
795
        pop     esi
677
        pop     esi
796
;destination string
678
;destination string
797
        pop     edi
679
        pop     edi
798
        cmp     edx, 1
680
        cmp     edx, 1
799
        jbe     .ret
681
        jbe     .ret
800
 
682
 
801
        mov     al, '/'         ;start string with '/'
683
        mov     al, '/'         ;start string with '/'
802
        stosb
684
        stosb
803
        mov     ecx, edx
685
        mov     ecx, edx
804
        rep movsb               ;copy string
686
        rep movsb               ;copy string
805
.ret:
687
.ret:
806
        ret
688
        ret
807
 
689
 
808
.error:
690
.error:
809
        add     esp, 8
691
        add     esp, 8
810
        or      dword [esp+32], -1      ;error not found zerro at string ->[eax+APPDATA.cur_dir]
692
        or      dword [esp+32], -1      ;error not found zerro at string ->[eax+APPDATA.cur_dir]
811
        ret
693
        ret
812
.set:
694
.set:
813
; sysfunction 30.1: [for app] eax=30,ebx=1,ecx->string
695
; sysfunction 30.1: [for app] eax=30,ebx=1,ecx->string
814
; for our code: ebx->string to set
696
; for our code: ebx->string to set
815
; use generic resolver with APPDATA.cur_dir as destination
697
; use generic resolver with APPDATA.cur_dir as destination
816
        push    max_cur_dir     ;0x1000
698
        push    max_cur_dir     ;0x1000
817
        push    edi     ;destination
699
        push    edi     ;destination
818
        mov     ebx, ecx
700
        mov     ebx, ecx
819
        call    get_full_file_name
701
        call    get_full_file_name
820
        ret
702
        ret
821
 
703
 
822
; in: ebx = file name, [esp+4] = destination, [esp+8] = sizeof destination
704
; in: ebx = file name, [esp+4] = destination, [esp+8] = sizeof destination
823
; destroys all registers except ebp,esp
705
; destroys all registers except ebp,esp
824
get_full_file_name:
706
get_full_file_name:
825
        push    ebp
707
        push    ebp
826
        mov     esi, [current_slot]
708
        mov     esi, [current_slot]
827
        mov     esi, [esi+APPDATA.cur_dir]
709
        mov     esi, [esi+APPDATA.cur_dir]
828
        mov     edx, esi
710
        mov     edx, esi
829
@@:
711
@@:
830
        inc     esi
712
        inc     esi
831
        cmp     byte [esi-1], 0
713
        cmp     byte [esi-1], 0
832
        jnz     @b
714
        jnz     @b
833
        dec     esi
715
        dec     esi
834
        cmp     byte [ebx], '/'
716
        cmp     byte [ebx], '/'
835
        jz      .set_absolute
717
        jz      .set_absolute
836
; string gives relative path
718
; string gives relative path
837
        mov     edi, [esp+8]    ; destination
719
        mov     edi, [esp+8]    ; destination
838
.relative:
720
.relative:
839
        cmp     byte [ebx], 0
721
        cmp     byte [ebx], 0
840
        jz      .set_ok
722
        jz      .set_ok
841
        cmp     word [ebx], '.'
723
        cmp     word [ebx], '.'
842
        jz      .set_ok
724
        jz      .set_ok
843
        cmp     word [ebx], './'
725
        cmp     word [ebx], './'
844
        jnz     @f
726
        jnz     @f
845
        add     ebx, 2
727
        add     ebx, 2
846
        jmp     .relative
728
        jmp     .relative
847
@@:
729
@@:
848
        cmp     word [ebx], '..'
730
        cmp     word [ebx], '..'
849
        jnz     .doset_relative
731
        jnz     .doset_relative
850
        cmp     byte [ebx+2], 0
732
        cmp     byte [ebx+2], 0
851
        jz      @f
733
        jz      @f
852
        cmp     byte [ebx+2], '/'
734
        cmp     byte [ebx+2], '/'
853
        jnz     .doset_relative
735
        jnz     .doset_relative
854
@@:
736
@@:
855
        dec     esi
737
        dec     esi
856
        cmp     byte [esi], '/'
738
        cmp     byte [esi], '/'
857
        jnz     @b
739
        jnz     @b
858
        add     ebx, 3
740
        add     ebx, 3
859
        jmp     .relative
741
        jmp     .relative
860
.set_ok:
742
.set_ok:
861
        cmp     edx, edi        ; is destination equal to APPDATA.cur_dir?
743
        cmp     edx, edi        ; is destination equal to APPDATA.cur_dir?
862
        jz      .set_ok.cur_dir
744
        jz      .set_ok.cur_dir
863
        sub     esi, edx
745
        sub     esi, edx
864
        cmp     esi, [esp+12]
746
        cmp     esi, [esp+12]
865
        jb      .set_ok.copy
747
        jb      .set_ok.copy
866
.fail:
748
.fail:
867
        mov     byte [edi], 0
749
        mov     byte [edi], 0
868
        xor     eax, eax        ; fail
750
        xor     eax, eax        ; fail
869
        pop     ebp
751
        pop     ebp
870
        ret     8
752
        ret     8
871
.set_ok.copy:
753
.set_ok.copy:
872
        mov     ecx, esi
754
        mov     ecx, esi
873
        mov     esi, edx
755
        mov     esi, edx
874
        rep movsb
756
        rep movsb
875
        mov     byte [edi], 0
757
        mov     byte [edi], 0
876
.ret.ok:
758
.ret.ok:
877
        mov     al, 1   ; ok
759
        mov     al, 1   ; ok
878
        pop     ebp
760
        pop     ebp
879
        ret     8
761
        ret     8
880
.set_ok.cur_dir:
762
.set_ok.cur_dir:
881
        mov     byte [esi], 0
763
        mov     byte [esi], 0
882
        jmp     .ret.ok
764
        jmp     .ret.ok
883
.doset_relative:
765
.doset_relative:
884
        cmp     edx, edi
766
        cmp     edx, edi
885
        jz      .doset_relative.cur_dir
767
        jz      .doset_relative.cur_dir
886
        sub     esi, edx
768
        sub     esi, edx
887
        cmp     esi, [esp+12]
769
        cmp     esi, [esp+12]
888
        jae     .fail
770
        jae     .fail
889
        mov     ecx, esi
771
        mov     ecx, esi
890
        mov     esi, edx
772
        mov     esi, edx
891
        mov     edx, edi
773
        mov     edx, edi
892
        rep movsb
774
        rep movsb
893
        jmp     .doset_relative.copy
775
        jmp     .doset_relative.copy
894
.doset_relative.cur_dir:
776
.doset_relative.cur_dir:
895
        mov     edi, esi
777
        mov     edi, esi
896
.doset_relative.copy:
778
.doset_relative.copy:
897
        add     edx, [esp+12]
779
        add     edx, [esp+12]
898
        mov     byte [edi], '/'
780
        mov     byte [edi], '/'
899
        inc     edi
781
        inc     edi
900
        cmp     edi, edx
782
        cmp     edi, edx
901
        jae     .overflow
783
        jae     .overflow
902
@@:
784
@@:
903
        mov     al, [ebx]
785
        mov     al, [ebx]
904
        inc     ebx
786
        inc     ebx
905
        stosb
787
        stosb
906
        test    al, al
788
        test    al, al
907
        jz      .ret.ok
789
        jz      .ret.ok
908
        cmp     edi, edx
790
        cmp     edi, edx
909
        jb      @b
791
        jb      @b
910
.overflow:
792
.overflow:
911
        dec     edi
793
        dec     edi
912
        jmp     .fail
794
        jmp     .fail
913
.set_absolute:
795
.set_absolute:
914
        lea     esi, [ebx+1]
796
        lea     esi, [ebx+1]
915
        call    process_replace_file_name
797
        call    process_replace_file_name
916
        mov     edi, [esp+8]
798
        mov     edi, [esp+8]
917
        mov     edx, [esp+12]
799
        mov     edx, [esp+12]
918
        add     edx, edi
800
        add     edx, edi
919
.set_copy:
801
.set_copy:
920
        lodsb
802
        lodsb
921
        stosb
803
        stosb
922
        test    al, al
804
        test    al, al
923
        jz      .set_part2
805
        jz      .set_part2
924
.set_copy_cont:
806
.set_copy_cont:
925
        cmp     edi, edx
807
        cmp     edi, edx
926
        jb      .set_copy
808
        jb      .set_copy
927
        jmp     .overflow
809
        jmp     .overflow
928
.set_part2:
810
.set_part2:
929
        mov     esi, ebp
811
        mov     esi, ebp
930
        xor     ebp, ebp
812
        xor     ebp, ebp
931
        test    esi, esi
813
        test    esi, esi
932
        jz      .ret.ok
814
        jz      .ret.ok
933
        mov     byte [edi-1], '/'
815
        mov     byte [edi-1], '/'
934
        jmp     .set_copy_cont
816
        jmp     .set_copy_cont