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