mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:37:34 +00:00
Implement sys$chdir() and teach sh+ls to cd around and browse different dirs.
This commit is contained in:
parent
ac738b03d6
commit
2749e7f1c2
16 changed files with 147 additions and 33 deletions
|
@ -110,6 +110,8 @@ DWORD handle(DWORD function, DWORD arg1, DWORD arg2, DWORD arg3)
|
|||
return 0;
|
||||
case Syscall::GetArguments:
|
||||
return current->sys$get_arguments((int*)arg1, (char***)arg2);
|
||||
case Syscall::PosixChdir:
|
||||
return current->sys$chdir((const char*)arg1);
|
||||
default:
|
||||
kprintf("int0x80: Unknown function %x requested {%x, %x, %x}\n", function, arg1, arg2, arg3);
|
||||
break;
|
||||
|
|
|
@ -32,6 +32,7 @@ enum Function {
|
|||
PosixGettimeofday = 0x2000,
|
||||
PosixGethostname = 0x2001,
|
||||
GetArguments = 0x2002,
|
||||
PosixChdir = 0x2003,
|
||||
};
|
||||
|
||||
void initialize();
|
||||
|
|
|
@ -205,7 +205,14 @@ Task* Task::createUserTask(const String& path, uid_t uid, gid_t gid, pid_t paren
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
auto handle = VirtualFileSystem::the().open(path);
|
||||
RetainPtr<VirtualFileSystem::Node> cwd;
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
if (auto* parentTask = Task::fromPID(parentPID))
|
||||
cwd = parentTask->m_cwd.copyRef();
|
||||
}
|
||||
|
||||
auto handle = VirtualFileSystem::the().open(path, cwd.ptr());
|
||||
if (!handle) {
|
||||
error = -ENOENT; // FIXME: Get a more detailed error from VFS.
|
||||
return nullptr;
|
||||
|
@ -327,9 +334,9 @@ Task::Task(String&& name, uid_t uid, gid_t gid, pid_t parentPID, RingLevel ring)
|
|||
|
||||
auto* parentTask = Task::fromPID(parentPID);
|
||||
if (parentTask)
|
||||
m_cwd = parentTask->m_cwd;
|
||||
m_cwd = parentTask->m_cwd.copyRef();
|
||||
else
|
||||
m_cwd = "/";
|
||||
m_cwd = nullptr;
|
||||
|
||||
m_nextRegion = LinearAddress(0x600000);
|
||||
|
||||
|
@ -712,22 +719,29 @@ int Task::sys$close(int fd)
|
|||
|
||||
int Task::sys$lstat(const char* path, void* statbuf)
|
||||
{
|
||||
auto handle = VirtualFileSystem::the().open(move(path));
|
||||
auto handle = VirtualFileSystem::the().open(move(path), m_cwd.ptr());
|
||||
if (!handle)
|
||||
return -1;
|
||||
handle->stat((Unix::stat*)statbuf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Task::sys$chdir(const char* path)
|
||||
{
|
||||
auto handle = VirtualFileSystem::the().open(path, m_cwd.ptr());
|
||||
if (!handle)
|
||||
return -ENOENT; // FIXME: More detailed error.
|
||||
if (!handle->isDirectory())
|
||||
return -ENOTDIR;
|
||||
m_cwd = handle->vnode();
|
||||
kprintf("m_cwd <- %p (%u)\n", m_cwd.ptr(), handle->vnode()->inode.index());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Task::sys$getcwd(char* buffer, size_t size)
|
||||
{
|
||||
if (size < m_cwd.length() + 1) {
|
||||
// FIXME: return -ERANGE;
|
||||
return -1;
|
||||
}
|
||||
memcpy(buffer, m_cwd.characters(), m_cwd.length());
|
||||
buffer[m_cwd.length()] = '\0';
|
||||
return 0;
|
||||
// FIXME: Implement!
|
||||
return -ENOTIMPL;
|
||||
}
|
||||
|
||||
int Task::sys$open(const char* path, size_t pathLength)
|
||||
|
@ -744,7 +758,7 @@ int Task::sys$open(const char* path, size_t pathLength)
|
|||
|
||||
FileHandle* Task::openFile(String&& path)
|
||||
{
|
||||
auto handle = VirtualFileSystem::the().open(move(path));
|
||||
auto handle = VirtualFileSystem::the().open(move(path), m_cwd.ptr());
|
||||
if (!handle) {
|
||||
#ifdef DEBUG_IO
|
||||
kprintf("vfs::open() failed\n");
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "TSS.h"
|
||||
#include <AK/Vector.h>
|
||||
#include "i386.h"
|
||||
#include <VirtualFileSystem/VirtualFileSystem.h>
|
||||
|
||||
//#define TASK_SANITY_CHECKS
|
||||
|
||||
|
@ -98,6 +99,7 @@ public:
|
|||
int sys$munmap(void*, size_t size);
|
||||
int sys$get_dir_entries(int fd, void*, size_t);
|
||||
int sys$getcwd(char*, size_t);
|
||||
int sys$chdir(const char*);
|
||||
int sys$sleep(unsigned seconds);
|
||||
int sys$gettimeofday(timeval*);
|
||||
int sys$gethostname(char* name, size_t length);
|
||||
|
@ -150,7 +152,7 @@ private:
|
|||
pid_t m_waitee { -1 };
|
||||
int m_fdBlockedOnRead { -1 };
|
||||
|
||||
String m_cwd;
|
||||
RetainPtr<VirtualFileSystem::Node> m_cwd;
|
||||
|
||||
struct Region {
|
||||
Region(LinearAddress, size_t, RetainPtr<Zone>&&, String&&);
|
||||
|
|
Binary file not shown.
|
@ -37,3 +37,5 @@
|
|||
#define ENAMETOOLONG 36 // Name too long
|
||||
|
||||
#define EOVERFLOW 75 // Value too large for defined data type
|
||||
|
||||
#define ENOTIMPL 999 // Not implemented
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue