forked from Bananymous/banan-os
Kernel/LibC: implement chmod syscall + libc wrapper
This commit is contained in:
@@ -242,6 +242,16 @@ namespace Kernel
|
||||
return {};
|
||||
}
|
||||
|
||||
BAN::ErrorOr<void> Ext2Inode::chmod_impl(mode_t mode)
|
||||
{
|
||||
ASSERT((mode & Inode::Mode::TYPE_MASK) == 0);
|
||||
if (m_inode.mode == mode)
|
||||
return {};
|
||||
m_inode.mode = (m_inode.mode & Inode::Mode::TYPE_MASK) | mode;
|
||||
TRY(sync());
|
||||
return {};
|
||||
}
|
||||
|
||||
BAN::ErrorOr<void> Ext2Inode::list_next_inodes_impl(off_t offset, DirectoryEntryList* list, size_t list_size)
|
||||
{
|
||||
ASSERT(mode().ifdir());
|
||||
|
||||
@@ -129,6 +129,14 @@ namespace Kernel
|
||||
return truncate_impl(size);
|
||||
}
|
||||
|
||||
BAN::ErrorOr<void> Inode::chmod(mode_t mode)
|
||||
{
|
||||
ASSERT((mode & Inode::Mode::TYPE_MASK) == 0);
|
||||
LockGuard _(m_lock);
|
||||
Thread::TerminateBlocker blocker(Thread::current());
|
||||
return chmod_impl(mode);
|
||||
}
|
||||
|
||||
bool Inode::has_data() const
|
||||
{
|
||||
LockGuard _(m_lock);
|
||||
|
||||
@@ -26,6 +26,14 @@ namespace Kernel
|
||||
this->rdev = 0;
|
||||
}
|
||||
|
||||
|
||||
BAN::ErrorOr<void> RamInode::chmod_impl(mode_t mode)
|
||||
{
|
||||
ASSERT((mode & Inode::Mode::TYPE_MASK) == 0);
|
||||
m_inode_info.mode = (m_inode_info.mode & Inode::Mode::TYPE_MASK) | mode;
|
||||
return {};
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
RAM FILE INODE
|
||||
@@ -193,9 +201,9 @@ namespace Kernel
|
||||
{
|
||||
BAN::RefPtr<RamInode> inode;
|
||||
if (Mode(mode).ifreg())
|
||||
inode = TRY(RamFileInode::create(m_fs, mode, uid, gid));
|
||||
inode = TRY(RamFileInode::create(m_fs, mode & ~Inode::Mode::TYPE_MASK, uid, gid));
|
||||
else if (Mode(mode).ifdir())
|
||||
inode = TRY(RamDirectoryInode::create(m_fs, ino(), mode, uid, gid));
|
||||
inode = TRY(RamDirectoryInode::create(m_fs, ino(), mode & ~Inode::Mode::TYPE_MASK, uid, gid));
|
||||
else
|
||||
ASSERT_NOT_REACHED();
|
||||
|
||||
|
||||
@@ -733,6 +733,21 @@ namespace Kernel
|
||||
return TRY(m_open_file_descriptors.write(fd, BAN::ByteSpan((uint8_t*)buffer, count)));
|
||||
}
|
||||
|
||||
BAN::ErrorOr<long> Process::sys_chmod(const char* path, mode_t mode)
|
||||
{
|
||||
if (mode & S_IFMASK)
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
|
||||
LockGuard _(m_lock);
|
||||
validate_string_access(path);
|
||||
|
||||
auto absolute_path = TRY(absolute_path_of(path));
|
||||
auto file = TRY(VirtualFileSystem::get().file_from_absolute_path(m_credentials, absolute_path, O_WRONLY));
|
||||
TRY(file.inode->chmod(mode));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BAN::ErrorOr<long> Process::sys_pipe(int fildes[2])
|
||||
{
|
||||
LockGuard _(m_lock);
|
||||
|
||||
@@ -199,6 +199,9 @@ namespace Kernel
|
||||
case SYS_POWEROFF:
|
||||
ret = Process::current().sys_poweroff((int)arg1);
|
||||
break;
|
||||
case SYS_CHMOD:
|
||||
ret = Process::current().sys_chmod((const char*)arg1, (mode_t)arg2);
|
||||
break;
|
||||
default:
|
||||
dwarnln("Unknown syscall {}", syscall);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user