1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
|
/* $OpenBSD: file.c,v 1.7 2003/12/01 00:56:51 avsm Exp $ */
/*
* Copyright (c) 1995-96 Mats O Jansson. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef LINT
static const char rcsid[] = "$OpenBSD: file.c,v 1.7 2003/12/01 00:56:51 avsm Exp $";
#endif
#include "os.h"
#include "common/common.h"
#include "common/mopdef.h"
#ifndef NOAOUT
#if defined(__NetBSD__) || defined(__OpenBSD__)
#include <sys/exec_aout.h>
#endif
#if defined(__bsdi__)
#define NOAOUT
#endif
#if defined(__FreeBSD__)
#include <sys/imgact_aout.h>
#endif
#if !defined(MID_I386)
#define MID_I386 134
#endif
#if !defined(MID_SPARC)
#define MID_SPARC 138
#endif
#if !defined(MID_VAX)
#define MID_VAX 140
#endif
#endif
void
mopFilePutLX(buf, index, value, cnt)
u_char *buf;
int index, cnt;
u_long value;
{
int i;
for (i = 0; i < cnt; i++) {
buf[index+i] = value % 256;
value = value / 256;
}
}
void
mopFilePutBX(buf, index, value, cnt)
u_char *buf;
int index, cnt;
u_long value;
{
int i;
for (i = 0; i < cnt; i++) {
buf[index+cnt-1-i] = value % 256;
value = value / 256;
}
}
u_long
mopFileGetLX(buf, index, cnt)
u_char *buf;
int index, cnt;
{
u_long ret = 0;
int i;
for (i = 0; i < cnt; i++) {
ret = ret*256 + buf[index+cnt-1-i];
}
return(ret);
}
u_long
mopFileGetBX(buf, index, cnt)
u_char *buf;
int index, cnt;
{
u_long ret = 0;
int i;
for (i = 0; i < cnt; i++) {
ret = ret*256 + buf[index+i];
}
return(ret);
}
void
mopFileSwapX(buf, index, cnt)
u_char *buf;
int index, cnt;
{
int i;
u_char c;
for (i = 0; i < (cnt / 2); i++) {
c = buf[index+i];
buf[index+i] = buf[index+cnt-1-i];
buf[index+cnt-1-i] = c;
}
}
int
CheckMopFile(fd)
int fd;
{
u_char header[512];
short image_type;
if (read(fd, header, 512) != 512)
return(-1);
(void)lseek(fd, (off_t) 0, SEEK_SET);
image_type = (u_short)(header[IHD_W_ALIAS+1]*256 +
header[IHD_W_ALIAS]);
switch(image_type) {
case IHD_C_NATIVE: /* Native mode image (VAX) */
case IHD_C_RSX: /* RSX image produced by TKB */
case IHD_C_BPA: /* BASIC plus analog */
case IHD_C_ALIAS: /* Alias */
case IHD_C_CLI: /* Image is CLI */
case IHD_C_PMAX: /* PMAX system image */
case IHD_C_ALPHA: /* ALPHA system image */
break;
default:
return(-1);
}
return(0);
}
int
GetMopFileInfo(fd, load, xfr)
int fd;
u_long *load, *xfr;
{
u_char header[512];
short image_type;
u_long load_addr, xfr_addr, isd, iha, hbcnt, isize;
if (read(fd, header, 512) != 512)
return(-1);
image_type = (u_short)(header[IHD_W_ALIAS+1]*256 +
header[IHD_W_ALIAS]);
switch(image_type) {
case IHD_C_NATIVE: /* Native mode image (VAX) */
isd = (header[IHD_W_SIZE+1]*256 +
header[IHD_W_SIZE]);
iha = (header[IHD_W_ACTIVOFF+1]*256 +
header[IHD_W_ACTIVOFF]);
hbcnt = (header[IHD_B_HDRBLKCNT]);
isize = (header[isd+ISD_W_PAGCNT+1]*256 +
header[isd+ISD_W_PAGCNT]) * 512;
load_addr = ((header[isd+ISD_V_VPN+1]*256 +
header[isd+ISD_V_VPN]) & ISD_M_VPN)
* 512;
xfr_addr = (header[iha+IHA_L_TFRADR1+3]*0x1000000 +
header[iha+IHA_L_TFRADR1+2]*0x10000 +
header[iha+IHA_L_TFRADR1+1]*0x100 +
header[iha+IHA_L_TFRADR1]) & 0x7fffffff;
#ifdef INFO
printf("Native Image (VAX)\n");
printf("Header Block Count: %lu\n",hbcnt);
printf("Image Size: %08lx\n",isize);
printf("Load Address: %08lx\n",load_addr);
printf("Transfer Address: %08lx\n",xfr_addr);
#endif
break;
case IHD_C_RSX: /* RSX image produced by TKB */
hbcnt = header[L_BBLK+1]*256 + header[L_BBLK];
isize = (header[L_BLDZ+1]*256 + header[L_BLDZ]) * 64;
load_addr = header[L_BSA+1]*256 + header[L_BSA];
xfr_addr = header[L_BXFR+1]*256 + header[L_BXFR];
#ifdef INFO
printf("RSX Image\n");
printf("Header Block Count: %lu\n",hbcnt);
printf("Image Size: %08lx\n",isize);
printf("Load Address: %08lx\n",load_addr);
printf("Transfer Address: %08lx\n",xfr_addr);
#endif
break;
case IHD_C_BPA: /* BASIC plus analog */
#ifdef INFO
printf("BASIC-Plus Image, not supported\n");
#endif
return(-1);
break;
case IHD_C_ALIAS: /* Alias */
#ifdef INFO
printf("Alias, not supported\n");
#endif
return(-1);
break;
case IHD_C_CLI: /* Image is CLI */
#ifdef INFO
printf("CLI, not supported\n");
#endif
return(-1);
break;
case IHD_C_PMAX: /* PMAX system image */
isd = (header[IHD_W_SIZE+1]*256 +
header[IHD_W_SIZE]);
iha = (header[IHD_W_ACTIVOFF+1]*256 +
header[IHD_W_ACTIVOFF]);
hbcnt = (header[IHD_B_HDRBLKCNT]);
isize = (header[isd+ISD_W_PAGCNT+1]*256 +
header[isd+ISD_W_PAGCNT]) * 512;
load_addr = (header[isd+ISD_V_VPN+1]*256 +
header[isd+ISD_V_VPN]) * 512;
xfr_addr = (header[iha+IHA_L_TFRADR1+3]*0x1000000 +
header[iha+IHA_L_TFRADR1+2]*0x10000 +
header[iha+IHA_L_TFRADR1+1]*0x100 +
header[iha+IHA_L_TFRADR1]);
#ifdef INFO
printf("PMAX Image \n");
printf("Header Block Count: %lu\n",hbcnt);
printf("Image Size: %08lx\n",isize);
printf("Load Address: %08lx\n",load_addr);
printf("Transfer Address: %08lx\n",xfr_addr);
#endif
break;
case IHD_C_ALPHA: /* ALPHA system image */
isd = (header[EIHD_L_ISDOFF+3]*0x1000000 +
header[EIHD_L_ISDOFF+2]*0x10000 +
header[EIHD_L_ISDOFF+1]*0x100 +
header[EIHD_L_ISDOFF]);
hbcnt = (header[EIHD_L_HDRBLKCNT+3]*0x1000000 +
header[EIHD_L_HDRBLKCNT+2]*0x10000 +
header[EIHD_L_HDRBLKCNT+1]*0x100 +
header[EIHD_L_HDRBLKCNT]);
isize = (header[isd+EISD_L_SECSIZE+3]*0x1000000 +
header[isd+EISD_L_SECSIZE+2]*0x10000 +
header[isd+EISD_L_SECSIZE+1]*0x100 +
header[isd+EISD_L_SECSIZE]);
load_addr = 0;
xfr_addr = 0;
#ifdef INFO
printf("Alpha Image \n");
printf("Header Block Count: %lu\n",hbcnt);
printf("Image Size: %08lx\n",isize);
printf("Load Address: %08lx\n",load_addr);
printf("Transfer Address: %08lx\n",xfr_addr);
#endif
break;
default:
#ifdef INFO
printf("Unknown Image (%d)\n",image_type);
#endif
return(-1);
}
if (load != NULL) {
*load = load_addr;
}
if (xfr != NULL) {
*xfr = xfr_addr;
}
return(0);
}
#ifndef NOAOUT
int
getMID(old_mid,new_mid)
int old_mid, new_mid;
{
int mid;
mid = old_mid;
switch (new_mid) {
case MID_I386:
mid = MID_I386;
break;
#ifdef MID_M68K
case MID_M68K:
mid = MID_M68K;
break;
#endif
#ifdef MID_M68K4K
case MID_M68K4K:
mid = MID_M68K4K;
break;
#endif
#ifdef MID_NS32532
case MID_NS32532:
mid = MID_NS32532;
break;
#endif
case MID_SPARC:
mid = MID_SPARC;
break;
#ifdef MID_PMAX
case MID_PMAX:
mid = MID_PMAX;
break;
#endif
#ifdef MID_VAX
case MID_VAX:
mid = MID_VAX;
break;
#endif
#ifdef MID_ALPHA
case MID_ALPHA:
mid = MID_ALPHA;
break;
#endif
#ifdef MID_MIPS
case MID_MIPS:
mid = MID_MIPS;
break;
#endif
#ifdef MID_ARM6
case MID_ARM6:
mid = MID_ARM6;
break;
#endif
default:
break;
}
return(mid);
}
int
getCLBYTES(mid)
int mid;
{
int clbytes;
switch (mid) {
#ifdef MID_VAX
case MID_VAX:
clbytes = 1024;
break;
#endif
case MID_I386:
#ifdef MID_M68K4K
case MID_M68K4K:
#endif
#ifdef MID_NS32532
case MID_NS32532:
#endif
case MID_SPARC: /* It might be 8192 */
#ifdef MID_PMAX
case MID_PMAX:
#endif
#ifdef MID_MIPS
case MID_MIPS:
#endif
#ifdef MID_ARM6
case MID_ARM6:
#endif
clbytes = 4096;
break;
#ifdef MID_M68K
case MID_M68K:
#endif
#ifdef MID_ALPHA
case MID_ALPHA:
#endif
#if defined(MID_M68K) || defined(MID_ALPHA)
clbytes = 8192;
break;
#endif
default:
clbytes = 0;
}
return(clbytes);
}
#endif
int
CheckAOutFile(fd)
int fd;
{
#ifdef NOAOUT
return(-1);
#else
struct exec ex, ex_swap;
int mid = -1;
if (read(fd, (char *)&ex, sizeof(ex)) != sizeof(ex))
return(-1);
(void)lseek(fd, (off_t) 0, SEEK_SET);
if (read(fd, (char *)&ex_swap, sizeof(ex_swap)) != sizeof(ex_swap))
return(-1);
(void)lseek(fd, (off_t) 0, SEEK_SET);
mid = getMID(mid, N_GETMID (ex));
if (mid == -1) {
mid = getMID(mid, N_GETMID (ex_swap));
}
if (mid != -1) {
return(0);
} else {
return(-1);
}
#endif /* NOAOUT */
}
int
GetAOutFileInfo(fd, load, xfr, a_text, a_text_fill,
a_data, a_data_fill, a_bss, a_bss_fill, aout)
int fd, *aout;
u_long *load, *xfr, *a_text, *a_text_fill;
u_long *a_data, *a_data_fill, *a_bss, *a_bss_fill;
{
#ifdef NOAOUT
return(-1);
#else
struct exec ex, ex_swap;
int mid = -1;
u_long magic, clbytes, clofset;
if (read(fd, (char *)&ex, sizeof(ex)) != sizeof(ex))
return(-1);
(void)lseek(fd, (off_t) 0, SEEK_SET);
if (read(fd, (char *)&ex_swap, sizeof(ex_swap)) != sizeof(ex_swap))
return(-1);
mopFileSwapX((u_char *)&ex_swap, 0, 4);
mid = getMID(mid, N_GETMID (ex));
if (mid == -1) {
mid = getMID(mid, N_GETMID (ex_swap));
if (mid != -1) {
mopFileSwapX((u_char *)&ex, 0, 4);
}
}
if (mid == -1) {
return(-1);
}
if (N_BADMAG (ex)) {
return(-1);
}
switch (mid) {
case MID_I386:
#ifdef MID_NS32532
case MID_NS32532:
#endif
#ifdef MID_PMAX
case MID_PMAX:
#endif
#ifdef MID_VAX
case MID_VAX:
#endif
#ifdef MID_ALPHA
case MID_ALPHA:
#endif
#ifdef MID_ARM6
case MID_ARM6:
#endif
ex.a_text = mopFileGetLX((u_char *)&ex_swap, 4, 4);
ex.a_data = mopFileGetLX((u_char *)&ex_swap, 8, 4);
ex.a_bss = mopFileGetLX((u_char *)&ex_swap, 12, 4);
ex.a_syms = mopFileGetLX((u_char *)&ex_swap, 16, 4);
ex.a_entry = mopFileGetLX((u_char *)&ex_swap, 20, 4);
ex.a_trsize= mopFileGetLX((u_char *)&ex_swap, 24, 4);
ex.a_drsize= mopFileGetLX((u_char *)&ex_swap, 28, 4);
break;
#ifdef MID_M68K
case MID_M68K:
#endif
#ifdef MID_M68K4K
case MID_M68K4K:
#endif
case MID_SPARC:
#ifdef MID_MIPS
case MID_MIPS:
#endif
ex.a_text = mopFileGetBX((u_char *)&ex_swap, 4, 4);
ex.a_data = mopFileGetBX((u_char *)&ex_swap, 8, 4);
ex.a_bss = mopFileGetBX((u_char *)&ex_swap, 12, 4);
ex.a_syms = mopFileGetBX((u_char *)&ex_swap, 16, 4);
ex.a_entry = mopFileGetBX((u_char *)&ex_swap, 20, 4);
ex.a_trsize= mopFileGetBX((u_char *)&ex_swap, 24, 4);
ex.a_drsize= mopFileGetBX((u_char *)&ex_swap, 28, 4);
break;
default:
break;
}
#ifdef INFO
printf("a.out image (");
switch (N_GETMID (ex)) {
case MID_I386:
printf("i386");
break;
#ifdef MID_M68K
case MID_M68K:
printf("m68k");
break;
#endif
#ifdef MID_M68K4K
case MID_M68K4K:
printf("m68k 4k");
break;
#endif
#ifdef MID_NS32532
case MID_NS32532:
printf("pc532");
break;
#endif
case MID_SPARC:
printf("sparc");
break;
#ifdef MID_PMAX
case MID_PMAX:
printf("pmax");
break;
#endif
#ifdef MID_VAX
case MID_VAX:
printf("vax");
break;
#endif
#ifdef MID_ALPHA
case MID_ALPHA:
printf("alpha");
break;
#endif
#ifdef MID_MIPS
case MID_MIPS:
printf("mips");
break;
#endif
#ifdef MID_ARM6
case MID_ARM6:
printf("arm32");
break;
#endif
default:
break;
}
printf(") Magic: ");
switch (N_GETMAGIC (ex)) {
case OMAGIC:
printf("OMAGIC");
break;
case NMAGIC:
printf("NMAGIC");
break;
case ZMAGIC:
printf("ZMAGIC");
break;
case QMAGIC:
printf("QMAGIC");
break;
default:
printf("Unknown %d",N_GETMAGIC (ex));
}
printf("\n");
printf("Size of text: %08x\n",ex.a_text);
printf("Size of data: %08x\n",ex.a_data);
printf("Size of bss: %08x\n",ex.a_bss);
printf("Size of symbol tab: %08x\n",ex.a_syms);
printf("Transfer Address: %08x\n",ex.a_entry);
printf("Size of reloc text: %08x\n",ex.a_trsize);
printf("Size of reloc data: %08x\n",ex.a_drsize);
#endif
magic = N_GETMAGIC (ex);
clbytes = getCLBYTES(mid);
clofset = clbytes - 1;
if (load != NULL) {
*load = 0;
}
if (xfr != NULL) {
*xfr = ex.a_entry;
}
if (a_text != NULL) {
*a_text = ex.a_text;
}
if (a_text_fill != NULL) {
if (magic == ZMAGIC || magic == NMAGIC) {
*a_text_fill = clbytes - (ex.a_text & clofset);
if (*a_text_fill == clbytes) {
*a_text_fill = 0;
}
} else {
*a_text_fill = 0;
}
}
if (a_data != NULL) {
*a_data = ex.a_data;
}
if (a_data_fill != NULL) {
if (magic == ZMAGIC || magic == NMAGIC) {
*a_data_fill = clbytes - (ex.a_data & clofset);
if (*a_data_fill == clbytes) {
*a_data_fill = 0;
}
} else {
*a_data_fill = 0;
}
}
if (a_bss != NULL) {
*a_bss = ex.a_bss;
}
if (a_bss_fill != NULL) {
if (magic == ZMAGIC || magic == NMAGIC) {
*a_bss_fill = clbytes - (ex.a_bss & clofset);
if (*a_bss_fill == clbytes) {
*a_bss_fill = 0;
}
} else {
*a_bss_fill = clbytes -
((ex.a_text+ex.a_data+ex.a_bss) & clofset);
if (*a_text_fill == clbytes) {
*a_text_fill = 0;
}
}
}
if (aout != NULL) {
*aout = mid;
}
return(0);
#endif /* NOAOUT */
}
int
GetFileInfo(fd, load, xfr, aout,
a_text, a_text_fill, a_data, a_data_fill, a_bss, a_bss_fill)
int fd, *aout;
u_long *load, *xfr, *a_text, *a_text_fill;
u_long *a_data, *a_data_fill, *a_bss, *a_bss_fill;
{
int err;
err = CheckAOutFile(fd);
if (err == 0) {
err = GetAOutFileInfo(fd, load, xfr,
a_text, a_text_fill,
a_data, a_data_fill,
a_bss, a_bss_fill,
aout);
if (err != 0) {
return(-1);
}
} else {
err = CheckMopFile(fd);
if (err == 0) {
err = GetMopFileInfo(fd, load, xfr);
if (err != 0) {
return(-1);
}
*aout = -1;
} else {
return(-1);
}
}
return(0);
}
ssize_t
mopFileRead(dlslot, buf)
struct dllist *dlslot;
u_char *buf;
{
ssize_t len, outlen;
int bsz;
long pos, notdone, total;
if (dlslot->aout == -1) {
len = read(dlslot->ldfd,buf,dlslot->dl_bsz);
} else {
bsz = dlslot->dl_bsz;
pos = dlslot->a_lseek;
len = 0;
total = dlslot->a_text;
if (pos < total) {
notdone = total - pos;
if (notdone <= bsz) {
outlen = read(dlslot->ldfd,&buf[len],notdone);
} else {
outlen = read(dlslot->ldfd,&buf[len],bsz);
}
len = len + outlen;
pos = pos + outlen;
bsz = bsz - outlen;
}
total = total + dlslot->a_text_fill;
if ((bsz > 0) && (pos < total)) {
notdone = total - pos;
if (notdone <= bsz) {
outlen = notdone;
} else {
outlen = bsz;
}
bzero(&buf[len],outlen);
len = len + outlen;
pos = pos + outlen;
bsz = bsz - outlen;
}
total = total + dlslot->a_data;
if ((bsz > 0) && (pos < total)) {
notdone = total - pos;
if (notdone <= bsz) {
outlen = read(dlslot->ldfd,&buf[len],notdone);
} else {
outlen = read(dlslot->ldfd,&buf[len],bsz);
}
len = len + outlen;
pos = pos + outlen;
bsz = bsz - outlen;
}
total = total + dlslot->a_data_fill;
if ((bsz > 0) && (pos < total)) {
notdone = total - pos;
if (notdone <= bsz) {
outlen = notdone;
} else {
outlen = bsz;
}
bzero(&buf[len],outlen);
len = len + outlen;
pos = pos + outlen;
bsz = bsz - outlen;
}
total = total + dlslot->a_bss;
if ((bsz > 0) && (pos < total)) {
notdone = total - pos;
if (notdone <= bsz) {
outlen = notdone;
} else {
outlen = bsz;
}
bzero(&buf[len],outlen);
len = len + outlen;
pos = pos + outlen;
bsz = bsz - outlen;
}
total = total + dlslot->a_bss_fill;
if ((bsz > 0) && (pos < total)) {
notdone = total - pos;
if (notdone <= bsz) {
outlen = notdone;
} else {
outlen = bsz;
}
bzero(&buf[len],outlen);
len = len + outlen;
pos = pos + outlen;
bsz = bsz - outlen;
}
dlslot->a_lseek = pos;
}
return(len);
}
|