Rev 10016 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2288 | clevermous | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
10051 | ace_dent | 3 | ;; Copyright (C) KolibriOS team 2004-2024. All rights reserved. ;; |
6462 | pathoswith | 4 | ;; Distributed under terms of the GNU General Public License. ;; |
2288 | clevermous | 5 | ;; ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
7 | |||
8 | |||
2889 | turbanoff | 9 | ERROR_SUCCESS = 0 |
10 | ERROR_DISK_BASE = 1 |
||
11 | ERROR_UNSUPPORTED_FS = 2 |
||
12 | ERROR_UNKNOWN_FS = 3 |
||
13 | ERROR_PARTITION = 4 |
||
14 | ERROR_FILE_NOT_FOUND = 5 |
||
15 | ERROR_END_OF_FILE = 6 |
||
16 | ERROR_MEMORY_POINTER = 7 |
||
17 | ERROR_DISK_FULL = 8 |
||
18 | ERROR_FS_FAIL = 9 |
||
19 | ERROR_ACCESS_DENIED = 10 |
||
20 | ERROR_DEVICE = 11 |
||
2288 | clevermous | 21 | |
6468 | pathoswith | 22 | maxPathLength = 1000h |
23 | |||
2288 | clevermous | 24 | image_of_eax EQU esp+32 |
25 | image_of_ebx EQU esp+20 |
||
26 | |||
9894 | Doczom | 27 | ; fs api for drivers |
28 | struct FileSystem |
||
29 | Next dd ? |
||
30 | Prev dd ? |
||
31 | Creat_part dd ? ; %FSNAME%_create_partition |
||
32 | UserFuncs dd ? ; for fs_del |
||
33 | Name rd 16 ;ascii string + \n |
||
34 | ends |
||
35 | |||
36 | |||
37 | fs_list: |
||
38 | dd fs_list |
||
39 | dd fs_list |
||
40 | ;.look: dd 0 |
||
41 | |||
42 | ; IN: ecx = %FSNAME%_create_partition |
||
43 | ; edx = ptr to UserFuncs |
||
44 | ; [esp] = fs name |
||
45 | ;OUT: eax = list item |
||
46 | fs_add: |
||
47 | push ecx edx |
||
48 | ; add in fs_list |
||
49 | mov eax, sizeof.FileSystem |
||
50 | call malloc |
||
51 | pop edx ecx |
||
52 | test eax, eax |
||
53 | jz .err |
||
54 | |||
55 | mov [eax + FileSystem.Creat_part], ecx |
||
56 | mov [eax + FileSystem.UserFuncs], edx |
||
57 | mov edx, [esp + 4] |
||
58 | mov [eax + FileSystem.Name], edx |
||
59 | mov edx, eax |
||
60 | |||
61 | cli ; DELETE |
||
62 | list_add_tail edx, fs_list |
||
63 | sti ; DELETE |
||
64 | mov edx, ecx ; save function |
||
65 | |||
66 | ;DEBUGF 1, 'K : FS: find partition\n' |
||
67 | ; check all disks |
||
68 | mov esi, [disk_list] |
||
69 | .new_disk: |
||
70 | cmp dword[esi], disk_list |
||
71 | jz .end |
||
72 | |||
73 | push edx |
||
74 | mov eax, [esi + DISK.MediaInfo.SectorSize] |
||
75 | shl eax, 2 |
||
76 | stdcall kernel_alloc, eax ;get buffer |
||
77 | test eax, eax |
||
78 | pop edx |
||
79 | jz .end ; no memory |
||
80 | mov ebx, eax |
||
81 | |||
82 | mov ecx, [esi + DISK.NumPartitions] |
||
83 | dec ecx |
||
84 | shl ecx, 2 ; to dword |
||
85 | add ecx, [esi + DISK.Partitions] |
||
86 | @@: |
||
87 | mov ebp, [ecx] |
||
88 | cmp [ebp + PARTITION.FSUserFunctions], default_fs_functions |
||
89 | jnz .no_fs |
||
90 | |||
91 | ;DEBUGF 1, 'K : FS: found partition\n' |
||
92 | push ecx edx |
||
93 | |||
94 | xor eax, eax ; first sector of the partition |
||
95 | call fs_read32_sys |
||
96 | push eax |
||
97 | ;DEBUGF 1, 'K : FS: call driver func = %x\n', edx |
||
98 | |||
99 | call edx ; creat_partition |
||
100 | add esp, 4 |
||
101 | ;DEBUGF 1, 'K : FS: end call\n' |
||
102 | pop edx ecx |
||
103 | |||
104 | test eax, eax |
||
105 | jz .no_fs |
||
106 | ; save and delete old struct |
||
107 | xchg [ecx], eax |
||
108 | push ecx edx |
||
109 | call free |
||
110 | pop edx ecx |
||
111 | ;DEBUGF 1, 'K : FS: set fs for partition\n' |
||
112 | .no_fs: |
||
113 | ;sub ecx, 4 |
||
114 | cmp ecx, [esi + DISK.Partitions] |
||
115 | lea ecx, [ecx - 4] |
||
116 | jnz @b |
||
117 | |||
118 | push edx |
||
119 | stdcall kernel_free, ebx |
||
120 | pop edx |
||
121 | |||
122 | mov esi, [esi] |
||
123 | jmp .new_disk |
||
124 | .end: |
||
125 | .err: |
||
126 | ret |
||
127 | ; IN: ecx = list item |
||
128 | ;OUT: - |
||
129 | ;fs_del: |
||
130 | ; |
||
131 | ; ret |
||
132 | |||
133 | |||
134 | |||
9698 | turbocat | 135 | ; System function 70 security check |
136 | align 4 |
||
137 | proc file_system_is_operation_safe stdcall, inf_struct_ptr: dword |
||
138 | ; in: |
||
139 | ; inf_struct_ptr = pointer to information structure was given to sysfn70 |
||
140 | ; out: ZF = 1 if operation is safe |
||
141 | ; ZF = 0 if operation can cause kernel crash |
||
142 | push ebx ecx edx |
||
143 | xor ecx, ecx ; ecx - length of target buffer |
||
8680 | rgimad | 144 | |
9698 | turbocat | 145 | mov ebx, [inf_struct_ptr] |
146 | mov edx, [ebx + 16] ; base of target buffer |
||
8680 | rgimad | 147 | |
9698 | turbocat | 148 | cmp dword [ebx], 0 ; if 70.0 |
149 | jnz .case1 |
||
150 | mov ecx, dword [ebx + 12] |
||
151 | jmp .end_switch |
||
8680 | rgimad | 152 | |
9698 | turbocat | 153 | .case1: |
154 | cmp dword [ebx], 1 ; if 70.1 |
||
155 | jnz .case2_3 |
||
156 | ;mov ecx, 32 |
||
157 | cmp dword [ebx + 8], 1 ; check encoding |
||
10051 | ace_dent | 158 | jbe .case1_304 ; if encdoing <= 1 i.e cpp866 |
9698 | turbocat | 159 | mov ecx, 560 ; if unicode then bdvk block len is 560 bytes |
160 | jmp .case1_end |
||
161 | .case1_304: |
||
162 | mov ecx, 304 ; if cp866 then bdvk block len is 304 bytes |
||
163 | .case1_end: |
||
164 | imul ecx, dword [ebx + 12] ; multiply bdvk length by their count |
||
165 | add ecx, 32 ; add result header len |
||
166 | jmp .end_switch |
||
8680 | rgimad | 167 | |
9698 | turbocat | 168 | .case2_3: |
169 | cmp dword [ebx], 3 |
||
170 | ja .case5 ; if subfn > 3 |
||
171 | mov ecx, dword [ebx + 12] |
||
172 | jmp .end_switch |
||
8680 | rgimad | 173 | |
9698 | turbocat | 174 | .case5: |
175 | cmp dword [ebx], 5 |
||
176 | jnz .case6 |
||
177 | mov ecx, 40 |
||
178 | jmp .end_switch |
||
8680 | rgimad | 179 | |
9698 | turbocat | 180 | .case6: |
181 | cmp dword [ebx], 6 |
||
182 | jnz .switch_none |
||
183 | mov ecx, 32 |
||
184 | jmp .end_switch |
||
8680 | rgimad | 185 | |
9698 | turbocat | 186 | .switch_none: |
187 | cmp ecx, ecx |
||
188 | jmp .ret |
||
10051 | ace_dent | 189 | |
9698 | turbocat | 190 | .end_switch: |
191 | stdcall is_region_userspace, edx, ecx |
||
192 | .ret: |
||
193 | pop edx ecx ebx |
||
194 | ret |
||
195 | endp |
||
8680 | rgimad | 196 | |
9698 | turbocat | 197 | sys_fileSystemUnicode: ; with user pointer correctness checking |
198 | ; in: ebx -> f.80 parameter structure |
||
199 | stdcall file_system_is_operation_safe, ebx |
||
200 | jz @f |
||
8680 | rgimad | 201 | |
9698 | turbocat | 202 | DEBUGF 1, "sysfn80 addr error\n" |
203 | mov dword [image_of_eax], ERROR_MEMORY_POINTER |
||
204 | ret |
||
205 | @@: |
||
206 | jmp fileSystemUnicode |
||
8680 | rgimad | 207 | |
9698 | turbocat | 208 | ;System function 70 |
209 | sys_file_system_lfn: ; with user pointer correctness checking |
||
210 | ; in: ebx -> f.70 parameter structure |
||
211 | stdcall file_system_is_operation_safe, ebx |
||
212 | jz @f |
||
8680 | rgimad | 213 | |
9698 | turbocat | 214 | DEBUGF 1, "sysfn70 addr error\n" |
215 | mov dword [image_of_eax], ERROR_MEMORY_POINTER |
||
216 | ret |
||
217 | @@: |
||
218 | jmp file_system_lfn |
||
8680 | rgimad | 219 | |
9698 | turbocat | 220 | ;file_system_lfn_protected returns values not in registers, but in their images |
221 | ;on stack. Make a short wrapper to actually return values in registers. |
||
9185 | dunkaist | 222 | file_system_lfn_protected_registers: |
223 | pushad |
||
224 | call file_system_lfn_protected |
||
225 | popad |
||
226 | ret |
||
227 | |||
3296 | clevermous | 228 | file_system_lfn_protected: |
229 | pushad |
||
230 | call protect_from_terminate |
||
231 | call file_system_lfn |
||
232 | call unprotect_from_terminate |
||
233 | popad |
||
234 | mov [image_of_eax], eax |
||
235 | mov [image_of_ebx], ebx |
||
236 | ret |
||
237 | |||
6798 | pathoswith | 238 | fileSystemUnicode: |
239 | ; in: ebx -> f.80 parameter structure |
||
240 | mov edi, [ebx+20] |
||
241 | mov esi, [ebx+24] |
||
242 | jmp @f |
||
243 | |||
2288 | clevermous | 244 | file_system_lfn: |
6798 | pathoswith | 245 | ; in: ebx -> f.70 parameter structure |
246 | xor edi, edi |
||
247 | lea esi, [ebx+20] |
||
248 | cmp byte [esi], 0 |
||
2288 | clevermous | 249 | jnz @f |
6798 | pathoswith | 250 | mov esi, [ebx+21] |
2288 | clevermous | 251 | @@: |
6798 | pathoswith | 252 | cmp word [esi], '/' |
6502 | pathoswith | 253 | jnz @f |
6798 | pathoswith | 254 | cmp edi, 2 |
6502 | pathoswith | 255 | jnz .rootdir |
6798 | pathoswith | 256 | cmp dword[esi], '/' |
6502 | pathoswith | 257 | jz .rootdir |
258 | @@: |
||
6792 | pathoswith | 259 | stdcall kernel_alloc, maxPathLength |
260 | push eax ebx |
||
261 | xchg eax, edi |
||
262 | call getFullPath |
||
263 | pop ebx ebp |
||
264 | test eax, eax |
||
265 | jz .notfound |
||
6464 | pathoswith | 266 | cmp dword[ebx], 7 ; start application |
6502 | pathoswith | 267 | jnz @f |
6333 | serge | 268 | mov edx, [ebx+4] |
6792 | pathoswith | 269 | mov ecx, [ebx+8] |
270 | mov ebx, ebp |
||
271 | call fs_execute |
||
6333 | serge | 272 | mov [image_of_eax], eax |
273 | ret |
||
6464 | pathoswith | 274 | |
6333 | serge | 275 | @@: |
6502 | pathoswith | 276 | lea esi, [ebp+2] |
277 | mov ax, [esi] |
||
6464 | pathoswith | 278 | or ax, 2020h |
279 | cmp ax, 'cd' |
||
280 | jz .CD |
||
281 | call dyndisk_handler ; not returns if success |
||
282 | .notfound: |
||
6468 | pathoswith | 283 | stdcall kernel_free, ebp |
6464 | pathoswith | 284 | mov dword[image_of_eax], ERROR_FILE_NOT_FOUND |
285 | ret |
||
286 | |||
287 | .CD: |
||
288 | add esi, 2 |
||
289 | xor eax, eax |
||
290 | lodsb ; disk number |
||
291 | sub eax, '0' |
||
292 | cmp eax, 10 |
||
293 | jnc .notfound |
||
294 | mov edi, eax |
||
2288 | clevermous | 295 | lodsb |
6464 | pathoswith | 296 | test eax, eax |
297 | jz .maindir |
||
2288 | clevermous | 298 | cmp al, '/' |
6464 | pathoswith | 299 | jnz .notfound |
300 | lodsb ; partition number |
||
301 | test eax, eax |
||
302 | jz .maindir |
||
303 | cmp al, '1' |
||
304 | jnz .notfound |
||
305 | cmp byte [esi], '/' |
||
306 | jnz @f |
||
307 | inc esi |
||
308 | @@: |
||
309 | call reserve_cd |
||
310 | mov eax, edi |
||
311 | bt eax, 0 |
||
312 | setc [DiskNumber] |
||
313 | bt eax, 1 |
||
314 | setc [ChannelNumber] |
||
315 | inc [ChannelNumber] |
||
316 | inc eax |
||
317 | mov [cdpos], eax |
||
318 | call reserve_cd_channel |
||
319 | mov eax, edi |
||
320 | not eax |
||
321 | and eax, 3 |
||
322 | shl eax, 1 |
||
323 | inc eax |
||
324 | shr edi, 2 |
||
325 | mov dword[image_of_eax], ERROR_FILE_NOT_FOUND |
||
326 | bt [edi*5+DRIVE_DATA+1], ax |
||
327 | jnc @f |
||
328 | mov ecx, [ebx+12] |
||
329 | mov edx, [ebx+16] |
||
330 | mov eax, [ebx] |
||
331 | mov dword[image_of_eax], ERROR_UNSUPPORTED_FS |
||
332 | cmp eax, fs_NumCdServices |
||
333 | jae @f |
||
334 | add ebx, 4 |
||
6611 | clevermous | 335 | push ebp |
6464 | pathoswith | 336 | call dword[fs_CdServices + eax*4] |
6611 | clevermous | 337 | pop ebp |
6464 | pathoswith | 338 | mov [image_of_eax], eax |
339 | mov [image_of_ebx], ebx |
||
340 | @@: |
||
341 | call free_cd_channel |
||
342 | and [cd_status], 0 |
||
6468 | pathoswith | 343 | stdcall kernel_free, ebp |
6464 | pathoswith | 344 | ret |
345 | |||
346 | .nextCD: |
||
347 | test eax, eax ; partition number |
||
6875 | pathoswith | 348 | jnz @f |
349 | inc eax ; /cdX/1 |
||
350 | ret |
||
351 | |||
352 | @@: |
||
6464 | pathoswith | 353 | stc |
354 | ret |
||
355 | |||
356 | .maindir: ; list partitions |
||
357 | mov esi, .nextCD |
||
6875 | pathoswith | 358 | xor ecx, ecx |
6464 | pathoswith | 359 | .maindir_noesi: ; backjump from dyndisk_handler |
6468 | pathoswith | 360 | push ebp |
361 | mov ebp, ecx |
||
362 | call kernel_free |
||
6875 | pathoswith | 363 | mov edi, [ebx+16] ; buffer |
364 | cmp byte [ebx], 5 |
||
365 | jz .deviceInfo |
||
366 | cmp byte [ebx], 1 ; read folder? |
||
367 | jnz .access_denied |
||
6468 | pathoswith | 368 | push ebp |
369 | pushd [ebx+4] ; first block |
||
6464 | pathoswith | 370 | mov ebp, [ebx+12] ; the number of blocks to read |
2288 | clevermous | 371 | mov ebx, [ebx+8] ; flags |
6464 | pathoswith | 372 | mov ecx, 32/4 |
6875 | pathoswith | 373 | mov edx, edi |
6464 | pathoswith | 374 | xor eax, eax |
2288 | clevermous | 375 | rep stosd |
376 | mov byte [edx], 1 ; version |
||
377 | .maindir_loop: |
||
378 | call esi |
||
379 | jc .maindir_done |
||
6464 | pathoswith | 380 | inc dword[edx+8] |
381 | dec dword[esp] |
||
2288 | clevermous | 382 | jns .maindir_loop |
383 | dec ebp |
||
384 | js .maindir_loop |
||
6464 | pathoswith | 385 | inc dword[edx+4] |
386 | mov dword[edi], 16 ; attributes: folder |
||
387 | mov dword[edi+4], ebx ; name encoding |
||
2288 | clevermous | 388 | push eax |
6464 | pathoswith | 389 | mov ecx, 32/4 |
390 | add edi, 8 |
||
2288 | clevermous | 391 | xor eax, eax |
392 | rep stosd |
||
393 | pop eax |
||
6464 | pathoswith | 394 | push eax edx edi |
395 | ; convert number in eax to decimal string |
||
2288 | clevermous | 396 | push -'0' |
397 | mov ecx, 10 |
||
398 | @@: |
||
399 | xor edx, edx |
||
400 | div ecx |
||
401 | push edx |
||
402 | test eax, eax |
||
403 | jnz @b |
||
6875 | pathoswith | 404 | cmp ebx, 2 |
6464 | pathoswith | 405 | jz .uni |
2288 | clevermous | 406 | @@: |
407 | pop eax |
||
6464 | pathoswith | 408 | add eax, '0' |
2288 | clevermous | 409 | stosb |
6464 | pathoswith | 410 | test eax, eax |
2288 | clevermous | 411 | jnz @b |
6464 | pathoswith | 412 | pop edi edx eax |
6875 | pathoswith | 413 | cmp ebx, 3 |
414 | jz @f |
||
6464 | pathoswith | 415 | add edi, 264 |
416 | jmp .maindir_loop |
||
417 | |||
418 | .uni: |
||
419 | pop eax |
||
420 | add eax, '0' |
||
421 | stosw |
||
422 | test eax, eax |
||
423 | jnz .uni |
||
424 | pop edi edx eax |
||
6875 | pathoswith | 425 | @@: |
2288 | clevermous | 426 | add edi, 520 |
427 | jmp .maindir_loop |
||
6464 | pathoswith | 428 | |
2288 | clevermous | 429 | .maindir_done: |
6464 | pathoswith | 430 | pop eax eax |
2288 | clevermous | 431 | mov ebx, [edx+4] |
432 | xor eax, eax |
||
433 | dec ebp |
||
434 | js @f |
||
435 | mov al, ERROR_END_OF_FILE |
||
436 | @@: |
||
437 | mov [image_of_eax], eax |
||
438 | mov [image_of_ebx], ebx |
||
439 | ret |
||
6464 | pathoswith | 440 | |
2288 | clevermous | 441 | .access_denied: |
6464 | pathoswith | 442 | mov dword[image_of_eax], ERROR_ACCESS_DENIED |
2288 | clevermous | 443 | ret |
444 | |||
6875 | pathoswith | 445 | .deviceInfo: |
446 | test ebp, ebp |
||
447 | jz @f |
||
448 | mov eax, dword[ebp+DISK.MediaInfo.Capacity] |
||
449 | mov edx, dword[ebp+DISK.MediaInfo.Capacity+4] |
||
10016 | Doczom | 450 | mov ecx, [ebp + DISK.MediaInfo.SectorSize] |
451 | bsf ecx, ecx |
||
452 | shld edx, eax, cl |
||
453 | shl eax, cl |
||
6875 | pathoswith | 454 | mov [edi+36], edx |
455 | mov [edi+32], eax |
||
456 | @@: |
||
457 | and dword[image_of_eax], 0 |
||
458 | ret |
||
459 | |||
6464 | pathoswith | 460 | .rootdir: ; / - virtual root folder |
6875 | pathoswith | 461 | cmp byte [ebx], 5 |
462 | jz @b |
||
463 | cmp byte [ebx], 1 ; read folder? |
||
6464 | pathoswith | 464 | jnz .access_denied |
465 | mov ebp, [ebx+12] ; number of blocks |
||
466 | mov edx, [ebx+16] ; return area |
||
467 | push dword[ebx+4] ; first block |
||
2288 | clevermous | 468 | mov ebx, [ebx+8] ; flags |
6464 | pathoswith | 469 | mov ecx, 32/4 |
470 | mov edi, edx |
||
2288 | clevermous | 471 | xor eax, eax |
472 | rep stosd |
||
473 | mov byte [edx], 1 ; version |
||
4277 | clevermous | 474 | sub esp, 16 |
6464 | pathoswith | 475 | .rootdir_loop: |
4277 | clevermous | 476 | push edi |
477 | lea edi, [esp+4] |
||
478 | call dyndisk_enum_root |
||
479 | pop edi |
||
480 | test eax, eax |
||
6464 | pathoswith | 481 | jz .rootdirCD |
482 | inc dword[edx+8] |
||
483 | dec dword[esp+16] |
||
484 | jns .rootdir_loop |
||
4277 | clevermous | 485 | dec ebp |
6464 | pathoswith | 486 | js .rootdir_loop |
487 | inc dword[edx+4] |
||
488 | mov dword[edi], 16 ; attributes: folder |
||
489 | mov dword[edi+4], ebx ; name encoding |
||
4277 | clevermous | 490 | push eax |
6464 | pathoswith | 491 | mov ecx, 32/4 |
492 | add edi, 8 |
||
4277 | clevermous | 493 | xor eax, eax |
494 | rep stosd |
||
6468 | pathoswith | 495 | push edi |
496 | lea esi, [esp+8] |
||
6875 | pathoswith | 497 | cmp ebx, 2 |
6464 | pathoswith | 498 | jz .uni2 |
4277 | clevermous | 499 | @@: |
500 | lodsb |
||
501 | stosb |
||
6464 | pathoswith | 502 | test eax, eax |
4277 | clevermous | 503 | jnz @b |
6468 | pathoswith | 504 | pop edi eax |
6875 | pathoswith | 505 | cmp ebx, 3 |
506 | jz @f |
||
6464 | pathoswith | 507 | add edi, 264 |
508 | jmp .rootdir_loop |
||
509 | |||
510 | .uni2: |
||
511 | lodsb |
||
512 | stosw |
||
513 | test eax, eax |
||
514 | jnz .uni2 |
||
6468 | pathoswith | 515 | pop edi eax |
6875 | pathoswith | 516 | @@: |
4277 | clevermous | 517 | add edi, 520 |
6464 | pathoswith | 518 | jmp .rootdir_loop |
519 | |||
520 | .rootdirCD: |
||
4277 | clevermous | 521 | add esp, 16 |
6464 | pathoswith | 522 | or esi, -1 |
523 | .rootdirCD_loop: |
||
524 | inc esi |
||
525 | cmp esi, 10 |
||
526 | jnc .rootdir_done |
||
527 | mov eax, esi |
||
528 | not eax |
||
529 | and eax, 3 |
||
530 | shl eax, 1 |
||
531 | inc eax |
||
532 | mov ecx, esi |
||
533 | shr ecx, 2 |
||
534 | bt [ecx*5+DRIVE_DATA+1], ax |
||
535 | jnc .rootdirCD_loop |
||
536 | inc dword[edx+8] |
||
537 | dec dword[esp] |
||
538 | jns .rootdirCD_loop |
||
2288 | clevermous | 539 | dec ebp |
6464 | pathoswith | 540 | js .rootdirCD_loop |
541 | inc dword[edx+4] |
||
542 | mov dword[edi], 16 ; attributes: folder |
||
543 | mov dword[edi+4], ebx ; name encoding |
||
544 | mov ecx, 32/4 |
||
2288 | clevermous | 545 | add edi, 8 |
6464 | pathoswith | 546 | xor eax, eax |
2288 | clevermous | 547 | rep stosd |
6464 | pathoswith | 548 | mov eax, esi |
549 | add eax, '0' |
||
550 | cmp ebx, 1 |
||
551 | jz @f |
||
552 | mov word [edi], 'cd' |
||
553 | mov [edi+2], ax |
||
554 | add edi, 264 |
||
555 | jmp .rootdirCD_loop |
||
556 | |||
2288 | clevermous | 557 | @@: |
6464 | pathoswith | 558 | mov dword[edi], 640063h |
559 | mov [edi+4], eax |
||
2288 | clevermous | 560 | add edi, 520 |
6464 | pathoswith | 561 | jmp .rootdirCD_loop |
562 | |||
563 | .rootdir_done: |
||
2288 | clevermous | 564 | pop eax |
565 | mov ebx, [edx+4] |
||
566 | xor eax, eax |
||
567 | dec ebp |
||
568 | js @f |
||
569 | mov al, ERROR_END_OF_FILE |
||
570 | @@: |
||
571 | mov [image_of_eax], eax |
||
572 | mov [image_of_ebx], ebx |
||
573 | ret |
||
574 | |||
4700 | mario79 | 575 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 576 | process_replace_file_name: |
6464 | pathoswith | 577 | ; in: [esi] = virtual path |
578 | ; out: [esi]+[ebp] = physical path |
||
3689 | mario79 | 579 | xor edi, edi |
6471 | pathoswith | 580 | xor ebp, ebp |
2288 | clevermous | 581 | .loop: |
3711 | clevermous | 582 | cmp edi, [full_file_name_table.size] |
3689 | mario79 | 583 | jae .notfound |
2288 | clevermous | 584 | push esi edi |
6464 | pathoswith | 585 | shl edi, 7 |
6471 | pathoswith | 586 | add edi, [full_file_name_table] |
2288 | clevermous | 587 | @@: |
6464 | pathoswith | 588 | cmp byte [edi], 0 |
2288 | clevermous | 589 | jz .dest_done |
590 | lodsb |
||
591 | test al, al |
||
592 | jz .cont |
||
593 | scasb |
||
594 | jz @b |
||
6798 | pathoswith | 595 | or al, 20h |
596 | cmp [edi-1], al |
||
597 | jz @b |
||
6464 | pathoswith | 598 | .cont: |
599 | pop edi esi |
||
600 | inc edi |
||
601 | jmp .loop |
||
602 | |||
2288 | clevermous | 603 | .dest_done: |
604 | cmp byte [esi], 0 |
||
605 | jz .found |
||
606 | cmp byte [esi], '/' |
||
607 | jnz .cont |
||
608 | .found: |
||
609 | pop edi eax |
||
6464 | pathoswith | 610 | shl edi, 7 |
6471 | pathoswith | 611 | add edi, [full_file_name_table] |
2288 | clevermous | 612 | mov ebp, esi |
613 | lea esi, [edi+64] |
||
614 | .notfound: |
||
615 | ret |
||
6464 | pathoswith | 616 | |
3689 | mario79 | 617 | ;----------------------------------------------------------------------------- |
3663 | mario79 | 618 | uglobal |
6471 | pathoswith | 619 | addDirSeal db ? |
3663 | mario79 | 620 | endg |
6338 | serge | 621 | |
6464 | pathoswith | 622 | sys_current_directory: ; sysfunction 30 |
2288 | clevermous | 623 | mov eax, [current_slot] |
624 | mov edi, [eax+APPDATA.cur_dir] |
||
6798 | pathoswith | 625 | xor eax, eax |
2288 | clevermous | 626 | dec ebx |
627 | jz .set |
||
628 | dec ebx |
||
629 | jz .get |
||
3663 | mario79 | 630 | dec ebx |
631 | jz .mount_additional_directory |
||
6798 | pathoswith | 632 | mov eax, edx |
6471 | pathoswith | 633 | dec ebx |
6798 | pathoswith | 634 | jz .set |
635 | mov eax, esi |
||
636 | dec ebx |
||
637 | jz .get |
||
6471 | pathoswith | 638 | @@: |
2288 | clevermous | 639 | ret |
3663 | mario79 | 640 | |
641 | .mount_additional_directory: |
||
6464 | pathoswith | 642 | ; in: ecx -> dir name+dir path (128) |
6471 | pathoswith | 643 | mov al, 1 |
644 | xchg [addDirSeal], al |
||
645 | test al, al |
||
646 | jnz @b |
||
3663 | mario79 | 647 | mov esi, ecx |
648 | mov edi, sysdir_name1 |
||
6798 | pathoswith | 649 | mov ecx, 64 |
6464 | pathoswith | 650 | rep movsb ; copying fake directory name |
6798 | pathoswith | 651 | mov byte [edi-1], 0 |
6471 | pathoswith | 652 | mov cl, 63 |
653 | call cp866toUTF8_string |
||
654 | mov byte [edi], 0 |
||
3663 | mario79 | 655 | mov [full_file_name_table.size], 2 |
656 | ret |
||
6338 | serge | 657 | |
6798 | pathoswith | 658 | .get: |
659 | ; in: ecx -> buffer, edx = length, eax = encoding |
||
8676 | rgimad | 660 | stdcall is_region_userspace, ecx, edx |
9045 | dunkaist | 661 | jz @f |
8676 | rgimad | 662 | |
663 | ; if illegal buffer given |
||
664 | xor edx, edx |
||
665 | jmp .ret |
||
666 | @@: |
||
667 | |||
6471 | pathoswith | 668 | mov esi, edi |
6534 | pathoswith | 669 | inc esi |
6471 | pathoswith | 670 | mov edi, ecx |
671 | cmp edx, maxPathLength |
||
672 | jc @f |
||
673 | mov edx, maxPathLength |
||
2288 | clevermous | 674 | @@: |
675 | mov ecx, edx |
||
6798 | pathoswith | 676 | jecxz .ret |
677 | cmp eax, 2 |
||
678 | jz .get16 |
||
679 | cmp eax, 3 |
||
680 | jz .get8 |
||
6471 | pathoswith | 681 | @@: |
682 | dec ecx |
||
683 | js @f |
||
684 | call utf8to16 |
||
685 | call uni2ansi_char |
||
686 | stosb |
||
687 | test al, al |
||
688 | jnz @b |
||
689 | sub edx, ecx |
||
690 | @@: |
||
6798 | pathoswith | 691 | mov byte [edi-1], 0 |
692 | .ret: |
||
693 | mov [esp+32], edx |
||
2288 | clevermous | 694 | ret |
695 | |||
6798 | pathoswith | 696 | .get8: |
697 | push edi |
||
698 | mov edi, esi |
||
699 | xor eax, eax |
||
700 | repnz scasb |
||
701 | sub edx, ecx |
||
702 | mov ecx, edx |
||
703 | pop edi |
||
704 | rep movsb |
||
705 | jmp @b |
||
706 | |||
6471 | pathoswith | 707 | .get16: |
6798 | pathoswith | 708 | shr ecx, 1 |
6471 | pathoswith | 709 | shr edx, 1 |
710 | @@: |
||
711 | dec ecx |
||
712 | js @f |
||
713 | call utf8to16 |
||
714 | stosw |
||
715 | test ax, ax |
||
716 | jnz @b |
||
717 | sub edx, ecx |
||
718 | @@: |
||
6798 | pathoswith | 719 | shl edx, 1 |
720 | mov word [edi-2], 0 |
||
721 | jmp .ret |
||
6464 | pathoswith | 722 | |
2288 | clevermous | 723 | .set: |
6792 | pathoswith | 724 | mov esi, ecx |
725 | getFullPath: |
||
726 | ; in: esi -> file path, eax = string encoding, edi -> destination |
||
727 | ; out: UTF-8 string (with marker), eax = length, 0 -> error |
||
728 | test eax, eax |
||
729 | jnz @f |
||
730 | cmp byte [esi], 4 |
||
6502 | pathoswith | 731 | jnc @f |
6792 | pathoswith | 732 | cmp byte [esi], 0 |
733 | jz @f |
||
734 | lodsb |
||
6471 | pathoswith | 735 | @@: |
736 | cmp byte [esi], '/' |
||
6792 | pathoswith | 737 | jnz .relative |
738 | cmp eax, 2 |
||
739 | jnz @f |
||
740 | cmp word [esi], '/' |
||
741 | jnz .relative |
||
6471 | pathoswith | 742 | inc esi |
6792 | pathoswith | 743 | inc esi |
744 | jmp .start |
||
745 | |||
746 | @@: |
||
747 | inc esi |
||
6758 | pathoswith | 748 | cmp byte [esi], 4 |
6792 | pathoswith | 749 | jnc .start |
750 | lodsb |
||
6758 | pathoswith | 751 | cmp byte [esi], '/' |
752 | jnz .start |
||
753 | inc esi |
||
754 | .start: |
||
6792 | pathoswith | 755 | push eax edi |
6468 | pathoswith | 756 | call process_replace_file_name |
6792 | pathoswith | 757 | mov edi, [esp] |
758 | mov ecx, maxPathLength |
||
6502 | pathoswith | 759 | mov al, 3 |
760 | mov ah, '/' |
||
761 | stosw |
||
762 | sub ecx, 2 |
||
6471 | pathoswith | 763 | test ebp, ebp |
764 | jz .absolute |
||
765 | @@: |
||
6468 | pathoswith | 766 | lodsb |
767 | stosb |
||
6471 | pathoswith | 768 | dec ecx |
6468 | pathoswith | 769 | test al, al |
6471 | pathoswith | 770 | jnz @b |
771 | mov esi, ebp |
||
6468 | pathoswith | 772 | dec edi |
6471 | pathoswith | 773 | .absolute: |
6792 | pathoswith | 774 | cmp byte [esp+4], 2 |
6502 | pathoswith | 775 | jz .utf16 |
6792 | pathoswith | 776 | cmp byte [esp+4], 3 |
6502 | pathoswith | 777 | jz .utf8 |
6471 | pathoswith | 778 | call cp866toUTF8_string |
6787 | pathoswith | 779 | jns .end |
6471 | pathoswith | 780 | jmp .fail |
781 | |||
6502 | pathoswith | 782 | .utf8: |
783 | dec ecx |
||
784 | js .fail |
||
785 | lodsb |
||
786 | stosb |
||
787 | test al, al |
||
6787 | pathoswith | 788 | jz .end |
6502 | pathoswith | 789 | jmp .utf8 |
790 | |||
791 | .utf16: |
||
6471 | pathoswith | 792 | call UTF16to8_string |
6787 | pathoswith | 793 | jns .end |
6468 | pathoswith | 794 | .fail: |
795 | mov byte [edi], 0 |
||
6792 | pathoswith | 796 | pop eax eax |
6468 | pathoswith | 797 | xor eax, eax |
6792 | pathoswith | 798 | ret |
6468 | pathoswith | 799 | |
6792 | pathoswith | 800 | .relative: |
801 | push eax edi |
||
802 | mov ebx, esi |
||
6468 | pathoswith | 803 | mov edi, [current_slot] |
804 | mov edi, [edi+APPDATA.cur_dir] |
||
805 | mov edx, edi |
||
6792 | pathoswith | 806 | mov ecx, maxPathLength |
6468 | pathoswith | 807 | xor eax, eax |
808 | repnz scasb |
||
809 | mov esi, edi |
||
6792 | pathoswith | 810 | mov edi, [esp] |
6468 | pathoswith | 811 | jecxz .fail |
6502 | pathoswith | 812 | cmp byte [ebx], 0 |
813 | jz .set_ok |
||
6792 | pathoswith | 814 | dec esi |
6471 | pathoswith | 815 | cmp edx, edi ; is destination equal to cur_dir? |
816 | mov edi, esi |
||
817 | jz @f |
||
6792 | pathoswith | 818 | mov edi, [esp] |
2288 | clevermous | 819 | mov ecx, esi |
6468 | pathoswith | 820 | sub ecx, edx |
2288 | clevermous | 821 | mov esi, edx |
822 | mov edx, edi |
||
823 | rep movsb |
||
6471 | pathoswith | 824 | @@: |
2288 | clevermous | 825 | mov byte [edi], '/' |
826 | inc edi |
||
6471 | pathoswith | 827 | mov esi, ebx |
828 | mov ecx, edx |
||
6792 | pathoswith | 829 | add ecx, maxPathLength |
6471 | pathoswith | 830 | sub ecx, edi |
831 | jmp .absolute |
||
832 | |||
6787 | pathoswith | 833 | .set_ok: |
834 | cmp edx, edi ; is destination equal to cur_dir? |
||
6471 | pathoswith | 835 | jz @f |
6787 | pathoswith | 836 | mov ecx, esi |
837 | sub ecx, edx |
||
838 | mov esi, edx |
||
839 | rep movsb |
||
2288 | clevermous | 840 | @@: |
6792 | pathoswith | 841 | pop eax |
842 | sub edi, eax |
||
843 | pop eax |
||
844 | mov eax, edi |
||
845 | ret |
||
6787 | pathoswith | 846 | |
847 | .end: |
||
848 | or ecx, -1 |
||
6792 | pathoswith | 849 | mov edi, [esp] |
6787 | pathoswith | 850 | xor eax, eax |
851 | push edi |
||
852 | repnz scasb |
||
853 | not ecx |
||
854 | pop edi |
||
855 | .parse: |
||
856 | mov al, '/' |
||
857 | repnz scasb |
||
858 | jecxz @b |
||
859 | cmp byte [edi], '.' |
||
860 | jnz .parse |
||
861 | mov esi, edi |
||
862 | @@: |
||
863 | lodsw |
||
864 | sub ecx, 2 |
||
865 | cmp ax, './' |
||
866 | jz @b |
||
867 | cmp ax, '..' |
||
868 | jnz @f |
||
6471 | pathoswith | 869 | cmp byte [esi], '/' |
6787 | pathoswith | 870 | jnz @f |
871 | mov edx, ecx |
||
872 | mov ecx, edi |
||
6792 | pathoswith | 873 | sub ecx, [esp] |
6787 | pathoswith | 874 | sub ecx, 2 |
875 | jc .fail |
||
876 | sub edi, 2 |
||
877 | lodsb |
||
878 | dec edx |
||
879 | std |
||
880 | repnz scasb |
||
881 | cld |
||
882 | add edi, 2 |
||
883 | mov ecx, edx |
||
884 | jmp @b |
||
6464 | pathoswith | 885 | |
6787 | pathoswith | 886 | @@: |
887 | sub esi, 2 |
||
888 | add ecx, 2 |
||
889 | cmp esi, edi |
||
890 | jz .parse |
||
891 | push edi ecx |
||
892 | rep movsb |
||
893 | pop ecx edi |
||
894 | jmp .parse |
||
895 | |||
6462 | pathoswith | 896 | include "parse_fn.inc" |
897 | include "fs_common.inc" |
||
898 | include "iso9660.inc" ; read for CD filesystem |
||
899 | include "fat.inc" |
||
9734 | sober_dev | 900 | include "exfat.inc" |
6462 | pathoswith | 901 | include "ntfs.inc" |
902 | include "ext.inc" |
||
7736 | dunkaist | 903 | include "xfs.asm"=> |