Package ghidra.formats.gfilesystem

# Class GFileSystemBase

java.lang.Object
ghidra.formats.gfilesystem.GFileSystemBase

All Implemented Interfaces:
  `GFileSystem`, `ExtensionPoint`, `Closeable`, `AutoCloseable`

public abstract class GFileSystemBase extends Object implements GFileSystem
This is the original GFileSystem implementation abstract base class, with most of the initially implemented filesystem types extending this class.

The new GFileSystem interface is being retro-fitted into this equation to support better probing and factory syntax, and new implementations should be based on the interface instead of extending this abstract class.

NOTE: ALL GFileSystem sub-CLASSES MUST END IN "FileSystem". If not, the ClassSearcher will not find them. Yes, it is an implementation detail.

GFileSystemBase instances are constructed when probing a container file and are queried with `isValid(TaskMonitor)` to determine if the container file is handled by the GFileSystemBase subclass.

The `ByteProvider` given to the constructor is not considered 'owned' by the GFileSystemBase instance until after it passes the `isValid` check and is `opened`.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected String`
  `fileSystemName`
  `protected FileSystemService`
  `fsService`
  `protected ByteProvider`
  `provider`
  `protected GFileImpl`
  `root`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `GFileSystemBase(String fileSystemName, ByteProvider provider)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  Closes the file system.
  `protected void`
  `debug(byte[] bytes, String fileName)`
  Writes the given bytes to a tempfile in the temp directory.
  `protected Comparator<String>`
  `getFilenameComparator()`
  Override to specify a file-system specific name comparator.
  `FSRLRoot`
  `getFSRL()`
  File system's FSRL
  `abstract List<GFile>`
  `getListing(GFile directory)`
  Returns a list of `files` that reside in the specified directory on this filesystem.
  `final String`
  `getName()`
  Returns the name of this file system.
  `FileSystemRefManager`
  `getRefManager()`
  Returns the `ref manager` that is responsible for creating and releasing `refs` to this filesystem.
  `boolean`
  `isClosed()`
  Returns true if the filesystem has been `closed`
  `abstract boolean`
  `isValid(TaskMonitor monitor)`
  Returns true if this file system implementation can handle the bytes provided.
  `GFile`
  `lookup(String path)`
  Retrieves a `GFile` from this filesystem based on its full path and filename, using this filesystem's default name comparison logic (eg.
  `abstract void`
  `open(TaskMonitor monitor)`
  Opens the file system.
  `void`
  `setFilesystemService(FileSystemService fsService)`
  `void`
  `setFSRL(FSRLRoot fsrl)`
  `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

  `getByteProvider, getDescription, getFileAttributes, getFileCount, getInputStream, getType, isStatic`

- ## Field Details

  - ### fileSystemName

    protected String fileSystemName

  - ### root

    protected GFileImpl root

  - ### provider

    protected ByteProvider provider

  - ### fsService

    protected FileSystemService fsService

- ## Constructor Details

  - ### GFileSystemBase

    protected GFileSystemBase(String fileSystemName, ByteProvider provider)

- ## Method Details

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### getFSRL

    public FSRLRoot getFSRL()
    Description copied from interface: `GFileSystem`
    File system's FSRL
    Specified by:
      `getFSRL` in interface `GFileSystem`
    Returns:
      `FSRLRoot` of this filesystem.

  - ### setFSRL

    public void setFSRL(FSRLRoot fsrl)

  - ### setFilesystemService

    public void setFilesystemService(FileSystemService fsService)

  - ### isValid

    public abstract boolean isValid(TaskMonitor monitor) throws IOException
    Returns true if this file system implementation can handle the bytes provided. This method should perform the minimal amount of checks required to determine validity. Keep it quick and tight!
    Parameters:
      `monitor` - a task monitor
    Returns:
      true if valid for the byte provider
    Throws:
      `IOException` - if an I/O error occurs

  - ### open

    public abstract void open(TaskMonitor monitor) throws IOException, CryptoException, CancelledException
    Opens the file system.
    Throws:
      `IOException` - if an I/O error occurs
      `CryptoException` - if an encryption error occurs
      `CancelledException`

  - ### close

    public void close() throws IOException
    Closes the file system. All resources should be released. (programs, temporary files, etc.)
    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `Closeable`
    Throws:
      `IOException` - if an I/O error occurs

  - ### isClosed

    public boolean isClosed()
    Description copied from interface: `GFileSystem`
    Returns true if the filesystem has been `closed`
    Specified by:
      `isClosed` in interface `GFileSystem`
    Returns:
      boolean true if the filesystem has been closed.

  - ### getName

    public final String getName()
    Returns the name of this file system.
    Specified by:
      `getName` in interface `GFileSystem`
    Returns:
      the name of this file system

  - ### getListing

    public abstract List<GFile> getListing(GFile directory) throws IOException
    Description copied from interface: `GFileSystem`
    Returns a list of `files` that reside in the specified directory on this filesystem.

    Specified by:
      `getListing` in interface `GFileSystem`
    Parameters:
      `directory` - NULL means root of filesystem.
    Returns:
      `List` of `GFile` instances of file in the requested directory.
    Throws:
      `IOException` - if IO problem.

  - ### debug

    protected void debug(byte[] bytes, String fileName)
    Writes the given bytes to a tempfile in the temp directory.
    Parameters:
      `bytes` - the bytes to write
      `fileName` - the prefix of the temp file name

  - ### getFilenameComparator

    protected Comparator<String> getFilenameComparator()
    Override to specify a file-system specific name comparator.
    Returns:
      `Comparator` such as `String.compareTo(String)` or `String.compareToIgnoreCase(String)`

  - ### lookup

    public GFile lookup(String path) throws IOException
    Description copied from interface: `GFileSystem`
    Retrieves a `GFile` from this filesystem based on its full path and filename, using this filesystem's default name comparison logic (eg. case sensitive vs insensitive).

    Specified by:
      `lookup` in interface `GFileSystem`
    Parameters:
      `path` - string path and filename of a file located in this filesystem. Use `null` or "/" to retrieve the root directory
    Returns:
      `GFile` instance of requested file, null if not found.
    Throws:
      `IOException` - if IO error when looking up file.

  - ### getRefManager

    public FileSystemRefManager getRefManager()
    Description copied from interface: `GFileSystem`
    Returns the `ref manager` that is responsible for creating and releasing `refs` to this filesystem.

    Specified by:
      `getRefManager` in interface `GFileSystem`
    Returns:
      `FileSystemRefManager` that manages references to this filesystem.