18 #if STXXL_HAVE_BOOSTFD_FILE 
   23 #include <boost/filesystem/operations.hpp> 
   24 #include <boost/filesystem/fstream.hpp> 
   25 #include <boost/version.hpp> 
   29 void boostfd_file::serve(
void* buffer, offset_type offset, size_type 
bytes,
 
   30                          request::request_type type)
 
   32     scoped_mutex_lock fd_lock(m_fd_mutex);
 
   36         m_file_des.seek(offset, BOOST_IOS::beg);
 
   38     catch (
const std::exception& ex)
 
   42             "Error doing seek() in boostfd_request::serve()" <<
 
   43             " offset=" << offset <<
 
   45             " buffer=" << buffer <<
 
   47             " type=" << ((type == request::READ) ? 
"READ" : 
"WRITE") <<
 
   51     stats::scoped_read_write_timer read_write_timer(bytes, type == request::WRITE);
 
   53     if (type == request::READ)
 
   57             std::streamsize rc = m_file_des.read((
char*)buffer, bytes);
 
   58             if (rc != std::streamsize(bytes)) {
 
   59                 STXXL_THROW_ERRNO(io_error, 
" partial read: " << rc << 
" missing " << (bytes - rc) << 
" out of " << bytes << 
" bytes");
 
   62         catch (
const std::exception& ex)
 
   66                 "Error doing read() in boostfd_request::serve()" <<
 
   67                 " offset=" << offset <<
 
   69                 " buffer=" << buffer <<
 
   71                 " type=" << ((type == request::READ) ? 
"READ" : 
"WRITE") <<
 
   79             std::streamsize rc = m_file_des.write((
char*)buffer, bytes);
 
   80             if (rc != std::streamsize(bytes)) {
 
   81                 STXXL_THROW_ERRNO(io_error, 
" partial write: " << rc << 
" missing " << (bytes - rc) << 
" out of " << bytes << 
" bytes");
 
   84         catch (
const std::exception& ex)
 
   88                 "Error doing write() in boostfd_request::serve()" <<
 
   89                 " offset=" << offset <<
 
   91                 " buffer=" << buffer <<
 
   93                 " type=" << ((type == request::READ) ? 
"READ" : 
"WRITE") <<
 
   99 const char* boostfd_file::io_type()
 const 
  104 boostfd_file::boostfd_file(
 
  105     const std::string& filename,
 
  107     int queue_id, 
int allocator_id, 
unsigned int device_id)
 
  109       disk_queued_file(queue_id, allocator_id),
 
  112     BOOST_IOS::openmode boostfd_mode =
 
  113         (mode & RDWR) ? (BOOST_IOS::out | BOOST_IOS::in) :
 
  114         (mode & WRONLY) ? (BOOST_IOS::out) :
 
  115         (mode & RDONLY) ? (BOOST_IOS::in) :
 
  118 #if defined(BOOST_FILESYSTEM_VERSION) && (BOOST_FILESYSTEM_VERSION >= 3) 
  119     const boost::filesystem::path fspath(filename);
 
  121     const boost::filesystem::path fspath(filename,
 
  122                                          boost::filesystem::native);
 
  127         if (boost::filesystem::exists(fspath))
 
  129             boost::filesystem::remove(fspath);
 
  130             boost::filesystem::ofstream f(fspath);
 
  132             assert(boost::filesystem::exists(fspath));
 
  139         if (!boost::filesystem::exists(fspath))
 
  141             boost::filesystem::ofstream f(fspath);
 
  143             assert(boost::filesystem::exists(fspath));
 
  150         STXXL_MSG(
"Warning: open()ing " << filename << 
" without DIRECT mode, boostfd does not support it.");
 
  153     if (mode & REQUIRE_DIRECT)
 
  156         STXXL_ERRMSG(
"Error: open()ing " << filename << 
" with REQUIRE_DIRECT mode, but boostfd does not support it.");
 
  165 #if (BOOST_VERSION >= 104100) 
  166     m_file_des.open(filename, boostfd_mode);      
 
  168     m_file_des.open(filename, boostfd_mode, boostfd_mode);
 
  172 boostfd_file::~boostfd_file()
 
  174     scoped_mutex_lock fd_lock(m_fd_mutex);
 
  178 inline file::offset_type boostfd_file::_size()
 
  180     return m_file_des.seek(0, BOOST_IOS::end);
 
  183 file::offset_type boostfd_file::size()
 
  185     scoped_mutex_lock fd_lock(m_fd_mutex);
 
  189 void boostfd_file::set_size(offset_type newsize)
 
  191     scoped_mutex_lock fd_lock(m_fd_mutex);
 
  192     offset_type oldsize = _size();
 
  193     m_file_des.seek(newsize, BOOST_IOS::beg);
 
  194     m_file_des.seek(0, BOOST_IOS::beg); 
 
  198 void boostfd_file::lock()
 
  205 #endif  // #if STXXL_HAVE_BOOSTFD_FILE 
#define STXXL_ASSERT(condition)
#define STXXL_BEGIN_NAMESPACE
#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 
#define STXXL_END_NAMESPACE