Package ghidra.formats.gfilesystem
Class LocalFileSystem
- java.lang.Object
-
- ghidra.formats.gfilesystem.LocalFileSystem
-
- All Implemented Interfaces:
GFileHashProvider
,GFileSystem
,ExtensionPoint
,java.io.Closeable
,java.lang.AutoCloseable
public class LocalFileSystem extends java.lang.Object implements GFileSystem, GFileHashProvider
AGFileSystem
implementation giving access to the user's operating system's local file system.This implementation does not have a
GFileSystemFactory
as this class will be used as the single root filesystem.Closing() this filesystem does nothing.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
FSTYPE
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
ByteProvider
getByteProvider(GFile file, TaskMonitor monitor)
Returns aByteProvider
that contains the contents of the specifiedGFile
.FileAttributes
getFileAttributes(GFile file, TaskMonitor monitor)
Returns a container ofFileAttribute
values.FileAttributes
getFileAttributes(java.io.File f)
Create aFileAttributes
container with info about the specified local file.FSRLRoot
getFSRL()
File system's FSRLjava.io.InputStream
getInputStream(GFile file, TaskMonitor monitor)
Returns anInputStream
that contains the contents of the specifiedGFile
.java.util.List<GFile>
getListing(GFile directory)
Returns a list offiles
that reside in the specified directory on this filesystem.java.io.File
getLocalFile(FSRL fsrl)
Convert a FSRL that points to this file system into a javaFile
.FSRL
getLocalFSRL(java.io.File f)
Converts aFile
into aFSRL
.java.lang.String
getMD5Hash(GFile file, boolean required, TaskMonitor monitor)
Returns the MD5 hash of the specified file.java.lang.String
getName()
File system volume name.FileSystemRefManager
getRefManager()
Returns theref manager
that is responsible for creating and releasingrefs
to this filesystem.LocalFileSystemSub
getSubFileSystem(FSRL fsrl)
Creates a new file system instance that is a sub-view limited to the specified directory.boolean
isClosed()
Returns true if the filesystem has beenclosed
boolean
isLocalSubdir(FSRL fsrl)
Returns true if theFSRL
is a local filesystem subdirectory.boolean
isStatic()
Indicates if this filesystem is a static snapshot or changes.GFileImpl
lookup(java.lang.String path)
Retrieves aGFile
from this filesystem based on its full path and filename.static LocalFileSystem
makeGlobalRootFS()
Create a new instancejava.lang.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ghidra.formats.gfilesystem.GFileSystem
getDescription, getFileCount, getType
-
-
-
-
Field Detail
-
FSTYPE
public static final java.lang.String FSTYPE
- See Also:
- Constant Field Values
-
-
Method Detail
-
makeGlobalRootFS
public static LocalFileSystem makeGlobalRootFS()
Create a new instance- Returns:
- new
LocalFileSystem
instance usingFSTYPE
as its FSRL type.
-
getSubFileSystem
public LocalFileSystemSub getSubFileSystem(FSRL fsrl) throws java.io.IOException
Creates a new file system instance that is a sub-view limited to the specified directory.- Parameters:
fsrl
-FSRL
that must be a directory in this local filesystem- Returns:
- new
LocalFileSystemSub
instance - Throws:
java.io.IOException
- if bad FSRL
-
isLocalSubdir
public boolean isLocalSubdir(FSRL fsrl)
Returns true if theFSRL
is a local filesystem subdirectory.- Parameters:
fsrl
-FSRL
to test.- Returns:
- boolean true if local filesystem directory.
-
getLocalFile
public java.io.File getLocalFile(FSRL fsrl) throws java.io.IOException
Convert a FSRL that points to this file system into a javaFile
.- Parameters:
fsrl
-FSRL
- Returns:
File
- Throws:
java.io.IOException
- if FSRL does not point to this file system
-
getLocalFSRL
public FSRL getLocalFSRL(java.io.File f)
Converts aFile
into aFSRL
.- Parameters:
f
-File
- Returns:
FSRL
-
getName
public java.lang.String getName()
Description copied from interface:GFileSystem
File system volume name.Typically the name of the container file, or a internally stored 'volume' name.
- Specified by:
getName
in interfaceGFileSystem
- Returns:
- string filesystem volume name.
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
isStatic
public boolean isStatic()
Description copied from interface:GFileSystem
Indicates if this filesystem is a static snapshot or changes.- Specified by:
isStatic
in interfaceGFileSystem
- Returns:
- boolean true if the filesystem is static or false if dynamic content.
-
getListing
public java.util.List<GFile> getListing(GFile directory)
Description copied from interface:GFileSystem
Returns a list offiles
that reside in the specified directory on this filesystem.- Specified by:
getListing
in interfaceGFileSystem
- Parameters:
directory
- NULL means root of filesystem.- Returns:
List
ofGFile
instances of file in the requested directory.
-
getFileAttributes
public FileAttributes getFileAttributes(GFile file, TaskMonitor monitor)
Description copied from interface:GFileSystem
Returns a container ofFileAttribute
values.Implementors of this method are not required to add FSRL, NAME, or PATH values unless the values are non-standard.
- Specified by:
getFileAttributes
in interfaceGFileSystem
- Parameters:
file
-GFile
to get the attributes formonitor
-TaskMonitor
- Returns:
FileAttributes
instance (possibly read-only), maybe empty but never null
-
getFileAttributes
public FileAttributes getFileAttributes(java.io.File f)
Create aFileAttributes
container with info about the specified local file.- Parameters:
f
-File
to query- Returns:
FileAttributes
instance
-
getFSRL
public FSRLRoot getFSRL()
Description copied from interface:GFileSystem
File system's FSRL- Specified by:
getFSRL
in interfaceGFileSystem
- Returns:
FSRLRoot
of this filesystem.
-
lookup
public GFileImpl lookup(java.lang.String path) throws java.io.IOException
Description copied from interface:GFileSystem
Retrieves aGFile
from this filesystem based on its full path and filename.- Specified by:
lookup
in interfaceGFileSystem
- Parameters:
path
- string path and filename of a file located in this filesystem. Usenull
or "/" to retrieve the root directory- Returns:
GFile
instance of requested file, null if not found.- Throws:
java.io.IOException
- if IO error when looking up file.
-
isClosed
public boolean isClosed()
Description copied from interface:GFileSystem
Returns true if the filesystem has beenclosed
- Specified by:
isClosed
in interfaceGFileSystem
- Returns:
- boolean true if the filesystem has been closed.
-
getRefManager
public FileSystemRefManager getRefManager()
Description copied from interface:GFileSystem
Returns theref manager
that is responsible for creating and releasingrefs
to this filesystem.- Specified by:
getRefManager
in interfaceGFileSystem
- Returns:
FileSystemRefManager
that manages references to this filesystem.
-
getInputStream
public java.io.InputStream getInputStream(GFile file, TaskMonitor monitor) throws java.io.IOException
Description copied from interface:GFileSystem
Returns anInputStream
that contains the contents of the specifiedGFile
.The caller is responsible for closing the stream.
- Specified by:
getInputStream
in interfaceGFileSystem
- Parameters:
file
-GFile
to get an InputStream formonitor
-TaskMonitor
to watch and update progress- Returns:
- new
InputStream
contains the contents of the file or NULL if the file doesn't have data. - Throws:
java.io.IOException
- if IO problem
-
getByteProvider
public ByteProvider getByteProvider(GFile file, TaskMonitor monitor) throws java.io.IOException
Description copied from interface:GFileSystem
Returns aByteProvider
that contains the contents of the specifiedGFile
.The caller is responsible for closing the provider.
- Specified by:
getByteProvider
in interfaceGFileSystem
- Parameters:
file
-GFile
to get bytes formonitor
-TaskMonitor
to watch and update progress- Returns:
- new
ByteProvider
that contains the contents of the file, or NULL if file doesn't have data - Throws:
java.io.IOException
- if error
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getMD5Hash
public java.lang.String getMD5Hash(GFile file, boolean required, TaskMonitor monitor) throws CancelledException, java.io.IOException
Description copied from interface:GFileHashProvider
Returns the MD5 hash of the specified file.- Specified by:
getMD5Hash
in interfaceGFileHashProvider
- Parameters:
file
- theGFile
required
- boolean flag, if true the hash will always be returned, even if it has to be calculated. If false, the hash will be returned if easily availablemonitor
-TaskMonitor
- Returns:
- MD5 hash as a string
- Throws:
CancelledException
- if cancelledjava.io.IOException
- if error
-
-