Kernel/LibC: Add syscall and wrapper for unlink
This commit is contained in:
@@ -98,6 +98,7 @@ namespace Kernel
|
||||
BAN::ErrorOr<long> sys_write(int fd, const void* buffer, size_t count);
|
||||
BAN::ErrorOr<long> sys_create(const char*, mode_t);
|
||||
BAN::ErrorOr<long> sys_create_dir(const char*, mode_t);
|
||||
BAN::ErrorOr<long> sys_unlink(const char*);
|
||||
|
||||
BAN::ErrorOr<long> sys_chmod(const char*, mode_t);
|
||||
|
||||
|
||||
@@ -634,7 +634,7 @@ namespace Kernel
|
||||
auto directory = absolute_path.sv().substring(0, index);
|
||||
auto file_name = absolute_path.sv().substring(index);
|
||||
|
||||
auto parent_inode = TRY(VirtualFileSystem::get().file_from_absolute_path(m_credentials, directory, O_WRONLY)).inode;
|
||||
auto parent_inode = TRY(VirtualFileSystem::get().file_from_absolute_path(m_credentials, directory, O_EXEC | O_WRONLY)).inode;
|
||||
|
||||
if (Inode::Mode(mode).ifdir())
|
||||
TRY(parent_inode->create_directory(file_name, mode, m_credentials.euid(), m_credentials.egid()));
|
||||
@@ -762,6 +762,26 @@ namespace Kernel
|
||||
return 0;
|
||||
}
|
||||
|
||||
BAN::ErrorOr<long> Process::sys_unlink(const char* path)
|
||||
{
|
||||
LockGuard _(m_lock);
|
||||
validate_string_access(path);
|
||||
|
||||
auto absolute_path = TRY(absolute_path_of(path));
|
||||
|
||||
size_t index = absolute_path.size();
|
||||
for (; index > 0; index--)
|
||||
if (absolute_path[index - 1] == '/')
|
||||
break;
|
||||
auto directory = absolute_path.sv().substring(0, index);
|
||||
auto file_name = absolute_path.sv().substring(index);
|
||||
|
||||
auto parent = TRY(VirtualFileSystem::get().file_from_absolute_path(m_credentials, directory, O_EXEC | O_WRONLY)).inode;
|
||||
TRY(parent->unlink(file_name));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BAN::ErrorOr<long> Process::sys_chmod(const char* path, mode_t mode)
|
||||
{
|
||||
if (mode & S_IFMASK)
|
||||
|
||||
@@ -208,6 +208,9 @@ namespace Kernel
|
||||
case SYS_CREATE_DIR:
|
||||
ret = Process::current().sys_create_dir((const char*)arg1, (mode_t)arg2);
|
||||
break;
|
||||
case SYS_UNLINK:
|
||||
ret = Process::current().sys_unlink((const char*)arg1);
|
||||
break;
|
||||
default:
|
||||
dwarnln("Unknown syscall {}", syscall);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user