]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
feat: pivot_root — syscall for swapping root filesystem
authorTulio A M Mendes <[email protected]>
Sun, 15 Feb 2026 08:18:03 +0000 (05:18 -0300)
committerTulio A M Mendes <[email protected]>
Sun, 15 Feb 2026 08:18:03 +0000 (05:18 -0300)
include/syscall.h
src/kernel/syscall.c

index 3fc293c87fbe2ebfc07974114c1f130f2293effe..547b199f072882c9c90b8066b8e06a4819066f78 100644 (file)
@@ -155,6 +155,8 @@ enum {
 
     SYSCALL_SENDMSG  = 118,
     SYSCALL_RECVMSG  = 119,
+
+    SYSCALL_PIVOT_ROOT = 120,
 };
 
 #endif
index da7ca31e15f2fb70cfaee380b4032c2552bff157..fedaa4e6b6f597df399a1d3bcfeba3734ec82278 100644 (file)
@@ -4503,6 +4503,34 @@ static void socket_syscall_dispatch(struct registers* regs, uint32_t syscall_no)
         return;
     }
 
+    if (syscall_no == SYSCALL_PIVOT_ROOT) {
+        if (!current_process || current_process->euid != 0) {
+            sc_ret(regs) = (uint32_t)-EPERM;
+            return;
+        }
+        const char* user_new = (const char*)sc_arg0(regs);
+        const char* user_put = (const char*)sc_arg1(regs);
+        char knew[128], kput[128];
+        if (path_resolve_user(user_new, knew, sizeof(knew)) < 0 ||
+            path_resolve_user(user_put, kput, sizeof(kput)) < 0) {
+            sc_ret(regs) = (uint32_t)-EFAULT;
+            return;
+        }
+        fs_node_t* new_root = vfs_lookup(knew);
+        if (!new_root || !(new_root->flags & FS_DIRECTORY)) {
+            sc_ret(regs) = (uint32_t)-EINVAL;
+            return;
+        }
+        fs_node_t* old_root = fs_root;
+        fs_root = new_root;
+        (void)vfs_mount("/", new_root);
+        if (old_root) {
+            (void)vfs_mount(kput, old_root);
+        }
+        sc_ret(regs) = 0;
+        return;
+    }
+
     sc_ret(regs) = (uint32_t)-ENOSYS;
 }