1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 07:04:58 +00:00

Kernel+Userland: Implement fchmod() syscall and use it to improve /bin/cp.

/bin/cp will now copy the permission bits from source to destination. :^)
This commit is contained in:
Andreas Kling 2019-03-01 10:39:19 +01:00
parent b5e5f26a82
commit 1b16a29044
10 changed files with 54 additions and 14 deletions

View file

@ -290,24 +290,26 @@ KResult VFS::access(const String& path, int mode, Inode& base)
return KSuccess;
}
KResult VFS::chmod(Inode& inode, mode_t mode)
{
if (inode.fs().is_readonly())
return KResult(-EROFS);
if (current->euid() != inode.metadata().uid && !current->is_superuser())
return KResult(-EPERM);
// Only change the permission bits.
mode = (inode.mode() & ~04777u) | (mode & 04777u);
return inode.chmod(mode);
}
KResult VFS::chmod(const String& path, mode_t mode, Inode& base)
{
auto inode_or_error = resolve_path_to_inode(path, base);
if (inode_or_error.is_error())
return inode_or_error.error();
auto inode = inode_or_error.value();
if (inode->fs().is_readonly())
return KResult(-EROFS);
if (current->euid() != inode->metadata().uid && !current->is_superuser())
return KResult(-EPERM);
// Only change the permission bits.
mode = (inode->mode() & ~04777) | (mode & 04777);
kprintf("VFS::chmod(): %u:%u mode %o\n", inode->fsid(), inode->index(), mode);
return inode->chmod(mode);
return chmod(*inode, mode);
}
KResult VFS::chown(const String& path, uid_t a_uid, gid_t a_gid, Inode& base)