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 ofGFileSysteminstances (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 voidadd(GFileSystem fs)Adds a newGFileSystemto the cache.voidcacheMaint()Performs maintainence on the filesystem cache, closing() any filesystems that are not used anymore.voidclear()Forcefully closes any filesystems in the cache, then clears the list of cached filesystems.voidcloseAllUnused()Removes any unused filesystems in the cache.FileSystemRefgetFilesystemRefMountedAt(FSRL containerFSRL)Returns a newFileSystemRefto 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.FileSystemRefgetRef(FSRLRoot fsrl)Returns a newFileSystemRefto an existing, already openfilesystem.booleanisFilesystemMountedAt(FSRL containerFSRL)Returns true if there is a filesystem in the cache that has a containerFSRL that isequivto the specified FSRL.voidonFilesystemClose(GFileSystem fs)Called by GFilesystem'sCloseable.close(), before any destructive changes are made to the filesystem instance.voidonFilesystemRefChange(GFileSystem fs, FileSystemRefManager refManager)Called byFileSystemRefManagerwhen a newFileSystemRefis 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:
ListofFSRLRootof filesystems that are currently mounted.
-
add
public void add(GFileSystem fs)
Adds a newGFileSystemto the cache.- Parameters:
fs-GFileSystemto add to this cache.
-
getRef
public FileSystemRef getRef(FSRLRoot fsrl)
Returns a newFileSystemRefto an existing, already openfilesystem. Caller is responsible forclosingit.Returns NULL if the requested filesystem isn't already open and mounted in the cache.
- Parameters:
fsrl-FSRLRootof the desired filesystem.- Returns:
- a new
FileSystemRefor 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 isequivto the specified FSRL.- Parameters:
containerFSRL-FSRLlocation 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 newFileSystemRefto 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
closingit when done.Returns null if there is no filesystem mounted at the requested container fsrl.
- Parameters:
containerFSRL-FSRLlocation where a filesystem is already mounted- Returns:
- new
FileSystemRefto the already mounted filesystem, or null
-
onFilesystemClose
public void onFilesystemClose(GFileSystem fs)
Description copied from interface:FileSystemEventListenerCalled by GFilesystem'sCloseable.close(), before any destructive changes are made to the filesystem instance.- Specified by:
onFilesystemClosein interfaceFileSystemEventListener- Parameters:
fs-GFileSystemthat is about to be closed.
-
onFilesystemRefChange
public void onFilesystemRefChange(GFileSystem fs, FileSystemRefManager refManager)
Description copied from interface:FileSystemEventListenerCalled byFileSystemRefManagerwhen a newFileSystemRefis created or released.- Specified by:
onFilesystemRefChangein interfaceFileSystemEventListener- Parameters:
fs-GFileSystemthat is being updated.refManager-FileSystemRefManagerthat is tracking the modified GFileSystem.
-
cacheMaint
public void cacheMaint()
Performs maintainence on the filesystem cache, closing() any filesystems that are not used anymore.
-
-