2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
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:
|
2021-05-11 13:54:44 +03:00
|
|
|
static KResultOr<NonnullRefPtr<InodeFile>> create(NonnullRefPtr<Inode>&& inode)
|
2019-05-30 14:39:17 +03:00
|
|
|
{
|
2021-05-11 13:54:44 +03:00
|
|
|
auto file = adopt_ref_if_nonnull(new InodeFile(move(inode)));
|
|
|
|
if (!file)
|
|
|
|
return ENOMEM;
|
|
|
|
return file.release_nonnull();
|
2019-05-30 14:39:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~InodeFile() override;
|
|
|
|
|
|
|
|
const Inode& inode() const { return *m_inode; }
|
|
|
|
Inode& inode() { return *m_inode; }
|
|
|
|
|
2020-04-10 12:44:42 +03: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 14:39:17 +03:00
|
|
|
|
2021-03-17 15:18:51 +03: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-01-30 23:12:49 +03:00
|
|
|
virtual int ioctl(FileDescription&, unsigned request, FlatPtr arg) override;
|
2021-03-19 00:57:25 +03:00
|
|
|
virtual KResultOr<Region*> mmap(Process&, FileDescription&, const Range&, u64 offset, int prot, bool shared) override;
|
2019-05-30 14:39:17 +03:00
|
|
|
|
2019-06-07 10:36:51 +03:00
|
|
|
virtual String absolute_path(const FileDescription&) const override;
|
2019-05-30 14:39:17 +03:00
|
|
|
|
2020-02-08 14:07:04 +03: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 14:39:17 +03:00
|
|
|
|
|
|
|
virtual const char* class_name() const override { return "InodeFile"; }
|
|
|
|
|
|
|
|
virtual bool is_seekable() const override { return true; }
|
|
|
|
virtual bool is_inode() const override { return true; }
|
|
|
|
|
|
|
|
private:
|
2019-06-21 19:37:47 +03:00
|
|
|
explicit InodeFile(NonnullRefPtr<Inode>&&);
|
|
|
|
NonnullRefPtr<Inode> m_inode;
|
2019-05-30 14:39:17 +03:00
|
|
|
};
|
2020-02-16 03:27:42 +03:00
|
|
|
|
|
|
|
}
|