1#ifndef UVW_FS_INCLUDE_H
2#define UVW_FS_INCLUDE_H
19enum class uvw_fs_type : std::underlying_type_t<uv_fs_type> {
20 UNKNOWN = UV_FS_UNKNOWN,
21 CUSTOM = UV_FS_CUSTOM,
26 SENDFILE = UV_FS_SENDFILE,
30 FTRUNCATE = UV_FS_FTRUNCATE,
32 FUTIME = UV_FS_FUTIME,
33 ACCESS = UV_FS_ACCESS,
35 FCHMOD = UV_FS_FCHMOD,
37 FDATASYNC = UV_FS_FDATASYNC,
38 UNLINK = UV_FS_UNLINK,
41 MKDTEMP = UV_FS_MKDTEMP,
42 RENAME = UV_FS_RENAME,
43 SCANDIR = UV_FS_SCANDIR,
45 SYMLINK = UV_FS_SYMLINK,
46 READLINK = UV_FS_READLINK,
48 FCHOWN = UV_FS_FCHOWN,
49 REALPATH = UV_FS_REALPATH,
50 COPYFILE = UV_FS_COPYFILE,
51 LCHOWN = UV_FS_LCHOWN,
52 OPENDIR = UV_FS_OPENDIR,
53 READDIR = UV_FS_READDIR,
54 CLOSEDIR = UV_FS_CLOSEDIR,
55 STATFS = UV_FS_STATFS,
56 MKSTEMP = UV_FS_MKSTEMP,
60enum class uvw_dirent_type_t : std::underlying_type_t<uv_dirent_type_t> {
61 UNKNOWN = UV_DIRENT_UNKNOWN,
62 FILE = UV_DIRENT_FILE,
64 LINK = UV_DIRENT_LINK,
65 FIFO = UV_DIRENT_FIFO,
66 SOCKET = UV_DIRENT_SOCKET,
67 CHAR = UV_DIRENT_CHAR,
68 BLOCK = UV_DIRENT_BLOCK
71enum class uvw_file_open_flags :
int {
72 APPEND = UV_FS_O_APPEND,
73 CREAT = UV_FS_O_CREAT,
74 DIRECT = UV_FS_O_DIRECT,
75 DIRECTORY = UV_FS_O_DIRECTORY,
76 DSYNC = UV_FS_O_DSYNC,
78 EXLOCK = UV_FS_O_EXLOCK,
79 FILEMAP = UV_FS_O_FILEMAP,
80 NOATIME = UV_FS_O_NOATIME,
81 NOCTTY = UV_FS_O_NOCTTY,
82 NOFOLLOW = UV_FS_O_NOFOLLOW,
83 NONBLOCK = UV_FS_O_NONBLOCK,
84 RANDOM = UV_FS_O_RANDOM,
85 RDONLY = UV_FS_O_RDONLY,
87 SEQUENTIAL = UV_FS_O_SEQUENTIAL,
88 SHORT_LIVED = UV_FS_O_SHORT_LIVED,
89 SYMLINK = UV_FS_O_SYMLINK,
91 TEMPORARY = UV_FS_O_TEMPORARY,
92 TRUNC = UV_FS_O_TRUNC,
93 WRONLY = UV_FS_O_WRONLY,
97enum class uvw_copy_file_flags :
int {
98 EXCL = UV_FS_COPYFILE_EXCL,
99 FICLONE = UV_FS_COPYFILE_FICLONE,
100 FICLONE_FORCE = UV_FS_COPYFILE_FICLONE_FORCE,
104enum class uvw_symlink_flags :
int {
105 DIR = UV_FS_SYMLINK_DIR,
106 JUNCTION = UV_FS_SYMLINK_JUNCTION,
161 using fs_type = details::uvw_fs_type;
162 using entry_type = details::uvw_dirent_type_t;
164 fs_event(
const uv_fs_t &req, std::unique_ptr<
const char[]>
data)
166 read.data = std::move(
data);
172 result{
static_cast<std::size_t
>(req.result)} {
179 case fs_type::READLINK:
180 readlink.data =
static_cast<char *
>(req.ptr);
182 case fs_type::READDIR:
183 dirent.name =
static_cast<uv_dir_t *
>(req.ptr)->dirents[0].
name;
184 dirent.type =
static_cast<entry_type
>(
static_cast<uv_dir_t *
>(req.ptr)->dirents[0].
type);
185 dirent.eos = !req.result;
187 case fs_type::STATFS:
201 std::unique_ptr<const char[]>
data;
226 static void fs_request_callback(uv_fs_t *req) {
235 using time = std::chrono::duration<double>;
236 using fs_type = details::uvw_fs_type;
237 using entry_type = details::uvw_dirent_type_t;
255 static constexpr uv_file BAD_FD = -1;
257 static void fs_open_callback(uv_fs_t *req);
258 static void fs_close_callback(uv_fs_t *req);
259 static void fs_read_callback(uv_fs_t *req);
262 using file_open_flags = details::uvw_file_open_flags;
264 using fs_request::fs_request;
319 void open(
const std::string &path, file_open_flags flags,
int mode);
358 bool open_sync(
const std::string &path, file_open_flags flags,
int mode);
368 void read(int64_t offset,
unsigned int len);
382 std::pair<bool, std::pair<std::unique_ptr<const char[]>, std::size_t>>
read_sync(int64_t offset,
unsigned int len);
396 void write(std::unique_ptr<
char[]> buf,
unsigned int len, int64_t offset);
410 void write(
char *buf,
unsigned int len, int64_t offset);
423 std::pair<bool, std::size_t>
write_sync(std::unique_ptr<
char[]> buf,
unsigned int len, int64_t offset);
574 std::unique_ptr<
char[]> current{
nullptr};
576 uv_file file{BAD_FD};
593 using copy_file_flags = details::uvw_copy_file_flags;
594 using symlink_flags = details::uvw_symlink_flags;
596 using fs_request::fs_request;
624 void mkdir(
const std::string &path,
int mode);
683 std::pair<bool, std::pair<std::string, std::size_t>>
mkstemp_sync(
const std::string &tpl);
696 void lutime(
const std::string &path, time atime, time mtime);
707 bool lutime_sync(
const std::string &path, time atime, time mtime);
716 void rmdir(
const std::string &path);
733 void scandir(
const std::string &path,
int flags);
745 std::pair<bool, std::size_t>
scandir_sync(
const std::string &path,
int flags);
785 void stat(
const std::string &path);
796 std::pair<bool, file_info>
stat_sync(
const std::string &path);
805 void lstat(
const std::string &path);
816 std::pair<bool, file_info>
lstat_sync(
const std::string &path);
852 void rename(
const std::string &old,
const std::string &path);
860 bool rename_sync(
const std::string &old,
const std::string &path);
889 void copyfile(
const std::string &old,
const std::string &path, copy_file_flags flags = copy_file_flags::_UVW_ENUM);
910 bool copyfile_sync(
const std::string &old,
const std::string &path, copy_file_flags flags = copy_file_flags::_UVW_ENUM);
920 void access(
const std::string &path,
int mode);
938 void chmod(
const std::string &path,
int mode);
959 void utime(
const std::string &path, time atime, time mtime);
970 bool utime_sync(
const std::string &path, time atime, time mtime);
980 void link(
const std::string &old,
const std::string &path);
988 bool link_sync(
const std::string &old,
const std::string &path);
1006 void symlink(
const std::string &old,
const std::string &path, symlink_flags flags = symlink_flags::_UVW_ENUM);
1023 bool symlink_sync(
const std::string &old,
const std::string &path, symlink_flags flags = symlink_flags::_UVW_ENUM);
1045 std::pair<bool, std::pair<const char *, std::size_t>>
readlink_sync(
const std::string &path);
1199 uv_dirent_t dirents[1];
std::pair< bool, std::size_t > sendfile_sync(file_handle out, int64_t offset, std::size_t length)
Sync sendfile.
bool datasync_sync()
Sync fdatasync.
void chown(uid_type uid, gid_type gid)
Async fchown.
void write(std::unique_ptr< char[]> buf, unsigned int len, int64_t offset)
Async write.
bool chown_sync(uid_type uid, gid_type gid)
Sync fchown.
std::pair< bool, std::size_t > write_sync(std::unique_ptr< char[]> buf, unsigned int len, int64_t offset)
Sync write.
std::pair< bool, file_info > stat_sync()
Sync fstat.
bool chmod_sync(int mode)
Sync fchmod.
void sendfile(file_handle out, int64_t offset, std::size_t length)
Async sendfile.
void chmod(int mode)
Async fchmod.
void datasync()
Async fdatasync.
bool close_sync()
Sync close.
bool futime_sync(time atime, time mtime)
Sync futime.
void futime(time atime, time mtime)
Async futime.
std::pair< bool, std::pair< std::unique_ptr< const char[]>, std::size_t > > read_sync(int64_t offset, unsigned int len)
Sync read.
bool open_sync(const std::string &path, file_open_flags flags, int mode)
Sync open.
void write(char *buf, unsigned int len, int64_t offset)
Async write.
void read(int64_t offset, unsigned int len)
Async read.
void open(const std::string &path, file_open_flags flags, int mode)
Async open.
void truncate(int64_t offset)
Async ftruncate.
bool sync_sync()
Sync fsync.
bool truncate_sync(int64_t offset)
Sync ftruncate.
bool lutime_sync(const std::string &path, time atime, time mtime)
Sync lutime.
void mkdtemp(const std::string &tpl)
Async mktemp.
void opendir(const std::string &path)
Opens a path asynchronously as a directory stream.
bool rmdir_sync(const std::string &path)
Sync rmdir.
std::pair< bool, std::pair< entry_type, const char * > > readdir_sync()
Iterates synchronously over a directory stream one entry at a time.
bool mkdir_sync(const std::string &path, int mode)
Sync mkdir.
void lutime(const std::string &path, time atime, time mtime)
Async lutime.
bool copyfile_sync(const std::string &old, const std::string &path, copy_file_flags flags=copy_file_flags::_UVW_ENUM)
Copies a file synchronously from a path to a new one.
bool utime_sync(const std::string &path, time atime, time mtime)
Sync utime.
void readdir()
Iterates asynchronously over a directory stream one entry at a time.
void copyfile(const std::string &old, const std::string &path, copy_file_flags flags=copy_file_flags::_UVW_ENUM)
Copies a file asynchronously from a path to a new one.
void chown(const std::string &path, uid_type uid, gid_type gid)
Async chown.
void access(const std::string &path, int mode)
Async access.
bool opendir_sync(const std::string &path)
Opens a path synchronously as a directory stream.
bool chown_sync(const std::string &path, uid_type uid, gid_type gid)
Sync chown.
void utime(const std::string &path, time atime, time mtime)
Async utime.
void closedir()
Closes asynchronously a directory stream.
std::pair< bool, file_info > stat_sync(const std::string &path)
Sync stat.
void symlink(const std::string &old, const std::string &path, symlink_flags flags=symlink_flags::_UVW_ENUM)
Async symlink.
std::pair< bool, std::size_t > scandir_sync(const std::string &path, int flags)
Sync scandir.
void link(const std::string &old, const std::string &path)
Async link.
void chmod(const std::string &path, int mode)
Async chmod.
bool access_sync(const std::string &path, int mode)
Sync access.
void rename(const std::string &old, const std::string &path)
Async rename.
bool unlink_sync(const std::string &path)
Sync unlink.
std::pair< bool, const char * > mkdtemp_sync(const std::string &tpl)
Sync mktemp.
bool rename_sync(const std::string &old, const std::string &path)
Sync rename.
std::pair< bool, fs_info > statfs_sync(const std::string &path)
Sync statfs.
void realpath(const std::string &path)
Async realpath.
void lchown(const std::string &path, uid_type uid, gid_type gid)
Async lchown.
void unlink(const std::string &path)
Async unlink.
bool chmod_sync(const std::string &path, int mode)
Sync chmod.
void readlink(const std::string &path)
Async readlink.
void mkdir(const std::string &path, int mode)
Async mkdir.
std::pair< bool, std::pair< std::string, std::size_t > > mkstemp_sync(const std::string &tpl)
Sync mkstemp.
std::pair< bool, file_info > lstat_sync(const std::string &path)
Sync lstat.
std::pair< bool, std::pair< const char *, std::size_t > > readlink_sync(const std::string &path)
Sync readlink.
std::pair< bool, std::pair< entry_type, const char * > > scandir_next()
Gets entries populated with the next directory entry data.
bool symlink_sync(const std::string &old, const std::string &path, symlink_flags flags=symlink_flags::_UVW_ENUM)
Sync symlink.
std::pair< bool, const char * > realpath_sync(const std::string &path)
Sync realpath.
void lstat(const std::string &path)
Async lstat.
void mkstemp(const std::string &tpl)
Async mkstemp.
bool link_sync(const std::string &old, const std::string &path)
Sync link.
bool lchown_sync(const std::string &path, uid_type uid, gid_type gid)
Sync lchown.
void statfs(const std::string &path)
Async statfs.
void rmdir(const std::string &path)
Async rmdir.
void scandir(const std::string &path, int flags)
Async scandir.
void stat(const std::string &path)
Async stat.
bool closedir_sync()
Closes synchronously a directory stream.
Base class for fs/file request.
details::uv_type_wrapper< uv_os_fd_t > os_file_descriptor
details::uv_type_wrapper< uv_file > file_handle
std::unique_ptr< const char[]> data
static os_file_descriptor handle(file_handle file) noexcept
Gets the OS dependent handle.
static file_handle open(os_file_descriptor descriptor) noexcept
Gets the file descriptor.