15 #ifndef STXXL_IO_FILE_HEADER
16 #define STXXL_IO_FILE_HEADER
18 #ifdef STXXL_BOOST_CONFIG
19 #include <boost/config.hpp>
22 #if defined (__linux__)
23 #define STXXL_CHECK_BLOCK_ALIGNING
27 #include <sys/types.h>
35 #include <sys/resource.h>
54 #if defined (__linux__)
55 #if ! defined(O_DIRECT)
56 #error O_DIRECT is not defined while __linux__ is - PLEASE REPORT THIS BUG
60 #if !defined (O_DIRECT) && (defined (__alpha__) || defined (__i386__))
61 #define O_DIRECT 040000
66 #define O_DIRECT O_SYNC
72 #include <stxxl/bits/libstxxl.h>
73 #include <stxxl/bits/namespace.h>
74 #include <stxxl/bits/noncopyable.h>
75 #include <stxxl/bits/common/exceptions.h>
76 #include <stxxl/bits/common/mutex.h>
77 #include <stxxl/bits/io/request.h>
78 #include <stxxl/bits/io/request_ptr.h>
81 __STXXL_BEGIN_NAMESPACE
90 class file :
private noncopyable
92 mutex request_ref_cnt_mutex;
99 file() : request_ref_cnt(0) { }
103 typedef request::offset_type offset_type;
105 typedef request::size_type size_type;
123 static const int DEFAULT_QUEUE = -1;
124 static const int NO_QUEUE = -2;
125 static const int NO_ALLOCATOR = -1;
145 virtual void serve(
const request * req)
throw (io_error) = 0;
147 void add_request_ref()
153 void delete_request_ref()
156 assert(request_ref_cnt > 0);
160 int get_request_nref()
163 return request_ref_cnt;
168 virtual void set_size(offset_type newsize) = 0;
171 virtual offset_type
size() = 0;
180 virtual int get_physical_device_id()
const
186 virtual void lock() = 0;
192 STXXL_UNUSED(offset);
196 virtual void export_files(offset_type offset, offset_type length, std::string prefix)
198 STXXL_UNUSED(offset);
199 STXXL_UNUSED(length);
200 STXXL_UNUSED(prefix);
203 virtual void remove() { }
207 int nr = get_request_nref();
209 STXXL_ERRMSG(
"stxxl::file is being deleted while there are still " << nr <<
" (unfinished) requests referencing it");
222 __STXXL_END_NAMESPACE
224 #endif // !STXXL_IO_FILE_HEADER
read and write of the file are allowed
Definition: file.h:115
virtual void discard(offset_type offset, offset_type size)
Discard a region of the file (mark it unused) some specialized file types may need to know freed regi...
Definition: file.h:190
virtual void set_size(offset_type newsize)=0
Changes the size of the file.
Defines interface of file.
Definition: file.h:90
virtual const char * io_type() const
Identifies the type of I/O implementation.
Definition: file.h:214
virtual request_ptr awrite(void *buffer, offset_type pos, size_type bytes, const completion_handler &on_cmpl)=0
Schedules an asynchronous write request to the file.
Request with basic properties like file and offset.
Definition: request.h:39
Completion handler class (Loki-style)
Definition: completion_handler.h:63
only writing of the file is allowed
Definition: file.h:114
open_mode
Definition of acceptable file open modes.
Definition: file.h:111
virtual int get_allocator_id() const =0
Returns the file's allocator.
I/Os proceed bypassing file system buffers, i.e. unbuffered I/O.
Definition: file.h:117
only reading of the file is allowed
Definition: file.h:113
open the file with O_SYNC | O_DSYNC | O_RSYNC flags set
Definition: file.h:119
virtual int get_queue_id() const =0
Returns the identifier of the file's queue.
Aquire a lock that's valid until the end of scope.
Definition: mutex.h:82
virtual offset_type size()=0
Returns size of the file.
Implemented as reference counting smart pointer.
Definition: request_ptr.h:34
virtual request_ptr aread(void *buffer, offset_type pos, size_type bytes, const completion_handler &on_cmpl)=0
Schedules an asynchronous read request to the file.
once file is opened its length becomes zero
Definition: file.h:118
in case file does not exist no error occurs and file is newly created
Definition: file.h:116
do not aquire an exclusive lock by default
Definition: file.h:120
virtual void lock()=0
Locks file for reading and writing (acquires a lock in the file system)
file()
Initializes file object.
Definition: file.h:99