Class AbstractEmuUnixFile<T>

java.lang.Object
ghidra.pcode.emu.unix.AbstractEmuUnixFile<T>
Type Parameters:
T - the type of values stored in the file
All Implemented Interfaces:
EmuUnixFile<T>
Direct Known Subclasses:
BytesEmuUnixFileSystem.BytesEmuUnixFile

public abstract class AbstractEmuUnixFile<T> extends Object implements EmuUnixFile<T>
An abstract file contained in an emulated file system

Contrast this with DefaultEmuUnixFileHandle, which is a particular process's handle when opening the file, not the file itself.

  • Field Details

  • Constructor Details

    • AbstractEmuUnixFile

      public AbstractEmuUnixFile(String pathname, int mode)
      Construct a new file

      TODO: Technically, a file can be hardlinked to several pathnames, but for simplicity, or for diagnostics, we let the file know its own original name.

      Parameters:
      pathname - the pathname of the file
      mode - the mode of the file
      See Also:
  • Method Details

    • createStat

      protected EmuUnixFileStat createStat()
      A factory method for the file's stat structure.
      Returns:
      the stat structure.
    • createDefaultContents

      protected abstract EmuFileContents<T> createDefaultContents()
      A factory method for the file's default contents
      Returns:
      the contents
    • getPathname

      public String getPathname()
      Description copied from interface: EmuUnixFile
      Get the original pathname of this file

      Depending on the fidelity of the file system simulator, and the actions taken by the target program, the file may no longer actually exist at this path, but it ought be have been the pathname at some point in the file life.

      Specified by:
      getPathname in interface EmuUnixFile<T>
      Returns:
      the pathname
    • getStat

      public EmuUnixFileStat getStat()
      Description copied from interface: EmuUnixFile
      Get the file's stat structure, as defined by the simulator.
      Specified by:
      getStat in interface EmuUnixFile<T>
      Returns:
      the stat
    • read

      public T read(PcodeArithmetic<T> arithmetic, T offset, T buf)
      Description copied from interface: EmuUnixFile
      Read contents from the file starting at the given offset into the given buffer

      This roughly follows the semantics of the UNIX read(). While the offset and return value may depend on the arithmetic, the actual contents read from the file should not.

      Specified by:
      read in interface EmuUnixFile<T>
      Parameters:
      arithmetic - the arithmetic
      offset - the offset
      buf - the buffer
      Returns:
      the number of bytes read
    • write

      public T write(PcodeArithmetic<T> arithmetic, T offset, T buf)
      Description copied from interface: EmuUnixFile
      Write contents into the file starting at the given offset from the given buffer

      This roughly follows the semantics of the UNIX write(). While the offset and return value may depend on the arithmetic, the actual contents written to the file should not.

      Specified by:
      write in interface EmuUnixFile<T>
      Parameters:
      arithmetic - the arithmetic
      offset - the offset
      buf - the buffer
      Returns:
      the number of bytes written
    • truncate

      public void truncate()
      Description copied from interface: EmuUnixFile
      Erase the contents of the file
      Specified by:
      truncate in interface EmuUnixFile<T>