]> 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 9f6aae023cd729c0c29dce149b78e5ae7598754b..cae934454ff754caae02eb5d12d55a9e614bed6c 100644 (file)
@@ -146,6 +146,8 @@ enum {
 
     SYSCALL_SENDMSG  = 118,
     SYSCALL_RECVMSG  = 119,
+
+    SYSCALL_PIVOT_ROOT = 120,
 };
 
 #endif
index 0e03f025930c189ec23057449b4751484c6beca8..896e68fe2d5bdc46545d907d297c973b1941f560 100644 (file)
@@ -4494,6 +4494,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;
 }