2020-01-18 11:38:21 +03:00
|
|
|
/*
|
2022-08-23 19:51:18 +03:00
|
|
|
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
|
2020-01-18 11:38:21 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-05-30 14:39:17 +03:00
|
|
|
#pragma once
|
|
|
|
|
2019-07-09 15:46:23 +03:00
|
|
|
#include <Kernel/FileSystem/File.h>
|
2019-05-30 14:39:17 +03:00
|
|
|
|
2020-02-16 03:27:42 +03:00
|
|
|
namespace Kernel {
|
|
|
|
|
2019-05-30 14:39:17 +03:00
|
|
|
class Inode;
|
|
|
|
|
|
|
|
class InodeFile final : public File {
|
|
|
|
public:
|
2022-08-19 21:53:40 +03:00
|
|
|
static ErrorOr<NonnullLockRefPtr<InodeFile>> create(NonnullLockRefPtr<Inode>&& inode)
|
2019-05-30 14:39:17 +03:00
|
|
|
{
|
2022-08-19 21:53:40 +03:00
|
|
|
auto file = adopt_lock_ref_if_nonnull(new (nothrow) InodeFile(move(inode)));
|
2021-05-11 13:54:44 +03:00
|
|
|
if (!file)
|
|
|
|
return ENOMEM;
|
|
|
|
return file.release_nonnull();
|
2019-05-30 14:39:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~InodeFile() override;
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
Inode const& inode() const { return *m_inode; }
|
2019-05-30 14:39:17 +03:00
|
|
|
Inode& inode() { return *m_inode; }
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
virtual bool can_read(OpenFileDescription const&, u64) const override { return true; }
|
|
|
|
virtual bool can_write(OpenFileDescription const&, u64) const override { return true; }
|
2019-05-30 14:39:17 +03:00
|
|
|
|
2021-11-08 02:51:39 +03:00
|
|
|
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
|
2022-04-01 20:58:27 +03:00
|
|
|
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, UserOrKernelBuffer const&, size_t) override;
|
2021-11-08 02:51:39 +03:00
|
|
|
virtual ErrorOr<void> ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override;
|
2022-08-23 19:51:18 +03:00
|
|
|
virtual ErrorOr<NonnullLockRefPtr<Memory::VMObject>> vmobject_for_mmap(Process&, Memory::VirtualRange const&, u64& offset, bool shared) override;
|
2021-12-17 13:22:27 +03:00
|
|
|
virtual ErrorOr<struct stat> stat() const override { return inode().metadata().stat(); }
|
2019-05-30 14:39:17 +03:00
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_path(OpenFileDescription const&) const override;
|
2019-05-30 14:39:17 +03:00
|
|
|
|
2021-11-08 02:51:39 +03:00
|
|
|
virtual ErrorOr<void> truncate(u64) override;
|
|
|
|
virtual ErrorOr<void> sync() override;
|
2022-08-21 17:15:29 +03:00
|
|
|
virtual ErrorOr<void> chown(Credentials const&, OpenFileDescription&, UserID, GroupID) override;
|
|
|
|
virtual ErrorOr<void> chmod(Credentials const&, OpenFileDescription&, mode_t) override;
|
2019-05-30 14:39:17 +03:00
|
|
|
|
2021-10-03 01:24:00 +03:00
|
|
|
virtual StringView class_name() const override { return "InodeFile"sv; }
|
2019-05-30 14:39:17 +03:00
|
|
|
|
|
|
|
virtual bool is_seekable() const override { return true; }
|
|
|
|
virtual bool is_inode() const override { return true; }
|
|
|
|
|
|
|
|
private:
|
2022-11-28 01:50:28 +03:00
|
|
|
virtual bool is_regular_file() const override;
|
|
|
|
|
2022-08-19 21:53:40 +03:00
|
|
|
explicit InodeFile(NonnullLockRefPtr<Inode>&&);
|
|
|
|
NonnullLockRefPtr<Inode> m_inode;
|
2019-05-30 14:39:17 +03:00
|
|
|
};
|
2020-02-16 03:27:42 +03:00
|
|
|
|
|
|
|
}
|