ladybird/Kernel/FileSystem/InodeFile.h
Andreas Kling b91c49364d AK: Rename adopt() to adopt_ref()
This makes it more symmetrical with adopt_own() (which is used to
create a NonnullOwnPtr from the result of a naked new.)
2021-04-23 16:46:57 +02:00

52 lines
1.6 KiB
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <Kernel/FileSystem/File.h>
namespace Kernel {
class Inode;
class InodeFile final : public File {
public:
static NonnullRefPtr<InodeFile> create(NonnullRefPtr<Inode>&& inode)
{
return adopt_ref(*new InodeFile(move(inode)));
}
virtual ~InodeFile() override;
const Inode& inode() const { return *m_inode; }
Inode& inode() { return *m_inode; }
virtual bool can_read(const FileDescription&, size_t) const override { return true; }
virtual bool can_write(const FileDescription&, size_t) const override { return true; }
virtual KResultOr<size_t> read(FileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual KResultOr<size_t> write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
virtual int ioctl(FileDescription&, unsigned request, FlatPtr arg) override;
virtual KResultOr<Region*> mmap(Process&, FileDescription&, const Range&, u64 offset, int prot, bool shared) override;
virtual String absolute_path(const FileDescription&) const override;
virtual KResult truncate(u64) override;
virtual KResult chown(FileDescription&, uid_t, gid_t) override;
virtual KResult chmod(FileDescription&, mode_t) override;
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:
explicit InodeFile(NonnullRefPtr<Inode>&&);
NonnullRefPtr<Inode> m_inode;
};
}