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 TypeMethodDescriptionboolean
chmod
(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.long
Get the free space on the filesystem.long
Get 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.void
Create a new directory with the given name and mode.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.Read the contents of a directory.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 a file or directory.boolean
setTimes
(JObjectKey fileUuid, long mtimeMs) Set the access and modification times of a file.long
size
(JObjectKey fileUuid) Get the size of a file.Create a symlink.boolean
truncate
(JObjectKey fileUuid, long length) Truncate a file to the given length.void
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.
-
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
-