1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:17:35 +00:00

More work on CoreInode.

This commit is contained in:
Andreas Kling 2018-11-13 23:44:54 +01:00
parent 26852a8363
commit c735c56e4c
13 changed files with 342 additions and 172 deletions

View file

@ -134,15 +134,17 @@ ByteBuffer procfs$pid_regs(Process& process)
ByteBuffer procfs$pid_exe(Process& process)
{
ProcessInspectionHandle handle(process);
auto inode = process.executableInode();
return VirtualFileSystem::the().absolutePath(inode).toByteBuffer();
auto inode = process.executable_inode();
ASSERT(inode);
return VirtualFileSystem::the().absolute_path(*inode).toByteBuffer();
}
ByteBuffer procfs$pid_cwd(Process& process)
{
ProcessInspectionHandle handle(process);
auto inode = process.cwdInode();
return VirtualFileSystem::the().absolutePath(inode).toByteBuffer();
auto inode = process.cwd_inode();
ASSERT(inode);
return VirtualFileSystem::the().absolute_path(*inode).toByteBuffer();
}
void ProcFileSystem::addProcess(Process& process)
@ -150,15 +152,15 @@ void ProcFileSystem::addProcess(Process& process)
InterruptDisabler disabler;
char buf[16];
ksprintf(buf, "%d", process.pid());
auto dir = addFile(createDirectory(buf));
auto dir = addFile(create_directory(buf));
m_pid2inode.set(process.pid(), dir.index());
addFile(createGeneratedFile("vm", [&process] { return procfs$pid_vm(process); }), dir.index());
addFile(createGeneratedFile("stack", [&process] { return procfs$pid_stack(process); }), dir.index());
addFile(createGeneratedFile("regs", [&process] { return procfs$pid_regs(process); }), dir.index());
addFile(createGeneratedFile("fds", [&process] { return procfs$pid_fds(process); }), dir.index());
if (process.executableInode().isValid())
addFile(createGeneratedFile("exe", [&process] { return procfs$pid_exe(process); }, 00120777), dir.index());
addFile(createGeneratedFile("cwd", [&process] { return procfs$pid_cwd(process); }, 00120777), dir.index());
addFile(create_generated_file("vm", [&process] { return procfs$pid_vm(process); }), dir.index());
addFile(create_generated_file("stack", [&process] { return procfs$pid_stack(process); }), dir.index());
addFile(create_generated_file("regs", [&process] { return procfs$pid_regs(process); }), dir.index());
addFile(create_generated_file("fds", [&process] { return procfs$pid_fds(process); }), dir.index());
if (process.executable_inode())
addFile(create_generated_file("exe", [&process] { return procfs$pid_exe(process); }, 00120777), dir.index());
addFile(create_generated_file("cwd", [&process] { return procfs$pid_cwd(process); }, 00120777), dir.index());
}
void ProcFileSystem::removeProcess(Process& process)
@ -336,7 +338,9 @@ ByteBuffer procfs$vnodes()
// FIXME: Retain the vnode while inspecting it.
if (!vnode.inUse())
continue;
auto path = vfs.absolutePath(vnode.inode);
String path;
if (vnode.core_inode())
path = vfs.absolute_path(*vnode.core_inode());
if (path.isEmpty()) {
if (auto* dev = vnode.characterDevice()) {
if (dev->isTTY())
@ -353,13 +357,13 @@ ByteBuffer procfs$vnodes()
bool ProcFileSystem::initialize()
{
SyntheticFileSystem::initialize();
addFile(createGeneratedFile("mm", procfs$mm));
addFile(createGeneratedFile("regions", procfs$regions));
addFile(createGeneratedFile("mounts", procfs$mounts));
addFile(createGeneratedFile("kmalloc", procfs$kmalloc));
addFile(createGeneratedFile("summary", procfs$summary));
addFile(createGeneratedFile("cpuinfo", procfs$cpuinfo));
addFile(createGeneratedFile("vnodes", procfs$vnodes));
addFile(create_generated_file("mm", procfs$mm));
addFile(create_generated_file("regions", procfs$regions));
addFile(create_generated_file("mounts", procfs$mounts));
addFile(create_generated_file("kmalloc", procfs$kmalloc));
addFile(create_generated_file("summary", procfs$summary));
addFile(create_generated_file("cpuinfo", procfs$cpuinfo));
addFile(create_generated_file("vnodes", procfs$vnodes));
return true;
}

View file

@ -1124,7 +1124,7 @@ int Process::sys$lstat(const char* path, Unix::stat* statbuf)
{
VALIDATE_USER_WRITE(statbuf, sizeof(Unix::stat));
int error;
auto descriptor = VirtualFileSystem::the().open(move(path), error, O_NOFOLLOW_NOERROR, cwdInode());
auto descriptor = VirtualFileSystem::the().open(move(path), error, O_NOFOLLOW_NOERROR, cwd_inode()->identifier());
if (!descriptor)
return error;
descriptor->stat(statbuf);
@ -1135,7 +1135,7 @@ int Process::sys$stat(const char* path, Unix::stat* statbuf)
{
VALIDATE_USER_WRITE(statbuf, sizeof(Unix::stat));
int error;
auto descriptor = VirtualFileSystem::the().open(move(path), error, 0, cwdInode());
auto descriptor = VirtualFileSystem::the().open(move(path), error, 0, cwd_inode()->identifier());
if (!descriptor)
return error;
descriptor->stat(statbuf);
@ -1148,7 +1148,7 @@ int Process::sys$readlink(const char* path, char* buffer, size_t size)
VALIDATE_USER_WRITE(buffer, size);
int error;
auto descriptor = VirtualFileSystem::the().open(path, error, O_RDONLY | O_NOFOLLOW_NOERROR, cwdInode());
auto descriptor = VirtualFileSystem::the().open(path, error, O_RDONLY | O_NOFOLLOW_NOERROR, cwd_inode()->identifier());
if (!descriptor)
return error;
@ -1169,7 +1169,7 @@ int Process::sys$chdir(const char* path)
{
VALIDATE_USER_READ(path, strlen(path));
int error;
auto descriptor = VirtualFileSystem::the().open(path, error, 0, cwdInode());
auto descriptor = VirtualFileSystem::the().open(path, error, 0, cwd_inode()->identifier());
if (!descriptor)
return error;
if (!descriptor->isDirectory())
@ -1181,7 +1181,8 @@ int Process::sys$chdir(const char* path)
int Process::sys$getcwd(char* buffer, size_t size)
{
VALIDATE_USER_WRITE(buffer, size);
auto path = VirtualFileSystem::the().absolutePath(cwdInode());
ASSERT(cwd_inode());
auto path = VirtualFileSystem::the().absolute_path(*cwd_inode());
if (path.isNull())
return -EINVAL;
if (size < path.length() + 1)
@ -1209,7 +1210,7 @@ int Process::sys$open(const char* path, int options)
if (number_of_open_file_descriptors() >= m_max_open_file_descriptors)
return -EMFILE;
int error;
auto descriptor = VirtualFileSystem::the().open(path, error, options, cwdInode());
auto descriptor = VirtualFileSystem::the().open(path, error, options, cwd_inode()->identifier());
if (!descriptor)
return error;
if (options & O_DIRECTORY && !descriptor->isDirectory())

View file

@ -200,8 +200,8 @@ public:
bool validate_user_read(LinearAddress) const;
bool validate_user_write(LinearAddress) const;
InodeIdentifier cwdInode() const { return m_cwd ? m_cwd->inode : InodeIdentifier(); }
InodeIdentifier executableInode() const { return m_executable ? m_executable->inode : InodeIdentifier(); }
CoreInode* cwd_inode() { return m_cwd ? m_cwd->core_inode() : nullptr; }
CoreInode* executable_inode() { return m_executable ? m_executable->core_inode() : nullptr; }
size_t number_of_open_file_descriptors() const;
size_t max_open_file_descriptors() const { return m_max_open_file_descriptors; }