2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
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:
|
2021-05-11 03:54:44 -07:00
|
|
|
static KResultOr<NonnullRefPtr<InodeFile>> create(NonnullRefPtr<Inode>&& inode)
|
2019-05-30 13:39:17 +02:00
|
|
|
{
|
2021-06-20 10:21:16 +02:00
|
|
|
auto file = adopt_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;
|
|
|
|
|
|
|
|
const Inode& inode() const { return *m_inode; }
|
|
|
|
Inode& inode() { return *m_inode; }
|
|
|
|
|
2020-04-10 19:44:42 +10:00
|
|
|
virtual bool can_read(const FileDescription&, size_t) const override { return true; }
|
|
|
|
virtual bool can_write(const FileDescription&, size_t) const override { return true; }
|
2019-05-30 13:39:17 +02:00
|
|
|
|
2021-03-17 13:18:51 +01:00
|
|
|
virtual KResultOr<size_t> read(FileDescription&, u64, UserOrKernelBuffer&, size_t) override;
|
|
|
|
virtual KResultOr<size_t> write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
|
2021-07-26 03:47:25 -07:00
|
|
|
virtual KResult ioctl(FileDescription&, unsigned request, Userspace<void*> arg) override;
|
2021-08-06 13:54:48 +02:00
|
|
|
virtual KResultOr<Memory::Region*> mmap(Process&, FileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override;
|
2021-06-07 09:47:21 +02:00
|
|
|
virtual KResult stat(::stat& buffer) const override { return inode().metadata().stat(buffer); }
|
2019-05-30 13:39:17 +02:00
|
|
|
|
2019-06-07 09:36:51 +02:00
|
|
|
virtual String absolute_path(const FileDescription&) const override;
|
2019-05-30 13:39:17 +02:00
|
|
|
|
2020-02-08 12:07:04 +01:00
|
|
|
virtual KResult truncate(u64) override;
|
2020-05-28 17:32:20 +03:00
|
|
|
virtual KResult chown(FileDescription&, uid_t, gid_t) override;
|
|
|
|
virtual KResult chmod(FileDescription&, mode_t) override;
|
2019-05-30 13:39:17 +02:00
|
|
|
|
2021-07-11 01:46:09 +02:00
|
|
|
virtual StringView class_name() const override { return "InodeFile"; }
|
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:
|
2019-06-21 18:37:47 +02:00
|
|
|
explicit InodeFile(NonnullRefPtr<Inode>&&);
|
|
|
|
NonnullRefPtr<Inode> m_inode;
|
2019-05-30 13:39:17 +02:00
|
|
|
};
|
2020-02-16 01:27:42 +01:00
|
|
|
|
|
|
|
}
|