33 const int page_size = getpagesize();
51 if (m_map_descriptor!=0) {
71 m_map_descriptor->close();
72 delete(m_map_descriptor);
84 int flags = MAP_FILE | MAP_SHARED;
91 m_map_address = ::mmap(0,m_map_size,prot,flags,*m_map_descriptor,m_map_offset);
92 if (m_map_address==MAP_FAILED || m_map_address==0) {
94 std::string message =
"on file " + this->full_name();
95 throw OksSystem::OksSystemCallIssue(
ERS_HERE, errno,
"mmap", message.c_str() );
107 const int status = munmap(m_map_address,m_map_size);
110 std::string message =
"on file " + this->full_name();
111 throw OksSystem::OksSystemCallIssue(
ERS_HERE, errno,
"munmap", message.c_str() );
124 const int page_size = ::getpagesize();
125 const int page_num = (m_map_size+m_map_offset) / page_size;
126 void *buffer= calloc(1,page_size);
127 for(
int i=0;i<page_num;i++) {
128 fd.
write(buffer,page_size);
158 return (m_map_address!=0);
168 return m_map_address;
186 return m_map_descriptor;
#define ERS_PRECONDITION(expression)
#define ERS_ASSERT(expression)
File descriptor / Socket wrapper.
static int flags(bool read_mode, bool write_mode)
void close()
close the descriptor
int write(const void *buffer, size_t number) const
Wrapper for file operations.
void unmap_mem()
unmaps the file into memory
void * m_map_address
the address of the map in memory
void zero() const
builds a zeroed file with correct length
size_t m_map_offset
offset in the file of the map
size_t m_map_size
the size of the map
MapFile(const std::string &file, size_t size, size_t offset, bool read_mode, bool write_mode, mode_t permissions=0666)
bool is_mapped() const
is the file mopped im memory
bool m_map_write
is the map writable
void unmap()
unmaps the file
Descriptor * m_map_descriptor
internal file descriptor
bool m_is_mapped
is the file mapped in memory
bool is_loaded() const
is the map loaded in memory
OksSystem::Descriptor * fd() const
the file descriptor. This method returns a valid pointer only if called after map().
void open_fd()
opens the file descriptor for the map
void close_fd()
closes the file descriptor for the map
size_t memory_size() const
the size of the map
void map_mem()
maps the file into memory
bool m_map_read
is the map readable
void map()
maps the file in memory
mode_t m_map_permission
permissions associated with the file
void * address() const
the address of the memory mapped file