summaryrefslogtreecommitdiff
path: root/Kernel/VirtualFileSystem.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-01-29 04:55:08 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-01-29 04:55:08 +0100
commitc30e2c8d440de7a8abbc1935cb5fb79b82d3421f (patch)
tree6ddae2118d2eec002f0327ff30d5a792828f3002 /Kernel/VirtualFileSystem.cpp
parentad53f6afd3de86fa927a2f8cdacdcbf5134af916 (diff)
downloadserenity-c30e2c8d440de7a8abbc1935cb5fb79b82d3421f.zip
Implement basic chmod() syscall and /bin/chmod helper.
Only raw octal modes are supported right now. This patch also changes mode_t from 32-bit to 16-bit to match the on-disk type used by Ext2FS. I also ran into EPERM being errno=0 which was confusing, so I inserted an ESUCCESS in its place.
Diffstat (limited to 'Kernel/VirtualFileSystem.cpp')
-rw-r--r--Kernel/VirtualFileSystem.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/Kernel/VirtualFileSystem.cpp b/Kernel/VirtualFileSystem.cpp
index 46f2ad99db..5b187f9232 100644
--- a/Kernel/VirtualFileSystem.cpp
+++ b/Kernel/VirtualFileSystem.cpp
@@ -228,6 +228,37 @@ bool VFS::mkdir(const String& path, mode_t mode, InodeIdentifier base, int& erro
return false;
}
+bool VFS::chmod(const String& path, mode_t mode, Inode& base, int& error)
+{
+ error = -EWHYTHO;
+ // FIXME: This won't work nicely across mount boundaries.
+ FileSystemPath p(path);
+ if (!p.is_valid()) {
+ error = -EINVAL;
+ return false;
+ }
+
+ InodeIdentifier parent_dir;
+ auto inode_id = resolve_path(path, base.identifier(), error, 0, &parent_dir);
+ if (!inode_id.is_valid()) {
+ error = -ENOENT;
+ return false;
+ }
+
+ auto inode = get_inode(inode_id);
+
+ // FIXME: Permission checks.
+
+ // Only change the permission bits.
+ mode = (inode->mode() & ~04777) | (mode & 04777);
+
+ kprintf("VFS::chmod(): %u:%u mode %o\n", inode_id.fsid(), inode_id.index(), mode);
+ if (!inode->chmod(mode, error))
+ return false;
+ error = 0;
+ return true;
+}
+
bool VFS::unlink(const String& path, Inode& base, int& error)
{
error = -EWHYTHO;