Kernel/LibC: Add syscall and wrapper for unlink
This commit is contained in:
parent
b7007016c0
commit
87ff38664a
|
@ -98,6 +98,7 @@ namespace Kernel
|
||||||
BAN::ErrorOr<long> sys_write(int fd, const void* buffer, size_t count);
|
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(const char*, mode_t);
|
||||||
BAN::ErrorOr<long> sys_create_dir(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);
|
BAN::ErrorOr<long> sys_chmod(const char*, mode_t);
|
||||||
|
|
||||||
|
|
|
@ -634,7 +634,7 @@ namespace Kernel
|
||||||
auto directory = absolute_path.sv().substring(0, index);
|
auto directory = absolute_path.sv().substring(0, index);
|
||||||
auto file_name = absolute_path.sv().substring(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())
|
if (Inode::Mode(mode).ifdir())
|
||||||
TRY(parent_inode->create_directory(file_name, mode, m_credentials.euid(), m_credentials.egid()));
|
TRY(parent_inode->create_directory(file_name, mode, m_credentials.euid(), m_credentials.egid()));
|
||||||
|
@ -762,6 +762,26 @@ namespace Kernel
|
||||||
return 0;
|
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)
|
BAN::ErrorOr<long> Process::sys_chmod(const char* path, mode_t mode)
|
||||||
{
|
{
|
||||||
if (mode & S_IFMASK)
|
if (mode & S_IFMASK)
|
||||||
|
|
|
@ -208,6 +208,9 @@ namespace Kernel
|
||||||
case SYS_CREATE_DIR:
|
case SYS_CREATE_DIR:
|
||||||
ret = Process::current().sys_create_dir((const char*)arg1, (mode_t)arg2);
|
ret = Process::current().sys_create_dir((const char*)arg1, (mode_t)arg2);
|
||||||
break;
|
break;
|
||||||
|
case SYS_UNLINK:
|
||||||
|
ret = Process::current().sys_unlink((const char*)arg1);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
dwarnln("Unknown syscall {}", syscall);
|
dwarnln("Unknown syscall {}", syscall);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -58,6 +58,7 @@ __BEGIN_DECLS
|
||||||
#define SYS_CHMOD 55
|
#define SYS_CHMOD 55
|
||||||
#define SYS_CREATE 56 // creat, mkfifo
|
#define SYS_CREATE 56 // creat, mkfifo
|
||||||
#define SYS_CREATE_DIR 57 // mkdir
|
#define SYS_CREATE_DIR 57 // mkdir
|
||||||
|
#define SYS_UNLINK 58
|
||||||
|
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -210,6 +210,11 @@ void syncsync(int should_block)
|
||||||
syscall(SYS_SYNC, should_block);
|
syscall(SYS_SYNC, should_block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int unlink(const char* path)
|
||||||
|
{
|
||||||
|
return syscall(SYS_UNLINK, path);
|
||||||
|
}
|
||||||
|
|
||||||
pid_t getpid(void)
|
pid_t getpid(void)
|
||||||
{
|
{
|
||||||
return syscall(SYS_GET_PID);
|
return syscall(SYS_GET_PID);
|
||||||
|
|
Loading…
Reference in New Issue