summaryrefslogtreecommitdiff
path: root/src/kernel/syscalls.c
diff options
context:
space:
mode:
authordzwdz2024-08-18 23:06:26 +0200
committerdzwdz2024-08-18 23:06:26 +0200
commit8b4a2d50de67b746bcc472bd46c55d83eff668fc (patch)
tree21bcf9814b07bc54e7705f4e9ae93528d627e838 /src/kernel/syscalls.c
parent446acde84c7f244792bf412996678254ee296356 (diff)
kernel: basic _sys_setxattr implementationHEADmain
Diffstat (limited to 'src/kernel/syscalls.c')
-rw-r--r--src/kernel/syscalls.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index 436000c..50ff589 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -548,6 +548,41 @@ ssize_t _sys_getxattr(hid_t hid, const char __user *name, void __user *buf, size
return 0;
}
+ssize_t _sys_setxattr(hid_t hid, const char __user *name, const void __user *buf, size_t len, int flags) {
+ Handle *h = hs_get(proc_cur->hs, hid);
+ if (!h) {
+ SYSCALL_RETURN(-EBADF);
+ }
+ if (h->type != HANDLE_FILE || flags != 0) {
+ SYSCALL_RETURN(-ENOSYS);
+ }
+ if (!h->writeable) {
+ SYSCALL_RETURN(-EACCES);
+ }
+ char tmpbuf[XATTRNAME_MAX];
+ size_t namelen = pcpy_from_str(proc_cur, tmpbuf, name, XATTRNAME_MAX);
+ if (namelen == 0) {
+ SYSCALL_RETURN(-EFAULT);
+ }
+ assert(namelen <= XATTRNAME_MAX);
+ assert(tmpbuf[namelen-1] == '\0');
+
+ char *namebuf = kmalloc(namelen, TagXattrName);
+ memcpy(namebuf, tmpbuf, namelen);
+
+ vfsreq_dispatchcopy((VfsReq) {
+ .type = VFSOP_SETXATTR,
+ .backend = h->backend,
+ .id = h->file_id,
+ .caller = proc_cur,
+ .kin = namebuf,
+ .kinlen = namelen-1,
+ .uin = buf,
+ .uinlen = len,
+ });
+ return 0;
+}
+
long _sys_execbuf(void __user *ubuf, size_t len) {
if (len == 0) SYSCALL_RETURN(0);
static_assert(EXECBUF_MAX_LEN <= KMALLOC_MAX);
@@ -607,6 +642,7 @@ long _syscall(long num, long a, long b, long c, long d, long e) {
break; case _SYS_DUPLEX: _sys_duplex(a, b, c);
break; case _SYS_INTR_RETURN: _sys_intr_return((userptr_t)a, b);
break; case _SYS_GETXATTR: _sys_getxattr(a, (userptr_t)b, (userptr_t)c, d, e);
+ break; case _SYS_SETXATTR: _sys_setxattr(a, (userptr_t)b, (userptr_t)c, d, e);
break; case _SYS_EXECBUF: _sys_execbuf((userptr_t)a, b);
break; case _SYS_DEBUG_KLOG: _sys_debug_klog((userptr_t)a, b);
break;