27 const char* ufs_file_base::io_type()
const
32 ufs_file_base::ufs_file_base(
33 const std::string& filename,
35 : file_des(-1), m_mode(mode), filename(filename)
68 #elif !STXXL_DIRECT_IO_OFF
71 if (mode & REQUIRE_DIRECT) {
72 STXXL_ERRMSG(
"Error: open()ing " << filename <<
" with DIRECT mode required, but the system does not support it.");
77 STXXL_MSG(
"Warning: open()ing " << filename <<
" without DIRECT mode, as the system does not support it.");
93 #if STXXL_WINDOWS || defined(__MINGW32__)
94 const int perms = S_IREAD | S_IWRITE;
96 const int perms = S_IREAD | S_IWRITE | S_IRGRP | S_IWGRP;
99 if ((
file_des = ::open(filename.c_str(), flags, perms)) >= 0)
105 #if !STXXL_DIRECT_IO_OFF
106 if ((mode & DIRECT) && !(mode & REQUIRE_DIRECT) && errno == EINVAL)
108 STXXL_MSG(
"open() error on path=" << filename <<
" flags=" << flags <<
", retrying without O_DIRECT.");
113 if ((
file_des = ::open(filename.c_str(), flags, perms)) >= 0)
132 #if STXXL_WINDOWS || defined(__MINGW32__)
151 if (fcntl(
file_des, F_NOCACHE, 1) != 0) {
153 " fd=" <<
file_des <<
" : " << strerror(errno));
155 if (fcntl(
file_des, F_RDAHEAD, 0) != 0) {
157 " fd=" <<
file_des <<
" : " << strerror(errno));
182 #if STXXL_WINDOWS || defined(__MINGW32__)
186 struct flock lock_struct;
187 lock_struct.l_type = (short)(
m_mode &
RDONLY ? F_RDLCK : F_RDLCK | F_WRLCK);
188 lock_struct.l_whence = SEEK_SET;
189 lock_struct.l_start = 0;
190 lock_struct.l_len = 0;
191 if ((::fcntl(
file_des, F_SETLK, &lock_struct)) < 0)
228 #if STXXL_WINDOWS || defined(__MINGW32__)
229 HANDLE hfile = (HANDLE) ::_get_osfhandle(
file_des);
233 LARGE_INTEGER desired_pos;
234 desired_pos.QuadPart = newsize;
236 if (!SetFilePointerEx(hfile, desired_pos, NULL, FILE_BEGIN))
238 "SetFilePointerEx in ufs_file_base::set_size(..) oldsize=" << cur_size <<
239 " newsize=" << newsize <<
" ");
241 if (!SetEndOfFile(hfile))
243 "SetEndOfFile oldsize=" << cur_size <<
244 " newsize=" << newsize <<
" ");
252 if (newsize > cur_size)
254 "lseek() path=" <<
filename <<
" fd=" <<
file_des <<
" pos=" << newsize - 1);
267 if (::
remove(
filename.c_str()) != 0)
read and write of the file are allowed
I/Os proceed bypassing file system buffers, i.e.
const std::string filename
#define STXXL_THROW_ERRNO_NE_0(expr, exception_type, error_message)
Throws exception_type if (expr != 0) with "Error in [function] : [error_message] : [errno message]"...
open the file with O_SYNC | O_DSYNC | O_RSYNC flags set
in case file does not exist no error occurs and file is newly created
only writing of the file is allowed
void close_remove()
close and remove file
do not acquire an exclusive lock by default
implies DIRECT, fail if opening with DIRECT flag does not work.
void set_size(offset_type newsize)
#define STXXL_THROW_WIN_LASTERROR(exception_type, error_message)
Throws exception_type with "Error in [function] : [error_message] : [formatted GetLastError()]".
only reading of the file is allowed
void unlink()
unlink file without closing it.
Aquire a lock that's valid until the end of scope.
#define STXXL_BEGIN_NAMESPACE
void lock()
Locks file for reading and writing (acquires a lock in the file system).
once file is opened its length becomes zero
#define STXXL_THROW_ERRNO_LT_0(expr, exception_type, error_message)
Throws exception_type if (expr < 0) with "Error in [function] : [error_message] : [errno message]"...
bool m_is_device
is special device node
#define STXXL_THROW_ERRNO(exception_type, error_message)
Throws exception_type with "Error in [function] : [error_message] : [errno message]".
void _set_size(offset_type newsize)
request::offset_type offset_type
the offset of a request, also the size of the file
offset_type size()
Returns size of the file.
bool is_device() const
return true if file is special device node
#define STXXL_END_NAMESPACE