Class FileSystemIndexHelper<METADATATYPE>

  • Type Parameters:
    METADATATYPE - the filesystem specific native file object that the user of this class wants to be able to correlate with Ghidra GFile instances.

    public class FileSystemIndexHelper<METADATATYPE>
    extends java.lang.Object
    A helper class used by GFilesystem implementors to track mappings between GFile instances and the underlying container filesystem's native file objects.

    Threadsafe (methods are synchronized).

    This class also provides filename 'unique-ifying' (per directory) where an auto-incrementing number will be added to a file's filename if it is not unique in the directory.

    • Field Detail

      • fileToEntryMap MODIFIED

        type: Map → Map
        -java.util.Map<ghidra.formats.gfilesystem.GFile,METADATATYPE> fileToEntryMap
        +java.util.Map<ghidra.formats.gfilesystem.GFile,ghidra.formats.gfilesystem.FileSystemIndexHelper.FileData<METADATATYPE>> fileToEntryMap
        protected java.util.Map<GFile,​ghidra.formats.gfilesystem.FileSystemIndexHelper.FileData<METADATATYPE>> fileToEntryMap
      • fileIndexToEntryMap NEW

        protected java.util.Map<java.lang.Long,​ghidra.formats.gfilesystem.FileSystemIndexHelper.FileData<METADATATYPE>> fileIndexToEntryMap
      • directoryToListing MODIFIED

        type: Map → Map
        -java.util.Map<ghidra.formats.gfilesystem.GFile,java.util.Map<java.lang.String,ghidra.formats.gfilesystem.GFile>> directoryToListing
        +java.util.Map<ghidra.formats.gfilesystem.GFile,java.util.Map<java.lang.String,ghidra.formats.gfilesystem.FileSystemIndexHelper.FileData<METADATATYPE>>> directoryToListing
        protected java.util.Map<GFile,​java.util.Map<java.lang.String,​ghidra.formats.gfilesystem.FileSystemIndexHelper.FileData<METADATATYPE>>> directoryToListing

Constructor Detail

  • Method Detail

    • getRootDir

      public GFile getRootDir()
      Gets the root GFile object for this filesystem index.
      Returns:
      root GFile object.
    • clear

      public void clear()
      Removes all file info from this index.
    • getFileCount

      public int getFileCount()
      Number of files in this index.
      Returns:
      number of file in this index
    • getMetadata

      public METADATATYPE getMetadata​(GFile f)
      Gets the opaque filesystem specific blob that was associated with the specified file.
      Parameters:
      f - GFile to look for
      Returns:
      Filesystem specific blob associated with the specified file, or null if not found
    • setMetadata NEW

      public void setMetadata​(GFile f,
                              METADATATYPE metaData)
                       throws java.io.IOException
      Sets the associated metadata blob for the specified file.
      Parameters:
      f - GFile to update
      metaData - new metdata blob
      Throws:
      java.io.IOException - if unknown file
    • getFileByIndex NEW

      public GFile getFileByIndex​(long fileIndex)
      Gets the GFile instance that was associated with the filesystem file index.
      Parameters:
      fileIndex - index of the file in its filesystem
      Returns:
      the associated GFile instance, or null if not found
    • getListing

      public java.util.List<GFile> getListing​(GFile directory)
      Mirror's GFileSystem.getListing(GFile) interface.
      Parameters:
      directory - GFile directory to get the list of child files that have been added to this index, null means root directory
      Returns:
      List of GFile files that are in the specified directory, never null
    • lookup

      public GFile lookup​(java.lang.String path)
      Mirror's GFileSystem.lookup(String) interface.
      Parameters:
      path - path and filename of a file to find
      Returns:
      GFile instance or null if no file was added to the index at that path
    • storeFile NEW

      public GFile storeFile​(java.lang.String path,
                             long fileIndex,
                             boolean isDirectory,
                             long length,
                             METADATATYPE metadata)
      Creates and stores a file entry into in-memory indexes.

      The string path will be normalized to forward slashes before being split into directory components.

      Filenames that are not unique in their directory will have a "[nnn]" suffix added to the resultant GFile name, where nnn is the file's order of occurrence in the container file.

      Parameters:
      path - string path and filename of the file being added to the index. Back slashes are normalized to forward slashes
      fileIndex - the filesystem specific unique index for this file, or -1 if not available
      isDirectory - boolean true if the new file is a directory
      length - number of bytes in the file or -1 if not known or directory
      metadata - opaque blob that will be stored and associated with the new GFile instance
      Returns:
      new GFile instance
    • storeFileWithParent NEW

      public GFile storeFileWithParent​(java.lang.String filename,
                                       GFile parent,
                                       long fileIndex,
                                       boolean isDirectory,
                                       long length,
                                       METADATATYPE metadata)
      Creates and stores a file entry into in-memory indexes.

      Use this when you already know the parent directory GFile object.

      Filenames that are not unique in their directory will have a "[nnn]" suffix added to the resultant GFile name, where nnn is the file's order of occurrence in the container file.

      Parameters:
      filename - the new file's name
      parent - the new file's parent directory
      fileIndex - the filesystem specific unique index for this file, or -1 if not available
      isDirectory - boolean true if the new file is a directory
      length - number of bytes in the file or -1 if not known or directory
      metadata - opaque blob that will be stored and associated with the new GFile instance
      Returns:
      new GFile instance
    • lookupParent

      protected GFile lookupParent​(java.lang.String[] nameparts)
      Walks a list of names of directories in nameparts (stopping prior to the last element) starting at the root of the filesystem and returns the final directory.

      Directories in a path that have not been encountered before (ie. a file's path references a directory that hasn't been mentioned yet as its own file entry) will have a stub entry GFile created for them.

      Superfluous slashes in the original filename (ie. name/sub//subafter_extra_slash) will be represented as empty string elements in the nameparts array and will be skipped as if they were not there.

      Parameters:
      nameparts -
      Returns:
    • createNewFile

      protected GFileImpl createNewFile​(GFile parentFile,
                                        java.lang.String name,
                                        boolean isDirectory,
                                        long size,
                                        METADATATYPE metadata)
      Creates a new GFile instance, using per-filesystem custom logic.

      Parameters:
      parentFile - the parent file of the new instance. Never null.
      name - the name of the file
      isDirectory - is this is file or directory?
      size - length of the file data
      metadata - filesystem specific BLOB that may have data that this method needs to create the new GFile instance. Can be null if this method is being called to create a missing directory that was referenced in a filename.
      Returns:
      new GFileImpl instance
    • updateFSRL NEW

      public void updateFSRL​(GFile file,
                             FSRL newFSRL)
      Updates the FSRL of a file already in the index.
      Parameters:
      file - current GFile
      newFSRL - the new FSRL the new file will be given
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object