Package ghidra.formats.gfilesystem
Class FileSystemCache
- java.lang.Object
-
- ghidra.formats.gfilesystem.FileSystemCache
-
- All Implemented Interfaces:
FileSystemEventListener
public class FileSystemCache extends java.lang.Object implements FileSystemEventListener
A threadsafe cache ofGFileSystem
instances (organized by theirFSRLRoot
)Any filesystems that are not referenced by outside users (via a
FileSystemRef
) will be closed and removed from the cache when the nextcacheMaint()
is performed.
-
-
Constructor Summary
Constructors Constructor Description FileSystemCache(GFileSystem rootFS)
Creates a new FileSystemCache object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(GFileSystem fs)
Adds a newGFileSystem
to the cache.void
cacheMaint()
Performs maintainence on the filesystem cache, closing() any filesystems that are not used anymore.void
clear()
Forcefully closes any filesystems in the cache, then clears the list of cached filesystems.void
closeAllUnused()
Removes any unused filesystems in the cache.FileSystemRef
getFilesystemRefMountedAt(FSRL containerFSRL)
Returns a newFileSystemRef
to a already mountedfilesystem
(keeping the filesystem pinned in memory without the risk of it being closed during a race condition).java.util.List<FSRLRoot>
getMountedFilesystems()
Returns a list of mounted file systems.FileSystemRef
getRef(FSRLRoot fsrl)
Returns a newFileSystemRef
to an existing, already openfilesystem
.boolean
isFilesystemMountedAt(FSRL containerFSRL)
Returns true if there is a filesystem in the cache that has a containerFSRL that isequiv
to the specified FSRL.void
onFilesystemClose(GFileSystem fs)
Called by GFilesystem'sCloseable.close()
, before any destructive changes are made to the filesystem instance.void
onFilesystemRefChange(GFileSystem fs, FileSystemRefManager refManager)
Called byFileSystemRefManager
when a newFileSystemRef
is created or released.
-
-
-
Constructor Detail
-
FileSystemCache
public FileSystemCache(GFileSystem rootFS)
Creates a new FileSystemCache object.- Parameters:
rootFS
- reference to the global root file system, which is a special case file system that is not subject to eviction.
-
-
Method Detail
-
clear
public void clear()
Forcefully closes any filesystems in the cache, then clears the list of cached filesystems.
-
closeAllUnused
public void closeAllUnused()
Removes any unused filesystems in the cache.
-
getMountedFilesystems
public java.util.List<FSRLRoot> getMountedFilesystems()
Returns a list of mounted file systems.- Returns:
List
ofFSRLRoot
of filesystems that are currently mounted.
-
add
public void add(GFileSystem fs)
Adds a newGFileSystem
to the cache.- Parameters:
fs
-GFileSystem
to add to this cache.
-
getRef
public FileSystemRef getRef(FSRLRoot fsrl)
Returns a newFileSystemRef
to an existing, already openfilesystem
. Caller is responsible forclosing
it.Returns NULL if the requested filesystem isn't already open and mounted in the cache.
- Parameters:
fsrl
-FSRLRoot
of the desired filesystem.- Returns:
- a new
FileSystemRef
or null if the filesystem is not currently mounted.
-
isFilesystemMountedAt
public boolean isFilesystemMountedAt(FSRL containerFSRL)
Returns true if there is a filesystem in the cache that has a containerFSRL that isequiv
to the specified FSRL.- Parameters:
containerFSRL
-FSRL
location to query for currently mounted filesystem.- Returns:
- true if there is a filesystem mounted using that containerFSRL.
-
getFilesystemRefMountedAt
public FileSystemRef getFilesystemRefMountedAt(FSRL containerFSRL)
Returns a newFileSystemRef
to a already mountedfilesystem
(keeping the filesystem pinned in memory without the risk of it being closed during a race condition).The caller is responsible for
closing
it when done.Returns null if there is no filesystem mounted at the requested container fsrl.
- Parameters:
containerFSRL
-FSRL
location where a filesystem is already mounted- Returns:
- new
FileSystemRef
to the already mounted filesystem, or null
-
onFilesystemClose
public void onFilesystemClose(GFileSystem fs)
Description copied from interface:FileSystemEventListener
Called by GFilesystem'sCloseable.close()
, before any destructive changes are made to the filesystem instance.- Specified by:
onFilesystemClose
in interfaceFileSystemEventListener
- Parameters:
fs
-GFileSystem
that is about to be closed.
-
onFilesystemRefChange
public void onFilesystemRefChange(GFileSystem fs, FileSystemRefManager refManager)
Description copied from interface:FileSystemEventListener
Called byFileSystemRefManager
when a newFileSystemRef
is created or released.- Specified by:
onFilesystemRefChange
in interfaceFileSystemEventListener
- Parameters:
fs
-GFileSystem
that is being updated.refManager
-FileSystemRefManager
that is tracking the modified GFileSystem.
-
cacheMaint
public void cacheMaint()
Performs maintainence on the filesystem cache, closing() any filesystems that are not used anymore.
-
-