1@findex struct bfd_iovec 2@subsubsection @code{struct bfd_iovec} 3@strong{Description}@* 4The @code{struct bfd_iovec} contains the internal file I/O class. 5Each @code{BFD} has an instance of this class and all file I/O is 6routed through it (it is assumed that the instance implements 7all methods listed below). 8@example 9struct bfd_iovec 10@{ 11 /* To avoid problems with macros, a "b" rather than "f" 12 prefix is prepended to each method name. */ 13 /* Attempt to read/write NBYTES on ABFD's IOSTREAM storing/fetching 14 bytes starting at PTR. Return the number of bytes actually 15 transfered (a read past end-of-file returns less than NBYTES), 16 or -1 (setting @code{bfd_error}) if an error occurs. */ 17 file_ptr (*bread) (struct bfd *abfd, void *ptr, file_ptr nbytes); 18 file_ptr (*bwrite) (struct bfd *abfd, const void *ptr, 19 file_ptr nbytes); 20 /* Return the current IOSTREAM file offset, or -1 (setting @code{bfd_error} 21 if an error occurs. */ 22 file_ptr (*btell) (struct bfd *abfd); 23 /* For the following, on successful completion a value of 0 is returned. 24 Otherwise, a value of -1 is returned (and @code{bfd_error} is set). */ 25 int (*bseek) (struct bfd *abfd, file_ptr offset, int whence); 26 int (*bclose) (struct bfd *abfd); 27 int (*bflush) (struct bfd *abfd); 28 int (*bstat) (struct bfd *abfd, struct stat *sb); 29 /* Mmap a part of the files. ADDR, LEN, PROT, FLAGS and OFFSET are the usual 30 mmap parameter, except that LEN and OFFSET do not need to be page 31 aligned. Returns (void *)-1 on failure, mmapped address on success. 32 Also write in MAP_ADDR the address of the page aligned buffer and in 33 MAP_LEN the size mapped (a page multiple). Use unmap with MAP_ADDR and 34 MAP_LEN to unmap. */ 35 void *(*bmmap) (struct bfd *abfd, void *addr, bfd_size_type len, 36 int prot, int flags, file_ptr offset, 37 void **map_addr, bfd_size_type *map_len); 38@}; 39extern const struct bfd_iovec _bfd_memory_iovec; 40@end example 41 42@findex bfd_get_mtime 43@subsubsection @code{bfd_get_mtime} 44@strong{Synopsis} 45@example 46long bfd_get_mtime (bfd *abfd); 47@end example 48@strong{Description}@* 49Return the file modification time (as read from the file system, or 50from the archive header for archive members). 51 52@findex bfd_get_size 53@subsubsection @code{bfd_get_size} 54@strong{Synopsis} 55@example 56ufile_ptr bfd_get_size (bfd *abfd); 57@end example 58@strong{Description}@* 59Return the file size (as read from file system) for the file 60associated with BFD @var{abfd}. 61 62The initial motivation for, and use of, this routine is not 63so we can get the exact size of the object the BFD applies to, since 64that might not be generally possible (archive members for example). 65It would be ideal if someone could eventually modify 66it so that such results were guaranteed. 67 68Instead, we want to ask questions like "is this NNN byte sized 69object I'm about to try read from file offset YYY reasonable?" 70As as example of where we might do this, some object formats 71use string tables for which the first @code{sizeof (long)} bytes of the 72table contain the size of the table itself, including the size bytes. 73If an application tries to read what it thinks is one of these 74string tables, without some way to validate the size, and for 75some reason the size is wrong (byte swapping error, wrong location 76for the string table, etc.), the only clue is likely to be a read 77error when it tries to read the table, or a "virtual memory 78exhausted" error when it tries to allocate 15 bazillon bytes 79of space for the 15 bazillon byte table it is about to read. 80This function at least allows us to answer the question, "is the 81size reasonable?". 82 83A return value of zero indicates the file size is unknown. 84 85@findex bfd_get_file_size 86@subsubsection @code{bfd_get_file_size} 87@strong{Synopsis} 88@example 89ufile_ptr bfd_get_file_size (bfd *abfd); 90@end example 91@strong{Description}@* 92Return the file size (as read from file system) for the file 93associated with BFD @var{abfd}. It supports both normal files 94and archive elements. 95 96@findex bfd_mmap 97@subsubsection @code{bfd_mmap} 98@strong{Synopsis} 99@example 100void *bfd_mmap (bfd *abfd, void *addr, bfd_size_type len, 101 int prot, int flags, file_ptr offset, 102 void **map_addr, bfd_size_type *map_len); 103@end example 104@strong{Description}@* 105Return mmap()ed region of the file, if possible and implemented. 106LEN and OFFSET do not need to be page aligned. The page aligned 107address and length are written to MAP_ADDR and MAP_LEN. 108 109