Package com.usatiuk.dhfsfs.service

# Class DhfsFileService

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

@ApplicationScoped public class DhfsFileService extends Object
Actual filesystem implementation.

## Constructor Summary

Constructors
Constructor
Description
`DhfsFileService()`

## Method Summary

Modifier and Type
Method
Description
`Boolean`
`chmod(JObjectKey uuid, long mode)`
Change the mode of a file or directory.
`Optional<JObjectKey>`
`create(String name, long mode)`
Create a new file with the given name and mode.
`Optional<GetattrRes>`
`getattr(JObjectKey uuid)`
Get the attributes of a file or directory.
`org.apache.commons.lang3.tuple.Pair<String,JObjectKey>`
`inoToParent(JObjectKey ino)`
Get the parent directory of a file or directory.
`void`
`mkdir(String name, long mode)`
Create a new directory with the given name and mode.
`Optional<JObjectKey>`
`open(String name)`
Try to resolve a path to a file or directory.
`com.google.protobuf.ByteString`
`read(JObjectKey fileUuid, long offset, int length)`
Read the contents of a file.
`Iterable<String>`
`readDir(String name)`
Read the contents of a directory.
`String`
`readlink(JObjectKey uuid)`
Read the contents of a symlink.
`com.google.protobuf.ByteString`
`readlinkBS(JObjectKey uuid)`
Read the contents of a symlink as a ByteString.
`Boolean`
`rename(String from, String to)`
Rename a file or directory.
`Boolean`
`setTimes(JObjectKey fileUuid, long atimeMs, long mtimeMs)`
Set the access and modification times of a file.
`long`
`size(JObjectKey fileUuid)`
Get the size of a file.
`JObjectKey`
`symlink(String oldpath, String newpath)`
Create a symlink.
`Boolean`
`truncate(JObjectKey fileUuid, long length)`
Truncate a file to the given length.
`void`
`unlink(String name)`
Unlink a file or directory.
`Long`
`write(JObjectKey fileUuid, long offset, byte[] data)`
Write data to a file.
`Long`
`write(JObjectKey fileUuid, long offset, com.google.protobuf.ByteString data)`
Write data to a file.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## 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 atimeMs, long mtimeMs)
Set the access and modification times of a file.

Parameters:
  `fileUuid` - the ID of the file
  `atimeMs` - the access time in milliseconds
  `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