43 template <
class base_file_type>
45 const std::string& filename_prefix,
50 filename_prefix(filename_prefix),
53 lock_file_created(false),
54 lock_file(filename_prefix +
"_fpb_lock", mode, queue_id)
57 template <
class base_file_type>
60 if (lock_file_created)
62 if (::
remove((filename_prefix +
"_fpb_lock").c_str()) != 0)
63 STXXL_ERRMSG(
"remove() error on path=" << filename_prefix <<
"_fpb_lock error=" << strerror(errno));
67 template <
class base_file_type>
70 std::ostringstream name;
72 name << filename_prefix <<
"_fpb_" << std::setw(20) << std::setfill(
'0') << offset;
76 template <
class base_file_type>
79 assert(req->get_file() ==
this);
81 base_file_type base_file(filename_for_block(req->get_offset()), mode, get_queue_id());
82 base_file.set_size(req->get_size());
89 template <
class base_file_type>
92 if (!lock_file_created)
96 void* one_page = aligned_alloc<BLOCK_ALIGN>(page_size);
97 #if STXXL_WITH_VALGRIND
98 memset(one_page, 0, page_size);
100 lock_file.set_size(page_size);
103 aligned_dealloc<BLOCK_ALIGN>(one_page);
104 lock_file_created =
true;
109 template <
class base_file_type>
113 #ifdef STXXL_FILEPERBLOCK_NO_DELETE
114 if (::truncate(filename_for_block(offset).c_str(), 0) != 0)
115 STXXL_ERRMSG(
"truncate() error on path=" << filename_for_block(offset) <<
" error=" << strerror(errno));
117 if (::
remove(filename_for_block(offset).c_str()) != 0)
118 STXXL_ERRMSG(
"remove() error on path=" << filename_for_block(offset) <<
" error=" << strerror(errno));
124 template <
class base_file_type>
127 std::string original(filename_for_block(offset));
128 filename.insert(0, original.substr(0, original.find_last_of(
"/") + 1));
129 if (::
remove(filename.c_str()) != 0)
130 STXXL_ERRMSG(
"remove() error on path=" << filename <<
" error=" << strerror(errno));
132 if (::rename(original.c_str(), filename.c_str()) != 0)
133 STXXL_ERRMSG(
"rename() error on path=" << filename <<
" to=" << original <<
" error=" << strerror(errno));
137 if (::truncate(filename.c_str(), length) != 0) {
145 template <
class base_file_type>
148 return "fileperblock";
155 #if STXXL_HAVE_MMAP_FILE
159 #if STXXL_HAVE_WINCALL_FILE
163 #if STXXL_HAVE_BOOSTFD_FILE
virtual void discard(offset_type offset, offset_type length)
Frees the specified region. Actually deletes the corresponding file if the whole thing is deleted...
Default completion handler class.
#define STXXL_VERBOSE2(x)
virtual void export_files(offset_type offset, offset_type length, std::string filename)
Rename the file corresponding to the offset such that it is out of reach for deleting.
Request which serves an I/O by calling the synchronous routine of the file.
virtual void wait(bool measure_time=true)=0
Suspends calling thread until completion of the request.
virtual void serve(const request *req)
#define STXXL_BEGIN_NAMESPACE
void STXXL_UNUSED(const U &)
Implementation of some file methods based on serving_request.
Implementation of file based on other files, dynamically allocate one file per block. Allows for dynamic disk space consumption.
#define STXXL_THROW_ERRNO(exception_type, error_message)
Throws exception_type with "Error in [function] : [error_message] : [errno message]".
request::offset_type offset_type
the offset of a request, also the size of the file
Request with basic properties like file and offset.
virtual ~fileperblock_file()
virtual void lock()
Locks file for reading and writing (acquires a lock in the file system).
std::string filename_for_block(offset_type offset)
Constructs a file name for a given block.
const char * io_type() const
Identifies the type of I/O implementation.
#define STXXL_END_NAMESPACE