27 const char* ufs_file_base::io_type()
const
32 ufs_file_base::ufs_file_base(
33 const std::string& filename,
34 int mode) : file_des(-1), m_mode(mode), filename(filename)
67 #elif !STXXL_DIRECT_IO_OFF
70 if (mode & REQUIRE_DIRECT) {
71 STXXL_ERRMSG(
"Error: open()ing " << filename <<
" with DIRECT mode required, but the system does not support it.");
76 STXXL_MSG(
"Warning: open()ing " << filename <<
" without DIRECT mode, as the system does not support it.");
92 #if STXXL_WINDOWS || defined(__MINGW32__)
93 const int perms = S_IREAD | S_IWRITE;
95 const int perms = S_IREAD | S_IWRITE | S_IRGRP | S_IWGRP;
98 if ((
file_des = ::open(filename.c_str(), flags, perms)) >= 0)
104 #if !STXXL_DIRECT_IO_OFF
105 if ((mode & DIRECT) && !(mode & REQUIRE_DIRECT) && errno == EINVAL)
107 STXXL_MSG(
"open() error on path=" << filename <<
" flags=" << flags <<
", retrying without O_DIRECT.");
112 if ((
file_des = ::open(filename.c_str(), flags, perms)) >= 0)
131 #if STXXL_WINDOWS || defined(__MINGW32__)
150 if (fcntl(
file_des, F_NOCACHE, 1) != 0) {
152 " fd=" <<
file_des <<
" : " << strerror(errno));
154 if (fcntl(
file_des, F_RDAHEAD, 0) != 0) {
156 " fd=" <<
file_des <<
" : " << strerror(errno));
181 #if STXXL_WINDOWS || defined(__MINGW32__)
185 struct flock lock_struct;
186 lock_struct.l_type = (
m_mode &
RDONLY) ? F_RDLCK : F_RDLCK | F_WRLCK;
187 lock_struct.l_whence = SEEK_SET;
188 lock_struct.l_start = 0;
189 lock_struct.l_len = 0;
190 if ((::fcntl(
file_des, F_SETLK, &lock_struct)) < 0)
227 #if STXXL_WINDOWS || defined(__MINGW32__)
228 HANDLE hfile = (HANDLE) ::_get_osfhandle(
file_des);
232 LARGE_INTEGER desired_pos;
233 desired_pos.QuadPart = newsize;
235 if (!SetFilePointerEx(hfile, desired_pos, NULL, FILE_BEGIN))
237 "SetFilePointerEx in ufs_file_base::set_size(..) oldsize=" << cur_size <<
238 " newsize=" << newsize <<
" ");
240 if (!SetEndOfFile(hfile))
242 "SetEndOfFile oldsize=" << cur_size <<
243 " newsize=" << newsize <<
" ");
251 if (newsize > cur_size)
253 "lseek() path=" <<
filename <<
" fd=" <<
file_des <<
" pos=" << newsize - 1);
266 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 aquire 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