21 #include <foxxll/config.hpp> 67 #elif !FOXXLL_DIRECT_IO_OFF 70 if (mode & REQUIRE_DIRECT) {
72 <<
" with DIRECT mode required, but the system does not support it.";
78 <<
" without DIRECT mode, as the system does not support it.";
94 #if FOXXLL_WINDOWS || defined(__MINGW32__) 95 const int perms = S_IREAD | S_IWRITE;
97 const int perms = S_IREAD | S_IWRITE | S_IRGRP | S_IWGRP;
107 #if !FOXXLL_DIRECT_IO_OFF 108 if ((mode & DIRECT) && !(mode & REQUIRE_DIRECT) && errno == EINVAL)
111 <<
" flags=" << flags <<
", retrying without O_DIRECT.";
126 <<
" path=" <<
filename_ <<
" flags=" << flags
138 #if FOXXLL_WINDOWS || defined(__MINGW32__) 165 if (fcntl(
file_des_, F_NOCACHE, 1) != 0) {
167 <<
"fcntl(fd,F_NOCACHE,1) failed on path=" <<
filename_ 168 <<
" fd=" <<
file_des_ <<
" : " << strerror(errno);
170 if (fcntl(
file_des_, F_RDAHEAD, 0) != 0) {
172 <<
" fd=" <<
file_des_ <<
" : " << strerror(errno);
184 std::unique_lock<std::mutex> fd_lock(
fd_mutex_);
197 #if FOXXLL_WINDOWS || defined(__MINGW32__) 200 std::unique_lock<std::mutex> fd_lock(
fd_mutex_);
201 struct flock lock_struct;
202 lock_struct.l_type =
static_cast<short>(
mode_ &
RDONLY ? F_RDLCK : F_RDLCK | F_WRLCK);
203 lock_struct.l_whence = SEEK_SET;
204 lock_struct.l_start = 0;
205 lock_struct.l_len = 0;
206 if ((::fcntl(
file_des_, F_SETLK, &lock_struct)) < 0)
217 off_t rc = ::lseek(
file_des_, 0, SEEK_END);
227 std::unique_lock<std::mutex> fd_lock(
fd_mutex_);
233 std::unique_lock<std::mutex> fd_lock(
fd_mutex_);
243 #if FOXXLL_WINDOWS || defined(__MINGW32__) 244 HANDLE hfile = (HANDLE)::_get_osfhandle(
file_des_);
246 (hfile == INVALID_HANDLE_VALUE),
io_error,
250 LARGE_INTEGER desired_pos;
251 desired_pos.QuadPart = newsize;
253 if (!SetFilePointerEx(hfile, desired_pos,
nullptr, FILE_BEGIN))
254 FOXXLL_THROW_WIN_LASTERROR(
256 "SetFilePointerEx in ufs_file_base::set_size(..) oldsize=" << cur_size <<
257 " newsize=" << newsize <<
" " 260 if (!SetEndOfFile(hfile))
261 FOXXLL_THROW_WIN_LASTERROR(
263 "SetEndOfFile oldsize=" << cur_size <<
264 " newsize=" << newsize <<
" " 275 if (newsize > cur_size)
289 <<
" skipped as file is device node";
295 <<
" error=" << strerror(errno);
302 <<
" skipped as file is device node";
only reading of the file is allowed
only writing of the file is allowed
void close_remove() final
close and remove file
request::offset_type offset_type
the offset of a request, also the size of the file
do not acquire an exclusive lock by default
implies DIRECT, fail if opening with DIRECT flag does not work.
bool is_device_
is special device node
void set_size(offset_type newsize) final
#define FOXXLL_THROW_ERRNO(exception_type, error_message)
Throws exception_type with "Error in [function] : [error_message] : [errno message]".
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
bool is_device() const
return true if file is special device node
ufs_file_base(const std::string &filename, int mode)
const char * io_type() const override
#define FOXXLL_THROW_IF(expr, exception_type, error_message)
Throws exception_type if (expr) with "Error in [function] : [error_message]".
void lock() final
Locks file for reading and writing (acquires a lock in the file system).
const std::string filename_
bool need_alignment_
Flag whether read/write operations REQUIRE alignment.
once file is opened its length becomes zero
read and write of the file are allowed
#define FOXXLL_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
void _set_size(offset_type newsize)
void unlink()
unlink file without closing it.