LogCabin
|
Namespaces | |
namespace | System |
Classes | |
class | File |
A File object is just a wrapper around a file descriptor; it represents either an open file, an open directory, or an empty placeholder. More... | |
class | FileContents |
Provides random access to a file. More... | |
Functions | |
void | allocate (const File &file, uint64_t offset, uint64_t bytes) |
Allocate a contiguous range of a file, padding with zeros if necessary. | |
File | dup (const File &file) |
Clones a file descriptor. | |
void | fsync (const File &file) |
Flush changes to a File to its underlying storage device. | |
void | fdatasync (const File &file) |
Flush changes to a File to its underlying storage device, except for atime/mtime. | |
void | flock (const File &file, int operation) |
Apply or remove an advisory lock on a file or directory. | |
std::string | tryFlock (const File &file, int operation) |
Apply or remove an advisory lock on a file or directory. | |
uint64_t | getSize (const File &file) |
Returns the size of the file in bytes. | |
std::vector< std::string > | lsHelper (DIR *dir, const std::string &path) |
std::vector< std::string > | ls (const std::string &path) |
List the contents of a directory by path. | |
std::vector< std::string > | ls (const File &dir) |
List the contents of an open directory. | |
File | openDir (const std::string &path) |
Open a directory, creating it if it doesn't exist. | |
File | openDir (const File &dir, const std::string &child) |
Open a directory relative to an already open directory, creating it if it doesn't exist. | |
File | openFile (const File &dir, const std::string &child, int flags) |
Open a file. | |
File | tryOpenFile (const File &dir, const std::string &child, int flags) |
Open a file. | |
void | remove (const std::string &path) |
Remove the file or directory at path. | |
void | removeFile (const File &dir, const std::string &path) |
Remove the file relative to an open directory. | |
void | rename (const File &oldDir, const std::string &oldChild, const File &newDir, const std::string &newChild) |
Rename a file. | |
void | syncDir (const std::string &path) |
Open a directory, fsync it, and close it. | |
void | truncate (const File &file, uint64_t bytes) |
Shrink or grow a file to the specified length, padding with zeros if necessary. | |
std::string | mkdtemp () |
Return a path to a temporary directory. | |
ssize_t | write (int fildes, const void *data, uint64_t dataLen) |
A wrapper around write that retries interrupted calls. | |
ssize_t | write (int fildes, std::initializer_list< std::pair< const void *, uint64_t >> data) |
A wrapper around write that retries interrupted calls. | |
Variables | |
bool | skipFsync |
Set to true in some unit tests to skip fsync() and fdatasync(), which can speeds up some tests significantly. |
void LogCabin::Storage::FilesystemUtil::allocate | ( | const File & | file, |
uint64_t | offset, | ||
uint64_t | bytes | ||
) |
Allocate a contiguous range of a file, padding with zeros if necessary.
See man 3 posix_fallocate. Does not fsync the file.
Definition at line 94 of file FilesystemUtil.cc.
File LogCabin::Storage::FilesystemUtil::dup | ( | const File & | file | ) |
Clones a file descriptor.
See man 2 dup.
file | An open file descriptor. |
Definition at line 106 of file FilesystemUtil.cc.
void LogCabin::Storage::FilesystemUtil::fsync | ( | const File & | file | ) |
Flush changes to a File to its underlying storage device.
See skipFsync.
file | An open file descriptor. |
Definition at line 117 of file FilesystemUtil.cc.
void LogCabin::Storage::FilesystemUtil::fdatasync | ( | const File & | file | ) |
Flush changes to a File to its underlying storage device, except for atime/mtime.
See fdatasync man page.
file | An open file descriptor. See skipFsync. |
Definition at line 128 of file FilesystemUtil.cc.
void LogCabin::Storage::FilesystemUtil::flock | ( | const File & | file, |
int | operation | ||
) |
Apply or remove an advisory lock on a file or directory.
See man 2 flock. PANICs if any errors are encountered, even EWOULDBLOCK (see tryFlock).
Definition at line 140 of file FilesystemUtil.cc.
std::string LogCabin::Storage::FilesystemUtil::tryFlock | ( | const File & | file, |
int | operation | ||
) |
Apply or remove an advisory lock on a file or directory.
See man 2 flock.
file | File or directory to lock. |
operation | LOCK_SH, LOCK_EX, or LOCK_UN, usually ORed with LOCK_NB. |
Definition at line 148 of file FilesystemUtil.cc.
uint64_t LogCabin::Storage::FilesystemUtil::getSize | ( | const File & | file | ) |
Returns the size of the file in bytes.
Definition at line 169 of file FilesystemUtil.cc.
std::vector<std::string> LogCabin::Storage::FilesystemUtil::lsHelper | ( | DIR * | dir, |
const std::string & | path | ||
) |
Definition at line 180 of file FilesystemUtil.cc.
std::vector< std::string > LogCabin::Storage::FilesystemUtil::ls | ( | const std::string & | path | ) |
List the contents of a directory by path.
Panics if the 'path' is not a directory.
path | The path to the directory whose contents to list. |
Definition at line 217 of file FilesystemUtil.cc.
std::vector< std::string > LogCabin::Storage::FilesystemUtil::ls | ( | const File & | dir | ) |
List the contents of an open directory.
Panics if 'dir' is not a directory.
dir | An open file descriptor to the directory whose contents to list. |
Definition at line 223 of file FilesystemUtil.cc.
File LogCabin::Storage::FilesystemUtil::openDir | ( | const std::string & | path | ) |
Open a directory, creating it if it doesn't exist.
Definition at line 229 of file FilesystemUtil.cc.
File LogCabin::Storage::FilesystemUtil::openDir | ( | const File & | dir, |
const std::string & | child | ||
) |
Open a directory relative to an already open directory, creating it if it doesn't exist.
Definition at line 253 of file FilesystemUtil.cc.
File LogCabin::Storage::FilesystemUtil::openFile | ( | const File & | dir, |
const std::string & | child, | ||
int | flags | ||
) |
Open a file.
See man 2 openat.
Panics if the file could not be opened; see tryOpenFile() if this isn't what you want.
Definition at line 277 of file FilesystemUtil.cc.
File LogCabin::Storage::FilesystemUtil::tryOpenFile | ( | const File & | dir, |
const std::string & | child, | ||
int | flags | ||
) |
Open a file.
See man 2 openat.
Returns a default-constructed File object if the file could not be opened due to EEXIST or ENOENT; see openFile() if this isn't what you want.
Definition at line 289 of file FilesystemUtil.cc.
void LogCabin::Storage::FilesystemUtil::remove | ( | const std::string & | path | ) |
Remove the file or directory at path.
If path is a directory, its contents will also be removed. If path does not exist, this returns without an error. This operation is not atomic but is idempotent.
Definition at line 303 of file FilesystemUtil.cc.
void LogCabin::Storage::FilesystemUtil::removeFile | ( | const File & | dir, |
const std::string & | path | ||
) |
Remove the file relative to an open directory.
If path does not exist, this returns without an error. This does not fsync the directory.
dir | An open file descriptor to the directory containing path. |
path | The path of the file to remove, relative to dirFd. This must be a file; it may not be a directory. |
Definition at line 322 of file FilesystemUtil.cc.
void LogCabin::Storage::FilesystemUtil::rename | ( | const File & | oldDir, |
const std::string & | oldChild, | ||
const File & | newDir, | ||
const std::string & | newChild | ||
) |
Rename a file.
See man 2 renameat. This does not fsync the directories.
Definition at line 334 of file FilesystemUtil.cc.
void LogCabin::Storage::FilesystemUtil::syncDir | ( | const std::string & | path | ) |
Open a directory, fsync it, and close it.
This is useful to fsync a directory after creating a file or directory within it. See skipFsync.
Definition at line 349 of file FilesystemUtil.cc.
void LogCabin::Storage::FilesystemUtil::truncate | ( | const File & | file, |
uint64_t | bytes | ||
) |
Shrink or grow a file to the specified length, padding with zeros if necessary.
See man 2 ftruncate. Does not fsync the file.
Definition at line 369 of file FilesystemUtil.cc.
std::string LogCabin::Storage::FilesystemUtil::mkdtemp | ( | ) |
Return a path to a temporary directory.
Definition at line 379 of file FilesystemUtil.cc.
ssize_t LogCabin::Storage::FilesystemUtil::write | ( | int | fildes, |
const void * | data, | ||
uint64_t | dataLen | ||
) |
A wrapper around write that retries interrupted calls.
fildes | The file handle on which to write data. |
data | A pointer to the data to write. |
dataLen | The number of bytes of 'data' to write. |
Definition at line 396 of file FilesystemUtil.cc.
ssize_t LogCabin::Storage::FilesystemUtil::write | ( | int | fildes, |
std::initializer_list< std::pair< const void *, uint64_t >> | data | ||
) |
A wrapper around write that retries interrupted calls.
fildes | The file handle on which to write data. |
data | An I/O vector of data to write (pointer, length pairs). |
Definition at line 402 of file FilesystemUtil.cc.
Set to true in some unit tests to skip fsync() and fdatasync(), which can speeds up some tests significantly.
Definition at line 36 of file FilesystemUtil.cc.