mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
ae197deb6b
Prior to this change, both uid_t and gid_t were typedef'ed to `u32`. This made it easy to use them interchangeably. Let's not allow that. This patch adds UserID and GroupID using the AK::DistinctNumeric mechanism we've already been employing for pid_t/ProcessID.
55 lines
1.9 KiB
C++
55 lines
1.9 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 KResultOr<NonnullRefPtr<InodeFile>> create(NonnullRefPtr<Inode>&& inode)
|
|
{
|
|
auto file = adopt_ref_if_nonnull(new (nothrow) InodeFile(move(inode)));
|
|
if (!file)
|
|
return ENOMEM;
|
|
return file.release_nonnull();
|
|
}
|
|
|
|
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 KResult ioctl(FileDescription&, unsigned request, Userspace<void*> arg) override;
|
|
virtual KResultOr<Memory::Region*> mmap(Process&, FileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override;
|
|
virtual KResult stat(::stat& buffer) const override { return inode().metadata().stat(buffer); }
|
|
|
|
virtual String absolute_path(const FileDescription&) const override;
|
|
|
|
virtual KResult truncate(u64) override;
|
|
virtual KResult chown(FileDescription&, UserID, GroupID) override;
|
|
virtual KResult chmod(FileDescription&, mode_t) override;
|
|
|
|
virtual StringView 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;
|
|
};
|
|
|
|
}
|