/* * Copyright (c) 2018-2021, Andreas Kling * Copyright (c) 2024, Liav A. * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace Kernel { // Kernel internal options. #define O_NOFOLLOW_NOERROR (1 << 29) #define O_UNLINK_INTERNAL (1 << 30) struct UidAndGid { UserID uid; GroupID gid; }; enum class AccessFlags { None = 0, EffectiveAccess = 1 << 0, DoNotFollowSymlinks = 1 << 1, }; AK_ENUM_BITWISE_OPERATORS(AccessFlags); namespace VirtualFileSystem { // Required to be at least 8 by POSIX // https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html static constexpr int symlink_recursion_limit = 8; bool check_matching_absolute_path_hierarchy(Custody const& first_custody, Custody const& second_custody); ErrorOr find_filesystem_type_initializer(StringView fs_type); ErrorOr remove_mount(Mount& mount, FileBackedFileSystem::List& file_backed_fs_list); ErrorOr mount(VFSRootContext&, MountFile&, OpenFileDescription*, Custody& mount_point, int flags); ErrorOr bind_mount(VFSRootContext&, Custody& source, Custody& mount_point, int flags); ErrorOr copy_mount(Custody& source, VFSRootContext& destination, Custody& mount_point, int flags); ErrorOr remount(VFSRootContext&, Custody& mount_point, int new_flags); ErrorOr unmount(VFSRootContext&, Custody& mount_point); ErrorOr unmount(VFSRootContext&, Inode& guest_inode, StringView custody_path); ErrorOr> open(VFSRootContext const&, Credentials const&, StringView path, int options, mode_t mode, CustodyBase const& base, Optional = {}); ErrorOr> open(Process const&, VFSRootContext const&, Credentials const&, StringView path, int options, mode_t mode, CustodyBase const& base, Optional = {}); ErrorOr> create(Credentials const&, StringView path, int options, mode_t mode, Custody& parent_custody, Optional = {}); ErrorOr> create(Process const&, Credentials const&, StringView path, int options, mode_t mode, Custody& parent_custody, Optional = {}); ErrorOr mkdir(VFSRootContext const&, Credentials const&, StringView path, mode_t mode, CustodyBase const& base); ErrorOr link(VFSRootContext const&, Credentials const&, StringView old_path, StringView new_path, CustodyBase const& base); ErrorOr unlink(VFSRootContext const&, Credentials const&, StringView path, CustodyBase const& base); ErrorOr symlink(VFSRootContext const&, Credentials const&, StringView target, StringView linkpath, CustodyBase const& base); ErrorOr rmdir(VFSRootContext const&, Credentials const&, StringView path, CustodyBase const& base); ErrorOr chmod(VFSRootContext const&, Credentials const&, StringView path, mode_t, CustodyBase const& base, int options = 0); ErrorOr chmod(Credentials const&, Custody&, mode_t); ErrorOr chown(VFSRootContext const&, Credentials const&, StringView path, UserID, GroupID, CustodyBase const& base, int options); ErrorOr chown(Credentials const&, Custody&, UserID, GroupID); ErrorOr access(VFSRootContext const&, Credentials const&, StringView path, int mode, CustodyBase const& base, AccessFlags); ErrorOr lookup_metadata(VFSRootContext const&, Credentials const&, StringView path, CustodyBase const& base, int options = 0); ErrorOr utime(VFSRootContext const&, Credentials const&, StringView path, CustodyBase const& base, time_t atime, time_t mtime); ErrorOr utimensat(VFSRootContext const&, Credentials const&, StringView path, CustodyBase const& base, timespec const& atime, timespec const& mtime, int options = 0); ErrorOr do_utimens(Credentials const&, Custody& custody, timespec const& atime, timespec const& mtime); ErrorOr rename(VFSRootContext const&, Credentials const&, CustodyBase const& old_base, StringView oldpath, CustodyBase const& new_base, StringView newpath); ErrorOr mknod(VFSRootContext const&, Credentials const&, StringView path, mode_t, dev_t, CustodyBase const& base); ErrorOr> open_directory(VFSRootContext const&, Credentials const&, StringView path, CustodyBase const& base); ErrorOr> resolve_path(VFSRootContext const&, Credentials const&, StringView path, CustodyBase const& base, RefPtr* out_parent = nullptr, int options = 0, int symlink_recursion_level = 0); ErrorOr> resolve_path(Process const&, VFSRootContext const&, Credentials const&, StringView path, CustodyBase const& base, RefPtr* out_parent = nullptr, int options = 0, int symlink_recursion_level = 0); ErrorOr> resolve_path_without_veil(VFSRootContext const&, Credentials const&, StringView path, NonnullRefPtr base, RefPtr* out_parent = nullptr, int options = 0, int symlink_recursion_level = 0); void sync_filesystems(); }; }