4#include <linux/close_range.h>
13#include <cosmos/SysString.hxx>
14#include <cosmos/dso_export.h>
15#include <cosmos/error/errno.hxx>
16#include <cosmos/fs/DirFD.hxx>
17#include <cosmos/fs/FileDescriptor.hxx>
18#include <cosmos/fs/types.hxx>
19#include <cosmos/types.hxx>
41COSMOS_API FileDescriptor open(
42 const SysString path,
const OpenMode mode,
43 const OpenFlags flags,
const std::optional<FileMode> fmode = {});
62COSMOS_API FileDescriptor open_at(
63 const DirFD dir_fd,
const SysString path,
64 const OpenMode mode,
const OpenFlags flags,
65 const std::optional<FileMode> fmode = {});
94COSMOS_API
void close_range(
const FileNum first,
95 const FileNum last = FileNum::MAX_FD,
127COSMOS_API std::pair<FileDescriptor, std::string> make_tempfile(
146COSMOS_API std::string make_tempdir(
const SysString _template);
170COSMOS_API
void make_fifo(
const SysString path,
const FileMode mode);
181COSMOS_API
void make_fifo_at(
const DirFD dir_fd,
const SysString path,
182 const FileMode mode);
213COSMOS_API FileMode set_umask(
const FileMode mode);
235COSMOS_API
bool exists_file(
const SysString path);
248COSMOS_API
void unlink_file(
const SysString path);
262COSMOS_API
void unlink_file_at(
const DirFD dir_fd,
const SysString path);
268COSMOS_API
void change_dir(
const SysString path);
275COSMOS_API std::string get_working_dir();
290COSMOS_API std::optional<std::string> which(
const std::string_view exec_base)
noexcept;
301COSMOS_API
void make_dir(
const SysString path,
const FileMode mode);
310COSMOS_API
void make_dir_at(
const DirFD dir_fd,
const SysString path,
const FileMode mode);
317COSMOS_API
void remove_dir(
const SysString path);
326COSMOS_API
void remove_dir_at(
const DirFD dir_fd,
const SysString path);
342COSMOS_API Errno make_all_dirs(
const SysString path,
const FileMode mode);
356COSMOS_API
void remove_tree(
const SysString path);
377COSMOS_API
void change_mode(
const SysString path,
const FileMode mode);
389COSMOS_API
void change_mode(
const FileDescriptor fd,
const FileMode mode);
405COSMOS_API
void change_owner(
const SysString path,
const UserID uid,
const GroupID gid = GroupID::INVALID);
417COSMOS_API
void change_owner(
const FileDescriptor fd,
const UserID uid,
const GroupID gid = GroupID::INVALID);
432COSMOS_API
void change_owner(
const SysString path,
const SysString user,
433 const SysString group = {});
441COSMOS_API
void change_owner(
const FileDescriptor fd,
const SysString user,
442 const SysString group = {});
446 change_owner(fd, UserID::INVALID,
id);
451 change_owner(fd, {}, group);
456 change_owner(path, UserID::INVALID,
id);
461 change_owner(path, {}, group);
474COSMOS_API
void change_owner_nofollow(
const SysString path,
const UserID uid,
475 const GroupID gid = GroupID::INVALID);
506COSMOS_API
void make_symlink(
const SysString target,
const SysString path);
513COSMOS_API
void make_symlink_at(
const SysString target,
const DirFD dir_fd,
514 const SysString path);
526COSMOS_API std::string read_symlink(
const SysString path);
535COSMOS_API std::string read_symlink_at(
const DirFD dir_fd,
const SysString path);
556COSMOS_API
void link(
const SysString old_path,
const SysString new_path);
572COSMOS_API
void linkat(
const DirFD old_dir,
const SysString old_path,
573 const DirFD new_dir,
const SysString new_path,
574 const FollowSymlinks follow_old = FollowSymlinks{
false});
597COSMOS_API
void linkat_fd(
const FileDescriptor fd,
const DirFD new_dir,
598 const SysString new_path);
606COSMOS_API
void linkat_proc_fd(
const FileDescriptor fd,
const DirFD new_dir,
607 const SysString new_path);
618COSMOS_API
void truncate(
const FileDescriptor fd, off_t length);
626COSMOS_API
void truncate(
const SysString path, off_t length);
633 std::optional<off_t> off_in;
634 std::optional<off_t> off_out;
677COSMOS_API
size_t copy_file_range(
712COSMOS_API
void check_access(
const SysString path,
const AccessChecks checks = {});
734COSMOS_API
void check_access_at(
const DirFD dir_fd,
const SysString path,
735 const AccessChecks checks = {},
const AccessFlags flags = {});
742COSMOS_API
void check_access_fd(
const FileDescriptor fd,
const AccessChecks check = {},
743 const AccessFlags flags = {});
A typesafe bit mask representation using class enums.
A specialized FileDescriptor for directory objects.
Thin Wrapper around OS file descriptors.
AccessCheck
Different access checks that can be performed in check_access().
@ EXEC_OK
Execution is allowed.
@ WRITE_OK
Write access is allowed.
@ READ_OK
Read access is allowed.
@ LOCK_NONBLOCK
don't block if a lock cannot be placed, throw ApiError with Errno::WOULD_BLOCK instead.
LockOperation
Flags used with flock().
@ UNLOCK
remove an existing lock (regardless of shared or exclusive)
@ LOCK_SHARED
place a shared lock of which multiple may exist at the same time (for reading)
@ LOCK_EXCLUSIVE
place an exclusive lock of which only one may exist at the same time (for writing)
@ CLOEXEC
Instead of closing, mark all matching file descriptors as CLOEXEC.
@ UNSHARE
Unshare specified file descriptors before closing to avoid race conditions with other threads.
void change_group(const FileDescriptor fd, const GroupID id)
Convenience wrapper of change_owner() to change only the group of a file.
AccessFlag
Extra flags that influence the behaviour of check_access_at(), and check_access_fd().
@ NO_FOLLOW
don't resolve symlinks in path but check access to the link itself.
@ EFFECTIVE_CREDS
use the caller's effective UID and GID for the access check.
FileNum
Primitive file descriptor.
Wrapper type around a C-style string for use with system APIs.
set of parameters for copy_file_range().