libfoedus-core
FOEDUS Core Library
foedus::fs Namespace Reference

Filesystem wrapper, an analogue of boost::filesystem. More...

Detailed Description

Filesystem wrapper, an analogue of boost::filesystem.

These methods abstract accesses to filesystems like boost::filesystem and std::filesystem in C++1z(?). We should not directly call POSIX or Windows filesystem APIs in other modules. Instead, all of them should go through this package.

Why this package exists
The best case scenario for us is the standard C++ library provides filesystem abstraction. However, the spec (based on Boost filesystem ver2) didn't get into even C++14, let alone its implmentations. Thus, we can't rely on it at all. Boost filesystem has a few issues, too. First, it is changing and has some issue when C++11 is enabled. Furthermore, the filesystem package is NOT a header-only module in boost. We do not want to introduce additional dependencies to the gigantic boost shared library, which might not be available or has versioning issues in some environment. Rather, we just need only a small subset of functionalities in those libraries because our usage of filesystem is quite minimal and simplistic. Hence, we do it ourselves.
Direct File I/O
Another goal to have this package is to abstract Direct I/O (O_DIRECT in linux and FILE_FLAG_NO_BUFFERING in Windows). We need them to bypass filesystem-level caching, but these are not in C++ standards at all and won't be (if it happens, Linus would get a heart attack: https://lkml.org/lkml/2007/1/10/233 ).
Class/method designs
Basically, we clone Boost filesystem's class/method into this package when we find a need for some filesystem API access in our code. Due to our specialized needs, we might simplify the API. Our goal is not to duplicate all Boost filesystem classes. Just add what we need.

Classes

struct  DeviceEmulationOptions
 Set of configurations to emulate slower devices for some experiments. More...
 
class  DirectIoFile
 Represents an I/O stream on one file without filesystem caching. More...
 
struct  FileStatus
 Analogue of boost::filesystem::file_status. More...
 
class  Path
 Analogue of boost::filesystem::path. More...
 
struct  SpaceInfo
 Analogue of boost::filesystem::space_info. More...
 

Typedefs

typedef assorted::FixedString< 508 > FixedPath
 Represents a fixed (thus can be placed in shared memory) path string. More...
 

Enumerations

enum  FileType {
  kStatusError = 0, kFileNotFound, kRegularFile, kDirectoryFile,
  kTypeUnknown
}
 Analogue of boost::filesystem::file_type. More...
 
enum  FilePermission {
  kNoPerms = 0, kOwnerRead = 0400, kOwnerWrite = 0200, kOwnerExe = 0100,
  kOwnerAll = 0700, kGroupRead = 040, kGroupWrite = 020, kGroupExe = 010,
  kGroupAll = 070, kOthersRead = 04, kOthersWrite = 02, kOthersExe = 01,
  kOthersAll = 07, kAllAll = kOwnerAll|kGroupAll|kOthersAll, kPermsNotKnown = 0xFFFF
}
 Analogue of boost::filesystem::perm. More...
 

Functions

FileStatus status (const Path &p)
 Returns the status of the file. More...
 
bool exists (const Path &p)
 Returns if the file exists. More...
 
bool is_directory (const Path &p)
 Returns if the file is a directory. More...
 
bool is_regular_file (const Path &p)
 Returns if the file is a regular file. More...
 
Path current_path ()
 Returns the current working directory. More...
 
Path home_path ()
 Returns the absolute path of the home directory of the user running this process. More...
 
Path absolute (const std::string &p)
 Returns the absolue path of the specified path. More...
 
bool create_directories (const Path &p, bool sync=false)
 Recursive mkdir (mkdirs). More...
 
bool create_directory (const Path &p, bool sync=false)
 mkdir. More...
 
uint64_t file_size (const Path &p)
 Returns size of the file. More...
 
bool remove (const Path &p)
 Deletes a regular file or an empty directory. More...
 
uint64_t remove_all (const Path &p)
 Recursively deletes a directory. More...
 
SpaceInfo space (const Path &p)
 Returns free space information for the device the file is on. More...
 
std::string unique_name (uint64_t differentiator=0)
 Equivalent to unique_path("%%%%-%%%%-%%%%-%%%%"). More...
 
std::string unique_name (const std::string &model, uint64_t differentiator=0)
 Returns a randomly generated file name with the given template. More...
 
bool fsync (const Path &path, bool sync_parent_directory=false)
 Makes the content and metadata of the file durable all the way up to devices. More...
 
bool atomic_rename (const Path &old_path, const Path &new_path)
 Renames the old file to the new file with the POSIX atomic-rename semantics. More...
 
bool durable_atomic_rename (const Path &old_path, const Path &new_path)
 fsync() on source file before rename, then fsync() on the parent folder after rename. More...
 
bool rename (const Path &old_path, const Path &new_path)
 Just a synonym of atomic_rename() to avoid confusion. More...
 
bool operator== (const Path &lhs, const Path &rhs)
 
bool operator== (const Path &lhs, const std::string &rhs)
 
bool operator== (const std::string &lhs, const Path &rhs)
 
bool operator!= (const Path &lhs, const Path &rhs)
 
bool operator!= (const Path &lhs, const std::string &rhs)
 
bool operator!= (const std::string &lhs, const Path &rhs)
 
bool operator< (const Path &lhs, const Path &rhs)
 
bool operator<= (const Path &lhs, const Path &rhs)
 
bool operator> (const Path &lhs, const Path &rhs)
 
bool operator>= (const Path &lhs, const Path &rhs)
 
bool is_odirect_aligned (uint64_t value)
 
bool is_odirect_aligned (const void *ptr)
 
std::ostream & operator<< (std::ostream &o, const DirectIoFile &v)
 
std::ostream & operator<< (std::ostream &o, const SpaceInfo &v)
 
std::ostream & operator<< (std::ostream &o, const Path &v)
 

Variables

const uint64_t kOdirectAlignment = 0x1000
 

Function Documentation

bool foedus::fs::is_odirect_aligned ( uint64_t  value)
inline
bool foedus::fs::is_odirect_aligned ( const void *  ptr)
inline

Definition at line 40 of file direct_io_file.cpp.

40  {
41  return (reinterpret_cast<uintptr_t>(ptr) % kOdirectAlignment) == 0;
42 }
const uint64_t kOdirectAlignment
bool foedus::fs::operator!= ( const Path lhs,
const Path rhs 
)
inline

Definition at line 89 of file path.hpp.

References foedus::fs::Path::compare().

89 {return lhs.compare(rhs) != 0;}

Here is the call graph for this function:

bool foedus::fs::operator!= ( const Path lhs,
const std::string &  rhs 
)
inline

Definition at line 90 of file path.hpp.

References foedus::fs::Path::compare().

90 {return lhs.compare(rhs) != 0;}

Here is the call graph for this function:

bool foedus::fs::operator!= ( const std::string &  lhs,
const Path rhs 
)
inline

Definition at line 91 of file path.hpp.

References foedus::fs::Path::compare().

91 {return rhs.compare(lhs) != 0;}

Here is the call graph for this function:

bool foedus::fs::operator< ( const Path lhs,
const Path rhs 
)
inline

Definition at line 93 of file path.hpp.

References foedus::fs::Path::compare().

93 {return lhs.compare(rhs) < 0;}

Here is the call graph for this function:

std::ostream& foedus::fs::operator<< ( std::ostream &  o,
const Path v 
)

Definition at line 84 of file path.cpp.

References foedus::fs::Path::string().

84  {
85  o << v.string();
86  return o;
87 }

Here is the call graph for this function:

std::ostream& foedus::fs::operator<< ( std::ostream &  o,
const SpaceInfo v 
)

Definition at line 193 of file filesystem.cpp.

References foedus::fs::SpaceInfo::available_, foedus::fs::SpaceInfo::capacity_, and foedus::fs::SpaceInfo::free_.

193  {
194  o << "SpaceInfo: available_=" << v.available_ << ", capacity_=" << v.capacity_
195  << ", free_=" << v.free_;
196  return o;
197 }
std::ostream& foedus::fs::operator<< ( std::ostream &  o,
const DirectIoFile v 
)

Definition at line 388 of file direct_io_file.cpp.

References foedus::fs::DirectIoFile::get_current_offset(), foedus::fs::DirectIoFile::get_descriptor(), foedus::fs::DirectIoFile::get_path(), foedus::fs::DirectIoFile::is_read(), and foedus::fs::DirectIoFile::is_write().

388  {
389  o << "<DirectIoFile>"
390  << "<path>" << v.get_path() << "</path>"
391  << "<descriptor>" << v.get_descriptor() << "</descriptor>"
392  << "<read>" << v.is_read() << "</read>"
393  << "<write>" << v.is_write() << "</write>"
394  << "<current_offset>" << v.get_current_offset() << "</current_offset>"
395  << "</DirectIoFile>";
396  return o;
397 }

Here is the call graph for this function:

bool foedus::fs::operator<= ( const Path lhs,
const Path rhs 
)
inline

Definition at line 94 of file path.hpp.

94 {return !(rhs < lhs);}
bool foedus::fs::operator== ( const Path lhs,
const Path rhs 
)
inline

Definition at line 85 of file path.hpp.

References foedus::fs::Path::compare().

85 {return lhs.compare(rhs) == 0;}

Here is the call graph for this function:

bool foedus::fs::operator== ( const Path lhs,
const std::string &  rhs 
)
inline

Definition at line 86 of file path.hpp.

References foedus::fs::Path::compare().

86 {return lhs.compare(rhs) == 0;}

Here is the call graph for this function:

bool foedus::fs::operator== ( const std::string &  lhs,
const Path rhs 
)
inline

Definition at line 87 of file path.hpp.

References foedus::fs::Path::compare().

87 {return rhs.compare(lhs) == 0;}

Here is the call graph for this function:

bool foedus::fs::operator> ( const Path lhs,
const Path rhs 
)
inline

Definition at line 95 of file path.hpp.

95 {return rhs < lhs;}
bool foedus::fs::operator>= ( const Path lhs,
const Path rhs 
)
inline

Definition at line 96 of file path.hpp.

96 {return !(lhs < rhs);}

Variable Documentation

const uint64_t foedus::fs::kOdirectAlignment = 0x1000

Definition at line 36 of file direct_io_file.cpp.