44 template <
class base_file_type>
46 const std::string& filename_prefix,
50 unsigned int device_id)
53 filename_prefix(filename_prefix),
56 lock_file_created(false),
57 lock_file(filename_prefix +
"_fpb_lock", mode, queue_id)
60 template <
class base_file_type>
63 if (lock_file_created)
65 if (::
remove((filename_prefix +
"_fpb_lock").c_str()) != 0)
66 STXXL_ERRMSG(
"remove() error on path=" << filename_prefix <<
"_fpb_lock error=" << strerror(errno));
70 template <
class base_file_type>
73 std::ostringstream name;
75 name << filename_prefix <<
"_fpb_" << std::setw(20) << std::setfill(
'0') << offset;
79 template <
class base_file_type>
83 base_file_type base_file(filename_for_block(offset), mode, get_queue_id());
84 base_file.set_size(bytes);
85 base_file.serve(buffer, 0, bytes, type);
88 template <
class base_file_type>
91 if (!lock_file_created)
95 void* one_page = aligned_alloc<STXXL_BLOCK_ALIGN>(page_size);
96 #if STXXL_WITH_VALGRIND
97 memset(one_page, 0, page_size);
99 lock_file.set_size(page_size);
100 request_ptr r = lock_file.awrite(one_page, 0, page_size);
102 aligned_dealloc<STXXL_BLOCK_ALIGN>(one_page);
103 lock_file_created =
true;
108 template <
class base_file_type>
112 #ifdef STXXL_FILEPERBLOCK_NO_DELETE
113 if (::truncate(filename_for_block(offset).c_str(), 0) != 0)
114 STXXL_ERRMSG(
"truncate() error on path=" << filename_for_block(offset) <<
" error=" << strerror(errno));
116 if (::
remove(filename_for_block(offset).c_str()) != 0)
117 STXXL_ERRMSG(
"remove() error on path=" << filename_for_block(offset) <<
" error=" << strerror(errno));
123 template <
class base_file_type>
126 std::string original(filename_for_block(offset));
127 filename.insert(0, original.substr(0, original.find_last_of(
"/") + 1));
128 if (::
remove(filename.c_str()) != 0)
129 STXXL_ERRMSG(
"remove() error on path=" << filename <<
" error=" << strerror(errno));
131 if (::rename(original.c_str(), filename.c_str()) != 0)
132 STXXL_ERRMSG(
"rename() error on path=" << filename <<
" to=" << original <<
" error=" << strerror(errno));
136 if (::truncate(filename.c_str(), length) != 0) {
144 template <
class base_file_type>
147 return "fileperblock";
154 #if STXXL_HAVE_MMAP_FILE
158 #if STXXL_HAVE_WINCALL_FILE
162 #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...
#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.
#define STXXL_BLOCK_ALIGN
virtual void serve(void *buffer, offset_type offset, size_type bytes, request::request_type type)
request::size_type size_type
the size of a request
virtual void wait(bool measure_time=true)=0
Suspends calling thread until completion of the request.
Defines interface of file.
#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]".
static const size_t bytes
number of bytes in uint_pair
request::offset_type offset_type
the offset of a request, also the size of the file
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