Subversion Repositories Kolibri OS

Rev

Rev 7113 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7113 GerdtR 1
 
2
_FILE:
3
.pos		dq	?
4
.bufpos 	dq	?
5
.bufsize	dd	?
6
.mode		dd	?
7
.hPlugin	dd	?
8
.hFile		dd	?
9
.fileinfo:
10
.fimode 	dd	?
11
.fioffset	dq	?
12
.fisize 	dd	?
13
.fibuf		dd	?
14
.finame 	rb	1024
15
.attr		rb	40
16
align 512
17
.buf		rb	2048
18
.size = $
19
end virtual
20
21
 
22
O_WRITE = 2	; allows write to file
23
O_CREATE = 4	; if file does not exist and this flag is set, create file;
24
		; if file does not exist and this flag is not set, fail
25
O_TRUNCATE = 8	; truncate file if it exists
26
O_SEQUENTIAL_ONLY = 10h ; there will be no 'seek'/'setpos' calls
27
28
 
29
 
30
close:
31
	pushad
32
	mov	ecx, [esp+24h]
33
	mov	eax, [ecx+_FILE.hPlugin]
34
	test	eax, eax
35
	jz	@f
36
	push	ecx
37
	push	[ecx+_FILE.hFile]
38
	call	[aClose]
39
	pop	ecx
40
@@:
41
	call	pgfree
42
	popad
43
	ret	4
44
45
 
46
read:
47
	xor	eax, eax
48
	pushad
49
	mov	ecx, [esp+36]
50
	test	[ecx+_FILE.mode], O_READ
51
	jnz	@f
52
.ret:
53
	popad
54
	ret	12
55
@@:
56
	cmp	dword [esp+44], eax
57
	jz	.ret
58
	mov	[ecx+_FILE.fimode], eax
59
	mov	ebx, [ecx+_FILE.bufsize]
60
	mov	eax, dword [ecx+_FILE.pos]
61
	and	eax, 2047
62
	sub	ebx, eax
63
	jbe	.nobuf0
64
	cmp	ebx, [esp+44]
65
	jbe	@f
66
	mov	ebx, [esp+44]
67
@@:
68
	push	ecx
69
	lea	esi, [ecx+eax+_FILE.buf]
70
	mov	ecx, ebx
71
	mov	edi, [esp+44]
72
	rep	movsb
73
	pop	ecx
74
	mov	[esp+40], edi
75
	add	[esp+28], ebx
76
	add	dword [ecx+_FILE.pos], ebx
77
	adc	dword [ecx+_FILE.pos+4], 0
78
	test	dword [ecx+_FILE.pos], 2047
79
	jnz	@f
80
	and	[ecx+_FILE.bufsize], 0
81
@@:
82
	sub	[esp+44], ebx
83
	jz	.ret
84
.nobuf0:
85
	test	dword [ecx+_FILE.pos], 2047
86
	jz	.aligned
87
	cmp	dword [ecx+_FILE.bufsize], 0
88
	jnz	.ret
89
	lea	ebx, [ecx+_FILE.fileinfo]
90
	mov	dword [ebx+12], 2048
91
	lea	eax, [ecx+_FILE.buf]
92
	mov	dword [ebx+16], eax
93
	mov	eax, dword [ecx+_FILE.fioffset]
94
	mov	dword [ecx+_FILE.bufpos], eax
95
	mov	eax, dword [ecx+_FILE.fioffset+4]
96
	mov	dword [ecx+_FILE.bufpos+4], eax
97
	call	.doread
98
	test	eax, eax
99
	jnz	.ret
100
	mov	[ecx+_FILE.bufsize], ebx
101
	mov	eax, dword [ecx+_FILE.pos]
102
	and	eax, 2047
103
	sub	ebx, eax
104
	jbe	.ret
105
	cmp	ebx, [esp+44]
106
	jbe	@f
107
	mov	ebx, [esp+44]
108
@@:
109
	push	ecx
110
	lea	esi, [ecx+eax+_FILE.buf]
111
	mov	ecx, ebx
112
	mov	edi, [esp+44]
113
	rep	movsb
114
	pop	ecx
115
	add	dword [ecx+_FILE.pos], ebx
116
	adc	dword [ecx+_FILE.pos+4], 0
117
	mov	[esp+40], edi
118
	add	[esp+28], ebx
119
	sub	[esp+44], ebx
120
	jz	.ret
121
	test	dword [ecx+_FILE.pos], 2047
122
	jnz	.ret
123
.aligned:
124
	lea	ebx, [ecx+_FILE.fileinfo]
125
	mov	eax, [esp+44]
126
	and	eax, not 2047
127
	jz	.finish
128
	and	[ecx+_FILE.bufsize], 0
129
	mov	[ebx+12], eax
130
	mov	eax, [esp+40]
131
	mov	[ebx+16], eax
132
	call	.doread
133
	test	eax, eax
134
	jnz	.ret
135
	add	dword [ecx+_FILE.pos], ebx
136
	adc	dword [ecx+_FILE.pos+4], 0
137
	add	[esp+28], ebx
138
	add	[esp+40], ebx
139
	sub	[esp+44], ebx
140
	jz	.ret
141
	cmp	ebx, [ecx+_FILE.fisize]
142
	jb	.ret
143
.finish:
144
	lea	ebx, [ecx+_FILE.fileinfo]
145
	mov	dword [ebx+12], 2048
146
	lea	eax, [ecx+_FILE.buf]
147
	mov	[ebx+16], eax
148
	and	[ecx+_FILE.bufsize], 0
149
	mov	eax, dword [ecx+_FILE.fioffset]
150
	mov	dword [ecx+_FILE.bufpos], eax
151
	mov	eax, dword [ecx+_FILE.fioffset+4]
152
	mov	dword [ecx+_FILE.bufpos+4], eax
153
	call	.doread
154
	test	eax, eax
155
	jnz	.ret
156
	mov	[ecx+_FILE.bufsize], ebx
157
	cmp	ebx, [esp+44]
158
	jb	@f
159
	mov	ebx, [esp+44]
160
@@:
161
	add	[esp+28], ebx
162
	add	dword [ecx+_FILE.pos], ebx
163
	adc	dword [ecx+_FILE.pos+4], 0
164
	lea	esi, [ecx+_FILE.buf]
165
	mov	edi, [esp+40]
166
	mov	ecx, ebx
167
	rep	movsb
168
	popad
169
	ret	12
170
.doread:
171
	mov	eax, [ecx+_FILE.hPlugin]
172
	test	eax, eax
173
	jz	.native
174
	push	ecx
175
	push	[ecx+_FILE.fisize]
176
	push	[ecx+_FILE.fibuf]
177
	push	[ecx+_FILE.hFile]
178
	call	[eax+aRead]
179
	pop	ecx
180
	cmp	eax, -1
181
	jz	@f
182
	mov	ebx, eax
183
	xor	eax, eax
184
	jmp	.addpos
185
@@:
186
	ret
187
.native:
188
	push	70
189
	pop	eax
190
	int	0x40
191
	test	eax, eax
192
	jz	.addpos
193
	cmp	eax, 6
194
	jnz	@b
195
	xor	eax, eax
196
.addpos:
197
	add	dword [ecx+_FILE.fioffset], ebx
198
	adc	dword [ecx+_FILE.fioffset+4], 0
199
	ret
200
201
 
202
seek:
203
	pushad
204
	mov	ecx, [esp+36]
205
	mov	eax, [esp+44]
206
	mov	edx, [esp+48]
207
	cmp	dword [esp+40], 1
208
	jb	.set
209
	ja	.end
210
	add	eax, dword [ecx+_FILE.pos]
211
	adc	edx, dword [ecx+_FILE.pos+4]
212
	jmp	.set
213
.end:
214
	add	eax, dword [ecx+_FILE.attr+32]
215
	adc	edx, dword [ecx+_FILE.attr+36]
216
.set:
217
	mov	dword [ecx+_FILE.pos], eax
218
	mov	dword [ecx+_FILE.pos+4], edx
219
	and	eax, not 2047
220
	cmp	eax, dword [ecx+_FILE.bufpos]
221
	jnz	@f
222
	cmp	edx, dword [ecx+_FILE.bufpos+4]
223
	jz	.bufposok
224
@@:
225
	and	[ecx+_FILE.bufsize], 0
226
	mov	dword [ecx+_FILE.bufpos], eax
227
	mov	dword [ecx+_FILE.bufpos+4], edx
228
.bufposok:
229
	cmp	[ecx+_FILE.bufsize], 0
230
	jnz	.ret
231
	cmp	eax, dword [ecx+_FILE.fioffset]
232
	jnz	@f
233
	cmp	edx, dword [ecx+_FILE.fioffset+4]
234
	jz	.ret
235
@@:
236
	mov	dword [ecx+_FILE.fioffset], eax
237
	mov	dword [ecx+_FILE.fioffset+4], edx
238
	mov	eax, [ecx+_FILE.hPlugin]
239
	test	eax, eax
240
	jz	@f
241
	push	dword [ecx+_FILE.fioffset+4]
242
	push	dword [ecx+_FILE.fioffset]
243
	push	[ecx+_FILE.hFile]
244
	call	[eax+aSetpos]
245
@@:
246
.ret:
247
	popad
248
	ret	16
249
250
 
251
 
252
tell:
253
	mov	eax, [esp+4]
254
	mov	edx, dword [eax+_FILE.pos+4]
255
	mov	eax, dword [eax+_FILE.pos]
256
	ret	4
257
258
 
259
; Opens physical file
260
open:
261
	pushad
262
	mov	ecx, _FILE.size
263
	call	xpgalloc
264
	test	eax, eax
265
	jz	.ret0z
266
	mov	[esp+28], eax
267
	mov	ecx, eax
268
	mov	esi, [esp+36]
269
	lea	edi, [eax+_FILE.finame]
270
	lea	edx, [eax+_FILE.finame+1024]
271
@@:
272
	lodsb
273
	stosb
274
	test	al, al
275
	jz	@f
276
	cmp	edi, edx
277
	jb	@b
278
.ret0:
279
	call	pgfree
280
.ret0z:
281
	popad
282
	xor	eax, eax
283
	ret	8
284
@@:
285
	mov	eax, [esp+40]
286
	mov	[ecx+_FILE.mode], eax
287
.getattr:
288
	lea	edi, [ecx+_FILE.fileinfo]
289
	mov	ebx, edi
290
	push	5
291
	pop	eax
292
	stosd
293
	xor	eax, eax
294
	stosd
295
	stosd
296
	stosd
297
	lea	eax, [ecx+_FILE.attr]
298
	stosd
299
	push	70
300
	pop	eax
301
	int	0x40
302
	test	eax, eax
303
	jz	.found
304
	cmp	eax, 5
305
	jnz	.ret0
306
; file does not exist
307
	test	[ecx+_FILE.mode], O_CREATE
308
	jz	.ret0
309
.truncate:
310
	lea	ebx, [ecx+_FILE.fileinfo]
311
	mov	byte [ebx], 2
312
	push	70
313
	pop	eax
314
	int	0x40
315
	test	eax, eax
316
	jz	.getattr
317
	jmp	.ret0
318
.found:
319
	test	[ecx+_FILE.mode], O_TRUNCATE
320
	jz	@f
321
	cmp	dword [ecx+_FILE.attr+36], eax
322
	jnz	.truncate
323
	cmp	dword [ecx+_FILE.attr+32], eax
324
	jnz	.truncate
325
@@:
326
	mov	dword [ecx+_FILE.pos], eax
327
	mov	dword [ecx+_FILE.pos+4], eax
328
	mov	dword [ecx+_FILE.bufpos], eax
329
	mov	dword [ecx+_FILE.bufpos+4], eax
330
	mov	[ecx+_FILE.bufsize], eax
331
	mov	[ecx+_FILE.hPlugin], eax
332
	mov	[ecx+_FILE.hFile], eax
333
	mov	dword [ecx+_FILE.fioffset], eax
334
	mov	dword [ecx+_FILE.fioffset+4], eax
335
	mov	[esp+28], ecx
336
	popad
337
	ret	8
338
339
 
340
; Opens file on plugin panel
341
open2:
342
	cmp	dword [esp+4], 0
343
	jnz	.plugin
344
	pop	eax
345
	add	esp, 8
346
	push	eax
347
	jmp	open
348
.plugin:
349
	pushad
350
	mov	ecx, _FILE.size
351
	call	xpgalloc
352
	test	eax, eax
353
	jz	.ret0z
354
	mov	[esp+28], eax
355
	mov	ecx, eax
356
	mov	esi, [esp+44]
357
	lea	edi, [eax+_FILE.finame]
358
	lea	edx, [eax+_FILE.finame+1024]
359
@@:
360
	lodsb
361
	stosb
362
	test	al, al
363
	jz	@f
364
	cmp	edi, edx
365
	jb	@b
366
.ret0:
367
	call	pgfree
368
.ret0z:
369
	popad
370
	xor	eax, eax
371
	ret	8
372
@@:
373
	mov	edx, [esp+36]
374
	mov	[ecx+_FILE.hPlugin], edx
375
	mov	ebx, [esp+40]
376
	mov	eax, [esp+48]
377
	mov	[ecx+_FILE.mode], eax
378
	push	ebx ecx
379
	push	eax
380
	lea	eax, [ecx+_FILE.finame]
381
	push	eax
382
	push	ebx
383
	call	[edx+aOpen]
384
	pop	ecx ebx
385
	test	eax, eax
386
	jz	.ret0
387
	mov	[ecx+_FILE.hFile], eax
388
	mov	edx, [esp+36]
389
	push	ecx
390
	lea	edi, [ecx+_FILE.fileinfo]
391
	push	edi
392
	xor	eax, eax
393
	push	ecx
394
	push	10
395
	pop	ecx
396
	rep	stosd
397
	pop	ecx
398
	lea	eax, [ecx+_FILE.finame]
399
	push	eax
400
	push	ebx
401
	call	[edx+aGetattr]
402
	pop	ecx
403
	xor	eax, eax
404
	mov	dword [ecx+_FILE.pos], eax
405
	mov	dword [ecx+_FILE.pos+4], eax
406
	mov	dword [ecx+_FILE.bufpos], eax
407
	mov	dword [ecx+_FILE.bufpos+4], eax
408
	mov	[ecx+_FILE.bufsize], eax
409
	mov	dword [ecx+_FILE.fioffset], eax
410
	mov	dword [ecx+_FILE.fioffset+4], eax
411
	mov	[esp+28], ecx
412
	popad
413
	ret	16
414
415
 
416
filesize:
417
	mov	eax, [esp+4]
418
	mov	edx, dword [eax+_FILE.attr+36]
419
	mov	eax, dword [eax+_FILE.attr+32]
420
	ret	4
421
422
 
423
 
424
;makedir:
425
;; create directory with name from CopyDestEditBuf+12
426
;; destroys eax
427
;        push    ebx
428
;        push    70
429
;        pop     eax
430
;        mov     ebx, mkdirinfo
431
;        int     0x40
432
;        pop     ebx
433
;        test    eax, eax
434
;        jz      .ret
435
;        cmp     dword [esp+8], DeleteErrorBtn
436
;        jnz     @f
437
;        cmp     [copy_bSkipAll], 0
438
;        jz      @f
439
;        push    1
440
;        pop     eax
441
;        jmp     .ret
442
;@@:
443
;        push    dword CopyDestEditBuf+12
444
;        push    dword aCannotMakeFolder
445
;        call    get_error_msg
446
;        push    eax
447
;        mov     eax, esp
448
;        push    dword [eax+20]
449
;        push    dword [eax+16]
450
;        push    eax
451
;        push    3
452
;        call    SayErr
453
;        add     esp, 3*4
454
;        test    eax, eax
455
;        jz      makedir
456
;.ret:
457
;        ret     8
458
;
459
460
 
461
 
462
 
463
;######################################################################################################
464
;######################################################################################################
465
;######################################################################################################
466
467
 
468
 
469
if CHECK_FOR_LEAKS
470
uglobal
471
allocatedregions rd 1024
472
endg
473
iglobal
474
numallocatedregions dd 0
475
endg
476
end if
477
pgalloc:
478
; in: ecx=size
479
; out: eax=pointer or NULL
480
	push	ebx
481
	push	68
482
	pop	eax
483
	push	12
484
	pop	ebx
485
	int	0x40
486
if CHECK_FOR_LEAKS
487
	test	eax, eax
488
	jz	.no
489
.b:
490
	mov	ebx, [numallocatedregions]
491
	cmp	ebx, 1024
492
	jb	@f
493
	int3
494
	jmp	$
495
@@:
496
	mov	[allocatedregions+ebx*4], eax
497
	inc	[numallocatedregions]
498
.no:
499
end if
500
	pop	ebx
501
	ret
502
503
 
504
; in: ecx=pointer
505
; destroys eax
506
if CHECK_FOR_LEAKS
507
	jecxz	.no
508
	mov	eax, [numallocatedregions]
509
@@:
510
	dec	eax
511
	js	.a
512
	cmp	[allocatedregions+eax*4], ecx
513
	jnz	@b
514
	jmp	@f
515
.a:
516
	int3
517
	jmp	$
518
@@:
519
	dec	[numallocatedregions]
520
@@:
521
	cmp	eax, [numallocatedregions]
522
	jae	@f
523
	push	[allocatedregions+eax*4+4]
524
	pop	[allocatedregions+eax*4]
525
	inc	eax
526
	jmp	@b
527
@@:
528
.no:
529
end if
530
	push	ebx
531
	push	68
532
	pop	eax
533
	push	13
534
	pop	ebx
535
	int	0x40
536
	pop	ebx
537
	ret
538
539
 
540
 
541
 
542
 
543
; in: ecx=size, edx=pointer
544
; out: eax=pointer
545
	push	ebx
546
	push	68
547
	pop	eax
548
	push	20
549
	pop	ebx
550
	int	0x40
551
if CHECK_FOR_LEAKS
552
	test	edx, edx
553
	jz	pgalloc.b
554
	test	eax, eax
555
	jz	.no
556
	cmp	eax, edx
557
	jz	.no
558
	xor	ebx, ebx
559
@@:
560
	cmp	ebx, [numallocatedregions]
561
	jae	.a
562
	cmp	[allocatedregions+ebx*4], edx
563
	jz	@f
564
	inc	ebx
565
	jmp	@b
566
@@:
567
	mov	[allocatedregions+ebx*4], eax
568
	jmp	.no
569
.a:
570
	int3
571
	jmp	$
572
.no:
573
end if
574
	pop	ebx
575
	ret
576
577
 
578
; in: ecx=size
579
; out: eax=pointer or NULL
580
	call	pgalloc
581
.common:
582
	test	eax, eax
583
	jnz	@f
584
	;call    SayNoMem
585
586
 
587
	ret
588
589
 
590
; in: edx=pointer, ecx=new size
591
; out: eax=pointer or NULL
592
	call	pgrealloc
593
	jmp	xpgalloc.common
594
595
 
596
; out: eax=size of free RAM in Kb
597
	push	ebx
598
	mcall	18,16
599
	pop	ebx
600
	ret
601
602
 
603
 
604
 
605
locals
606
   beginFile dd 0
607
   pos	dd 0
608
endl
609
610
 
611
;dpsP [name]
612
;dnl
613
	pusha
614
	mov	[pos],0
615
616
 
617
	stdcall [aRead], [hFile], copy_buf, SIZE_COPY_BUF
618
	pop	ebp
619
620
 
621
	mov	[fsWrite.pos],0
622
	mov	[fsWrite.size],eax
623
	mov	eax,[name]
624
	mov	[fsWrite.path],eax
625
	mcall	70,fsWrite
626
627
 
628
	mov	eax, [fsWrite.size]
629
	add	[pos], eax
630
631
 
632
 
633
	stdcall [aRead], [hFile], copy_buf, SIZE_COPY_BUF
634
	pop	ebp
635
636
 
637
	jz	.end
638
639
 
640
	mov	[fsWrite.size],eax
641
	mov	eax,[pos]
642
	mov	[fsWrite.pos],eax
643
	mcall	70,fsWrite
644
	jmp	.loop
645
   .end:
646
647
 
648
 
649
	mov	eax,1
650
	ret
651
endp
652
653
 
654
 
655
	dps 'log adddir'
656
	mov	eax,[name]
657
	dpsP eax
658
	dnl
659
660
 
661
	mov	eax,[name]
662
	mov	[fsNewDir.path],eax
663
	mcall	70,fsNewDir
664
   ;
665
   ;     mov     edi,[name]
666
   ;     xor     al,al
667
   ;     mov     ecx,256
668
   ;     repne scasb
669
   ;     mov     edx,256
670
   ;     sub     edx,ecx
671
   ;     mov     eax,[name]
672
   ;     mcall   30,1,eax
673
	popa
674
	mov	eax,1
675
	ret
676
endp
677
678
 
679
 
680
proc cpLastName inp:dword, outp:dword
681
	push	edi esi
682
	mov	edi,[inp]
683
	xor	al,al
684
	mov	ecx,256 	;                V
685
	repne scasb		;/fol1/file1.zip
686
687
 
688
	mov	ecx,256
689
	std			;   V
690
	repne scasb		;/fol1/file1.zip
691
	cld
692
693
 
694
	add	esi,2
695
	mov	ecx,256 	;/fol1/file1.zip
696
	mov	edi,[outp]	;file1.zip
697
    @@: lodsb
698
	stosb
699
	test	al,al
700
	jz	@f
701
	loop	@b
702
    @@:
703
704
 
705
	mov	ecx,256
706
	std			;    V
707
	repne scasb		;file1.zip
708
	cld
709
	mov	[edi+1], byte 0
710
711
 
712
	ret
713
endp
714
715
 
716
 
717
	push	edi esi
718
	mov	edi,[inp]
719
	xor	al,al
720
	mov	ecx,256 	;                V
721
	repne scasb		;/fol1/file1.zip
722
723
 
724
	mov	ecx,256
725
	std			;   V
726
	repne scasb		;/fol1/file1.zip
727
	cld
728
	mov	edx,edi
729
	add	edx, 2
730
731
 
732
	mov	ecx,256 	;/fol1/file1.zip
733
	mov	edi,[outp]	;file1.zip
734
    @@: lodsb
735
	stosb
736
	test	al,al
737
	jz	@f
738
	cmp	esi,edx
739
	jae	@f
740
	loop	@b
741
    @@:
742
	xor	al, al
743
	stosb
744
745
 
746
	ret
747
endp
748