DUNE-DAQ
DUNE Trigger and Data Acquisition software
|
Wrapper for memory map operations. More...
#include <MapFile.hpp>
Public Member Functions | |
MapFile (const std::string &file, size_t size, size_t offset, bool read_mode, bool write_mode, mode_t permissions=0666) | |
~MapFile () | |
void | zero () const |
builds a zeroed file with correct length | |
void | map () |
maps the file in memory | |
void | unmap () |
unmaps the file | |
bool | is_mapped () const |
is the file mopped im memory | |
bool | is_loaded () const throw () |
is the map loaded in memory | |
void * | address () const throw () |
the address of the memory mapped file | |
size_t | memory_size () const throw () |
the size of the map | |
OksSystem::Descriptor * | fd () const throw () |
the file descriptor. This method returns a valid pointer only if called after map(). | |
![]() | |
File (const std::string &name) | |
File (const char *name) | |
File (const File &other) | |
virtual | ~File () |
operator std::string () const throw () | |
operator const char * () const throw () | |
operator bool () const throw () | |
bool | equals (const File &other) const throw () |
compare two files */ | |
operator size_t () const | |
const std::string & | full_name () const throw () |
full name for file */ | |
const char * | c_full_name () const throw () |
std::string | short_name () const throw () |
short name for file */ | |
std::string | parent_name () const throw () |
path of directory containing file */ | |
std::string | extension () const throw () |
extension for file */ | |
int | depth () const throw () |
depth of the file */ | |
OksSystem::File | parent () const |
parent of the current file */ | |
OksSystem::File | child (const std::string &name) const |
named child of the current directory */ | |
OksSystem::File | temporary (const std::string &prefix) const |
bool | exists () const throw () |
does the file exist */ | |
mode_t | permissions () const |
permissions for the file */ | |
std::string | pretty_permissions () const |
pretty permissions for the file */ | |
size_t | size () const |
size of file */ | |
uid_t | owner_id () const |
owner id of file */ | |
User | owner () const |
owner of the file */ | |
gid_t | group () const |
group of file */ | |
bool | is_regular () const |
is the file a directory */ | |
bool | is_directory () const |
is the file a regular file */ | |
bool | is_fifo () const |
is the file a named pipe */ | |
std::string | file_type () const |
type of the file */ | |
file_list_t | directory () const |
list of file in directory */ | |
void | unlink () const |
deletes (unlinks) file */ | |
void | rmdir () const |
deletes directory */ | |
void | remove () const |
recursively delete files and directories */ | |
void | rename (const File &other) const |
rename or moves the file */ | |
void | permissions (mode_t permissions) const |
sets the type of the file */ | |
void | make_dir (mode_t permissions) const |
creates a directory */ | |
void | make_path (mode_t permissions) const |
creates a full path */ | |
void | make_fifo (mode_t permissions) const |
creates a FIFO (named pipe) */ | |
void | ensure_path (mode_t permissions) const |
creates the parent path */ | |
std::istream * | input () const |
returns an input stream from the file*/ | |
std::ostream * | output (bool append=false) const |
returns an output stream to the file*/ | |
Protected Member Functions | |
void | open_fd () |
opens the file descriptor for the map | |
void | close_fd () |
closes the file descriptor for the map | |
void | map_mem () |
maps the file into memory | |
void | unmap_mem () |
unmaps the file into memory | |
![]() | |
void | set_name (const std::string &name) |
sets the name of the file */ | |
mode_t | get_mode () const |
get mode associated with file (permission + type) */ | |
Protected Attributes | |
void * | m_map_address |
the address of the map in memory | |
size_t | m_map_size |
the size of the map | |
size_t | m_map_offset |
offset in the file of the map | |
Descriptor * | m_map_descriptor |
internal file descriptor | |
mode_t | m_map_permission |
permissions associated with the file | |
bool | m_map_read |
is the map readable | |
bool | m_map_write |
is the map writable | |
bool | m_is_mapped |
is the file mapped in memory | |
![]() | |
std::string | m_full_name |
full name (path) of the file */ | |
Static Private Attributes | |
static const char *const | MAP_LOAD_MSG |
message pattern - map is loaded | |
static const char *const | MAP_NOT_LOAD_MSG |
message pattern - map is not loaded | |
static const char *const | PAGE_SIZE_MSG |
message pattern - illegal page size | |
static const char *const | READ_OR_WRITE_MSG |
message pattern - map mode is neither read nor write | |
static const char *const | MAP_NOT_WRITE_MSG |
message pattern - map is not writable | |
Additional Inherited Members | |
![]() | |
typedef std::vector< OksSystem::File > | file_list_t |
![]() | |
static std::string | protocol (const std::string &url) throw () |
extracts the protocol part of an url */ | |
static std::string | extension (const std::string &url) throw () |
extracts the extension of a path or an url */ | |
static std::string | uri (const std::string &url) throw () |
extracts the local path of an url */ | |
static std::string | short_name (const std::string &url) throw () |
extracts the short file name of an url */ | |
static int | depth (const std::string &path) throw () |
calculates depth of a path */ | |
static std::string | first_line (const std::string &text) |
extracts the first line of a text */ | |
static File | from_url (const std::string &url) |
build a file out of an URL */ | |
static std::string | working_directory () |
current directory of process */ | |
static void | working_directory (const File &dir) |
set working directory of process */ | |
static std::string | expand_home (const std::string path) |
resolve home directory */ | |
static std::string | pretty_permissions (mode_t permissions) |
pretty prints permissions */ | |
static std::string | to_string (mode_t permissions) throw () |
converts permission to string */ | |
static std::string | pretty_open_flag (int flags) |
pretty prints open flags */ | |
static std::string | pretty_size (size_t size, bool cut_small) |
pretty prints a file size */ | |
![]() | |
static const char *const | FILE_FLAG_STR = "-rwxS" |
column headers for display of permissions */ | |
static const char *const | FILE_PROTOCOL = "file" |
string for the file protocol */ | |
![]() | |
static int | unit (int u) |
calculates the value of a computer unit of order n (i.e KB,GB, etc */ | |
![]() | |
static const char *const | HUMAN_SIZE_STR [] = { "B", "KB", "MB", "GB" } |
strings for pretty printing file sizes */ | |
static const char *const | HUMAN_OPEN_STR [] = { "READ", "WRITE", "NOBLOCK", "APPEND", "CREATE", "TRUNCATE","EXCLUSIVE" } |
strings for pretty printing open flags */ | |
static const int | KILOBYTE = 1024 |
number of bytes in a kilobyte */ | |
static const char *const | FILE_COMMAND_PATH = "/usr/bin/file" |
Wrapper for memory map operations.
This class offers facilities to handle memory mapped files. They can be used to map a file into memory
Definition at line 26 of file MapFile.hpp.
OksSystem::MapFile::MapFile | ( | const std::string & | name, |
size_t | s, | ||
size_t | o, | ||
bool | read_mode, | ||
bool | write_mode, | ||
mode_t | perm = 0666 ) |
Builds a memory mapped file.
name | the path of the file to map. |
size | the size of the region to memory map - should be a multiple of the pagesize. |
offset | the offset in the file - should be a multiple of pagesize. |
read_mode | should the map be read from the file. |
write_mode | should the map be writable. |
permissions | the permissions associated with the file |
Definition at line 31 of file MapFile.cpp.
OksSystem::MapFile::~MapFile | ( | ) |
Destructor - the file should be unmapped before destruction.
Definition at line 50 of file MapFile.cpp.
void * OksSystem::MapFile::address | ( | ) | const | |||
throw | ( | ) |
the address of the memory mapped file
Gives the actual address of the map in memory. If the file is not yet mapped, this will be 0.
Definition at line 167 of file MapFile.cpp.
|
protected |
closes the file descriptor for the map
Closes the file descriptor associated with the memory map.
CloseFail | if the close okssystem call fails |
Definition at line 70 of file MapFile.cpp.
OksSystem::Descriptor * OksSystem::MapFile::fd | ( | ) | const | |||
throw | ( | ) |
the file descriptor. This method returns a valid pointer only if called after map().
Definition at line 185 of file MapFile.cpp.
bool OksSystem::MapFile::is_loaded | ( | ) | const | |||
throw | ( | ) |
is the map loaded in memory
Definition at line 157 of file MapFile.cpp.
bool OksSystem::MapFile::is_mapped | ( | ) | const |
is the file mopped im memory
Returns if the file is mapped or not in memory
Definition at line 181 of file MapFile.cpp.
void OksSystem::MapFile::map | ( | ) |
maps the file in memory
Maps the file into memory. This is done first by opening the file descriptor for the file, then doing the actual map.
OpenFail | error while opening the file |
MMapFail | error while mapping the file |
Definition at line 141 of file MapFile.cpp.
|
protected |
maps the file into memory
Internal method - does the actual memory mapping.
MMapFail | if the mmap operation succeeded |
Precondition | if the file descriptor is not valid. |
Definition at line 81 of file MapFile.cpp.
size_t OksSystem::MapFile::memory_size | ( | ) | const | |||
throw | ( | ) |
the size of the map
Gives the actual size of the map in memory.
Definition at line 175 of file MapFile.cpp.
|
protected |
opens the file descriptor for the map
Opens the file descriptor associated with the memory map.
OpenFail | if the open okssystem call fails |
Definition at line 60 of file MapFile.cpp.
void OksSystem::MapFile::unmap | ( | ) |
unmaps the file
Unmaps the file from memory This is done first by unmapping the file, then closing the file-descriptor.
CloseFail | error while closing the file. |
MUnmapFail | error while unmapping the file. |
Definition at line 152 of file MapFile.cpp.
|
protected |
unmaps the file into memory
Internal method - does the actual memory unmapping.
MUnmapFail | if the munmap operation fails. |
Definition at line 105 of file MapFile.cpp.
void OksSystem::MapFile::zero | ( | ) | const |
builds a zeroed file with correct length
Creates a zero filled file with correct length
Definition at line 120 of file MapFile.cpp.
|
protected |
is the file mapped in memory
Definition at line 56 of file MapFile.hpp.
|
protected |
the address of the map in memory
Definition at line 49 of file MapFile.hpp.
|
protected |
internal file descriptor
Definition at line 52 of file MapFile.hpp.
|
protected |
offset in the file of the map
Definition at line 51 of file MapFile.hpp.
|
protected |
permissions associated with the file
Definition at line 53 of file MapFile.hpp.
|
protected |
is the map readable
Definition at line 54 of file MapFile.hpp.
|
protected |
the size of the map
Definition at line 50 of file MapFile.hpp.
|
protected |
is the map writable
Definition at line 55 of file MapFile.hpp.
|
staticprivate |
message pattern - map is loaded
Definition at line 60 of file MapFile.hpp.
|
staticprivate |
message pattern - map is not loaded
Definition at line 61 of file MapFile.hpp.
|
staticprivate |
message pattern - map is not writable
Definition at line 64 of file MapFile.hpp.
|
staticprivate |
message pattern - illegal page size
Definition at line 62 of file MapFile.hpp.
|
staticprivate |
message pattern - map mode is neither read nor write
Definition at line 63 of file MapFile.hpp.