* Merged in jbm's changes for Linux compatibility, fixing Mac compatibility in the process :)
* Fixed two regressions having to do with the _previousTrailerPosition in VersionDictionary.cpp.
* Made sure RTTI is enabled in the OttomanTest target because gtest requires it.
5 * Created by Jens Alfke on 8/20/09.
6 * Copyright 2009 Jens Alfke. All rights reserved.
7 * BSD-Licensed: See the file "LICENSE.txt" for details.
10 #ifndef _MOOSEYARD_FILE_
11 #define _MOOSEYARD_FILE_
19 /** An open file on disk; a thin wrapper around a Unix file descriptor. */
25 const char* const message;
27 Error(int c, const char *m) :code(c), message(m) { }
30 static const int kEOF = 10001;
33 File (const char *filename, int oflag, bool locked =false) throw(Error);
36 off_t length() const throw(Error);
37 void setLength (off_t) throw(Error);
39 off_t position() const throw(Error);
40 void setPosition (off_t) throw(Error);
41 off_t setPositionToEnd (off_t bytesBefore =0) throw(Error);
43 void read (void *dst, size_t) throw(Error);
44 size_t write (const void *src, size_t) throw(Error);
46 void readFrom (off_t where, void *dst, size_t) throw(Error);
47 void writeTo (off_t where, const void *src, size_t) throw(Error);
49 size_t writeMultiple (Blob blobs[], int count) throw(Error);
50 size_t writePadding (int alignment); // alignment should be a power of 2
53 const MemoryMap* map() const {return const_cast<File*>(this)->map();}
54 void mapRegion (off_t position, size_t length);
55 const void* mappedPosition (off_t position) const;
57 void flush() throw(Error); // Regular fsync call
58 void flushDisk() throw(Error); // Expensive F_FULLFSYNC call
61 void read (T& t) throw(Error) {read(&t,sizeof(t));}
63 size_t write (const T& t) throw(Error) {return write(&t,sizeof(t));}
65 void readFrom (off_t where, T &t) throw(Error) {readFrom(where,&t,sizeof(t));}
67 void writeTo (off_t where, const T &t) throw(Error) {writeTo(where,&t,sizeof(t));}
69 bool hasPath (const char *path) const throw(Error);
71 static void unlink (const char *filename) throw(Error);
72 static void rename (const char *srcFilename, const char *dstFilename) throw(Error);
77 Lock (File*, bool block =true) throw(Error);
79 bool isLocked() const {return _locked;}
80 operator bool() const {return _locked;}
90 static int _open (const char *filename, int posixMode) throw(Error);
91 static int _check (int result) throw(Error);
92 static void _checkRead (ssize_t result, size_t expectedSize) throw(Error);
93 bool _lock (bool block);
98 mutable MemoryMap *_memoryMap;
101 friend class MemoryMap;
106 #endif /* _MOOSEYARD_FILE_ */