Package com.usatiuk.dhfsfs.service
Class DhfsFileService
java.lang.Object
com.usatiuk.dhfsfs.service.DhfsFileService
Actual filesystem implementation.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanchmod(JObjectKey uuid, long mode) Change the mode of a file or directory.Create a new file with the given name and mode.getattr(JObjectKey uuid) Get the attributes of a file or directory.longGet the free space on the filesystem.longGet the total space on the filesystem.org.apache.commons.lang3.tuple.Pair<String, JObjectKey> inoToParent(JObjectKey ino) Get the parent directory of a file or directory.voidCreate a new directory with the given name and mode.Try to resolve a path to a file or directory.com.google.protobuf.ByteStringread(JObjectKey fileUuid, long offset, int length) Read the contents of a file.Read the contents of a directory.readlink(JObjectKey uuid) Read the contents of a symlink.com.google.protobuf.ByteStringreadlinkBS(JObjectKey uuid) Read the contents of a symlink as a ByteString.booleanRename a file or directory.booleansetTimes(JObjectKey fileUuid, long mtimeMs) Set the access and modification times of a file.longsize(JObjectKey fileUuid) Get the size of a file.Create a symlink.booleantruncate(JObjectKey fileUuid, long length) Truncate a file to the given length.voidUnlink a file or directory.longwrite(JObjectKey fileUuid, long offset, byte[] data) Write data to a file.longwrite(JObjectKey fileUuid, long offset, com.google.protobuf.ByteString data) Write data to a file.
-
Constructor Details
-
DhfsFileService
public DhfsFileService()
-
-
Method Details
-
getattr
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
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
Create a new file with the given name and mode.- Parameters:
name- the name of the filemode- the mode of the file- Returns:
- the key of the created file
-
inoToParent
Get the parent directory of a file or directory.- Parameters:
ino- the key of the file or directory- Returns:
- the parent directory
-
mkdir
Create a new directory with the given name and mode.- Parameters:
name- the name of the directorymode- the mode of the directory
-
unlink
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
Rename a file or directory.- Parameters:
from- the old nameto- the new name- Returns:
- true if the rename was successful, false otherwise
-
chmod
Change the mode of a file or directory.- Parameters:
uuid- the ID of the file or directorymode- the new mode- Returns:
- true if the mode was changed successfully, false otherwise
-
readDir
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
Read the contents of a file.- Parameters:
fileUuid- the ID of the fileoffset- the offset to start reading fromlength- the number of bytes to read- Returns:
- the contents of the file as a ByteString
-
write
Write data to a file.- Parameters:
fileUuid- the ID of the fileoffset- the offset to write todata- the data to write- Returns:
- the number of bytes written
-
truncate
Truncate a file to the given length.- Parameters:
fileUuid- the ID of the filelength- the new length of the file- Returns:
- true if the truncate was successful, false otherwise
-
readlink
Read the contents of a symlink.- Parameters:
uuid- the ID of the symlink- Returns:
- the contents of the symlink as a string
-
readlinkBS
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
Create a symlink.- Parameters:
oldpath- the target of the symlinknewpath- the path of the symlink- Returns:
- the key of the created symlink
-
setTimes
Set the access and modification times of a file.- Parameters:
fileUuid- the ID of the filemtimeMs- the modification time in milliseconds- Returns:
- true if the times were set successfully, false otherwise
-
size
Get the size of a file.- Parameters:
fileUuid- the ID of the file- Returns:
- the size of the file
-
write
Write data to a file.- Parameters:
fileUuid- the ID of the fileoffset- the offset to write todata- 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
-