1 /* $NetBSD: file.c,v 1.11 2009/04/17 04:16:57 lukem Exp $ */
4 * Copyright (c) 1995-96 Mats O Jansson. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
29 __RCSID("$NetBSD: file.c,v 1.11 2009/04/17 04:16:57 lukem Exp $");
39 # if defined(__NetBSD__) || defined(__OpenBSD__)
40 # include <sys/exec_aout.h>
42 # if defined(__bsdi__)
45 # if defined(__FreeBSD__)
46 # include <sys/imgact_aout.h>
48 # if !defined(MID_VAX)
54 # if defined(__NetBSD__)
55 # include <sys/exec_elf.h>
61 int getCLBYTES
__P((int));
62 int getMID
__P((int, int));
73 case IMAGE_TYPE_ELF32
:
84 mopFilePutLX(buf
, idx
, value
, cnt
)
90 for (i
= 0; i
< cnt
; i
++) {
91 buf
[idx
+i
] = value
% 256;
97 mopFilePutBX(buf
, idx
, value
, cnt
)
103 for (i
= 0; i
< cnt
; i
++) {
104 buf
[idx
+cnt
-1-i
] = value
% 256;
110 mopFileGetLX(buf
, idx
, cnt
)
117 for (i
= 0; i
< cnt
; i
++) {
118 ret
= ret
*256 + buf
[idx
+cnt
-1-i
];
125 mopFileGetBX(buf
, idx
, cnt
)
132 for (i
= 0; i
< cnt
; i
++) {
133 ret
= ret
*256 + buf
[idx
+i
];
140 mopFileSwapX(buf
, idx
, cnt
)
147 for (i
= 0; i
< (cnt
/ 2); i
++) {
149 buf
[idx
+i
] = buf
[idx
+cnt
-1-i
];
150 buf
[idx
+cnt
-1-i
] = c
;
162 if (read(fd
, header
, 512) != 512)
165 (void)lseek(fd
, (off_t
) 0, SEEK_SET
);
167 image_type
= (u_short
)(header
[IHD_W_ALIAS
+1]*256 +
168 header
[IHD_W_ALIAS
]);
171 case IHD_C_NATIVE
: /* Native mode image (VAX) */
172 case IHD_C_RSX
: /* RSX image produced by TKB */
173 case IHD_C_BPA
: /* BASIC plus analog */
174 case IHD_C_ALIAS
: /* Alias */
175 case IHD_C_CLI
: /* Image is CLI */
176 case IHD_C_PMAX
: /* PMAX system image */
177 case IHD_C_ALPHA
: /* ALPHA system image */
192 u_int32_t load_addr
, xfr_addr
, isd
, iha
, hbcnt
, isize
;
194 if (read(dl
->ldfd
, header
, 512) != 512)
197 image_type
= (u_short
)(header
[IHD_W_ALIAS
+1]*256 +
198 header
[IHD_W_ALIAS
]);
201 case IHD_C_NATIVE
: /* Native mode image (VAX) */
202 isd
= (header
[IHD_W_SIZE
+1]*256 +
204 iha
= (header
[IHD_W_ACTIVOFF
+1]*256 +
205 header
[IHD_W_ACTIVOFF
]);
206 hbcnt
= (header
[IHD_B_HDRBLKCNT
]);
207 isize
= (header
[isd
+ISD_W_PAGCNT
+1]*256 +
208 header
[isd
+ISD_W_PAGCNT
]) * 512;
209 load_addr
= ((header
[isd
+ISD_V_VPN
+1]*256 +
210 header
[isd
+ISD_V_VPN
]) & ISD_M_VPN
)
212 xfr_addr
= (header
[iha
+IHA_L_TFRADR1
+3]*0x1000000 +
213 header
[iha
+IHA_L_TFRADR1
+2]*0x10000 +
214 header
[iha
+IHA_L_TFRADR1
+1]*0x100 +
215 header
[iha
+IHA_L_TFRADR1
]) & 0x7fffffff;
216 printf("Native Image (VAX)\n");
217 printf("Header Block Count: %d\n",hbcnt
);
218 printf("Image Size: %08x\n",isize
);
219 printf("Load Address: %08x\n",load_addr
);
220 printf("Transfer Address: %08x\n",xfr_addr
);
222 case IHD_C_RSX
: /* RSX image produced by TKB */
223 hbcnt
= header
[L_BBLK
+1]*256 + header
[L_BBLK
];
224 isize
= (header
[L_BLDZ
+1]*256 + header
[L_BLDZ
]) * 64;
225 load_addr
= header
[L_BSA
+1]*256 + header
[L_BSA
];
226 xfr_addr
= header
[L_BXFR
+1]*256 + header
[L_BXFR
];
227 printf("RSX Image\n");
228 printf("Header Block Count: %d\n",hbcnt
);
229 printf("Image Size: %08x\n",isize
);
230 printf("Load Address: %08x\n",load_addr
);
231 printf("Transfer Address: %08x\n",xfr_addr
);
233 case IHD_C_BPA
: /* BASIC plus analog */
234 printf("BASIC-Plus Image, not supported\n");
237 case IHD_C_ALIAS
: /* Alias */
238 printf("Alias, not supported\n");
241 case IHD_C_CLI
: /* Image is CLI */
242 printf("CLI, not supported\n");
245 case IHD_C_PMAX
: /* PMAX system image */
246 isd
= (header
[IHD_W_SIZE
+1]*256 +
248 iha
= (header
[IHD_W_ACTIVOFF
+1]*256 +
249 header
[IHD_W_ACTIVOFF
]);
250 hbcnt
= (header
[IHD_B_HDRBLKCNT
]);
251 isize
= (header
[isd
+ISD_W_PAGCNT
+1]*256 +
252 header
[isd
+ISD_W_PAGCNT
]) * 512;
253 load_addr
= (header
[isd
+ISD_V_VPN
+1]*256 +
254 header
[isd
+ISD_V_VPN
]) * 512;
255 xfr_addr
= (header
[iha
+IHA_L_TFRADR1
+3]*0x1000000 +
256 header
[iha
+IHA_L_TFRADR1
+2]*0x10000 +
257 header
[iha
+IHA_L_TFRADR1
+1]*0x100 +
258 header
[iha
+IHA_L_TFRADR1
]);
259 printf("PMAX Image \n");
260 printf("Header Block Count: %d\n",hbcnt
);
261 printf("Image Size: %08x\n",isize
);
262 printf("Load Address: %08x\n",load_addr
);
263 printf("Transfer Address: %08x\n",xfr_addr
);
265 case IHD_C_ALPHA
: /* ALPHA system image */
266 isd
= (header
[EIHD_L_ISDOFF
+3]*0x1000000 +
267 header
[EIHD_L_ISDOFF
+2]*0x10000 +
268 header
[EIHD_L_ISDOFF
+1]*0x100 +
269 header
[EIHD_L_ISDOFF
]);
270 hbcnt
= (header
[EIHD_L_HDRBLKCNT
+3]*0x1000000 +
271 header
[EIHD_L_HDRBLKCNT
+2]*0x10000 +
272 header
[EIHD_L_HDRBLKCNT
+1]*0x100 +
273 header
[EIHD_L_HDRBLKCNT
]);
274 isize
= (header
[isd
+EISD_L_SECSIZE
+3]*0x1000000 +
275 header
[isd
+EISD_L_SECSIZE
+2]*0x10000 +
276 header
[isd
+EISD_L_SECSIZE
+1]*0x100 +
277 header
[isd
+EISD_L_SECSIZE
]);
280 printf("Alpha Image \n");
281 printf("Header Block Count: %d\n",hbcnt
);
282 printf("Image Size: %08x\n",isize
);
283 printf("Load Address: %08x\n",load_addr
);
284 printf("Transfer Address: %08x\n",xfr_addr
);
287 printf("Unknown Image (%d)\n",image_type
);
291 dl
->image_type
= IMAGE_TYPE_MOP
;
292 dl
->loadaddr
= load_addr
;
293 dl
->xferaddr
= xfr_addr
;
300 getMID(old_mid
,new_mid
)
301 int old_mid
, new_mid
;
391 #if defined(MID_I386) || defined(MID_M68K4K) || defined(MID_NS32532) || \
392 defined(MID_PMAX) || defined(MID_MIPS) || defined(MID_ARM6)
405 #if defined(MID_M68K) || defined(MID_ALPHA) || defined(MID_SPARC)
426 (void)lseek(fd
, (off_t
) 0, SEEK_SET
);
428 if (read(fd
, (char *)&ehdr
, sizeof(ehdr
)) != sizeof(ehdr
))
431 if (ehdr
.e_ident
[0] != ELFMAG0
||
432 ehdr
.e_ident
[1] != ELFMAG1
||
433 ehdr
.e_ident
[2] != ELFMAG2
||
434 ehdr
.e_ident
[3] != ELFMAG3
)
437 /* Must be Elf32... */
438 if (ehdr
.e_ident
[EI_CLASS
] != ELFCLASS32
)
454 uint32_t e_machine
, e_entry
;
455 uint32_t e_phoff
, e_phentsize
, e_phnum
;
458 (void)lseek(dl
->ldfd
, (off_t
) 0, SEEK_SET
);
460 if (read(dl
->ldfd
, (char *)&ehdr
, sizeof(ehdr
)) != sizeof(ehdr
))
463 if (ehdr
.e_ident
[0] != ELFMAG0
||
464 ehdr
.e_ident
[1] != ELFMAG1
||
465 ehdr
.e_ident
[2] != ELFMAG2
||
466 ehdr
.e_ident
[3] != ELFMAG3
)
469 /* Must be Elf32... */
470 if (ehdr
.e_ident
[EI_CLASS
] != ELFCLASS32
)
473 ei_data
= ehdr
.e_ident
[EI_DATA
];
477 e_machine
= mopFileGetLX((u_char
*) &ehdr
,
478 offsetof(Elf32_Ehdr
, e_machine
),
479 sizeof(ehdr
.e_machine
));
480 e_entry
= mopFileGetLX((u_char
*) &ehdr
,
481 offsetof(Elf32_Ehdr
, e_entry
),
482 sizeof(ehdr
.e_entry
));
484 e_phoff
= mopFileGetLX((u_char
*) &ehdr
,
485 offsetof(Elf32_Ehdr
, e_phoff
),
486 sizeof(ehdr
.e_phoff
));
487 e_phentsize
= mopFileGetLX((u_char
*) &ehdr
,
488 offsetof(Elf32_Ehdr
, e_phentsize
),
489 sizeof(ehdr
.e_phentsize
));
490 e_phnum
= mopFileGetLX((u_char
*) &ehdr
,
491 offsetof(Elf32_Ehdr
, e_phnum
),
492 sizeof(ehdr
.e_phnum
));
496 e_machine
= mopFileGetBX((u_char
*) &ehdr
,
497 offsetof(Elf32_Ehdr
, e_machine
),
498 sizeof(ehdr
.e_machine
));
499 e_entry
= mopFileGetBX((u_char
*) &ehdr
,
500 offsetof(Elf32_Ehdr
, e_entry
),
501 sizeof(ehdr
.e_entry
));
503 e_phoff
= mopFileGetBX((u_char
*) &ehdr
,
504 offsetof(Elf32_Ehdr
, e_phoff
),
505 sizeof(ehdr
.e_phoff
));
506 e_phentsize
= mopFileGetBX((u_char
*) &ehdr
,
507 offsetof(Elf32_Ehdr
, e_phentsize
),
508 sizeof(ehdr
.e_phentsize
));
509 e_phnum
= mopFileGetBX((u_char
*) &ehdr
,
510 offsetof(Elf32_Ehdr
, e_phnum
),
511 sizeof(ehdr
.e_phnum
));
518 dl
->image_type
= IMAGE_TYPE_ELF32
;
520 dl
->xferaddr
= e_entry
; /* will relocate itself if necessary */
522 if (e_phnum
> SEC_MAX
)
524 dl
->e_nsec
= e_phnum
;
525 for (i
= 0; i
< dl
->e_nsec
; i
++) {
526 if (lseek(dl
->ldfd
, (off_t
) e_phoff
+ (i
* e_phentsize
),
527 SEEK_SET
) == (off_t
) -1)
529 if (read(dl
->ldfd
, (char *) &phdr
, sizeof(phdr
)) !=
535 dl
->e_sections
[i
].s_foff
=
536 mopFileGetLX((u_char
*) &phdr
,
537 offsetof(Elf32_Phdr
, p_offset
),
538 sizeof(phdr
.p_offset
));
539 dl
->e_sections
[i
].s_vaddr
=
540 mopFileGetLX((u_char
*) &phdr
,
541 offsetof(Elf32_Phdr
, p_vaddr
),
542 sizeof(phdr
.p_vaddr
));
543 dl
->e_sections
[i
].s_fsize
=
544 mopFileGetLX((u_char
*) &phdr
,
545 offsetof(Elf32_Phdr
, p_filesz
),
546 sizeof(phdr
.p_filesz
));
547 dl
->e_sections
[i
].s_msize
=
548 mopFileGetLX((u_char
*) &phdr
,
549 offsetof(Elf32_Phdr
, p_memsz
),
550 sizeof(phdr
.p_memsz
));
554 dl
->e_sections
[i
].s_foff
=
555 mopFileGetBX((u_char
*) &phdr
,
556 offsetof(Elf32_Phdr
, p_offset
),
557 sizeof(phdr
.p_offset
));
558 dl
->e_sections
[i
].s_vaddr
=
559 mopFileGetBX((u_char
*) &phdr
,
560 offsetof(Elf32_Phdr
, p_vaddr
),
561 sizeof(phdr
.p_vaddr
));
562 dl
->e_sections
[i
].s_fsize
=
563 mopFileGetBX((u_char
*) &phdr
,
564 offsetof(Elf32_Phdr
, p_filesz
),
565 sizeof(phdr
.p_filesz
));
566 dl
->e_sections
[i
].s_msize
=
567 mopFileGetBX((u_char
*) &phdr
,
568 offsetof(Elf32_Phdr
, p_memsz
),
569 sizeof(phdr
.p_memsz
));
577 * In addition to padding between segments, this also
578 * takes care of memsz > filesz.
580 for (i
= 0; i
< dl
->e_nsec
- 1; i
++) {
581 dl
->e_sections
[i
].s_pad
=
582 dl
->e_sections
[i
+ 1].s_vaddr
-
583 (dl
->e_sections
[i
].s_vaddr
+ dl
->e_sections
[i
].s_fsize
);
585 dl
->e_sections
[dl
->e_nsec
- 1].s_pad
=
586 dl
->e_sections
[dl
->e_nsec
- 1].s_msize
-
587 dl
->e_sections
[dl
->e_nsec
- 1].s_fsize
;
589 * Now compute the logical offsets for each section.
591 dl
->e_sections
[0].s_loff
= 0;
592 for (i
= 1; i
< dl
->e_nsec
; i
++) {
593 dl
->e_sections
[i
].s_loff
=
594 dl
->e_sections
[i
- 1].s_loff
+
595 dl
->e_sections
[i
- 1].s_fsize
+
596 dl
->e_sections
[i
- 1].s_pad
;
599 /* Print info about the image. */
600 printf("Elf32 image (");
608 printf("machine %d", e_machine
);
612 printf("Transfer Address: %08x\n", dl
->xferaddr
);
613 printf("Program Sections: %d\n", dl
->e_nsec
);
614 for (i
= 0; i
< dl
->e_nsec
; i
++) {
615 printf(" S%d File Size: %08x\n", i
,
616 dl
->e_sections
[i
].s_fsize
);
617 printf(" S%d Pad Size: %08x\n", i
,
618 dl
->e_sections
[i
].s_pad
);
620 dl
->e_machine
= e_machine
;
636 struct exec ex
, ex_swap
;
639 if (read(fd
, (char *)&ex
, sizeof(ex
)) != sizeof(ex
))
642 (void)lseek(fd
, (off_t
) 0, SEEK_SET
);
644 if (read(fd
, (char *)&ex_swap
, sizeof(ex_swap
)) != sizeof(ex_swap
))
647 (void)lseek(fd
, (off_t
) 0, SEEK_SET
);
649 mid
= getMID(mid
, N_GETMID (ex
));
652 mid
= getMID(mid
, N_GETMID (ex_swap
));
670 struct exec ex
, ex_swap
;
672 u_int32_t magic
, clbytes
, clofset
;
674 if (read(dl
->ldfd
, (char *)&ex
, sizeof(ex
)) != sizeof(ex
))
677 (void)lseek(dl
->ldfd
, (off_t
) 0, SEEK_SET
);
679 if (read(dl
->ldfd
, (char *)&ex_swap
,
680 sizeof(ex_swap
)) != sizeof(ex_swap
))
683 mopFileSwapX((u_char
*)&ex_swap
, 0, 4);
685 mid
= getMID(mid
, N_GETMID (ex
));
687 if (mid
== (uint32_t)-1) {
688 mid
= getMID(mid
, N_GETMID (ex_swap
));
689 if (mid
!= (uint32_t)-1) {
690 mopFileSwapX((u_char
*)&ex
, 0, 4);
694 if (mid
== (uint32_t)-1) {
719 ex
.a_text
= mopFileGetLX((u_char
*)&ex_swap
, 4, 4);
720 ex
.a_data
= mopFileGetLX((u_char
*)&ex_swap
, 8, 4);
721 ex
.a_bss
= mopFileGetLX((u_char
*)&ex_swap
, 12, 4);
722 ex
.a_syms
= mopFileGetLX((u_char
*)&ex_swap
, 16, 4);
723 ex
.a_entry
= mopFileGetLX((u_char
*)&ex_swap
, 20, 4);
724 ex
.a_trsize
= mopFileGetLX((u_char
*)&ex_swap
, 24, 4);
725 ex
.a_drsize
= mopFileGetLX((u_char
*)&ex_swap
, 28, 4);
737 ex
.a_text
= mopFileGetBX((u_char
*)&ex_swap
, 4, 4);
738 ex
.a_data
= mopFileGetBX((u_char
*)&ex_swap
, 8, 4);
739 ex
.a_bss
= mopFileGetBX((u_char
*)&ex_swap
, 12, 4);
740 ex
.a_syms
= mopFileGetBX((u_char
*)&ex_swap
, 16, 4);
741 ex
.a_entry
= mopFileGetBX((u_char
*)&ex_swap
, 20, 4);
742 ex
.a_trsize
= mopFileGetBX((u_char
*)&ex_swap
, 24, 4);
743 ex
.a_drsize
= mopFileGetBX((u_char
*)&ex_swap
, 28, 4);
749 printf("a.out image (");
750 switch (N_GETMID (ex
)) {
801 switch (N_GETMAGIC (ex
)) {
815 printf("Unknown %ld", (long) N_GETMAGIC (ex
));
818 printf("Size of text: %08lx\n", (long)ex
.a_text
);
819 printf("Size of data: %08lx\n", (long)ex
.a_data
);
820 printf("Size of bss: %08lx\n", (long)ex
.a_bss
);
821 printf("Size of symbol tab: %08lx\n", (long)ex
.a_syms
);
822 printf("Transfer Address: %08lx\n", (long)ex
.a_entry
);
823 printf("Size of reloc text: %08lx\n", (long)ex
.a_trsize
);
824 printf("Size of reloc data: %08lx\n", (long)ex
.a_drsize
);
826 magic
= N_GETMAGIC (ex
);
827 clbytes
= getCLBYTES(mid
);
828 clofset
= clbytes
- 1;
830 dl
->image_type
= IMAGE_TYPE_AOUT
;
832 dl
->xferaddr
= ex
.a_entry
;
834 dl
->a_text
= ex
.a_text
;
835 if (magic
== ZMAGIC
|| magic
== NMAGIC
) {
836 dl
->a_text_fill
= clbytes
- (ex
.a_text
& clofset
);
837 if (dl
->a_text_fill
== clbytes
)
841 dl
->a_data
= ex
.a_data
;
842 if (magic
== ZMAGIC
|| magic
== NMAGIC
) {
843 dl
->a_data_fill
= clbytes
- (ex
.a_data
& clofset
);
844 if (dl
->a_data_fill
== clbytes
)
848 dl
->a_bss
= ex
.a_bss
;
849 if (magic
== ZMAGIC
|| magic
== NMAGIC
) {
850 dl
->a_bss_fill
= clbytes
- (ex
.a_bss
& clofset
);
851 if (dl
->a_bss_fill
== clbytes
)
854 dl
->a_bss_fill
= clbytes
-
855 ((ex
.a_text
+ex
.a_data
+ex
.a_bss
) & clofset
);
856 if (dl
->a_bss_fill
== clbytes
)
871 error
= CheckElfFile(dl
->ldfd
);
873 error
= GetElfFileInfo(dl
);
880 error
= CheckAOutFile(dl
->ldfd
);
882 error
= GetAOutFileInfo(dl
);
889 error
= CheckMopFile(dl
->ldfd
);
891 error
= GetMopFileInfo(dl
);
898 /* Unknown file format. */
903 mopFileRead(dlslot
, buf
)
904 struct dllist
*dlslot
;
909 int32_t pos
, notdone
, total
;
912 switch (dlslot
->image_type
) {
914 len
= read(dlslot
->ldfd
,buf
,dlslot
->dl_bsz
);
917 case IMAGE_TYPE_ELF32
:
918 sec
= dlslot
->e_cursec
;
921 * We're pretty simplistic here. We do only file-backed
925 /* Determine offset into section. */
926 secoff
= dlslot
->e_curpos
- dlslot
->e_sections
[sec
].s_loff
;
929 * If we're in the file-backed part of the section,
930 * transmit some of the file.
932 if (secoff
< dlslot
->e_sections
[sec
].s_fsize
) {
933 bsz
= dlslot
->e_sections
[sec
].s_fsize
- secoff
;
934 if (bsz
> dlslot
->dl_bsz
)
935 bsz
= dlslot
->dl_bsz
;
936 if (lseek(dlslot
->ldfd
,
937 dlslot
->e_sections
[sec
].s_foff
+ secoff
,
938 SEEK_SET
) == (off_t
) -1)
940 len
= read(dlslot
->ldfd
, buf
, bsz
);
943 * Otherwise, if we're in the zero-fill part of the
944 * section, transmit some zeros.
946 else if (secoff
< (dlslot
->e_sections
[sec
].s_fsize
+
947 dlslot
->e_sections
[sec
].s_pad
)) {
948 bsz
= dlslot
->e_sections
[sec
].s_pad
-
949 (secoff
- dlslot
->e_sections
[sec
].s_fsize
);
950 if (bsz
> dlslot
->dl_bsz
)
951 bsz
= dlslot
->dl_bsz
;
952 memset(buf
, 0, (len
= bsz
));
955 * ...and if we haven't hit either of those cases,
956 * that's the end of the image.
962 * Advance the logical image pointer.
964 dlslot
->e_curpos
+= bsz
;
965 if (dlslot
->e_curpos
>= (dlslot
->e_sections
[sec
].s_loff
+
966 dlslot
->e_sections
[sec
].s_fsize
+
967 dlslot
->e_sections
[sec
].s_pad
))
971 case IMAGE_TYPE_AOUT
:
972 bsz
= dlslot
->dl_bsz
;
973 pos
= dlslot
->a_lseek
;
976 total
= dlslot
->a_text
;
979 notdone
= total
- pos
;
980 if (notdone
<= bsz
) {
981 outlen
= read(dlslot
->ldfd
,&buf
[len
],notdone
);
983 outlen
= read(dlslot
->ldfd
,&buf
[len
],bsz
);
990 total
= total
+ dlslot
->a_text_fill
;
992 if ((bsz
> 0) && (pos
< total
)) {
993 notdone
= total
- pos
;
994 if (notdone
<= bsz
) {
999 memset(&buf
[len
], 0, outlen
);
1005 total
= total
+ dlslot
->a_data
;
1007 if ((bsz
> 0) && (pos
< total
)) {
1008 notdone
= total
- pos
;
1009 if (notdone
<= bsz
) {
1010 outlen
= read(dlslot
->ldfd
,&buf
[len
],notdone
);
1012 outlen
= read(dlslot
->ldfd
,&buf
[len
],bsz
);
1019 total
= total
+ dlslot
->a_data_fill
;
1021 if ((bsz
> 0) && (pos
< total
)) {
1022 notdone
= total
- pos
;
1023 if (notdone
<= bsz
) {
1028 memset(&buf
[len
], 0, outlen
);
1034 total
= total
+ dlslot
->a_bss
;
1036 if ((bsz
> 0) && (pos
< total
)) {
1037 notdone
= total
- pos
;
1038 if (notdone
<= bsz
) {
1043 memset(&buf
[len
], 0, outlen
);
1049 total
= total
+ dlslot
->a_bss_fill
;
1051 if ((bsz
> 0) && (pos
< total
)) {
1052 notdone
= total
- pos
;
1053 if (notdone
<= bsz
) {
1058 memset(&buf
[len
], 0, outlen
);
1064 dlslot
->a_lseek
= pos
;