Seastar
High performance C++ framework for concurrent servers
Classes | Typedefs | Enumerations | Functions
File Input/Output

Detailed Description

Seastar provides a file API to deal with persistent storage. Unlike most file APIs, seastar offers unbuffered file I/O (similar to, and based on, O_DIRECT). Unbuffered I/O means that the application is required to do its own caching, but delivers better performance if this caching is done correctly.

For random I/O or sequential unbuffered I/O, the file class provides a set of methods for reading, writing, discarding, or otherwise manipulating a file. For buffered sequential I/O, see make_file_input_stream() and make_file_output_stream().

Classes

struct  seastar::directory_entry
 A directory entry being listed. More...
 
struct  seastar::stat_data
 Filesystem object stat information. More...
 
struct  seastar::file_open_options
 
class  seastar::file
 
class  seastar::file_handle
 A shard-transportable handle to a file. More...
 

Typedefs

using seastar::follow_symlink = bool_class< follow_symlink_tag >
 

Enumerations

enum  seastar::directory_entry_type {
  unknown, block_device, char_device, directory,
  fifo, link, regular, socket
}
 
enum  seastar::fs_type {
  other, xfs, ext2, ext3,
  ext4, btrfs, hfs, tmpfs
}
 Enumeration describing the type of a particular filesystem.
 
enum  access_flags {
  exists = F_OK, read = R_OK, write = W_OK, execute = X_OK,
  lookup = execute
}
 
enum  file_permissions {
  user_read = S_IRUSR, user_write = S_IWUSR, user_execute = S_IXUSR, group_read = S_IRGRP,
  group_write = S_IWGRP, group_execute = S_IXGRP, others_read = S_IROTH, others_write = S_IWOTH,
  others_execute = S_IXOTH, user_permissions = user_read | user_write | user_execute, group_permissions = group_read | group_write | group_execute, others_permissions = others_read | others_write | others_execute,
  all_permissions = user_permissions | group_permissions | others_permissions, default_file_permissions = user_read | user_write | group_read | group_write | others_read | others_write, default_dir_permissions = all_permissions
}
 

Functions

access_flags seastar::operator| (access_flags a, access_flags b)
 
access_flags seastar::operator & (access_flags a, access_flags b)
 
constexpr file_permissions seastar::operator| (file_permissions a, file_permissions b)
 
constexpr file_permissions seastar::operator & (file_permissions a, file_permissions b)
 
future seastar::check_direct_io_support (sstring path)
 
future seastar::make_directory (sstring name, file_permissions permissions=file_permissions::default_dir_permissions)
 
future seastar::touch_directory (sstring name, file_permissions permissions=file_permissions::default_dir_permissions)
 
future seastar::recursive_touch_directory (sstring name, file_permissions permissions=file_permissions::default_dir_permissions)
 
future seastar::sync_directory (sstring name)
 
future seastar::remove_file (sstring name)
 
future seastar::rename_file (sstring old_name, sstring new_name)
 
future< stat_dataseastar::file_stat (sstring name, follow_symlink fs=follow_symlink::yes)
 
future< uint64_t > seastar::file_size (sstring name)
 
future< bool > seastar::file_accessible (sstring name, access_flags flags)
 
future< bool > seastar::file_exists (sstring name)
 
future seastar::link_file (sstring oldpath, sstring newpath)
 
future seastar::chmod (sstring name, file_permissions permissions)
 
future< fs_typeseastar::file_system_at (sstring name)
 
future< uint64_t > seastar::fs_avail (sstring name)
 
future< uint64_t > seastar::fs_free (sstring name)
 
future< fileopen_file_dma (sstring name, open_flags flags)
 
future< fileopen_file_dma (sstring name, open_flags flags, file_open_options options)
 
future< fileopen_directory (sstring name)
 

Class Documentation

◆ seastar::directory_entry

struct seastar::directory_entry
Class Members
sstring name Name of the file in a directory entry. Will never be "." or "..". Only the last component is included.
optional< directory_entry_type > type Type of the directory entry, if known.

◆ seastar::stat_data

struct seastar::stat_data
Class Members
uint64_t allocated_size
uint64_t block_size
uint64_t device_id
uint64_t gid
uint64_t inode_number
uint64_t mode
uint64_t number_of_links
uint64_t rdev
uint64_t size
time_point time_accessed
time_point time_changed
time_point time_modified
directory_entry_type type
uint64_t uid

◆ seastar::file_open_options

struct seastar::file_open_options
Class Members
file_permissions create_permissions File permissions to use when creating a file.
uint64_t extent_allocation_size_hint Allocate this much disk space when extending the file.
bool sloppy_size Allow the file size not to track the amount of data written until a flush.
uint64_t sloppy_size_hint Hint as to what the eventual file size will be.

◆ seastar::follow_symlink_tag

struct seastar::follow_symlink_tag

Enumeration Type Documentation

◆ directory_entry_type

Enumeration describing the type of a directory entry being listed.

See also
file::list_directory()

Function Documentation

◆ check_direct_io_support()

future seastar::check_direct_io_support ( sstring  path)

Checks if a given directory supports direct io

Seastar bypasses the Operating System caches and issues direct io to the underlying block devices. Projects using seastar should check if the directory lies in a filesystem that support such operations. This function can be used to do that.

It will return if direct io can be used, or throw an std::system_error exception, with the EINVAL error code.

A std::system_error with the respective error code is also thrown if path is not a directory.

Parameters
paththe directory we need to verify.

◆ chmod()

future seastar::chmod ( sstring  name,
file_permissions  permissions 
)

Changes the permissions mode of a file or directory

Parameters
namename of the file ot directory to change
permissionspermissions to set

◆ file_accessible()

future<bool> seastar::file_accessible ( sstring  name,
access_flags  flags 
)

Check file access.

Parameters
namename of the file to check
flagsbit pattern containing type of access to check (read/write/execute or exists).

If only access_flags::exists is queried, returns true if the file exists, or false otherwise. Throws a compat::filesystem::filesystem_error exception if any error other than ENOENT is encountered.

If any of the access_flags (read/write/execute) is set, returns true if the file exists and is accessible with the requested flags, or false if the file exists and is not accessible as queried. Throws a compat::filesystem::filesystem_error exception if any error other than EACCES is encountered. Note that if any path component leading to the file is not searchable, the file is considered inaccessible with the requested mode and false will be returned.

◆ file_exists()

future<bool> seastar::file_exists ( sstring  name)

check if a file exists.

Parameters
namename of the file to check

◆ file_size()

future<uint64_t> seastar::file_size ( sstring  name)

Return the size of a file.

Parameters
namename of the file to return the size

Note that file_size of a symlink is NOT the size of the symlink - which is the length of the pathname it contains - but rather the size of the file to which it points.

◆ file_stat()

future<stat_data> seastar::file_stat ( sstring  name,
follow_symlink  fs = follow_symlink::yes 
)

Return stat information about a file.

Parameters
namename of the file to return its stat information
follow_symlinkfollow symbolic links.
Returns
stat_data of the file identified by name. If name identifies a symbolic link then stat_data is returned either for the target of the link, with follow_symlink::yes, or for the link itself, with follow_symlink::no.

◆ file_system_at()

future<fs_type> seastar::file_system_at ( sstring  name)

Return information about the filesystem where a file is located.

Parameters
namename of the file to inspect

◆ fs_avail()

future<uint64_t> seastar::fs_avail ( sstring  name)

Return space available to unprivileged users in filesystem where a file is located, in bytes.

Parameters
namename of the file to inspect

◆ fs_free()

future<uint64_t> seastar::fs_free ( sstring  name)

Return free space in filesystem where a file is located, in bytes.

Parameters
namename of the file to inspect

◆ link_file()

future seastar::link_file ( sstring  oldpath,
sstring  newpath 
)

Creates a hard link for a file

Parameters
oldpathexisting file name
newpathname of link

◆ make_directory()

future seastar::make_directory ( sstring  name,
file_permissions  permissions = file_permissions::default_dir_permissions 
)

Creates a new directory.

Parameters
namename of the directory to create
permissionsoptional file permissions of the directory to create.
Note
The directory is not guaranteed to be stable on disk, unless the containing directory is sync'ed.

◆ open_directory()

future< file > open_directory ( sstring  name)
related

Opens a directory.

Parameters
namename of the directory to open
Returns
a file object representing a directory. The only legal operations are file::list_directory(), file::fsync(), and file::close().

◆ open_file_dma() [1/2]

future< file > open_file_dma ( sstring  name,
open_flags  flags 
)
related

Opens or creates a file. The "dma" in the name refers to the fact that data transfers are unbuffered and uncached.

Parameters
namethe name of the file to open or create
flagsvarious flags controlling the open process
Returns
a file object, as a future
Note
The file name is not guaranteed to be stable on disk, unless the containing directory is sync'ed.

◆ open_file_dma() [2/2]

future< file > open_file_dma ( sstring  name,
open_flags  flags,
file_open_options  options 
)
related

Opens or creates a file. The "dma" in the name refers to the fact that data transfers are unbuffered and uncached.

Parameters
namethe name of the file to open or create
flagsvarious flags controlling the open process
optionsoptions for opening the file
Returns
a file object, as a future
Note
The file name is not guaranteed to be stable on disk, unless the containing directory is sync'ed.

◆ recursive_touch_directory()

future seastar::recursive_touch_directory ( sstring  name,
file_permissions  permissions = file_permissions::default_dir_permissions 
)

Recursively ensures a directory exists

Checks whether each component of a directory exists, and if not, creates it.

Parameters
namename of the directory to potentially create
permissionsoptional file permissions of the directory to create.
Note
This function fsyncs each component created, and is therefore guaranteed to be stable on disk. The provided permissions are applied only on the last component in the path, if it needs to be created, if intermediate directories do not exist, they are created with the default_dir_permissions. If any directory exists, the provided permissions are not applied.

◆ remove_file()

future seastar::remove_file ( sstring  name)

Removes (unlinks) a file.

Parameters
namename of the file to remove
Note
The removal is not guaranteed to be stable on disk, unless the containing directory is sync'ed.

◆ rename_file()

future seastar::rename_file ( sstring  old_name,
sstring  new_name 
)

Renames (moves) a file.

Parameters
old_nameexisting file name
new_namenew file name
Note
The rename is not guaranteed to be stable on disk, unless the both containing directories are sync'ed.

◆ sync_directory()

future seastar::sync_directory ( sstring  name)

Synchronizes a directory to disk

Makes sure the modifications in a directory are synchronized in disk. This is useful, for instance, after creating or removing a file inside the directory.

Parameters
namename of the directory to potentially create

◆ touch_directory()

future seastar::touch_directory ( sstring  name,
file_permissions  permissions = file_permissions::default_dir_permissions 
)

Ensures a directory exists

Checks whether a directory exists, and if not, creates it. Only the last component of the directory name is created.

Parameters
namename of the directory to potentially create
permissionsoptional file permissions of the directory to create.
Note
The directory is not guaranteed to be stable on disk, unless the containing directory is sync'ed. If the directory exists, the provided permissions are not applied.