ucommon
|
Create and map a disk file into memory. More...
#include <file.h>
Public Member Functions | |
char * | fetch (size_t offset=0) |
Fetch a pointer to an offset within the memory mapped portion of the disk file. | |
char * | fetch (off_t pos, size_t len) |
Fetch and map a portion of a disk file to a logical memory block. | |
bool | lock (void) |
Lock the currently mapped portion of a file. | |
MappedFile (char *fname, Access mode) | |
Open a file for mapping. | |
MappedFile (char *fname, Access mode, size_t size) | |
Create if not exists, and map a file of specified size into memory. | |
MappedFile (char *fname, pos_t offset, size_t size, Access mode) | |
Map a portion or all of a specified file in the specified shared memory access mode. | |
size_t | pageAligned (size_t size) |
Compute map size to aligned page boundry. | |
void | release (char *address, size_t len) |
Release (unmap) a memory segment. | |
void | sync (void) |
Synchronize the contents of the mapped portion of memory with the disk file and wait for completion. | |
void | sync (char *address, size_t len) |
Synchronize a segment of memory mapped from a segment fetch. | |
void | unlock (void) |
Unlock a locked mapped portion of a file. | |
void | update (size_t offset=0, size_t len=0) |
Map a portion of the memory mapped from the file back to the file and do not wait for completion. | |
void | update (char *address, size_t len) |
Update a mapped region back to disk as specified by address and length. | |
virtual | ~MappedFile () |
Release a mapped section of memory associated with a file. | |
![]() | |
off_t | getCapacity (void) |
Get current file capacity. | |
Error | getErrorNumber (void) |
Return current error id. | |
char * | getErrorString (void) |
Return current error string. | |
bool | initial (void) |
This method should be called right after a RandomFile derived object has been created. | |
bool | operator! (void) |
virtual Error | restart (void) |
This method is commonly used to close and re-open an existing database. | |
virtual | ~RandomFile () |
Destroy a random access file or it's derived class. |
Additional Inherited Members | |
![]() | |
enum | Access { accessReadOnly = 00, accessWriteOnly = 01, accessReadWrite = 02 } |
typedef enum Access | Access |
enum | Attr { attrInvalid = 0, attrPrivate = 0400 | 0200, attrGroup = attrPrivate | ( 0400 >> 3) | ( 0200 >> 3), attrPublic = attrGroup | ( ( 0400 >> 3) >> 3) | ( ( 0200 >> 3) >> 3) } |
typedef enum Attr | Attr |
enum | Complete { completionImmediate, completionDelayed, completionDeferred } |
typedef enum Complete | Complete |
enum | Error { errSuccess = 0, errNotOpened, errMapFailed, errInitFailed, errOpenDenied, errOpenFailed, errOpenInUse, errReadInterrupted, errReadIncomplete, errReadFailure, errWriteInterrupted, errWriteIncomplete, errWriteFailure, errLockFailure, errExtended } |
typedef enum Error | Error |
enum | Mapping { mappedRead = accessReadOnly, mappedWrite = accessWriteOnly, mappedReadWrite = accessReadWrite } |
typedef enum Mapping | Mapping |
enum | Open { openReadOnly = 00, openWriteOnly = 01, openReadWrite = 02, openAppend = 01 | 02000, openSync = 02 | 04010000, openTruncate = 02 | 01000 } |
typedef enum Open | Open |
![]() | |
static char * | getDirname (char *path, char *buffer, size_t size=4096) |
static char * | getExtension (char *path) |
static char * | getFilename (char *path) |
static char * | getFilename (char *path, char *buffer, size_t size=255) |
static char * | getRealpath (char *path, char *buffer, size_t size=4096) |
![]() | |
typedef struct ost::File::_fcb | fcb_t |
![]() | |
Error | error (Error errid, char *errstr=((void *) 0)) |
Post an error event. | |
Error | error (char *err) |
Post an extended string error message. | |
void | final (void) |
Close the file. | |
virtual Attr | initialize (void) |
This method is used to initialize a newly created file as indicated by the "initial" flag. | |
RandomFile (char *name=((void *) 0)) | |
Create an unopened random access file. | |
RandomFile (RandomFile &rf) | |
Default copy constructor. | |
Error | setCompletion (Complete mode) |
Used to set file completion modes. | |
void | setError (bool enable) |
Used to enable or disable throwing of exceptions on errors. | |
void | setTemporary (bool enable) |
Used to set the temporary attribute for the file. | |
![]() | |
Access | access |
int | fd |
struct { | |
unsigned count: 16 | |
bool immediate: 1 | |
bool initial: 1 | |
bool temp: 1 | |
bool thrown: 1 | |
} | flags |
char * | pathname |
![]() | |
bool | canAccess (char *path) |
bool | canModify (char *path) |
bool | isDevice (char *path) |
bool | isDir (char *path) |
bool | isFile (char *path) |
time_t | lastAccessed (char *path) |
time_t | lastModified (char *path) |
Create and map a disk file into memory.
This portable class works under both Posix via mmap and under the win32 API. A mapped file can be referenced directly by it's memory segment. One can map and unmap portions of a file on demand, and update changed memory pages mapped from files immediately through sync().
ost::MappedFile::MappedFile | ( | char * | fname, |
Access | mode | ||
) |
Open a file for mapping.
More than one segment of a file may be mapped into seperate regions of memory.
fname | file name to access for mapping. |
mode | access mode to map file. |
ost::MappedFile::MappedFile | ( | char * | fname, |
Access | mode, | ||
size_t | size | ||
) |
Create if not exists, and map a file of specified size into memory.
fname | file name to access for mapping. |
mode | access mode to map file. |
size | of file to map. |
ost::MappedFile::MappedFile | ( | char * | fname, |
pos_t | offset, | ||
size_t | size, | ||
Access | mode | ||
) |
Map a portion or all of a specified file in the specified shared memory access mode.
Valid mapping modes include mappedRead, mappedWrite, and mappedReadWrite.
fname | pathname of file to map into memory. |
offset | from start of file to begin mapping in bytes. |
size | of mapped area in bytes. |
mode | to map file. |
|
virtual |
Release a mapped section of memory associated with a file.
The mapped area is updated back to disk.
|
inline |
Fetch a pointer to an offset within the memory mapped portion of the disk file.
This really is used for convience of matching operations between Update and Fetch, as one could simply have accessed the base pointer where the file was mapped directly.
offset | from start of mapped memory. |
char* ost::MappedFile::fetch | ( | off_t | pos, |
size_t | len | ||
) |
Fetch and map a portion of a disk file to a logical memory block.
pos | offset of file segment to map. |
len | size of memory segment to map. |
bool ost::MappedFile::lock | ( | void | ) |
Lock the currently mapped portion of a file.
Reimplemented from ucommon::RecursiveMutex.
size_t ost::MappedFile::pageAligned | ( | size_t | size | ) |
Compute map size to aligned page boundry.
size | request. |
void ost::MappedFile::release | ( | char * | address, |
size_t | len | ||
) |
Release (unmap) a memory segment.
address | address of memory segment to release. |
len | length of memory segment to release. |
void ost::MappedFile::sync | ( | void | ) |
Synchronize the contents of the mapped portion of memory with the disk file and wait for completion.
This assures the memory mapped from the file is written back.
void ost::MappedFile::sync | ( | char * | address, |
size_t | len | ||
) |
Synchronize a segment of memory mapped from a segment fetch.
address | memory address to update. |
len | size of segment. |
void ost::MappedFile::update | ( | size_t | offset = 0 , |
size_t | len = 0 |
||
) |
Map a portion of the memory mapped from the file back to the file and do not wait for completion.
This is useful when mapping a database file and updating a single record.
offset | offset into the mapped region of memory. |
len | length of partial region (example, record length). |
void ost::MappedFile::update | ( | char * | address, |
size_t | len | ||
) |
Update a mapped region back to disk as specified by address and length.
address | address of segment. |
len | length of segment. |