Class DhfsFileService

java.lang.Object
com.usatiuk.dhfsfs.service.DhfsFileService

@ApplicationScoped public class DhfsFileService extends Object
Actual filesystem implementation.
  • Constructor Details

    • DhfsFileService

      public DhfsFileService()
  • Method Details

    • getattr

      public Optional<GetattrRes> getattr(JObjectKey uuid)
      Get the attributes of a file or directory.
      Parameters:
      uuid - the UUID of the file or directory
      Returns:
      the attributes of the file or directory
    • open

      public Optional<JObjectKey> open(String name)
      Try to resolve a path to a file or directory.
      Parameters:
      name - the path to resolve
      Returns:
      the key of the file or directory, or an empty optional if it does not exist
    • create

      public Optional<JObjectKey> create(String name, long mode)
      Create a new file with the given name and mode.
      Parameters:
      name - the name of the file
      mode - the mode of the file
      Returns:
      the key of the created file
    • inoToParent

      public org.apache.commons.lang3.tuple.Pair<String,JObjectKey> inoToParent(JObjectKey ino)
      Get the parent directory of a file or directory.
      Parameters:
      ino - the key of the file or directory
      Returns:
      the parent directory
    • mkdir

      public void mkdir(String name, long mode)
      Create a new directory with the given name and mode.
      Parameters:
      name - the name of the directory
      mode - the mode of the directory
    • unlink

      public void unlink(String name)
      Unlink a file or directory.
      Parameters:
      name - the name of the file or directory
      Throws:
      DirectoryNotEmptyException - if the directory is not empty and recursive delete is not allowed
    • rename

      public boolean rename(String from, String to)
      Rename a file or directory.
      Parameters:
      from - the old name
      to - the new name
      Returns:
      true if the rename was successful, false otherwise
    • chmod

      public boolean chmod(JObjectKey uuid, long mode)
      Change the mode of a file or directory.
      Parameters:
      uuid - the ID of the file or directory
      mode - the new mode
      Returns:
      true if the mode was changed successfully, false otherwise
    • readDir

      public Iterable<String> readDir(String name)
      Read the contents of a directory.
      Parameters:
      name - the path of the directory
      Returns:
      an iterable of the names of the files in the directory
    • read

      public com.google.protobuf.ByteString read(JObjectKey fileUuid, long offset, int length)
      Read the contents of a file.
      Parameters:
      fileUuid - the ID of the file
      offset - the offset to start reading from
      length - the number of bytes to read
      Returns:
      the contents of the file as a ByteString
    • write

      public long write(JObjectKey fileUuid, long offset, com.google.protobuf.ByteString data)
      Write data to a file.
      Parameters:
      fileUuid - the ID of the file
      offset - the offset to write to
      data - the data to write
      Returns:
      the number of bytes written
    • truncate

      public boolean truncate(JObjectKey fileUuid, long length)
      Truncate a file to the given length.
      Parameters:
      fileUuid - the ID of the file
      length - the new length of the file
      Returns:
      true if the truncate was successful, false otherwise
    • readlink

      public String readlink(JObjectKey uuid)
      Read the contents of a symlink.
      Parameters:
      uuid - the ID of the symlink
      Returns:
      the contents of the symlink as a string
    • readlinkBS

      public com.google.protobuf.ByteString readlinkBS(JObjectKey uuid)
      Read the contents of a symlink as a ByteString.
      Parameters:
      uuid - the ID of the symlink
      Returns:
      the contents of the symlink as a ByteString
    • symlink

      public JObjectKey symlink(String oldpath, String newpath)
      Create a symlink.
      Parameters:
      oldpath - the target of the symlink
      newpath - the path of the symlink
      Returns:
      the key of the created symlink
    • setTimes

      public boolean setTimes(JObjectKey fileUuid, long mtimeMs)
      Set the access and modification times of a file.
      Parameters:
      fileUuid - the ID of the file
      mtimeMs - the modification time in milliseconds
      Returns:
      true if the times were set successfully, false otherwise
    • size

      public long size(JObjectKey fileUuid)
      Get the size of a file.
      Parameters:
      fileUuid - the ID of the file
      Returns:
      the size of the file
    • write

      public long write(JObjectKey fileUuid, long offset, byte[] data)
      Write data to a file.
      Parameters:
      fileUuid - the ID of the file
      offset - the offset to write to
      data - the data to write
      Returns:
      the number of bytes written
    • getFreeSpace

      public long getFreeSpace()
      Get the free space on the filesystem.
      Returns:
      the free space in bytes
    • getTotalSpace

      public long getTotalSpace()
      Get the total space on the filesystem.
      Returns:
      the total space in bytes