The file caching mechanism is embedded within BFD and allows
the application to open as many BFDs as it wants without
regard to the underlying operating system’s file descriptor
limit (often as low as 20 open files). The module in
cache.c
maintains a least recently used list of
bfd_cache_max_open
files, and exports the name
bfd_cache_lookup
, which runs around and makes sure that
the required BFD is open. If not, then it chooses a file to
close, closes it and opens the one wanted, returning its file
handle.
bfd_cache_init
bfd_cache_close
bfd_cache_close_all
bfd_cache_set_uncloseable
bfd_cache_size
bfd_open_file
bfd_cache_init
bool
bfd_cache_init (bfd *abfd);
¶Add a newly opened BFD to the cache.
bfd_cache_close
bool
bfd_cache_close (bfd *abfd);
¶Remove the BFD abfd from the cache. If the attached file is open, then close it too.
FALSE
is returned if closing the file fails, TRUE
is
returned if all is well.
bfd_cache_close_all
bool
bfd_cache_close_all (void);
¶Remove all BFDs from the cache. If the attached file is open, then close it too. Note - despite its name this function will close a BFD even if it is not marked as being cacheable, ie even if bfd_get_cacheable() returns false.
FALSE
is returned if closing one of the file fails, TRUE
is
returned if all is well.
bfd_cache_set_uncloseable
bool
bfd_cache_set_uncloseable (bfd *abfd, bool value, bool *old);
¶Internal function to mark ABFD as either closeable or not. This is used by bfd_check_format_matches to avoid races where bfd_cache_close_all is called in another thread. VALUE is true to mark the BFD as temporarily uncloseable by the cache; false to mark it as closeable once again. OLD, if non-NULL, is set to the previous value of the flag. Returns false on error, true on success.
bfd_cache_size
unsigned
bfd_cache_size (void);
¶Return the number of open files in the cache.
bfd_open_file
FILE*
bfd_open_file (bfd *abfd);
¶Call the OS to open a file for abfd. Return the FILE *
(possibly NULL
) that results from this operation. Set up the
BFD so that future accesses know the file is open. If the FILE *
returned is NULL
, then it won’t have been put in the
cache, so it won’t have to be removed from it.