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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/FileSystem/Inode.h>
#include <Kernel/FileSystem/InodeFile.h>
#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/Process.h>
InodeFile::InodeFile(NonnullRefPtr<Inode>&& inode)
: m_inode(move(inode))
{
}
InodeFile::~InodeFile()
{
}
ssize_t InodeFile::read(FileDescription& description, u8* buffer, ssize_t count)
{
ssize_t nread = m_inode->read_bytes(description.offset(), count, buffer, &description);
if (nread > 0)
current->did_file_read(nread);
return nread;
}
ssize_t InodeFile::write(FileDescription& description, const u8* data, ssize_t count)
{
ssize_t nwritten = m_inode->write_bytes(description.offset(), count, data, &description);
if (nwritten > 0) {
m_inode->set_mtime(kgettimeofday().tv_sec);
current->did_file_write(nwritten);
}
return nwritten;
}
KResultOr<Region*> InodeFile::mmap(Process& process, FileDescription& description, VirtualAddress preferred_vaddr, 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.
auto* region = process.allocate_file_backed_region(preferred_vaddr, size, inode(), description.absolute_path(), prot);
if (!region)
return KResult(-ENOMEM);
return region;
}
String InodeFile::absolute_path(const FileDescription& description) const
{
ASSERT_NOT_REACHED();
ASSERT(description.custody());
return description.absolute_path();
}
KResult InodeFile::truncate(off_t size)
{
return m_inode->truncate(size);
}
KResult InodeFile::chown(uid_t uid, gid_t gid)
{
return VFS::the().chown(*m_inode, uid, gid);
}
KResult InodeFile::chmod(mode_t mode)
{
return VFS::the().chmod(*m_inode, mode);
}
|