summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem/InodeFile.cpp
blob: f30fb655f1fc29fadba058aea5b581a64127ed1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <Kernel/FileSystem/InodeFile.h>
#include <Kernel/FileSystem/Inode.h>
#include <Kernel/FileSystem/FileDescriptor.h>
#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/Process.h>

InodeFile::InodeFile(Retained<Inode>&& inode)
    : m_inode(move(inode))
{
}

InodeFile::~InodeFile()
{
}

ssize_t InodeFile::read(FileDescriptor& descriptor, byte* buffer, ssize_t count)
{
    return m_inode->read_bytes(descriptor.offset(), count, buffer, &descriptor);
}

ssize_t InodeFile::write(FileDescriptor& descriptor, const byte* data, ssize_t count)
{
    return m_inode->write_bytes(descriptor.offset(), count, data, &descriptor);
}

KResultOr<Region*> InodeFile::mmap(Process& process, FileDescriptor& descriptor, LinearAddress preferred_laddr, size_t offset, size_t size, int prot)
{
    ASSERT(offset == 0);
    // FIXME: If PROT_EXEC, check that the underlying file system isn't mounted noexec.
    InterruptDisabler disabler;
    auto* region = process.allocate_file_backed_region(preferred_laddr, size, inode(), descriptor.absolute_path(), prot);
    if (!region)
        return KResult(-ENOMEM);
    return region;
}

String InodeFile::absolute_path(const FileDescriptor& descriptor) const
{
    ASSERT_NOT_REACHED();
    ASSERT(descriptor.custody());
    return descriptor.absolute_path();
}

KResult InodeFile::truncate(off_t size)
{
    return m_inode->truncate(size);
}